Skip to content

Commit 1b4c37d

Browse files
authored
fix(VariantManagement): support React 19 (#6639)
+ add tests for data-attributes in React 19
1 parent fe389bc commit 1b4c37d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

packages/main/src/components/VariantManagement/VariantManagement.cy.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ describe('VariantManagement', () => {
227227
<VariantItem>VariantItem 1</VariantItem>
228228
<VariantItem selected>VariantItem 2</VariantItem>
229229
<VariantItem readOnly>VariantItem 3</VariantItem>
230+
<VariantItem readOnly={false}>VariantItem 4</VariantItem>
231+
<VariantItem readOnly={true}>VariantItem 5</VariantItem>
232+
<VariantItem readOnly={null}>VariantItem 6</VariantItem>
233+
<VariantItem readOnly={undefined}>VariantItem 7</VariantItem>
230234
</VariantManagement>
231235
</>
232236
);
@@ -243,6 +247,14 @@ describe('VariantManagement', () => {
243247
cy.findByText('Save', { timeout: 200 }).should('not.exist');
244248
cy.findByText('VariantItem 1').click();
245249
cy.findByText('Save').should('be.visible');
250+
cy.findByText('VariantItem 4').click();
251+
cy.findByText('Save').should('be.visible');
252+
cy.findByText('VariantItem 5').click();
253+
cy.findByText('Save', { timeout: 200 }).should('not.exist');
254+
cy.findByText('VariantItem 6').click();
255+
cy.findByText('Save').should('be.visible');
256+
cy.findByText('VariantItem 7').click();
257+
cy.findByText('Save').should('be.visible');
246258

247259
cy.mount(<TestComp onSave={save} dirtyStateText="Dirty state" />);
248260
cy.findByText('*', { timeout: 200 }).should('not.exist');
@@ -452,6 +464,18 @@ describe('VariantManagement', () => {
452464
applyAutomatically: true,
453465
author: 'bla'
454466
}
467+
},
468+
{
469+
rowId: 'All props false',
470+
props: {
471+
labelReadOnly: false,
472+
favorite: false,
473+
isDefault: false,
474+
hideDelete: false,
475+
global: false,
476+
applyAutomatically: false,
477+
author: 'All false'
478+
}
455479
}
456480
];
457481
const TestComp = ({
@@ -575,7 +599,7 @@ describe('VariantManagement', () => {
575599
cy.findByText('Save').click();
576600
cy.get('@saveView').should('have.been.calledOnce');
577601
cy.findByText(
578-
'{"nativeDetail":1,"deletedVariants":[],"prevVariants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"}],"updatedVariants":[],"variants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"}]}'
602+
'{"nativeDetail":1,"deletedVariants":[],"prevVariants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"},{"labelReadOnly":false,"favorite":false,"isDefault":false,"hideDelete":false,"global":false,"applyAutomatically":false,"author":"All false","children":"All props false"}],"updatedVariants":[],"variants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"},{"labelReadOnly":false,"favorite":false,"isDefault":false,"hideDelete":false,"global":false,"applyAutomatically":false,"author":"All false","children":"All props false"}]}'
579603
);
580604

581605
cy.mount(<TestComp onSaveManageViews={onSaveView} showOnlyFavorites />);
@@ -586,7 +610,7 @@ describe('VariantManagement', () => {
586610
cy.findByText('Save').click();
587611
cy.get('@saveView').should('have.been.calledTwice');
588612
cy.findByText(
589-
'{"nativeDetail":1,"deletedVariants":[],"prevVariants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"}],"updatedVariants":[],"variants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"}]}'
613+
'{"nativeDetail":1,"deletedVariants":[],"prevVariants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"},{"labelReadOnly":false,"favorite":false,"isDefault":false,"hideDelete":false,"global":false,"applyAutomatically":false,"author":"All false","children":"All props false"}],"updatedVariants":[],"variants":[{"children":"Default VariantItem"},{"labelReadOnly":true,"children":"LabelReadOnly"},{"favorite":true,"children":"Favorite"},{"favorite":true,"isDefault":true,"children":"Favorite & isDefault"},{"isDefault":true,"children":"IsDefault"},{"hideDelete":true,"children":"HideDelete"},{"hideDelete":false,"global":true,"children":"HideDelete - false & global - true"},{"global":true,"children":"Global"},{"applyAutomatically":true,"children":"Apply Automatically (List item)"},{"applyAutomatically":true,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically with text"},{"applyAutomatically":false,"applyAutomaticallyText":"applyAutomaticallyText","children":"Apply Automatically (false) with text"},{"author":"author","children":"Author"},{"labelReadOnly":true,"favorite":true,"isDefault":true,"hideDelete":true,"global":true,"applyAutomatically":true,"author":"bla","children":"All props"},{"labelReadOnly":false,"favorite":false,"isDefault":false,"hideDelete":false,"global":false,"applyAutomatically":false,"author":"All false","children":"All props false"}]}'
590614
);
591615
});
592616

packages/main/src/components/VariantManagement/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,13 @@ const VariantManagement = forwardRef<HTMLDivElement, VariantManagementPropTypes>
317317
}
318318
}, [safeChildrenWithFavorites]);
319319

320-
const showSaveBtn = dirtyState && selectedVariant && !selectedVariant.readOnly;
320+
//todo: selectedVariant type needs to be enhanced for React19 (data attributes: true => "", false => "false")
321+
const showSaveBtn =
322+
dirtyState &&
323+
selectedVariant &&
324+
(typeof selectedVariant?.readOnly === 'string'
325+
? selectedVariant.readOnly !== '' && selectedVariant.readOnly === 'false'
326+
: !selectedVariant.readOnly);
321327

322328
return (
323329
<div className={variantManagementClasses} style={style} {...rest} ref={ref}>

0 commit comments

Comments
 (0)