Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss-react] [Editing Integration] Add support for chrome hydration for Placeholders #1776

Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d933925
conditinally emit edit chromes metadata for placeholders, rendering
addy-pathania Apr 17, 2024
24c36ee
refactor PlaceholderWithMetadata component
addy-pathania Apr 18, 2024
89d366c
update tests
addy-pathania Apr 18, 2024
fc6f25f
update changelog
addy-pathania Apr 18, 2024
983ace9
remove extra lines
addy-pathania Apr 18, 2024
d89ca37
remove editMode mock data
addy-pathania Apr 19, 2024
fd60d80
update unit test, change code tag chrometype
addy-pathania Apr 19, 2024
e9ae072
remove only
addy-pathania Apr 19, 2024
12e4926
refactor as per new requirements
addy-pathania Apr 22, 2024
9973138
Update packages/sitecore-jss/src/layout/models.ts
addy-pathania Apr 22, 2024
6449ec7
Update packages/sitecore-jss-react/src/components/PlaceholderMetadata…
addy-pathania Apr 22, 2024
57da890
Update packages/sitecore-jss-react/src/components/PlaceholderMetadata…
addy-pathania Apr 22, 2024
1ef2054
Update packages/sitecore-jss-react/src/components/PlaceholderMetadata…
addy-pathania Apr 22, 2024
504d5fd
Update CHANGELOG.md
addy-pathania Apr 22, 2024
bbb9efc
refactor unit test
addy-pathania Apr 22, 2024
db130e3
Merge branch 'feature/jss-1828-editing-integration-placeholder' of gi…
addy-pathania Apr 22, 2024
472328b
change naming of props and types
addy-pathania Apr 22, 2024
de00777
add test for placeholder
addy-pathania Apr 23, 2024
109e156
update PlaceholderMetadata to render a component
addy-pathania Apr 23, 2024
a81bb95
add test for missing component
addy-pathania Apr 24, 2024
b1a0c9e
merge with feature branch
addy-pathania Apr 24, 2024
c352fb3
merge with feature branch
addy-pathania Apr 24, 2024
8ca899a
fix nextjs placeholder
addy-pathania Apr 24, 2024
5b2a8af
remove context
addy-pathania Apr 24, 2024
934fe6e
reset nextjs placeholder
addy-pathania Apr 24, 2024
6a86756
update changelog
addy-pathania Apr 25, 2024
ee494c1
update test data
addy-pathania Apr 25, 2024
2a15ac2
change PlaceholderMetadata implmentation
addy-pathania Apr 29, 2024
364546f
Placeholder metadata refactor - wip
yavorsk Apr 29, 2024
7b9d42d
update tests, refactor Placeholder component
addy-pathania Apr 29, 2024
e1e6330
remove redundant data
addy-pathania Apr 30, 2024
a77fae6
update unit test - wip
yavorsk Apr 30, 2024
baa8ff8
move tests to placeholder, refactor placeholder
addy-pathania Apr 30, 2024
3a3d157
refactor tests
addy-pathania Apr 30, 2024
6343d4e
refactor placeholdermetadata component, update tests
addy-pathania May 1, 2024
b57941c
refactor placeholder tests, update jsdoc
addy-pathania May 1, 2024
ac4d813
update nextjs types
addy-pathania May 1, 2024
3c3b086
remove keys from code
addy-pathania May 2, 2024
1c25b89
fix nextjs placeholder props
addy-pathania May 3, 2024
5ad9d0e
change deprecated statement
addy-pathania May 3, 2024
25bf498
update deprecated 2
addy-pathania May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Our versioning strategy is as follows:
## Unreleased

