-
Notifications
You must be signed in to change notification settings - Fork 34
dotCMS/core#21558 Edit Template Properties Modal makes changes get lost #1865
dotCMS/core#21558 Edit Template Properties Modal makes changes get lost #1865
Conversation
|
@@ -1,4 +1,4 @@ | |||
import { pluck, filter, take } from 'rxjs/operators'; | |||
import { pluck, filter, take, debounceTime, tap } from 'rxjs/operators'; |
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.
Are we using this here?
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.
No, I'll remove it.
...-templates/dot-template-create-edit/dot-template-advanced/dot-template-advanced.component.ts
Show resolved
Hide resolved
switchMap((template: DotTemplateItem) => { | ||
return this.didTemplateChangedBeforeSave(template); | ||
}), | ||
switchMap((template: DotTemplateItem) => { |
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.
Why double switchMap
?
return result; | ||
} | ||
|
||
private didTemplateChangedBeforeSave(template: DotTemplateItem): Observable<DotTemplateItem> { |
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.
Shouldn't this return a boolean
?
/** | ||
* When we save the properties, we do not want to save the body/layout. | ||
* Therefore, we keep the same body/layout of the working template | ||
*/ |
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.
Please use the Document This extension.
if (template.type === 'design') { | ||
result = { | ||
...template, | ||
layout: (currentTemplate as DotTemplateItemDesign).layout | ||
}; | ||
} else { | ||
result = { | ||
...template, | ||
body: (currentTemplate as DotTemplateItemadvanced).body | ||
}; | ||
} | ||
|
||
return result; |
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.
if (template.type === 'design') { | |
result = { | |
...template, | |
layout: (currentTemplate as DotTemplateItemDesign).layout | |
}; | |
} else { | |
result = { | |
...template, | |
body: (currentTemplate as DotTemplateItemadvanced).body | |
}; | |
} | |
return result; | |
if (template.type === 'design') { | |
return { | |
...template, | |
layout: (currentTemplate as DotTemplateItemDesign).layout | |
}; | |
} | |
return { | |
...template, | |
body: (currentTemplate as DotTemplateItemadvanced).body | |
}; |
this.store.didTemplateChanged$ | ||
.pipe(takeUntil(this.destroy$)) | ||
.subscribe(( didTemplateChanged ) => this.didTemplateChanged = didTemplateChanged); |
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.
async pipe.
@@ -22,9 +21,9 @@ import { Site, SiteService } from '@dotcms/dotcms-js'; | |||
}) | |||
export class DotTemplateCreateEditComponent implements OnInit, OnDestroy { | |||
vm$ = this.store.vm$; | |||
didTemplateChanged = false; |
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.
observable candidate + async pipe.
/** | ||
* Save changes on working template to store | ||
* | ||
* @memberof DotTemplateCreateEditComponent | ||
*/ |
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.
Use Document This.
[item]="vm.original" | ||
[didTemplateChanged]="didTemplateChanged" | ||
[item]="vm.working" | ||
(saveDraft)="saveDraft($event)" |
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.
Are you 100% sure that we need a second save event?
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 second save event is to update the working template state
with the latest changes. In fact, that event does not make a request to save the changes. I will change the name of the event to not make it confusing
this.updateTemplate.next(value); | ||
} | ||
|
||
onSaveTemplate(updatedPage: DotPageRender) { |
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.
doc
this.pageState = updatedPage; | ||
} | ||
|
||
onErrorSavingTemplate(err: ResponseView) { |
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.
doc
this.updateTemplate.next(value); | ||
} | ||
|
||
onSaveTemplate(updatedPage: DotPageRender) { |
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.
Docs.
this.pageState = updatedPage; | ||
} | ||
|
||
onErrorSavingTemplate(err: ResponseView) { |
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.
Docs.
...dotcms-ui/src/app/portlets/dot-edit-page/layout/dot-edit-layout/dot-edit-layout.component.ts
Show resolved
Hide resolved
} | ||
|
||
ngOnChanges(changes: SimpleChanges){ | ||
if( changes.didTemplateChanged ) { |
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.
Does your vscode is not running the formatter on save?
saveTemplate: jasmine.createSpy(), | ||
updateWorkingTemplate: jasmine.createSpy(), | ||
goToTemplateList: jasmine.createSpy(), |
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.
You are repeating this, maybe create a base object and extend?
* | ||
* @memberof DotTemplateCreateEditComponent | ||
*/ | ||
updateTemplate({ layout, body, themeId }: DotTemplate): void { |
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.
updateTemplate({ layout, body, themeId }: DotTemplate): void { | |
updateWorkingTemplate({ layout, body, themeId }: DotTemplate): void { |
...rc/app/portlets/dot-templates/dot-template-create-edit/dot-template-create-edit.component.ts
Show resolved
Hide resolved
}; | ||
|
||
// Design templates need to be save 10 seconds after the last change. | ||
this.store.saveTemplateDebounce(value); |
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.
Why don't do this inside the store? for example, in updateWorkingTemplate
since we know if is a design template there and they way we let all the logic in the store.
@Output() | ||
save: EventEmitter<Event> = new EventEmitter(); | ||
|
||
@Output() | ||
updateTemplate: EventEmitter<Event> = new EventEmitter(); |
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.
Event
?
@@ -50,9 +55,37 @@ export class DotEditLayoutComponent implements OnInit { | |||
this.templateContainersCacheService.set(mappedContainers); | |||
}); | |||
|
|||
this.updateTemplate |
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.
Add doc explaining why this approach and if you can the link where you found this solution.
@@ -82,6 +84,10 @@ const messageServiceMock = new MockDotMessageService({ | |||
'templates.edit': 'Edit' | |||
}); | |||
|
|||
interface templateStoreValueType { |
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.
interface templateStoreValueType { | |
interface TemplateStoreValueType { |
Types are camelcase
/** | ||
* The reason why we are using a Subject [updateTemplate] here is | ||
* because we can not just simply add a debounceTime to the HTTP Request | ||
* we need to reset the time everytime the observable is called. | ||
* | ||
* More Information Here: | ||
* - https://stackoverflow.com/questions/35991867/angular-2-using-observable-debounce-with-http-get | ||
* - https://blog.bitsrc.io/3-ways-to-debounce-http-requests-in-angular-c407eb165ada | ||
* | ||
* @memberof DotEditLayoutComponent | ||
*/ |
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.
This is not doc, the is is a comment inside the method. If we leave this here it will show up in the generated documentation.
* update release version for dotcms-ui & dotcms-webcomponents * CI: bumps version to 22.2.0-rc.2 [skip ci] * dotCMS/core#21504 Template designer: container selector breaks while there are "Unsave Changes" * CI: bumps version to 22.2.0-rc.2 [skip ci] * dotCMS/core#21436 Enable the bring back button (#1846) * CI: bumps version to 22.2.0-rc.3 [skip ci] * dotCMS/core#21540 Add a form from the Contentlet palette in edit page is not working * CI: bumps version to 22.2.0-rc.4 [skip ci] * dotCMS/core#21122 Replace What's changed with the htmldiff js library (#1855) * replace backend library * cleanup * tests * cleanup * error handler * CI: bumps version to 22.2.0-rc.5 [skip ci] * dotCMS/core#21600 Remove "Unsaved changes" from auto saving * dotCMS/core#21240 Show global message on inline editing (#1861) * dotCMS/core #21436 Prevent the redirect of the page when we are in edit mode * CI: bumps version to 22.2.0-rc.6 [skip ci] * dotCMS/core#21599 Push Publishing Workflow Dialog is missing timezoneId * CI: bumps version to 22.2.0-rc.7 [skip ci] * dotCMS/core#21552 Avoid trigger the original form submit event (#1862) * dotCMS/core#21552 Add forms from content palette error (#1868) * initial progress * cleanup * test updates * test updates * feedback * rename functions * CI: bumps version to 22.2.0-rc.8 [skip ci] * dotCMS/core#21656 Once a fileAsset is saved. the file itself can not be replaced using Save (#1872) * CI: bumps version to 22.2.0-rc.3 [skip ci] * dotCMS/core#21558 Edit Template Properties Modal makes changes get lost (#1865) * fix: Must supply a value for form control with name: 'title' * remove dot-template store service from Dot Template Advanced Component * fix: Edit Template Properties Modal makes changes get lost on advance template * fix: Edit Template Properties Modal makes changes get lost on design template * update template design * clean up * feedback * clean up * fix dot-template store tests * fix tests on dot-template-create-edit * fix dot-template-builder tests * fix dot-template tests * fix DotEditLayoutComponent * clean up * rename saveDraft to updateTemplate * add docs * feedback * feedback * clean up * feedback * clean up * fix doc * CI: bumps version to 22.2.0-rc.9 [skip ci] * Update package * Update package-lock * Clean up * Fix conflicts * CI: bumps version to 22.3.0-next.13 [skip ci] Co-authored-by: victoralfaro-dotcms <[email protected]> Co-authored-by: Rafael Velazco <[email protected]> Co-authored-by: Humberto Morera <[email protected]> Co-authored-by: Freddy Rodriguez <[email protected]>
Checklist