Skip to content

Commit

Permalink
Addressed some bugs and feedback reviews Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
natashapl committed Jul 31, 2024
1 parent 12b016c commit 5066c38
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const PatternEditActions = ({ children }: PatternEditActionsProps) => {
);
const movePatternToPage = useFormManagerStore(state => state.movePattern);
let focusPatternId = useFormManagerStore(state => state.focus?.pattern.id);
const focusPatternType = useFormManagerStore(state => state.focus?.pattern.type);
const focusPatternType = useFormManagerStore(
state => state.focus?.pattern.type
);
const isPatternInFieldset = useMemo(() => {
if (!focusPatternId) return false;
return patterns.some(
Expand All @@ -65,17 +67,17 @@ export const PatternEditActions = ({ children }: PatternEditActionsProps) => {
const availablePages: PageWithLabel[] =
page1Count > 1
? pages.slice(1).map((page, index) => {
if (index + 1 === currentPageIndex) {
return { ...page, specialLabel: 'Current page' };
}
return page;
})
if (index + 1 === currentPageIndex) {
return { ...page, specialLabel: 'Current page' };
}
return page;
})
: pages.map((page, index) => {
if (index === currentPageIndex) {
return { ...page, specialLabel: 'Current page' };
}
return page;
});
if (index === currentPageIndex) {
return { ...page, specialLabel: 'Current page' };
}
return page;
});

return availablePages;
};
Expand Down Expand Up @@ -336,4 +338,4 @@ export const PatternEditActions = ({ children }: PatternEditActionsProps) => {
</div>
</>
);
};
};
21 changes: 16 additions & 5 deletions packages/forms/src/builder/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ describe('form builder', () => {
expect(builder.form.patterns[pattern.id]).toEqual(pattern);
const oldPage = getPattern<PagePattern>(initial, 'page-1');
const newPage = getPattern<PagePattern>(builder.form, 'page-1');
builder.movePatternBetweenPages(oldPage.id, newPage.id, pattern.id, 'bottom', true);

builder.movePatternBetweenPages(
oldPage.id,
newPage.id,
pattern.id,
'bottom',
true
);

expect(newPage.data).toEqual({
...oldPage.data,
patterns: [...newPage.data.patterns],
Expand All @@ -51,7 +57,13 @@ describe('form builder', () => {
expect(builder.form.patterns[pattern.id]).toEqual(pattern);
const oldPage = getPattern<PagePattern>(initial, 'page-1');
const newPage = getPattern<PagePattern>(builder.form, 'page-2');
builder.movePatternBetweenPages(oldPage.id, newPage.id, pattern.id, 'top', false);
builder.movePatternBetweenPages(
oldPage.id,
newPage.id,
pattern.id,
'top',
false
);

expect(newPage.data).toEqual({
...newPage.data,
Expand All @@ -67,7 +79,7 @@ describe('form builder', () => {
root: {
type: 'page-set',
id: 'root',
data: {
data: {
pages: ['page-1', 'page-2'],
},
} satisfies PageSetPattern,
Expand Down Expand Up @@ -177,4 +189,3 @@ export const createTestBlueprint = () => {
}
);
};

0 comments on commit 5066c38

Please sign in to comment.