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

fix(atomic): revert #4287 #4353

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ packages/atomic/src/external-builds/**/*
packages/atomic/src/generated/**
packages/quantic/docs/out/quantic-docs.json
packages/samples/headless-react/build/**/*
packages/samples/angular/src/lang/*.json
packages/samples/vuejs/public/lang/*.json
packages/samples/angular/src/lang/*.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ AtomicCommerceFacets,
AtomicCommerceInterface,
AtomicCommerceLoadMoreProducts,
AtomicCommercePager,
AtomicCommerceProductList,
AtomicCommerceProductsPerPage,
AtomicCommerceQuerySummary,
AtomicCommerceRefineModal,
Expand Down Expand Up @@ -129,7 +128,6 @@ AtomicCommerceFacets,
AtomicCommerceInterface,
AtomicCommerceLoadMoreProducts,
AtomicCommercePager,
AtomicCommerceProductList,
AtomicCommerceProductsPerPage,
AtomicCommerceQuerySummary,
AtomicCommerceRefineModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,29 +274,6 @@ export declare interface AtomicCommercePager extends Components.AtomicCommercePa
}


@ProxyCmp({
inputs: ['density', 'display', 'gridCellLinkTarget', 'imageSize', 'numberOfPlaceholders'],
methods: ['setRenderFunction']
})
@Component({
selector: 'atomic-commerce-product-list',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['density', 'display', 'gridCellLinkTarget', 'imageSize', 'numberOfPlaceholders'],
})
export class AtomicCommerceProductList {
protected el: HTMLElement;
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
}
}


export declare interface AtomicCommerceProductList extends Components.AtomicCommerceProductList {}


@ProxyCmp({
inputs: ['choicesDisplayed', 'initialChoice']
})
Expand Down Expand Up @@ -1302,14 +1279,14 @@ export declare interface AtomicRelevanceInspector extends Components.AtomicRelev


@ProxyCmp({
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'linkContent', 'result', 'stopPropagation']
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'result', 'stopPropagation']
})
@Component({
selector: 'atomic-result',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'linkContent', 'result', 'stopPropagation'],
inputs: ['classes', 'content', 'density', 'display', 'imageSize', 'result', 'stopPropagation'],
})
export class AtomicResult {
protected el: HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import type {Product} from '@coveo/headless/commerce';
import React, {useEffect, useRef} from 'react';
import {createRoot} from 'react-dom/client';
import {renderToString} from 'react-dom/server';
import {
AtomicCommerceProductList,
AtomicProductLink,
} from '../stencil-generated/commerce';

interface Template {
contentTemplate: JSX.Element;
linkTemplate: JSX.Element;
}
import {AtomicCommerceProductList} from '../stencil-generated/commerce';

/**
* The properties of the AtomicCommerceProductList component
Expand All @@ -21,7 +13,7 @@ interface WrapperProps extends AtomicJSX.AtomicCommerceProductList {
* A template function that takes a result item and outputs its target rendering as a JSX element.
* It can be used to conditionally render different type of result templates based on the properties of each result.
*/
template: (result: Product) => JSX.Element | Template;
template: (result: Product) => JSX.Element;
}

/**
Expand All @@ -35,30 +27,12 @@ export const ListWrapper: React.FC<WrapperProps> = (props) => {
const commerceProductListRef =
useRef<HTMLAtomicCommerceProductListElement>(null);
useEffect(() => {
commerceProductListRef.current?.setRenderFunction(
(product, root, linkContainer) => {
const templateResult = template(product as Product);
if (hasLinkTemplate(templateResult)) {
createRoot(linkContainer!).render(templateResult.linkTemplate);
createRoot(root).render(templateResult.contentTemplate);
return renderToString(templateResult.contentTemplate);
} else {
createRoot(root).render(templateResult);
createRoot(linkContainer!).render(
<AtomicProductLink></AtomicProductLink>
);
return renderToString(templateResult);
}
}
);
commerceProductListRef.current?.setRenderFunction((result, root) => {
createRoot(root).render(template(result as Product));
return renderToString(template(result as Product));
});
}, [commerceProductListRef]);
return (
<AtomicCommerceProductList ref={commerceProductListRef} {...otherProps} />
);
};

const hasLinkTemplate = (
template: JSX.Element | Template
): template is Template => {
return (template as Template).linkTemplate !== undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import type {Product} from '@coveo/headless/commerce';
import React, {useEffect, useRef} from 'react';
import {createRoot} from 'react-dom/client';
import {renderToString} from 'react-dom/server';
import {
AtomicCommerceRecommendationList,
AtomicProductLink,
} from '../stencil-generated/commerce';

interface Template {
contentTemplate: JSX.Element;
linkTemplate: JSX.Element;
}
import {AtomicCommerceRecommendationList} from '../stencil-generated/commerce';

/**
* The properties of the AtomicCommerceRecommendationList component
Expand All @@ -21,7 +13,7 @@ interface WrapperProps extends AtomicJSX.AtomicCommerceRecommendationList {
* A template function that takes a result item and outputs its target rendering as a JSX element.
* It can be used to conditionally render different type of result templates based on the properties of each result.
*/
template: (result: Product) => JSX.Element | Template;
template: (result: Product) => JSX.Element;
}

