Skip to content

Commit

Permalink
apply pr corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar committed Aug 28, 2024
1 parent 8a0a971 commit 096f184
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 50 deletions.
16 changes: 7 additions & 9 deletions packages/headless/src/app/commerce-engine/commerce-engine.ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export function defineCommerceEngine<
TControllerDefinitions,
SolutionType.search
>;
recommendationEngineDefinition: CommerceEngineDefinition<
standaloneEngineDefinition: CommerceEngineDefinition<
TControllerDefinitions,
SolutionType.recommendation
SolutionType.standalone
>;
} {
const {controllers: controllerDefinitions, ...engineOptions} = options;
Expand Down Expand Up @@ -299,16 +299,14 @@ export function defineCommerceEngine<
hydrateStaticState: hydrateStaticStateFactory(SolutionType.search),
setNavigatorContextProvider,
} as CommerceEngineDefinition<TControllerDefinitions, SolutionType.search>,
recommendationEngineDefinition: {
build: buildFactory(SolutionType.recommendation),
fetchStaticState: fetchStaticStateFactory(SolutionType.recommendation),
hydrateStaticState: hydrateStaticStateFactory(
SolutionType.recommendation
),
standaloneEngineDefinition: {
build: buildFactory(SolutionType.standalone),
fetchStaticState: fetchStaticStateFactory(SolutionType.standalone),
hydrateStaticState: hydrateStaticStateFactory(SolutionType.standalone),
setNavigatorContextProvider,
} as CommerceEngineDefinition<
TControllerDefinitions,
SolutionType.recommendation
SolutionType.standalone
>,
};
}
9 changes: 4 additions & 5 deletions packages/headless/src/app/commerce-ssr-engine/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,15 @@ export function buildControllerDefinitions<
definition['listing'] === false &&
solutionType === SolutionType['listing'];

const unavailableInRecommendationSolutionType =
solutionType === SolutionType['recommendation'] &&
'recommendation' in definition
? definition['recommendation'] === false
const unavailableInStandaloneSolutionType =
solutionType === SolutionType['standalone'] && 'standalone' in definition
? definition['standalone'] === false
: false;

