Skip to content

Commit

Permalink
feat(headless): add categoryFacet/updateBasePath action (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-bompart authored Aug 15, 2023
1 parent 9fce780 commit 304b550
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import {
import {
deselectAllCategoryFacetValues,
registerCategoryFacet,
RegisterCategoryFacetActionCreatorPayload,
toggleSelectCategoryFacetValue,
ToggleSelectCategoryFacetValueActionCreatorPayload,
updateCategoryFacetNumberOfValues,
UpdateCategoryFacetNumberOfValuesActionCreatorPayload,
updateCategoryFacetSortCriterion,
updateCategoryFacetBasePath,
RegisterCategoryFacetActionCreatorPayload,
ToggleSelectCategoryFacetValueActionCreatorPayload,
UpdateCategoryFacetNumberOfValuesActionCreatorPayload,
UpdateCategoryFacetSortCriterionActionCreatorPayload,
UpdateCategoryFacetBasePathActionCreatorPayload,
} from './category-facet-set-actions';

export type {
RegisterCategoryFacetActionCreatorPayload,
ToggleSelectCategoryFacetValueActionCreatorPayload,
UpdateCategoryFacetNumberOfValuesActionCreatorPayload,
UpdateCategoryFacetSortCriterionActionCreatorPayload,
UpdateCategoryFacetBasePathActionCreatorPayload,
UpdateFacetAutoSelectionActionCreatorPayload,
};

Expand Down Expand Up @@ -68,7 +71,7 @@ export interface CategoryFacetSetActionCreators {
): PayloadAction<UpdateCategoryFacetNumberOfValuesActionCreatorPayload>;

/**
* Updates the the sort criterion for the category facet.
* Updates the sort criterion for the category facet.
*
* @param payload - The action creator payload.
* @returns A dispatchable action.
Expand All @@ -85,6 +88,16 @@ export interface CategoryFacetSetActionCreators {
updateFacetAutoSelection(
payload: UpdateFacetAutoSelectionActionCreatorPayload
): PayloadAction<UpdateFacetAutoSelectionActionCreatorPayload>;

/**
* Updates the base path for the category facet.
*
* @param payload - The action creator payload.
* @returns A dispatchable action.
*/
updateCategoryFacetBasePath(
payload: UpdateCategoryFacetBasePathActionCreatorPayload
): PayloadAction<UpdateCategoryFacetBasePathActionCreatorPayload>;
}

/**
Expand All @@ -105,5 +118,6 @@ export function loadCategoryFacetSetActions(
updateCategoryFacetNumberOfValues,
updateCategoryFacetSortCriterion,
updateFacetAutoSelection,
updateCategoryFacetBasePath,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface RegisterCategoryFacetActionCreatorPayload {
sortCriteria?: CategoryFacetSortCriterion;
}

const registerCategoryFacetPayloadDefinition = {
const categoryFacetPayloadDefinition = {
facetId: facetIdDefinition,
field: requiredNonEmptyString,
delimitingCharacter: new StringValue({required: false, emptyAllowed: true}),
Expand All @@ -99,7 +99,7 @@ const registerCategoryFacetPayloadDefinition = {
export const registerCategoryFacet = createAction(
'categoryFacet/register',
(payload: RegisterCategoryFacetActionCreatorPayload) =>
validatePayload(payload, registerCategoryFacetPayloadDefinition)
validatePayload(payload, categoryFacetPayloadDefinition)
);

export interface ToggleSelectCategoryFacetValueActionCreatorPayload {
Expand Down Expand Up @@ -134,7 +134,8 @@ export const toggleSelectCategoryFacetValue = createAction(

export const deselectAllCategoryFacetValues = createAction(
'categoryFacet/deselectAll',
(payload: string) => validatePayload(payload, facetIdDefinition)
(payload: string) =>
validatePayload(payload, categoryFacetPayloadDefinition.facetId)
);

export interface UpdateCategoryFacetNumberOfValuesActionCreatorPayload {
Expand All @@ -153,8 +154,8 @@ export const updateCategoryFacetNumberOfValues = createAction(
'categoryFacet/updateNumberOfValues',
(payload: UpdateCategoryFacetNumberOfValuesActionCreatorPayload) =>
validatePayload(payload, {
facetId: facetIdDefinition,
numberOfValues: new NumberValue({required: true, min: 1}),
facetId: categoryFacetPayloadDefinition.facetId,
numberOfValues: categoryFacetPayloadDefinition.numberOfValues,
})
);

Expand All @@ -174,7 +175,28 @@ export const updateCategoryFacetSortCriterion = createAction(
'categoryFacet/updateSortCriterion',
(payload: UpdateCategoryFacetSortCriterionActionCreatorPayload) =>
validatePayload(payload, {
facetId: facetIdDefinition,
facetId: categoryFacetPayloadDefinition.facetId,
criterion: new Value<CategoryFacetSortCriterion>(),
})
);

export interface UpdateCategoryFacetBasePathActionCreatorPayload {
/**
* The unique identifier of the facet (e.g., `"1"`).
*/
facetId: string;

/**
* The base path shared by all values for the facet.
*/
basePath: string[];
}

export const updateCategoryFacetBasePath = createAction(
'categoryFacet/updateBasePath',
(payload: UpdateCategoryFacetBasePathActionCreatorPayload) =>
validatePayload(payload, {
facetId: categoryFacetPayloadDefinition.facetId,
basePath: new ArrayValue({each: requiredNonEmptyString}),
})
);
Loading

0 comments on commit 304b550

Please sign in to comment.