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

feat(commerce): exclude unused location facets properties #4574

Merged
merged 20 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7c53597
exclude numberOfResults from location facets
Spuffynism Oct 22, 2024
087e763
strip down facet values
Spuffynism Oct 22, 2024
8f77a3c
make non-excludable
Spuffynism Oct 24, 2024
1a609fd
remove preventAutoSelect and freezeCurrentValues
Spuffynism Oct 24, 2024
9d954ed
do not freeze location in breadcrumbs
Spuffynism Oct 24, 2024
9bf5d07
export type needed for documentation
Spuffynism Oct 24, 2024
72ad848
Merge branch 'master' into feature/comhub-247-remove-number-of-values
Spuffynism Oct 24, 2024
824925d
adapt atomic type
Spuffynism Oct 24, 2024
e255b42
prepare to handle location in atomic
Spuffynism Oct 24, 2024
2e743ca
Merge branch 'feature/comhub-247-remove-number-of-values' of github.c…
Spuffynism Oct 24, 2024
e6c0f91
location facet can have more values available
Spuffynism Oct 25, 2024
427fb42
type facet values appropriately
Spuffynism Oct 28, 2024
cb2dc39
Merge branch 'master' into feature/comhub-247-remove-number-of-values
Spuffynism Oct 30, 2024
35fa3b2
run build
Spuffynism Oct 30, 2024
8d52c42
type the facet value to prevent build error
Spuffynism Oct 31, 2024
800a367
Merge branch 'master' into feature/comhub-247-remove-number-of-values
Spuffynism Oct 31, 2024
4e4853a
add generated file
Spuffynism Oct 31, 2024
2a58c4e
Merge branch 'feature/comhub-247-remove-number-of-values' of github.c…
Spuffynism Oct 31, 2024
ecd2340
fix type issue
Spuffynism Oct 31, 2024
6e13101
Merge branch 'master' of github.com:coveo/ui-kit into feature/comhub-…
Spuffynism Oct 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import {
NumericFacetValue,
RegularFacetValue,
} from '../../../../features/commerce/facets/facet-set/interfaces/response.js';
import {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from '../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {toggleSelectLocationFacetValue} from '../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {
toggleExcludeNumericFacetValue,
toggleSelectNumericFacetValue,
Expand Down Expand Up @@ -270,10 +267,12 @@ describe('core breadcrumb manager', () => {
expectBreadcrumbToBePresentInState(breadcrumb);
});

describe.each([
['selected', toggleSelectLocationFacetValue],
['excluded', toggleExcludeLocationFacetValue],
])('#deselect when facet is %s', generateDeselectionTestCases(breadcrumb));
describe('#deselect when facet is selected', () => {
generateDeselectionTestCases(breadcrumb)(
'selected',
toggleSelectLocationFacetValue
);
});
});