if (
unavailableInSearchSolutionType ||
unavailableInListingSolutionType ||
unavailableInRecommendationSolutionType
unavailableInStandaloneSolutionType
) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/headless/src/app/commerce-ssr-engine/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type {
export enum SolutionType {
search = 'search',
listing = 'listing',
recommendation = 'recommendation',
standalone = 'standalone',
}

export interface ControllerDefinitionWithoutProps<
Expand Down Expand Up @@ -153,7 +153,7 @@ interface UniversalController {
/**
* @internal
*/
[SolutionType.recommendation]: true;
[SolutionType.standalone]: true;
}

interface SearchOnlyController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SearchAndListingControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {UniversalControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {
FieldSuggestionsGenerator,
buildFieldSuggestionsGenerator,
Expand All @@ -17,7 +17,7 @@ export type {GeneratedFieldSuggestionsControllers} from './headless-field-sugges
export type {FieldSuggestionsGenerator};

export interface FieldSuggestionsGeneratorDefinition
extends SearchAndListingControllerDefinitionWithoutProps<FieldSuggestionsGenerator> {}
extends UniversalControllerDefinitionWithoutProps<FieldSuggestionsGenerator> {}

/**
* Defines the `FieldSuggestionsGenerator` controller for the purpose of server-side rendering.
Expand All @@ -30,6 +30,7 @@ export function defineFieldSuggestionsGenerator(): FieldSuggestionsGeneratorDefi
return {
search: true,
listing: true,
standalone: true,
build: (engine) => buildFieldSuggestionsGenerator(engine),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function defineProductView(): ProductViewDefinition {
return {
listing: true,
search: true,
recommendation: true,
standalone: true,
build: (engine) => buildSSRProductView(engine),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function defineRecommendations(
return {
search: true,
listing: true,
recommendation: true,
standalone: true,
build: (engine) => buildRecommendations(engine, props),
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SearchAndListingControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {UniversalControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {StandaloneSearchBoxProps} from '../../standalone-search-box/headless-standalone-search-box';
import {
StandaloneSearchBox,
Expand All @@ -10,7 +10,7 @@ export type {StandaloneSearchBoxState} from './headless-standalone-search-box';
export type {StandaloneSearchBox, StandaloneSearchBoxProps};

export interface StandaloneSearchBoxDefinition
extends SearchAndListingControllerDefinitionWithoutProps<StandaloneSearchBox> {}
extends UniversalControllerDefinitionWithoutProps<StandaloneSearchBox> {}

/**
* Defines the `StandaloneSearchBox` controller for the purpose of server-side rendering.
Expand All @@ -26,6 +26,7 @@ export function defineStandaloneSearchBox(
return {
listing: true,
search: true,
standalone: true,
build: (engine) => buildStandaloneSearchBox(engine, props),
};
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {SearchAndListingControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {SearchOnlyControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {NotifyTrigger} from '../../core/triggers/headless-core-notify-trigger';
import {buildNotifyTrigger} from './headless-notify-trigger';

export type {NotifyTriggerState} from '../../core/triggers/headless-core-notify-trigger';
export type {NotifyTrigger};
export interface NotifyTriggerDefinition
extends SearchAndListingControllerDefinitionWithoutProps<NotifyTrigger> {}
extends SearchOnlyControllerDefinitionWithoutProps<NotifyTrigger> {}

/**
* Defines the `NotifyTrigger` controller for the purpose of server-side rendering.
Expand All @@ -17,7 +17,6 @@ export interface NotifyTriggerDefinition
export function defineNotifyTrigger(): NotifyTriggerDefinition {
return {
search: true,
listing: true,
build: (engine) => buildNotifyTrigger(engine),
};
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {SearchAndListingControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {SearchOnlyControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {QueryTrigger} from '../../core/triggers/headless-core-query-trigger';
import {buildQueryTrigger} from './headless-query-trigger';

export type {QueryTriggerState} from '../../core/triggers/headless-core-query-trigger';
export type {QueryTrigger};
export interface QueryTriggerDefinition
extends SearchAndListingControllerDefinitionWithoutProps<QueryTrigger> {}
extends SearchOnlyControllerDefinitionWithoutProps<QueryTrigger> {}

/**
* Defines the `NotifyTrigger` controller for the purpose of server-side rendering.
Expand All @@ -17,7 +17,6 @@ export interface QueryTriggerDefinition
export function defineQueryTrigger(): QueryTriggerDefinition {
return {
search: true,
listing: true,
build: (engine) => buildQueryTrigger(engine),
};
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {SearchAndListingControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {SearchOnlyControllerDefinitionWithoutProps} from '../../../app/commerce-ssr-engine/types/common';
import {RedirectionTrigger} from '../../core/triggers/headless-core-redirection-trigger';
import {buildRedirectionTrigger} from './headless-redirection-trigger';

export type {RedirectionTriggerState} from '../../core/triggers/headless-core-redirection-trigger';
export type {RedirectionTrigger};
export interface RedirectionTriggerDefinition
extends SearchAndListingControllerDefinitionWithoutProps<RedirectionTrigger> {}
extends SearchOnlyControllerDefinitionWithoutProps<RedirectionTrigger> {}

/**
* Defines the `NotifyTrigger` controller for the purpose of server-side rendering.
Expand All @@ -17,7 +17,6 @@ export interface RedirectionTriggerDefinition
export function defineRedirectionTrigger(): RedirectionTriggerDefinition {
return {
search: true,
listing: true,
build: (engine) => buildRedirectionTrigger(engine),
};
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
'use client';

import {
recommendationEngineDefinition,
RecommendationHydratedState,
RecommendationStaticState,
standaloneEngineDefinition,
StandaloneHydratedState,
StandaloneStaticState,
} from '@/app/_lib/commerce-engine';
import {NavigatorContext} from '@coveo/headless/ssr-commerce';
import {useSearchParams} from 'next/navigation';
import {useEffect, useState} from 'react';
import {Recommendations} from '../recommendation-list';

interface IProductPageProps {
staticState: RecommendationStaticState;
staticState: StandaloneStaticState;
navigatorContext: NavigatorContext;
productId: string;
}

export default function ProductPage(props: IProductPageProps) {
const [hydratedState, setHydratedState] = useState<
RecommendationHydratedState | undefined
StandaloneHydratedState | undefined
>(undefined);

const {staticState, navigatorContext, productId} = props;
Expand All @@ -29,12 +29,12 @@ export default function ProductPage(props: IProductPageProps) {
const name = searchParams.get('name') ?? productId;

// Setting the navigator context provider also in client-side before hydrating the application
recommendationEngineDefinition.setNavigatorContextProvider(
standaloneEngineDefinition.setNavigatorContextProvider(
() => navigatorContext
);

useEffect(() => {
recommendationEngineDefinition
standaloneEngineDefinition
.hydrateStaticState({
searchAction: staticState.searchAction,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
import {NavigatorContext} from '@coveo/headless/ssr-commerce';
import {useEffect, useState} from 'react';
import {
RecommendationStaticState,
RecommendationHydratedState,
recommendationEngineDefinition,
StandaloneStaticState,
StandaloneHydratedState,
standaloneEngineDefinition,
} from '../../_lib/commerce-engine';
import {Recommendations} from '../recommendation-list';

export default function Recommendation({
staticState,
navigatorContext,
}: {
staticState: RecommendationStaticState;
staticState: StandaloneStaticState;
navigatorContext: NavigatorContext;
}) {
const [hydratedState, setHydratedState] = useState<
RecommendationHydratedState | undefined
StandaloneHydratedState | undefined
>(undefined);

// Setting the navigator context provider also in client-side before hydrating the application
recommendationEngineDefinition.setNavigatorContextProvider(
standaloneEngineDefinition.setNavigatorContextProvider(
() => navigatorContext
);

useEffect(() => {
recommendationEngineDefinition
standaloneEngineDefinition
.hydrateStaticState({
searchAction: staticState.searchAction,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const engineDefinition = defineCommerceEngine(engineConfig);
export const {
listingEngineDefinition,
searchEngineDefinition,
recommendationEngineDefinition,
standaloneEngineDefinition,
} = engineDefinition;

export type ListingStaticState = InferStaticState<
Expand All @@ -25,9 +25,9 @@ export type SearchHydratedState = InferHydratedState<
typeof searchEngineDefinition
>;

export type RecommendationStaticState = InferStaticState<
typeof recommendationEngineDefinition
export type StandaloneStaticState = InferStaticState<
typeof standaloneEngineDefinition
>;
export type RecommendationHydratedState = InferHydratedState<
typeof recommendationEngineDefinition
export type StandaloneHydratedState = InferHydratedState<
typeof standaloneEngineDefinition
>;

0 comments on commit 096f184

Please sign in to comment.