Skip to content

Commit 644cf3c

Browse files
committed
migrate AtomicCommerceRecommendationInterface to lit
https://coveord.atlassian.net/browse/KIT-3934
1 parent 42b9d07 commit 644cf3c

File tree

12 files changed

+232
-245
lines changed

12 files changed

+232
-245
lines changed

packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/atomic-angular.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {APP_INITIALIZER, ModuleWithProviders, NgModule, Provider} from '@angular
66

77
import {
88
AtomicCommerceInterface,
9+
AtomicCommerceRecommendationInterface,
910
AtomicComponentError,
1011
AtomicIcon,
1112
AtomicAriaLive,
@@ -29,7 +30,6 @@ AtomicCommerceProductList,
2930
AtomicCommerceProductsPerPage,
3031
AtomicCommerceQueryError,
3132
AtomicCommerceQuerySummary,
32-
AtomicCommerceRecommendationInterface,
3333
AtomicCommerceRecommendationList,
3434
AtomicCommerceRefineModal,
3535
AtomicCommerceRefineToggle,
@@ -148,6 +148,7 @@ AtomicTimeframeFacet
148148

149149
const DECLARATIONS = [
150150
AtomicCommerceInterface,
151+
AtomicCommerceRecommendationInterface,
151152
AtomicComponentError,
152153
AtomicIcon,
153154
AtomicAriaLive,
@@ -171,7 +172,6 @@ AtomicCommerceProductList,
171172
AtomicCommerceProductsPerPage,
172173
AtomicCommerceQueryError,
173174
AtomicCommerceQuerySummary,
174-
AtomicCommerceRecommendationInterface,
175175
AtomicCommerceRecommendationList,
176176
AtomicCommerceRefineModal,
177177
AtomicCommerceRefineToggle,

packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/components.ts

+35-32
Large diffs are not rendered by default.

packages/atomic-react/src/components/commerce/CommerceInterfaceWrapper.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {JSX, i18n} from '@coveo/atomic';
1+
import type {i18n} from '@coveo/atomic';
22
import React, {useEffect, useRef} from 'react';
33
import {AtomicCommerceInterface} from './components';
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type {i18n} from '@coveo/atomic';
2+
import React, {useEffect, useRef} from 'react';
3+
import {AtomicCommerceRecommendationInterface} from './components.js';
4+
5+
export type AtomicCommerceRecommendationInterface = React.ComponentProps<
6+
typeof AtomicCommerceRecommendationInterface
7+
>;
8+
9+
/**
10+
* The properties of the AtomicCommerceRecommendationInterface component
11+
*/
12+
interface WrapperProps
13+
extends Omit<
14+
AtomicCommerceRecommendationInterface,
15+
'i18n' | 'pipeline' | 'searchHub'
16+
> {
17+
/**
18+
* An optional callback that lets you control the interface localization.
19+
*
20+
* The function receives the search interface 18n instance, which you can then modify (see [Localization](https://docs.coveo.com/en/atomic/latest/usage/atomic-localization/)).
21+
*
22+
*/
23+
localization?: (i18n: i18n) => void;
24+
}
25+
26+
const DefaultProps: Required<Pick<WrapperProps, 'localization'>> = {
27+
localization: () => {},
28+
};
29+
30+
/**
31+
* This component serves as a wrapper for the core AtomicCommerceRecommendationInterface.
32+
* @param props
33+
* @returns
34+
*/
35+
export const InterfaceWrapper = (
36+
props: React.PropsWithChildren<WrapperProps>
37+
) => {
38+
const mergedProps = {...DefaultProps, ...props};
39+
if (!mergedProps.engine) {
40+
throw new Error('The "engine" prop is required.');
41+
}
42+
const {engine, localization, ...allOtherProps} = mergedProps;
43+
const interfaceRef =
44+
useRef<React.ElementRef<typeof AtomicCommerceRecommendationInterface>>(
45+
null
46+
);
47+
let initialization: Promise<void> | null = null;
48+
49+
useEffect(() => {
50+
const CommerceRecommendationInterfaceAtomic = interfaceRef.current!;
51+
if (!initialization) {
52+
initialization =
53+
CommerceRecommendationInterfaceAtomic.initializeWithEngine(engine);
54+
initialization.then(() => {
55+
localization(CommerceRecommendationInterfaceAtomic.i18n);
56+
});
57+
}
58+
}, [interfaceRef]);
59+
60+
return (
61+
<AtomicCommerceRecommendationInterface
62+
engine={engine}
63+
ref={interfaceRef}
64+
{...allOtherProps}
65+
>
66+
{props.children}
67+
</AtomicCommerceRecommendationInterface>
68+
);
69+
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
AtomicCommerceInterface as LitAtomicCommerceInterface,
3-
AtomicComponentError as LitAtomicComponentError,
3+
AtomicCommerceRecommendationInterface as LitAtomicCommerceRecommendationInterface,
44
AtomicIcon as LitAtomicIcon,
5+
AtomicComponentError as LitAtomicComponentError,
56
} from '@coveo/atomic/components';
67
import {createComponent} from '@lit/react';
78
import React from 'react';
@@ -12,14 +13,20 @@ export const AtomicCommerceInterface = createComponent({
1213
elementClass: LitAtomicCommerceInterface,
1314
});
1415

15-
export const AtomicComponentError = createComponent({
16-
tagName: 'atomic-component-error',
16+
export const AtomicCommerceRecommendationInterface = createComponent({
17+
tagName: 'atomic-commerce-recommendation-interface',
1718
react: React,
18-
elementClass: LitAtomicComponentError,
19+
elementClass: LitAtomicCommerceRecommendationInterface,
1920
});
2021

2122
export const AtomicIcon = createComponent({
2223
tagName: 'atomic-icon',
2324
react: React,
2425
elementClass: LitAtomicIcon,
2526
});
27+
28+
export const AtomicComponentError = createComponent({
29+
tagName: 'atomic-component-error',
30+
react: React,
31+
elementClass: LitAtomicComponentError,
32+
});
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import {
2-
AtomicComponentError as LitAtomicComponentError,
32
AtomicIcon as LitAtomicIcon,
3+
AtomicComponentError as LitAtomicComponentError,
44
} from '@coveo/atomic/components';
55
import {createComponent} from '@lit/react';
66
import React from 'react';
77

8-
export const AtomicComponentError = createComponent({
9-
tagName: 'atomic-component-error',
10-
react: React,
11-
elementClass: LitAtomicComponentError,
12-
});
13-
148
export const AtomicIcon = createComponent({
159
tagName: 'atomic-icon',
1610
react: React,
1711
elementClass: LitAtomicIcon,
1812
});
13+
14+
export const AtomicComponentError = createComponent({
15+
tagName: 'atomic-component-error',
16+
react: React,
17+
elementClass: LitAtomicComponentError,
18+
});

packages/atomic-react/src/components/stencil-generated/commerce/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export const AtomicCommerceProductList = /*@__PURE__*/createReactComponent<JSX.A
2323
export const AtomicCommerceProductsPerPage = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceProductsPerPage, HTMLAtomicCommerceProductsPerPageElement>('atomic-commerce-products-per-page');
2424
export const AtomicCommerceQueryError = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceQueryError, HTMLAtomicCommerceQueryErrorElement>('atomic-commerce-query-error');
2525
export const AtomicCommerceQuerySummary = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceQuerySummary, HTMLAtomicCommerceQuerySummaryElement>('atomic-commerce-query-summary');
26-
export const AtomicCommerceRecommendationInterface = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceRecommendationInterface, HTMLAtomicCommerceRecommendationInterfaceElement>('atomic-commerce-recommendation-interface');
2726
export const AtomicCommerceRecommendationList = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceRecommendationList, HTMLAtomicCommerceRecommendationListElement>('atomic-commerce-recommendation-list');
2827
export const AtomicCommerceRefineModal = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceRefineModal, HTMLAtomicCommerceRefineModalElement>('atomic-commerce-refine-modal');
2928
export const AtomicCommerceRefineToggle = /*@__PURE__*/createReactComponent<JSX.AtomicCommerceRefineToggle, HTMLAtomicCommerceRefineToggleElement>('atomic-commerce-refine-toggle');

0 commit comments

Comments
 (0)