/**
Expand All @@ -35,22 +27,10 @@ export const ListWrapper: React.FC<WrapperProps> = (props) => {
const commerceRecsListRef =
useRef<HTMLAtomicCommerceRecommendationListElement>(null);
useEffect(() => {
commerceRecsListRef.current?.setRenderFunction(
(product, root, linkContainer) => {
const templateResult = template(product as Product);
if (hasLinkTemplate(templateResult)) {
createRoot(linkContainer!).render(templateResult.linkTemplate);
createRoot(root).render(templateResult.contentTemplate);
return renderToString(templateResult.contentTemplate);
} else {
createRoot(root).render(templateResult);
createRoot(linkContainer!).render(
<AtomicProductLink></AtomicProductLink>
);
return renderToString(templateResult);
}
}
);
commerceRecsListRef.current?.setRenderFunction((result, root) => {
createRoot(root).render(template(result as Product));
return renderToString(template(result as Product));
});
}, [commerceRecsListRef]);
return (
<AtomicCommerceRecommendationList
Expand All @@ -59,9 +39,3 @@ export const ListWrapper: React.FC<WrapperProps> = (props) => {
/>
);
};

const hasLinkTemplate = (
template: JSX.Element | Template
): template is Template => {
return (template as Template).linkTemplate !== undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import type {Result} from '@coveo/headless/recommendation';
import React, {useEffect, useRef} from 'react';
import {createRoot} from 'react-dom/client';
import {renderToString} from 'react-dom/server';
import {AtomicRecsList, AtomicResultLink} from '../stencil-generated/search';

interface Template {
contentTemplate: JSX.Element;
linkTemplate: JSX.Element;
}
import {AtomicRecsList} from '../stencil-generated/search';

/**
* The properties of the AtomicRecsList component
Expand All @@ -18,7 +13,7 @@ interface WrapperProps extends AtomicJSX.AtomicRecsList {
* A template function that takes a result item and outputs its target rendering as a JSX element.
* It can be used to conditionally render different type of result templates based on the properties of each result.
*/
template: (result: Result) => JSX.Element | Template;
template: (result: Result) => JSX.Element;
}

/**
Expand All @@ -31,26 +26,10 @@ export const RecsListWrapper: React.FC<WrapperProps> = (props) => {
const {template, ...otherProps} = props;
const recsListRef = useRef<HTMLAtomicRecsListElement>(null);
useEffect(() => {
recsListRef.current?.setRenderFunction((result, root, linkContainer) => {
const templateResult = template(result as Result);
if (hasLinkTemplate(templateResult)) {
createRoot(linkContainer!).render(templateResult.linkTemplate);
createRoot(root).render(templateResult.contentTemplate);
return renderToString(templateResult.contentTemplate);
} else {
createRoot(root).render(templateResult);
createRoot(linkContainer!).render(
<AtomicResultLink></AtomicResultLink>
);
return renderToString(templateResult);
}
recsListRef.current?.setRenderFunction((result, root) => {
createRoot(root).render(template(result as Result));
return renderToString(template(result as Result));
});
}, [recsListRef]);
return <AtomicRecsList ref={recsListRef} {...otherProps} />;
};

const hasLinkTemplate = (
template: JSX.Element | Template
): template is Template => {
return (template as Template).linkTemplate !== undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import type {Result} from '@coveo/headless';
import React, {useEffect, useRef} from 'react';
import {createRoot} from 'react-dom/client';
import {renderToString} from 'react-dom/server';
import {AtomicResultLink, AtomicResultList} from '../stencil-generated/search';

interface Template {
contentTemplate: JSX.Element;
linkTemplate: JSX.Element;
}
import {AtomicResultList} from '../stencil-generated/search';

/**
* The properties of the AtomicResultList component
Expand All @@ -18,7 +13,7 @@ interface WrapperProps extends AtomicJSX.AtomicResultList {
* A template function that takes a result item and outputs its target rendering as a JSX element.
* It can be used to conditionally render different type of result templates based on the properties of each result.
*/
template: (result: Result) => JSX.Element | Template;
template: (result: Result) => JSX.Element;
}

/**
Expand All @@ -31,26 +26,10 @@ export const ResultListWrapper: React.FC<WrapperProps> = (props) => {
const {template, ...otherProps} = props;
const resultListRef = useRef<HTMLAtomicResultListElement>(null);
useEffect(() => {
resultListRef.current?.setRenderFunction((result, root, linkContainer) => {
const templateResult = template(result as Result);
if (hasLinkTemplate(templateResult)) {
createRoot(linkContainer!).render(templateResult.linkTemplate);
createRoot(root).render(templateResult.contentTemplate);
return renderToString(templateResult.contentTemplate);
} else {
createRoot(root).render(templateResult);
createRoot(linkContainer!).render(
<AtomicResultLink></AtomicResultLink>
);
return renderToString(templateResult);
}
resultListRef.current?.setRenderFunction((result, root) => {
createRoot(root).render(template(result as Result));
return renderToString(template(result as Result));
});
}, [resultListRef]);
return <AtomicResultList ref={resultListRef} {...otherProps} />;
};

const hasLinkTemplate = (
template: JSX.Element | Template
): template is Template => {
return (template as Template).linkTemplate !== undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Result Link Component', () => {
});

it('should render an "atomic-result-text" component containing the title', () => {
ResultLinkSelectors.firstInResult().first().should('have.text', title);
ResultLinkSelectors.firstInResult().should('have.text', title);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const resultTextComponent = 'atomic-result-text';
export const ResultTextSelectors = {
shadow: () => cy.get(resultTextComponent),
firstInResult: () =>
ResultListSelectors.firstResult().find(resultTextComponent).first(),
ResultListSelectors.firstResult().find(resultTextComponent),
highlight: () => ResultTextSelectors.firstInResult().find('b'),
};
Loading
Loading