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 14 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
20 changes: 8 additions & 12 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { AutomaticFacet, CategoryFacetSortCriterion, DateFilterRange, DateRangeRequest, FacetResultsMustMatch, FacetSortCriterion, FoldedResult, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, InteractiveResult, LogLevel as LogLevel1, RangeFacetRangeAlgorithm, RangeFacetSortCriterion, Result, ResultTemplate, ResultTemplateCondition, SearchEngine, SearchStatus } from "@coveo/headless";
import { CategoryFacet, CommerceEngine, DateFacet, InteractiveProduct, LogLevel, NumericFacet, Product, ProductListing, ProductListingSummaryState, ProductTemplate, ProductTemplateCondition, RegularFacet, Search, SearchSummaryState, Summary } from "@coveo/headless/commerce";
import { AutomaticFacet, CategoryFacetSortCriterion, DateFilterRange, DateRangeRequest, FacetResultsMustMatch, FacetSortCriterion, FoldedResult, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, InteractiveResult, LogLevel, RangeFacetRangeAlgorithm, RangeFacetSortCriterion, Result, ResultTemplate, ResultTemplateCondition, SearchEngine, SearchStatus } from "@coveo/headless";
Spuffynism marked this conversation as resolved.
Show resolved Hide resolved
import { CommerceBindings as Bindings } from "./components/commerce/atomic-commerce-interface/atomic-commerce-interface";
import { Range } from "./components/commerce/facets/facet-number-input/atomic-commerce-facet-number-input";
import { i18n } from "i18next";
Expand All @@ -21,23 +20,21 @@ import { unknown as AnyBindings, ItemDisplayBasicLayout as ItemDisplayBasicLayou
import { AnyBindings as AnyBindings1 } from "./components/common/interface/bindings";
import { NumberInputType } from "./components/common/facets/facet-number-input/number-input-type";
import { NumericFilter, NumericFilterState, RelativeDateUnit } from "./components/common/types";
import { InsightEngine, FacetSortCriterion as InsightFacetSortCriterion, FoldedResult as InsightFoldedResult, InteractiveResult as InsightInteractiveResult, LogLevel as InsightLogLevel, RangeFacetRangeAlgorithm as InsightRangeFacetRangeAlgorithm, RangeFacetSortCriterion as InsightRangeFacetSortCriterion, Result as InsightResult, ResultTemplate as InsightResultTemplate, ResultTemplateCondition as InsightResultTemplateCondition, UserAction as IUserAction } from "./components/insight";
import { unknown as InsightEngine, unknown as InsightFacetSortCriterion, unknown as InsightFoldedResult, unknown as InsightInteractiveResult, unknown as InsightLogLevel, unknown as InsightRangeFacetRangeAlgorithm, unknown as InsightRangeFacetSortCriterion, unknown as InsightResult, unknown as InsightResultTemplate, unknown as InsightResultTemplateCondition, unknown as IUserAction } from "./components/insight";
import { InsightInitializationOptions } from "./components/insight/atomic-insight-interface/atomic-insight-interface";
import { AtomicInsightStore } from "./components/insight/atomic-insight-interface/store";
import { InsightResultActionClickedEvent } from "./components/insight/atomic-insight-result-action/atomic-insight-result-action";
import { Section } from "./components/common/atomic-layout-section/sections";
import { AtomicCommonStore, AtomicCommonStoreData } from "./components/common/interface/store";
import { SelectChildProductEventArgs } from "./components/commerce/product-template-components/atomic-product-children/atomic-product-children";
import { TruncateAfter } from "./components/common/expandable-text/expandable-text";
import { RecommendationEngine } from "@coveo/headless/recommendation";
import { InteractiveResult as RecsInteractiveResult, LogLevel as RecsLogLevel, Result as RecsResult, ResultTemplate as RecsResultTemplate, ResultTemplateCondition as RecsResultTemplateCondition } from "./components/recommendations";
import { unknown as RecsInteractiveResult, unknown as RecsLogLevel, unknown as RecsResult, unknown as RecsResultTemplate, unknown as RecsResultTemplateCondition } from "./components/recommendations";
import { RecsInitializationOptions } from "./components/recommendations/atomic-recs-interface/atomic-recs-interface";
import { AtomicRecsStore } from "./components/recommendations/atomic-recs-interface/store";
import { Bindings as Bindings1 } from "./components/search/atomic-search-interface/atomic-search-interface";
import { AriaLabelGenerator as AriaLabelGenerator1 } from "./components/search/search-box-suggestions/atomic-search-box-instant-results/atomic-search-box-instant-results";
import { InitializationOptions } from "./components/search/atomic-search-interface/atomic-search-interface";
export { AutomaticFacet, CategoryFacetSortCriterion, DateFilterRange, DateRangeRequest, FacetResultsMustMatch, FacetSortCriterion, FoldedResult, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, InteractiveResult, LogLevel as LogLevel1, RangeFacetRangeAlgorithm, RangeFacetSortCriterion, Result, ResultTemplate, ResultTemplateCondition, SearchEngine, SearchStatus } from "@coveo/headless";
export { CategoryFacet, CommerceEngine, DateFacet, InteractiveProduct, LogLevel, NumericFacet, Product, ProductListing, ProductListingSummaryState, ProductTemplate, ProductTemplateCondition, RegularFacet, Search, SearchSummaryState, Summary } from "@coveo/headless/commerce";
export { AutomaticFacet, CategoryFacetSortCriterion, DateFilterRange, DateRangeRequest, FacetResultsMustMatch, FacetSortCriterion, FoldedResult, GeneratedAnswer, GeneratedAnswerCitation, InlineLink, InteractiveCitation, InteractiveResult, LogLevel, RangeFacetRangeAlgorithm, RangeFacetSortCriterion, Result, ResultTemplate, ResultTemplateCondition, SearchEngine, SearchStatus } from "@coveo/headless";
export { CommerceBindings as Bindings } from "./components/commerce/atomic-commerce-interface/atomic-commerce-interface";
export { Range } from "./components/commerce/facets/facet-number-input/atomic-commerce-facet-number-input";
export { i18n } from "i18next";
Expand All @@ -52,16 +49,15 @@ export { unknown as AnyBindings, ItemDisplayBasicLayout as ItemDisplayBasicLayou
export { AnyBindings as AnyBindings1 } from "./components/common/interface/bindings";
export { NumberInputType } from "./components/common/facets/facet-number-input/number-input-type";
export { NumericFilter, NumericFilterState, RelativeDateUnit } from "./components/common/types";
export { InsightEngine, FacetSortCriterion as InsightFacetSortCriterion, FoldedResult as InsightFoldedResult, InteractiveResult as InsightInteractiveResult, LogLevel as InsightLogLevel, RangeFacetRangeAlgorithm as InsightRangeFacetRangeAlgorithm, RangeFacetSortCriterion as InsightRangeFacetSortCriterion, Result as InsightResult, ResultTemplate as InsightResultTemplate, ResultTemplateCondition as InsightResultTemplateCondition, UserAction as IUserAction } from "./components/insight";
export { unknown as InsightEngine, unknown as InsightFacetSortCriterion, unknown as InsightFoldedResult, unknown as InsightInteractiveResult, unknown as InsightLogLevel, unknown as InsightRangeFacetRangeAlgorithm, unknown as InsightRangeFacetSortCriterion, unknown as InsightResult, unknown as InsightResultTemplate, unknown as InsightResultTemplateCondition, unknown as IUserAction } from "./components/insight";
export { InsightInitializationOptions } from "./components/insight/atomic-insight-interface/atomic-insight-interface";
export { AtomicInsightStore } from "./components/insight/atomic-insight-interface/store";
export { InsightResultActionClickedEvent } from "./components/insight/atomic-insight-result-action/atomic-insight-result-action";
export { Section } from "./components/common/atomic-layout-section/sections";
export { AtomicCommonStore, AtomicCommonStoreData } from "./components/common/interface/store";
export { SelectChildProductEventArgs } from "./components/commerce/product-template-components/atomic-product-children/atomic-product-children";
export { TruncateAfter } from "./components/common/expandable-text/expandable-text";
export { RecommendationEngine } from "@coveo/headless/recommendation";
export { InteractiveResult as RecsInteractiveResult, LogLevel as RecsLogLevel, Result as RecsResult, ResultTemplate as RecsResultTemplate, ResultTemplateCondition as RecsResultTemplateCondition } from "./components/recommendations";
export { unknown as RecsInteractiveResult, unknown as RecsLogLevel, unknown as RecsResult, unknown as RecsResultTemplate, unknown as RecsResultTemplateCondition } from "./components/recommendations";
export { RecsInitializationOptions } from "./components/recommendations/atomic-recs-interface/atomic-recs-interface";
export { AtomicRecsStore } from "./components/recommendations/atomic-recs-interface/store";
export { Bindings as Bindings1 } from "./components/search/atomic-search-interface/atomic-search-interface";
Expand Down Expand Up @@ -3408,7 +3404,7 @@ export namespace Components {
/**
* The severity level of the messages to log in the console.
*/
"logLevel"?: LogLevel1;
"logLevel"?: LogLevel;
/**
* The search interface [query pipeline](https://docs.coveo.com/en/180/). If the search interface is initialized using [`initializeWithSearchEngine`](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-search-interface/#initializewithsearchengine), the query pipeline should instead be configured in the target engine.
*/
Expand Down Expand Up @@ -9374,7 +9370,7 @@ declare namespace LocalJSX {
/**
* The severity level of the messages to log in the console.
*/
"logLevel"?: LogLevel1;
"logLevel"?: LogLevel;
/**
* The search interface [query pipeline](https://docs.coveo.com/en/180/). If the search interface is initialized using [`initializeWithSearchEngine`](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-search-interface/#initializewithsearchengine), the query pipeline should instead be configured in the target engine.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Context,
ContextState,
buildContext,
LocationFacetValue,
} from '@coveo/headless/commerce';
import {Component, h, State, Element, Prop} from '@stencil/core';
import {FocusTargetController} from '../../../utils/accessibility-utils';
Expand Down Expand Up @@ -42,6 +43,7 @@ import {CommerceBindings} from '../atomic-commerce-interface/atomic-commerce-int

type AnyFacetValue =
| RegularFacetValue
| LocationFacetValue
| NumericFacetValue
| DateFacetValue
| CategoryFacetValue;
Expand Down Expand Up @@ -288,14 +290,19 @@ export class AtomicCommerceBreadbox
(pathValue: string) =>
getFieldValueCaption(field, pathValue, this.bindings.i18n)
);
default:
case 'regular':
return [
getFieldValueCaption(
field,
(value.value as RegularFacetValue).value,
this.bindings.i18n
),
];
default: {
// TODO COMHUB-291 support location breadcrumb
Spuffynism marked this conversation as resolved.
Show resolved Hide resolved
this.bindings.engine.logger.warn('Unexpected breadcrumb type.');
return [];
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class AtomicCommerceFacets implements InitializableComponent<Bindings> {
></atomic-commerce-category-facet>
);
default: {
// TODO COMHUB-291 support location facet
this.bindings.engine.logger.warn('Unexpected facet type.');
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/headless/src/commerce.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export type {
export type {DateFilterRange} from './controllers/core/facets/range-facet/date-facet/headless-core-date-filter.js';
export type {
FacetType,
BaseFacetValue,
FacetValueRequest,
RegularFacetValue,
LocationFacetValueRequest,
Expand Down
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,23 @@ 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', () => {
beforeEach(() => {
breadcrumb.state = 'selected';
deselectBreadcrumb();
});

it('dispatches #toggleSelectActionCreator', () => {
expect(toggleSelectLocationFacetValue).toHaveBeenCalledWith({
facetId,
selection: breadcrumb,
});
});

it('dispatches #fetchProductsActionCreator', () => {
expect(fetchProductsActionCreator).toHaveBeenCalled();
});
});
});

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 @@ -192,16 +186,19 @@ export function buildCoreBreadcrumbManager(
selection,
})
);
dispatch(
updateCoreFacetFreezeCurrentValues({
facetId: facet.facetId,
freezeCurrentValues: false,
})
);

if (facet.type !== 'location') {
dispatch(
updateCoreFacetFreezeCurrentValues({
facetId: facet.facetId,
freezeCurrentValues: false,
})
);
}
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
Expand Up @@ -16,6 +16,7 @@ import {
import {
AnyFacetResponse,
AnyFacetValueResponse,
BaseFacetValue,
CategoryFacetValue,
DateFacetValue,
LocationFacetValue,
Expand Down Expand Up @@ -47,6 +48,7 @@ export type {
DateFacetValue,
CategoryFacetValueRequest,
CategoryFacetValue,
BaseFacetValue,
};

export interface FacetControllerType<T extends FacetType> {
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
Loading
Loading