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 (#1862)

(cherry picked from commit dbe4f3d)
  • Loading branch information
art-alexeyenko committed Jul 29, 2024
1 parent 603d50a commit bdddb76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Our versioning strategy is as follows:

### 🛠 Breaking Change

* Editing Integration Support: ([#1776](https://github.com/Sitecore/jss/pull/1776))([#1792](https://github.com/Sitecore/jss/pull/1792))([#1773](https://github.com/Sitecore/jss/pull/1773))([#1797](https://github.com/Sitecore/jss/pull/1797))([#1800](https://github.com/Sitecore/jss/pull/1800))([#1803](https://github.com/Sitecore/jss/pull/1803))([#1806](https://github.com/Sitecore/jss/pull/1806))([#1809](https://github.com/Sitecore/jss/pull/1809))([#1814](https://github.com/Sitecore/jss/pull/1814))([#1816](https://github.com/Sitecore/jss/pull/1816))([#1819](https://github.com/Sitecore/jss/pull/1819))([#1828](https://github.com/Sitecore/jss/pull/1828))([#1835](https://github.com/Sitecore/jss/pull/1835))([#1849](https://github.com/Sitecore/jss/pull/1849))([#1831](https://github.com/Sitecore/jss/pull/1831))([#1853](https://github.com/Sitecore/jss/pull/1853))([#1854](https://github.com/Sitecore/jss/pull/1854))([#1857](https://github.com/Sitecore/jss/pull/1857))
* Editing Integration Support: ([#1776](https://github.com/Sitecore/jss/pull/1776))([#1792](https://github.com/Sitecore/jss/pull/1792))([#1773](https://github.com/Sitecore/jss/pull/1773))([#1797](https://github.com/Sitecore/jss/pull/1797))([#1800](https://github.com/Sitecore/jss/pull/1800))([#1803](https://github.com/Sitecore/jss/pull/1803))([#1806](https://github.com/Sitecore/jss/pull/1806))([#1809](https://github.com/Sitecore/jss/pull/1809))([#1814](https://github.com/Sitecore/jss/pull/1814))([#1816](https://github.com/Sitecore/jss/pull/1816))([#1819](https://github.com/Sitecore/jss/pull/1819))([#1828](https://github.com/Sitecore/jss/pull/1828))([#1835](https://github.com/Sitecore/jss/pull/1835))([#1849](https://github.com/Sitecore/jss/pull/1849))([#1831](https://github.com/Sitecore/jss/pull/1831))([#1853](https://github.com/Sitecore/jss/pull/1853))([#1854](https://github.com/Sitecore/jss/pull/1854))([#1857](https://github.com/Sitecore/jss/pull/1857))([#1862](https://github.com/Sitecore/jss/pull/1862))
* `[sitecore-jss-react]` Introduces `PlaceholderMetadata` component which supports the hydration of chromes on Pages by rendering the components and placeholders with required metadata.
* `[sitecore-jss]` Chromes are hydrated based on the basis of new `editMode` property derived from LayoutData, which is defined as an enum consisting of `metadata` and `chromes`.
* `ComponentConsumerProps` is removed. You might need to reuse `WithSitecoreContextProps` type.
Expand Down
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 bdddb76

Please sign in to comment.