From 2e4ac93921ee1a3e0fba6ea18985112ae42caf1d Mon Sep 17 00:00:00 2001 From: Tim Fischbach Date: Thu, 20 Jun 2024 07:04:33 +0200 Subject: [PATCH] Reset cutoff when cutoff section is destroyed REDMINE-20674 --- .../package/spec/editor/models/Cutoff-spec.js | 22 +++++++++++++++++++ .../package/src/editor/models/Cutoff.js | 6 +++++ .../src/editor/models/ScrolledEntry/index.js | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js diff --git a/entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js b/entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js new file mode 100644 index 000000000..a05170129 --- /dev/null +++ b/entry_types/scrolled/package/spec/editor/models/Cutoff-spec.js @@ -0,0 +1,22 @@ +import {useEditorGlobals, useFakeXhr} from 'support'; +import '@testing-library/jest-dom/extend-expect'; + +describe('Cutoff', () => { + useFakeXhr(); + + const {createEntry} = useEditorGlobals(); + + it('resets metadata configuration when deleting the cutoff section', () => { + const entry = createEntry({ + metadata: {configuration: {cutoff_section_perma_id: 100}}, + sections: [ + {id: 1, permaId: 100}, + {id: 2, permaId: 101}, + ] + }); + + entry.sections.get(1).destroy(); + + expect(entry.metadata.configuration.get('cutoff_section_perma_id')).toBeUndefined(); + }); +}); diff --git a/entry_types/scrolled/package/src/editor/models/Cutoff.js b/entry_types/scrolled/package/src/editor/models/Cutoff.js index baff2d859..7a1f75848 100644 --- a/entry_types/scrolled/package/src/editor/models/Cutoff.js +++ b/entry_types/scrolled/package/src/editor/models/Cutoff.js @@ -7,6 +7,12 @@ export const Cutoff = Object.extend({ this.listenTo(this.entry.metadata.configuration, 'change:cutoff_section_perma_id', () => this.trigger('change')); + + this.listenTo(this.entry.sections, 'destroy', (section) => { + if (this.isAtSection(section)) { + this.reset(); + } + }); }, isEnabled() { diff --git a/entry_types/scrolled/package/src/editor/models/ScrolledEntry/index.js b/entry_types/scrolled/package/src/editor/models/ScrolledEntry/index.js index 37b69c6ad..8d3470467 100644 --- a/entry_types/scrolled/package/src/editor/models/ScrolledEntry/index.js +++ b/entry_types/scrolled/package/src/editor/models/ScrolledEntry/index.js @@ -13,7 +13,6 @@ import {deleteContentElement} from './deleteContentElement'; export const ScrolledEntry = Entry.extend({ setupFromEntryTypeSeed(seed) { this.consentVendors = new ConsentVendors({hostMatchers: seed.consentVendorHostMatchers}); - this.cutoff = new Cutoff({entry: this}); this.contentElements = new ContentElementsCollection(seed.collections.contentElements); this.sections = new SectionsCollection(seed.collections.sections, @@ -25,6 +24,8 @@ export const ScrolledEntry = Entry.extend({ this.sections.sort(); + this.cutoff = new Cutoff({entry: this}); + editor.failures.watch(this.contentElements); editor.failures.watch(this.sections); editor.failures.watch(this.chapters);