Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

dotCMS/core#21558 Edit Template Properties Modal makes changes get lost #1865

Conversation

rjvelazco
Copy link
Contributor

@rjvelazco rjvelazco commented Jan 31, 2022

Checklist

  • Tests

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@rjvelazco rjvelazco marked this pull request as draft January 31, 2022 17:21
@@ -1,4 +1,4 @@
import { pluck, filter, take } from 'rxjs/operators';
import { pluck, filter, take, debounceTime, tap } from 'rxjs/operators';
Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines 156 to 159
switchMap((template: DotTemplateItem) => {
return this.didTemplateChangedBeforeSave(template);
}),
switchMap((template: DotTemplateItem) => {
Copy link
Member

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> {
Copy link
Member

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?

Comment on lines 318 to 321
/**
* 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
*/
Copy link
Member

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.

Comment on lines 328 to 340
if (template.type === 'design') {
result = {
...template,
layout: (currentTemplate as DotTemplateItemDesign).layout
};
} else {
result = {
...template,
body: (currentTemplate as DotTemplateItemadvanced).body
};
}

return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
};

Comment on lines 51 to 53
this.store.didTemplateChanged$
.pipe(takeUntil(this.destroy$))
.subscribe(( didTemplateChanged ) => this.didTemplateChanged = didTemplateChanged);
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

observable candidate + async pipe.

Comment on lines 80 to 84
/**
* Save changes on working template to store
*
* @memberof DotTemplateCreateEditComponent
*/
Copy link
Member

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)"
Copy link
Member

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?

Copy link
Contributor Author

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

@rjvelazco rjvelazco marked this pull request as ready for review February 2, 2022 13:01
this.updateTemplate.next(value);
}

onSaveTemplate(updatedPage: DotPageRender) {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs.

}

ngOnChanges(changes: SimpleChanges){
if( changes.didTemplateChanged ) {
Copy link
Member

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?

Comment on lines 620 to 622
saveTemplate: jasmine.createSpy(),
updateWorkingTemplate: jasmine.createSpy(),
goToTemplateList: jasmine.createSpy(),
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
updateTemplate({ layout, body, themeId }: DotTemplate): void {
updateWorkingTemplate({ layout, body, themeId }: DotTemplate): void {

};

// Design templates need to be save 10 seconds after the last change.
this.store.saveTemplateDebounce(value);
Copy link
Member

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();
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface templateStoreValueType {
interface TemplateStoreValueType {

Types are camelcase

Comment on lines 100 to 110
/**
* 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
*/
Copy link
Member

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.

@fmontes fmontes merged commit 01e78ad into release-22.02 Feb 7, 2022
@delete-merged-branch delete-merged-branch bot deleted the issue-21558-edit-template-properties-modal-makes-changes-get-lost branch February 7, 2022 18:08
fmontes added a commit that referenced this pull request Feb 10, 2022
* 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]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants