Skip to content

Commit

Permalink
[sitecore-jss-react] Use ComponentDataOverride instead of ComponentPr…
Browse files Browse the repository at this point in the history
…ops for BYOCComponent
  • Loading branch information
illiakovalenko committed Dec 4, 2023
1 parent a3b2318 commit 811c78a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { BYOCComponent } from './BYOCComponent';
import { MissingComponent, MissingComponentProps } from './MissingComponent';

describe('BYOCComponent', () => {
it('should render with props when ComponentProps is provided', () => {
it('should render with props when ComponentDataOverride is provided', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
ComponentDataOverride: JSON.stringify({ prop1: 'value1' }),
},
fetchedData: {},
};
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('BYOCComponent', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
ComponentDataOverride: JSON.stringify({ prop1: 'value1' }),
},
fetchedData,
};
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('BYOCComponent', () => {
const mockProps = {
params: {
ComponentName: 'Foo',
ComponentProps: JSON.stringify({ prop1: 'value1' }),
ComponentDataOverride: JSON.stringify({ prop1: 'value1' }),
},
};
const Foo = () => <p id="foo-content">Test</p>;
Expand All @@ -93,7 +93,7 @@ describe('Error handling', () => {
const props = {
params: {
ComponentName: 'ExampleComponent',
ComponentProps: 'invalid-json',
ComponentDataOverride: 'invalid-json',
},
fetchedData: {},
};
Expand All @@ -108,7 +108,7 @@ describe('Error handling', () => {
errorComponent: customErrorComponent,
params: {
ComponentName: 'ExampleComponent',
ComponentProps: 'invalid-json',
ComponentDataOverride: 'invalid-json',
},
fetchedData: {},
};
Expand All @@ -122,7 +122,7 @@ describe('Error handling', () => {
const props = {
params: {
ComponentName: '',
ComponentProps: JSON.stringify({ text: 'this is a BYOC component' }),
ComponentDataOverride: JSON.stringify({ text: 'this is a BYOC component' }),
},
};
const wrapper = mount(<BYOCComponent {...props} />);
Expand Down
10 changes: 5 additions & 5 deletions packages/sitecore-jss-react/src/components/BYOCComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type BYOCComponentParams = {
/**
* JSON props to pass into rendered component
*/
ComponentProps?: string;
ComponentDataOverride?: string;
/**
* A string with classes that can be used to apply themes, via SXA functionality
*/
Expand Down Expand Up @@ -133,9 +133,9 @@ export class BYOCComponent extends React.Component<BYOCComponentProps> {

let componentProps: { [key: string]: any } = null;

if (props.params?.ComponentProps) {
if (props.params?.ComponentDataOverride) {
try {
componentProps = JSON.parse(props.params.ComponentProps) ?? {};
componentProps = JSON.parse(props.params.ComponentDataOverride) ?? {};
} catch (e) {
console.error(
`Parsing props for ${componentName} component from rendering params failed. Error: ${e}`
Expand Down Expand Up @@ -169,8 +169,8 @@ export class BYOCComponent extends React.Component<BYOCComponentProps> {
export async function fetchBYOCComponentServerProps(
params: BYOCComponentParams
): Promise<BYOCComponentProps> {
const fetchDataOptions: FEAAS.DataOptions = params.ComponentProps
? JSON.parse(params.ComponentProps)
const fetchDataOptions: FEAAS.DataOptions = params.ComponentDataOverride
? JSON.parse(params.ComponentDataOverride)
: {};

const fetchedData: FEAAS.DataScopes = await FEAAS.DataSettings.fetch(fetchDataOptions || {});
Expand Down

0 comments on commit 811c78a

Please sign in to comment.