describe('numeric facet breadcrumbs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import {
NumericFacetResponse,
RegularFacetResponse,
} from '../../../../features/commerce/facets/facet-set/interfaces/response.js';
import {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from '../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {toggleSelectLocationFacetValue} from '../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {
toggleExcludeNumericFacetValue,
toggleSelectNumericFacetValue,
Expand Down Expand Up @@ -119,17 +116,11 @@ interface ActionCreators {
toggleExcludeActionCreator?: ToggleActionCreator;
}

const facetTypeWithoutExcludeAction: FacetType = 'hierarchical';

const actions: Record<FacetType, ActionCreators> = {
regular: {
toggleSelectActionCreator: toggleSelectFacetValue,
toggleExcludeActionCreator: toggleExcludeFacetValue,
},
location: {
toggleSelectActionCreator: toggleSelectLocationFacetValue,
toggleExcludeActionCreator: toggleExcludeLocationFacetValue,
},
numericalRange: {
toggleSelectActionCreator: toggleSelectNumericFacetValue,
toggleExcludeActionCreator: toggleExcludeNumericFacetValue,
Expand All @@ -138,7 +129,10 @@ const actions: Record<FacetType, ActionCreators> = {
toggleSelectActionCreator: toggleSelectDateFacetValue,
toggleExcludeActionCreator: toggleExcludeDateFacetValue,
},
[facetTypeWithoutExcludeAction]: {
location: {
toggleSelectActionCreator: toggleSelectLocationFacetValue,
},
hierarchical: {
toggleSelectActionCreator: deselectAllValuesInCoreFacet,
},
};
Expand Down Expand Up @@ -201,7 +195,7 @@ export function buildCoreBreadcrumbManager(
dispatch(options.fetchProductsActionCreator());
} else if (
selection.state === 'excluded' &&
facet.type !== facetTypeWithoutExcludeAction
Spuffynism marked this conversation as resolved.
Show resolved Hide resolved
facet.type !== 'location'
) {
dispatch(
actions[facet.type].toggleExcludeActionCreator!({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {LocationFacetRequest} from '../../../../../features/commerce/facets/facet-set/interfaces/request.js';
import {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from '../../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {toggleSelectLocationFacetValue} from '../../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {CommerceAppState} from '../../../../../state/commerce-app-state.js';
import {buildMockCommerceFacetRequest} from '../../../../../test/mock-commerce-facet-request.js';
import {buildMockCommerceLocationFacetResponse} from '../../../../../test/mock-commerce-facet-response.js';
Expand Down Expand Up @@ -88,16 +85,6 @@ describe('LocationFacet', () => {
});
});

it('#toggleExclude dispatches #toggleExcludeLocationFacetValue with correct payload', () => {
const facetValue = buildMockCommerceLocationFacetValue({value: 'TED'});
facet.toggleExclude(facetValue);

expect(toggleExcludeLocationFacetValue).toHaveBeenCalledWith({
facetId,
selection: facetValue,
});
});

it('#type returns "location"', () => {
expect(facet.type).toBe('location');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {CommerceEngine} from '../../../../../app/commerce-engine/commerce-engine.js';
import {LocationFacetValue} from '../../../../../features/commerce/facets/facet-set/interfaces/response.js';
import {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from '../../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {toggleSelectLocationFacetValue} from '../../../../../features/commerce/facets/location-facet/location-facet-actions.js';
import {
CoreCommerceFacet,
CoreCommerceFacetOptions,
Expand All @@ -29,9 +26,9 @@ export type LocationFacetState = Omit<
* The `LocationFacet` sub-controller offers a high-level programming interface for implementing a location commerce
* facet UI component.
*/
export type LocationFacet = CoreCommerceFacet<
FacetValueRequest,
LocationFacetValue
export type LocationFacet = Omit<
CoreCommerceFacet<FacetValueRequest, LocationFacetValue>,
'isValueExcluded' | 'toggleExclude' | 'toggleSingleExclude'
> & {
state: LocationFacetState;
} & FacetControllerType<'location'>;
Expand All @@ -52,14 +49,15 @@ export function buildCommerceLocationFacet(
engine: CommerceEngine,
options: LocationFacetOptions
): LocationFacet {
const coreController = buildCoreCommerceFacet<
FacetValueRequest,
LocationFacetValue
>(engine, {
const {
toggleSingleExclude,
toggleExclude,
isValueExcluded,
...coreController
} = buildCoreCommerceFacet<FacetValueRequest, LocationFacetValue>(engine, {
options: {
...options,
toggleSelectActionCreator: toggleSelectLocationFacetValue,
toggleExcludeActionCreator: toggleExcludeLocationFacetValue,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ import {
updateDateFacetValues,
} from '../date-facet/date-facet-actions.js';
import {getFacetIdWithCommerceFieldSuggestionNamespace} from '../facet-search-set/commerce-facet-search-actions.js';
import {
Spuffynism marked this conversation as resolved.
Show resolved Hide resolved
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from '../location-facet/location-facet-actions.js';
import {toggleSelectLocationFacetValue} from '../location-facet/location-facet-actions.js';
import {
toggleExcludeNumericFacetValue,
toggleSelectNumericFacetValue,
Expand Down Expand Up @@ -1005,12 +1002,6 @@ describe('commerceFacetSetReducer', () => {
facetValueState: 'selected' as FacetValueState,
toggleAction: toggleSelectLocationFacetValue,
},
{
title:
'dispatching #toggleExcludeLocationFacetValue with a registered facet id',
facetValueState: 'excluded' as FacetValueState,
toggleAction: toggleExcludeLocationFacetValue,
},
])(
'$title',
({
Expand Down Expand Up @@ -1104,63 +1095,13 @@ describe('commerceFacetSetReducer', () => {
).find((req) => req.value === facetValue.value);
expect(targetValue?.state).toBe('idle');
});

it('sets #preventAutoSelect to true', () => {
const facetValue = buildMockCommerceLocationFacetValue({
value: 'TED',
});
const facetValueRequest =
convertLocationFacetValueToRequest(facetValue);

state[facetId] = buildMockCommerceFacetSlice({
request: buildMockCommerceFacetRequest({
values: [facetValueRequest],
type: 'location',
}),
});

const action = toggleAction({
facetId,
selection: facetValue,
});
const finalState = commerceFacetSetReducer(state, action);

expect(finalState[facetId]?.request.preventAutoSelect).toBe(true);
});

it('sets #freezeCurrentValues to true', () => {
const facetValue = buildMockCommerceLocationFacetValue({
value: 'TED',
});
const facetValueRequest =
convertLocationFacetValueToRequest(facetValue);

state[facetId] = buildMockCommerceFacetSlice({
request: buildMockCommerceFacetRequest({
values: [facetValueRequest],
type: 'location',
}),
});

const action = toggleAction({
facetId,
selection: facetValue,
});
const finalState = commerceFacetSetReducer(state, action);

expect(finalState[facetId]?.request.freezeCurrentValues).toBe(true);
});
});

describe.each([
{
facetValueState: 'selected' as FacetValueState,
toggleAction: toggleSelectLocationFacetValue,
},
{
facetValueState: 'excluded' as FacetValueState,
toggleAction: toggleExcludeLocationFacetValue,
},
])(
'when the facet value does not exist',
({
Expand Down Expand Up @@ -1214,20 +1155,6 @@ describe('commerceFacetSetReducer', () => {
).toBe(2);
expect(finalState[facetId]?.request.values.length).toBe(4);
});

it('sets #preventAutoSelect to true', () => {
state[facetId] = buildMockCommerceFacetSlice({
request: buildMockCommerceFacetRequest({type: 'location'}),
});

const action = toggleAction({
facetId,
selection: buildMockCommerceLocationFacetValue({value: 'TED'}),
});
const finalState = commerceFacetSetReducer(state, action);

expect(finalState[facetId]?.request.preventAutoSelect).toBe(true);
});
}
);
}
Expand Down Expand Up @@ -1258,33 +1185,6 @@ describe('commerceFacetSetReducer', () => {

expect(() => commerceFacetSetReducer(state, action)).not.toThrow();
});

it('dispatching #toggleExcludeLocationFacetValue with an invalid id does not throw', () => {
const facetValue = buildMockCommerceLocationFacetValue({value: 'TED'});
const action = toggleExcludeLocationFacetValue({
facetId: '1',
selection: facetValue,
});

expect(() => commerceFacetSetReducer(state, action)).not.toThrow();
});

it('dispatching #toggleExcludeLocationFacetValue with an invalid facet type does not throw', () => {
const facetValue = buildMockCommerceLocationFacetValue({value: 'TED'});
const facet = buildMockCommerceFacetRequest({
type: 'numericalRange',
values: [facetValue],
});
state[facet.facetId] = buildMockCommerceFacetSlice({
request: facet,
});
const action = toggleExcludeLocationFacetValue({
facetId: facet.facetId,
selection: facetValue,
});

expect(() => commerceFacetSetReducer(state, action)).not.toThrow();
});
});

describe('for numericalRange facets', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ import {
executeCommerceFieldSuggest,
getFacetIdWithCommerceFieldSuggestionNamespace,
} from '../facet-search-set/commerce-facet-search-actions.js';
import {
toggleExcludeLocationFacetValue,
toggleSelectLocationFacetValue,
} from '../location-facet/location-facet-actions.js';
import {toggleSelectLocationFacetValue} from '../location-facet/location-facet-actions.js';
import {
toggleExcludeNumericFacetValue,
toggleSelectNumericFacetValue,
Expand Down Expand Up @@ -136,8 +133,6 @@ export const commerceFacetSetReducer = createReducer(
return;
}

facetRequest.preventAutoSelect = true;

const existingValue = facetRequest.values.find(
(req) => req.value === selection.value
);
Expand All @@ -147,7 +142,6 @@ export const commerceFacetSetReducer = createReducer(
}

updateExistingFacetValueState(existingValue, 'select');
facetRequest.freezeCurrentValues = true;
})
.addCase(toggleSelectNumericFacetValue, (state, action) => {
const {facetId, selection} = action.payload;
Expand Down Expand Up @@ -250,27 +244,6 @@ export const commerceFacetSetReducer = createReducer(
updateExistingFacetValueState(existingValue, 'exclude');
facetRequest.freezeCurrentValues = true;
})
.addCase(toggleExcludeLocationFacetValue, (state, action) => {
const {facetId, selection} = action.payload;
const facetRequest = state[facetId]?.request;

if (!facetRequest || !ensureLocationFacetRequest(facetRequest)) {
return;
}

facetRequest.preventAutoSelect = true;

const existingValue = facetRequest.values.find(
(req) => req.value === selection.value
);
if (!existingValue) {
insertNewValue(facetRequest, selection);
return;
}

updateExistingFacetValueState(existingValue, 'exclude');
facetRequest.freezeCurrentValues = true;
})
.addCase(toggleExcludeNumericFacetValue, (state, action) => {
const {facetId, selection} = action.payload;
const facetRequest = state[facetId]?.request;
Expand Down
Loading
Loading