Skip to content

Commit

Permalink
Bugfix: preserve page title on "add pattern" (#246)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
danielnaab authored Jul 3, 2024
1 parent 51c99ab commit 4a54cb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
16 changes: 8 additions & 8 deletions packages/forms/src/builder/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PagePattern>(initial, 'page-1');
const newPage = getPattern<PagePattern>(newBuilder.form, 'page-1');
expect(newPage.data.patterns).toEqual([
...oldPage.data.patterns,
newPattern.id,
]);
const newPage = getPattern<PagePattern>(builder.form, 'page-1');
expect(newPage.data).toEqual({
...oldPage.data,
patterns: [...oldPage.data.patterns, newPattern.id],
});
});

it('removePattern removes pattern and sequence reference', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/forms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export const addPatternToPage = (
[pagePattern.id]: {
...pagePattern,
data: {
...pagePattern.data,
patterns: [...pagePattern.data.patterns, pattern.id],
},
} satisfies SequencePattern,
Expand Down

0 comments on commit 4a54cb5

Please sign in to comment.