-
Notifications
You must be signed in to change notification settings - Fork 480
refactor(dot-page-layout): Enhance DotPageLayoutService #34229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ent and new saveLayout method - Replaced CoreWebService with HttpClient for improved HTTP handling. - Introduced a new saveLayout method to handle layout saving with variant support. - Updated EditEmaLayoutComponent to utilize signals for state management and improved lifecycle handling. - Adjusted debounce time for template updates to enhance user experience. This refactor improves modularity and performance while adhering to Angular best practices.
…geLayoutService - Eliminated the saveLayout method, which was previously responsible for saving page layouts. - Cleaned up the service by removing unnecessary imports and comments, enhancing code clarity and maintainability. This change streamlines the DotPageLayoutService, adhering to best practices for modularity and performance.
…o 34145-defect-layout-fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the DotPageLayoutService and EditEmaLayoutComponent to improve modularity and performance. Key changes include migrating from CoreWebService to Angular's native HttpClient, introducing signal-based state management, and enhancing lifecycle handling with DestroyRef and takeUntilDestroyed.
- Replaced
CoreWebServicewithHttpClientfor HTTP operations inDotPageLayoutService - Introduced signal-based state management (
$lastTemplate,$hasPendingSave) and improved lifecycle handling inEditEmaLayoutComponent - Changed debounce time from 5 seconds to 1 second and switched from
switchMaptoconcatMapfor sequential request processing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
core-web/libs/data-access/src/lib/dot-page-layout/dot-page-layout.service.ts |
Migrated from CoreWebService to HttpClient and added a new saveLayout method with variant support |
core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-layout/edit-ema-layout.component.ts |
Refactored to use signals for state management, improved lifecycle handling with DestroyRef, reduced debounce time, and switched to concatMap for sequential save operations |
Comments suppressed due to low confidence (4)
core-web/libs/data-access/src/lib/dot-page-layout/dot-page-layout.service.ts:62
- The saveLayout method is missing an explicit return type annotation. While TypeScript can infer it, explicit return types improve code clarity and prevent unintended return type changes. Add the return type Observable<{ layout: DotLayout }> to match the method's behavior.
core-web/libs/data-access/src/lib/dot-page-layout/dot-page-layout.service.ts:61 - The documentation comment is incorrect. The parameter type is DotTemplateDesigner (not DotLayout as stated), and the return type is not Observable. Update the JSDoc to accurately reflect that this method returns an Observable containing the layout object.
core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-layout/edit-ema-layout.component.ts:160 - The subscribe method in saveTemplate is using deprecated positional arguments for callbacks. Consider using the object notation with next, error, and complete properties for better readability and consistency with the rest of the codebase (as done in initSaveTemplateDebounce).
.subscribe(
() => this.handleSuccessSaveTemplate(),
(err: HttpErrorResponse) => this.handleErrorSaveTemplate(err),
() => this.dotRouterService.allowRouteDeactivation()
);
core-web/libs/data-access/src/lib/dot-page-layout/dot-page-layout.service.ts:75
- The saveLayout method is introduced but not used anywhere in the codebase. If this is intended for future use or as a public API, consider documenting the use case and differences from the save method. If it's not needed yet, consider removing it until there's a concrete use case to avoid maintaining unused code.
| const template = this.$lastTemplate(); | ||
| if (template) { | ||
| // Save immediately without debounce | ||
| // We don't use takeUntilDestroyed here because the component is already being destroyed | ||
| // and we want the HTTP request to complete | ||
| this.dotPageLayoutService | ||
| .save(this.uveStore.$layoutProps().pageId, { | ||
| ...template, | ||
| title: null | ||
| }) | ||
| .pipe(take(1)) | ||
| .subscribe({ | ||
| next: () => { | ||
| this.uveStore.reloadCurrentPage(); | ||
| }, | ||
| error: (err: HttpErrorResponse) => { | ||
| this.handleErrorSaveTemplate(err); | ||
| }, | ||
| complete: () => { | ||
| this.dotRouterService.allowRouteDeactivation(); | ||
| } | ||
| }); | ||
| } |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a redundant null check. Line 83 already checks if $lastTemplate() is truthy, so the nested check on line 84-85 is unnecessary. The template constant will always have a value within this block.
| const template = this.$lastTemplate(); | |
| if (template) { | |
| // Save immediately without debounce | |
| // We don't use takeUntilDestroyed here because the component is already being destroyed | |
| // and we want the HTTP request to complete | |
| this.dotPageLayoutService | |
| .save(this.uveStore.$layoutProps().pageId, { | |
| ...template, | |
| title: null | |
| }) | |
| .pipe(take(1)) | |
| .subscribe({ | |
| next: () => { | |
| this.uveStore.reloadCurrentPage(); | |
| }, | |
| error: (err: HttpErrorResponse) => { | |
| this.handleErrorSaveTemplate(err); | |
| }, | |
| complete: () => { | |
| this.dotRouterService.allowRouteDeactivation(); | |
| } | |
| }); | |
| } | |
| const template = this.$lastTemplate()!; | |
| // Save immediately without debounce | |
| // We don't use takeUntilDestroyed here because the component is already being destroyed | |
| // and we want the HTTP request to complete | |
| this.dotPageLayoutService | |
| .save(this.uveStore.$layoutProps().pageId, { | |
| ...template, | |
| title: null | |
| }) | |
| .pipe(take(1)) | |
| .subscribe({ | |
| next: () => { | |
| this.uveStore.reloadCurrentPage(); | |
| }, | |
| error: (err: HttpErrorResponse) => { | |
| this.handleErrorSaveTemplate(err); | |
| }, | |
| complete: () => { | |
| this.dotRouterService.allowRouteDeactivation(); | |
| } | |
| }); |
| * @memberof EditEmaLayoutComponent | ||
| */ | ||
| updateLastTemplate(template: Partial<DotTemplateDesigner>): void { | ||
| this.$lastTemplate.update((prev) => ({ ...prev, ...template })); |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updateLastTemplate method has a potential issue when $lastTemplate is null. The spread operator on line 133 will spread null, which could cause unexpected behavior. Consider initializing the signal with an empty object or adding a null check before the update.
| this.$lastTemplate.update((prev) => ({ ...prev, ...template })); | |
| this.$lastTemplate.update((prev) => ({ ...(prev ?? {}), ...template })); |
| import { UVEStore } from '../store/dot-uve.store'; | ||
|
|
||
| export const DEBOUNCE_TIME = 5000; | ||
| export const DEBOUNCE_TIME = 1000; |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reducing the debounce time from 5000ms to 1000ms will result in 5x more save requests to the backend during active editing. This could impact backend performance and increase network traffic. Consider whether this change is necessary, and if so, ensure the backend can handle the increased request frequency.
| export const DEBOUNCE_TIME = 1000; | |
| export const DEBOUNCE_TIME = 5000; |
Proposed Changes
This pull request refactors the page layout saving logic and improves the template auto-save mechanism in the
EditEmaLayoutComponent. The changes modernize the codebase by replacing legacy service dependencies, introduce signals for state management, and enhance reliability when saving templates—especially during component destruction or page navigation.Service Refactoring and API Improvements
CoreWebServicewith direct usage of Angular'sHttpClientinDotPageLayoutService, streamlining HTTP requests and removing unnecessary abstractions. Also added a newsaveLayoutmethod for saving layouts. [1] [2] [3]Template Auto-Save and State Management
EditEmaLayoutComponentto use Angular signals ($lastTemplate,$hasPendingSave) for tracking the latest template and pending save state, replacing the previous use of Subjects and class properties.concatMapfor sequential HTTP requests. The mechanism now accumulates changes and ensures pending saves are handled when the component is destroyed or the user navigates away. [1] [2] [3]Lifecycle and Reliability Enhancements
ngOnDestroyand page leave logic to ensure any unsaved template changes are immediately persisted, preventing data loss if the component is destroyed during a pending debounce. [1] [2]Code Quality and Documentation
Minor Improvements
Let me know if you want to dive deeper into any of these changes or see how the new signals and debounce logic work in practice!
Checklist
This PR related: #34145