Skip to content

Commit

Permalink
[sitecore-jss][nextjs-xmcloud] Ensure uid is preserved when variant i…
Browse files Browse the repository at this point in the history
…s hidden
  • Loading branch information
art-alexeyenko committed Jul 29, 2024
1 parent 6ca994d commit e7522d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/sitecore-jss/src/personalize/layout-personalizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ describe('layout-personalizer', () => {
});
});

it('should return HIDDEN_RENDERING variant in metadata mode with uid preserved', () => {
const variant = 'mountain_bike_audience';
const personalizedComponentResult = personalizeComponent(
(variantIsHidden as unknown) as ComponentRenderingWithExperiences,
[variant],
true
);
expect(personalizedComponentResult?.uid).to.equal(variantIsHidden.uid);
});

it('should return HIDDEN_RENDERING variant in metadata edit mode when non-default variant is hidden', () => {
const variant = 'mountain_bike_audience';
const personalizedComponentResult = personalizeComponent(
Expand Down
11 changes: 7 additions & 4 deletions packages/sitecore-jss/src/personalize/layout-personalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {
EditMode,
} from './../layout/models';

const hiddenRenderingVariant = {
const transformToHiddenRenderingVariant = (
component: ComponentRendering | HtmlElementRendering
) => ({
...component,
componentName: HIDDEN_RENDERING_NAME,
experiences: {},
};
});

export type ComponentRenderingWithExperiences = ComponentRendering & {
experiences: { [name: string]: ComponentRenderingWithExperiences };
Expand Down Expand Up @@ -106,14 +109,14 @@ export function personalizeComponent(
if (!variant && !component.componentName) {
// DEFAULT IS HIDDEN
if (metadataEditing) {
component = hiddenRenderingVariant;
component = transformToHiddenRenderingVariant(component);
} else {
return null;
}
} else if (variant && variant.componentName === null && variant.dataSource === null) {
// VARIANT IS HIDDEN
if (metadataEditing) {
component = hiddenRenderingVariant;
component = transformToHiddenRenderingVariant(component);
} else {
return null;
}
Expand Down

0 comments on commit e7522d2

Please sign in to comment.