Skip to content

Commit

Permalink
feat(commerce): add location facets actions loader (#4569)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spuffynism authored Oct 23, 2024
1 parent 7b9144d commit 05cb497
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/headless/doc-parser/use-cases/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ const actionLoaders: ActionLoaderConfiguration[] = [
{
initializer: 'loadRegularFacetActions',
},
{
initializer: 'loadLocationFacetActions',
},
// TODO: KIT-3422 - Uncomment when ready to generate typedoc docs
// {
// initializer: 'loadQuerySetActions',
Expand Down
2 changes: 1 addition & 1 deletion packages/headless/src/commerce.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export * from './features/commerce/sort/sort-actions-loader.js';
export * from './features/commerce/facets/core-facet/core-facet-actions-loader.js';
export * from './features/commerce/facets/category-facet/category-facet-actions-loader.js';
export * from './features/commerce/facets/regular-facet/regular-facet-actions-loader.js';
// TODO COMHUB-247 export location facets actions loader
export * from './features/commerce/facets/location-facet/location-facet-actions-loader.js';
export * from './features/commerce/facets/date-facet/date-facet-actions-loader.js';
export * from './features/commerce/facets/numeric-facet/numeric-facet-actions-loader.js';
export * from './features/commerce/query-set/query-set-actions-loader.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {PayloadAction} from '@reduxjs/toolkit';
import {CommerceEngine} from '../../../../app/commerce-engine/commerce-engine.js';
import {commerceFacetSetReducer as commerceFacetSet} from '../facet-set/facet-set-slice.js';
import {
ToggleExcludeFacetValuePayload,
ToggleSelectFacetValuePayload,
} from '../regular-facet/regular-facet-actions.js';
import {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from './location-facet-actions.js';

export type {ToggleExcludeFacetValuePayload, ToggleSelectFacetValuePayload};

/**
* The location facet action creators.
*/
export interface LocationFacetActionCreators {
/**
* Toggles the exclusion of a given location facet value.
*
* @param payload - The action creator payload.
* @returns A dispatchable action.
*/
toggleExcludeLocationFacetValue(
payload: ToggleExcludeFacetValuePayload
): PayloadAction<ToggleExcludeFacetValuePayload>;

/**
* Toggles the selection of a given location facet value.
*
* @param payload - The action creator payload.
* @returns A dispatchable action.
*/
toggleSelectLocationFacetValue(
payload: ToggleSelectFacetValuePayload
): PayloadAction<ToggleSelectFacetValuePayload>;
}

/**
* Loads the commerce facet set reducer and returns the available location facet action creators.
*
* @param engine - The commerce engine.
* @returns An object holding the location facet action creators.
*/
export function loadLocationFacetActions(
engine: CommerceEngine
): LocationFacetActionCreators {
engine.addReducers({commerceFacetSet});
return {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
};
}

0 comments on commit 05cb497

Please sign in to comment.