From 4a54cb51eddde4eb12d195123cadfb634230fa00 Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Wed, 3 Jul 2024 10:18:31 -0500 Subject: [PATCH] Bugfix: preserve page title on "add pattern" (#246) * Clarify comment * Bugfix: add missing page pattern data on addPatternToPage * Update existing addPatternToPage test to confirm that the page title is maintained when patterns are added to a page. --- .../components/PreviewSequencePattern/index.tsx | 1 + packages/forms/src/builder/builder.test.ts | 16 ++++++++-------- packages/forms/src/index.ts | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/index.tsx b/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/index.tsx index 0f7d0405..6dfe7144 100644 --- a/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/index.tsx +++ b/packages/design/src/FormManager/FormEdit/components/PreviewSequencePattern/index.tsx @@ -8,6 +8,7 @@ import { PatternEditComponent } from '../../types'; // TODO: consider merging this component with DraggableList, to clean up // sematics around how its children are handled. +// Counterpoint: it's nice to have state management separate from DraggableList. export const PatternPreviewSequence: PatternEditComponent< SequenceProps > = props => { diff --git a/packages/forms/src/builder/builder.test.ts b/packages/forms/src/builder/builder.test.ts index e15c80aa..96f4037b 100644 --- a/packages/forms/src/builder/builder.test.ts +++ b/packages/forms/src/builder/builder.test.ts @@ -17,15 +17,15 @@ describe('form builder', () => { it('addPattern preserves existing structure', () => { const initial = createTestBlueprint(); - const newBuilder = new BlueprintBuilder(defaultFormConfig, initial); - const newPattern = newBuilder.addPatternToPage('input'); - expect(newBuilder.form.patterns[newPattern.id]).toEqual(newPattern); + const builder = new BlueprintBuilder(defaultFormConfig, initial); + const newPattern = builder.addPatternToPage('input'); + expect(builder.form.patterns[newPattern.id]).toEqual(newPattern); const oldPage = getPattern(initial, 'page-1'); - const newPage = getPattern(newBuilder.form, 'page-1'); - expect(newPage.data.patterns).toEqual([ - ...oldPage.data.patterns, - newPattern.id, - ]); + const newPage = getPattern(builder.form, 'page-1'); + expect(newPage.data).toEqual({ + ...oldPage.data, + patterns: [...oldPage.data.patterns, newPattern.id], + }); }); it('removePattern removes pattern and sequence reference', () => { diff --git a/packages/forms/src/index.ts b/packages/forms/src/index.ts index b2027016..68edf48e 100644 --- a/packages/forms/src/index.ts +++ b/packages/forms/src/index.ts @@ -203,6 +203,7 @@ export const addPatternToPage = ( [pagePattern.id]: { ...pagePattern, data: { + ...pagePattern.data, patterns: [...pagePattern.data.patterns, pattern.id], }, } satisfies SequencePattern,