### 🎉 New Features & Improvements
* `[sitecore-jss-react]` `[sitecore-jss]` Editing Integration Support:
addy-pathania marked this conversation as resolved.
Show resolved Hide resolved
* Introduces `PlaceholderMetadata` component which supports the hydration of chromes on Pages by rendering the components and placeholders with required metadata. ([#1776](https://github.com/Sitecore/jss/pull/1776))
* `[sitecore-jss-react]` `[sitecore-jss-nextjs]` Introduce FieldMetadata component and functionality to render it when metadata field property is provided in the field's layout data. In such case the field component is wrapped with metadata markup to enable chromes hydration when editing in pages. Ability to render metadata has been added to the field rendering components for react and nextjs. ([#1773](https://github.com/Sitecore/jss/pull/1773))

### 🛠 Breaking Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Placeholder = (props: PlaceholderComponentProps) => {
return (
<ReactPlaceholder
{...props}
modifyComponentProps={(initialProps) => {
modifyComponentProps={(initialProps: { rendering: { uid: string | number } }) => {
addy-pathania marked this conversation as resolved.
Show resolved Hide resolved
if (!initialProps.rendering.uid) return initialProps;

const data = componentPropsContext[initialProps.rendering.uid] as {
Expand Down
1 change: 1 addition & 0 deletions packages/sitecore-jss-nextjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {
EDITING_COMPONENT_PLACEHOLDER,
EDITING_COMPONENT_ID,
getContentStylesheetLink,
EditMode,
} from '@sitecore-jss/sitecore-jss/layout';
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
export {
Expand Down
138 changes: 99 additions & 39 deletions packages/sitecore-jss-react/src/components/Placeholder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable react/prop-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ComponentRendering, RouteData } from '@sitecore-jss/sitecore-jss/layout';
import {
ComponentRendering,
LayoutServiceData,
RouteData,
} from '@sitecore-jss/sitecore-jss/layout';
import { expect } from 'chai';
import { mount, shallow } from 'enzyme';
import PropTypes from 'prop-types';
Expand All @@ -12,6 +16,7 @@ import { convertedData as eeData, emptyPlaceholderData } from '../test-data/ee-d
import {
byocWrapperData,
feaasWrapperData,
layoutDataWithMetadata,
convertedDevData as nonEeDevData,
convertedLayoutServiceData as nonEeLsData,
sxaRenderingColumnSplitterVariant,
Expand All @@ -31,6 +36,7 @@ import { Placeholder } from './Placeholder';
import { ComponentProps } from './PlaceholderCommon';
import { SitecoreContext } from './SitecoreContext';
import { ComponentFactory } from './sharedTypes';
import { PlaceholderMetadata } from './PlaceholderMetadata';

const componentFactory: ComponentFactory = (componentName: string) => {
const components = new Map<string, React.FC>();
Expand Down Expand Up @@ -101,7 +107,9 @@ describe('<Placeholder />', () => {
const phKey = 'page-content';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.download-callout-mock').length).to.equal(1);
Expand Down Expand Up @@ -300,7 +308,9 @@ describe('<Placeholder />', () => {
const phKey = 'main';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.rendering-variant').length).to.equal(1);
Expand All @@ -318,7 +328,9 @@ describe('<Placeholder />', () => {
const phKey = 'container-1';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.rendering-variant').length).to.equal(1);
Expand All @@ -334,7 +346,9 @@ describe('<Placeholder />', () => {
const phKey = 'richText';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.rendering-variant').length).to.equal(0);
Expand All @@ -346,7 +360,9 @@ describe('<Placeholder />', () => {
const phKey = 'dynamic-1-{*}';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.rendering-variant').length).to.equal(1);
Expand All @@ -362,7 +378,9 @@ describe('<Placeholder />', () => {
const phKey = 'main-second';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.rendering-variant').length).to.equal(1);
Expand All @@ -377,7 +395,9 @@ describe('<Placeholder />', () => {
const phKey = 'column-1-{*}';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.rendering-variant').length).to.equal(1);
Expand Down Expand Up @@ -410,7 +430,9 @@ describe('<Placeholder />', () => {
));

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.byoc-component').length).to.equal(2);
Expand Down Expand Up @@ -443,7 +465,9 @@ describe('<Placeholder />', () => {
));

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find('.feaas-component').length).to.equal(2);
Expand All @@ -459,7 +483,9 @@ describe('<Placeholder />', () => {
const phKey = 'main';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={component} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

const eeChrome = renderedComponent.find({ chrometype: 'placeholder', kind: 'open', id: phKey });
Expand All @@ -473,11 +499,9 @@ describe('<Placeholder />', () => {
const phKey = 'main';

const renderedComponent = mount(
<Placeholder
name={phKey}
rendering={emptyPlaceholderData.sitecore.route}
componentFactory={componentFactory}
/>
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={emptyPlaceholderData.sitecore.route} />
</SitecoreContext>
);
expect(renderedComponent.find('.sc-jss-empty-placeholder').length).to.equal(1);
});
Expand All @@ -495,7 +519,9 @@ describe('<Placeholder />', () => {
const phKey = 'unknown';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={route} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={route} />
</SitecoreContext>
);
expect(renderedComponent.html()).to.be.empty;
});
Expand Down Expand Up @@ -529,7 +555,9 @@ describe('<Placeholder />', () => {
const phKey = 'main';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={route} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={route} />
</SitecoreContext>
);
expect(renderedComponent.find('.sc-jss-placeholder-error').length).to.equal(1);
});
Expand All @@ -540,7 +568,9 @@ describe('<Placeholder />', () => {

const Home: React.FC<{ rendering?: RouteData }> = ({ rendering }) => (
<div className="home-mock">
<Placeholder name="main" rendering={rendering} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name="main" rendering={rendering} />
</SitecoreContext>
</div>
);

Expand All @@ -565,12 +595,9 @@ describe('<Placeholder />', () => {
const phKey = 'main';

const renderedComponent = mount(
<Placeholder
name={phKey}
rendering={route}
componentFactory={componentFactory}
errorComponent={CustomError}
/>
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={route} errorComponent={CustomError} />
</SitecoreContext>
);
expect(renderedComponent.find('.custom-error').length).to.equal(1);
});
Expand All @@ -595,12 +622,13 @@ it('should render MissingComponent for unknown rendering', () => {
);

const renderedComponent = mount(
<Placeholder
name={phKey}
rendering={route}
componentFactory={componentFactory}
missingComponentComponent={CustomMissingComponent}
/>
<SitecoreContext componentFactory={componentFactory}>
<Placeholder
name={phKey}
rendering={route}
missingComponentComponent={CustomMissingComponent}
/>
</SitecoreContext>
);
expect(renderedComponent.find('.missing-component').length).to.equal(1);
});
Expand Down Expand Up @@ -633,7 +661,9 @@ it('should render nothing for rendering without a name', () => {

const renderedComponent = mount(
<div className="empty-test">
<Placeholder name={phKey} rendering={route} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={route} />
</SitecoreContext>
</div>
);
expect(renderedComponent.children().length).to.equal(1);
Expand All @@ -652,7 +682,9 @@ it('should render HiddenRendering when rendering is hidden', () => {
const phKey = 'main';

const renderedComponent = mount(
<Placeholder name={phKey} rendering={route} componentFactory={componentFactory} />
<SitecoreContext componentFactory={componentFactory}>
<Placeholder name={phKey} rendering={route} />
</SitecoreContext>
);
expect(renderedComponent.find(HiddenRendering).length).to.equal(1);
});
Expand All @@ -677,18 +709,46 @@ it('should render custom HiddenRendering when rendering is hidden', () => {
);

const renderedComponent = mount(
<Placeholder
name={phKey}
rendering={route}
componentFactory={componentFactory}
hiddenRenderingComponent={CustomHiddenRendering}
/>
<SitecoreContext componentFactory={componentFactory}>
<Placeholder
name={phKey}
rendering={route}
hiddenRenderingComponent={CustomHiddenRendering}
/>
</SitecoreContext>
);
expect(renderedComponent.find('.hidden-rendering').length).to.equal(1);
expect(renderedComponent.find(HiddenRendering).length).to.equal(1);
expect(renderedComponent.find('p').props().children).to.equal('Hidden Rendering');
});

const testDataWithoutEE = [
addy-pathania marked this conversation as resolved.
Show resolved Hide resolved
{ label: 'Dev data', data: nonEeDevData },
{ label: 'LayoutService data - EE off', data: nonEeLsData },
];

testDataWithoutEE.forEach((dataSet) => {
describe(`with ${dataSet.label}`, () => {
it('renders <PlaceholderMetadata> when editMode is Metadata', () => {
const component = ((dataSet.data.sitecore.route.placeholders.main as unknown) as (
| ComponentRendering
| RouteData
)[]).find((c) => (c as ComponentRendering).componentName);
const phKey = 'page-content';

const mockLayoutData: LayoutServiceData = layoutDataWithMetadata;

const renderedComponent = mount(
<SitecoreContext componentFactory={componentFactory} layoutData={mockLayoutData}>
<Placeholder name={phKey} rendering={component} />
</SitecoreContext>
);

expect(renderedComponent.find(PlaceholderMetadata).length).to.equal(1);
});
});
});

after(() => {
(global as any).window.close();
});
7 changes: 6 additions & 1 deletion packages/sitecore-jss-react/src/components/Placeholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PlaceholderCommon, PlaceholderProps } from './PlaceholderCommon';
import { withComponentFactory } from '../enhancers/withComponentFactory';
import { ComponentRendering, HtmlElementRendering } from '@sitecore-jss/sitecore-jss/layout';
import { HorizonEditor } from '@sitecore-jss/sitecore-jss/utils';
import { withSitecoreContext } from '../enhancers/withSitecoreContext';

export interface PlaceholderComponentProps extends PlaceholderProps {
/**
Expand Down Expand Up @@ -120,4 +121,8 @@ class PlaceholderComponent extends PlaceholderCommon<PlaceholderComponentProps>
}
}

export const Placeholder = withComponentFactory(PlaceholderComponent);
const PlaceholderWithComponentFactory = withComponentFactory(PlaceholderComponent);

export const Placeholder = withSitecoreContext()<PlaceholderComponentProps>(
PlaceholderWithComponentFactory
);
Loading