Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/quantic-timeframe-facet-automatic-ranges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@coveo/quantic': minor
---

Added the `generateAutomaticRanges` public property to `QuanticTimeframeFacet`, allowing the component to display automatically generated date ranges returned by the API in addition to manually defined `c-quantic-timeframe` ranges.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
field={config.field}
label={config.label}
with-date-picker={config.withDatePicker}
is-collapsed={config.isCollapsed}>
is-collapsed={config.isCollapsed}
generate-automatic-ranges={config.generateAutomaticRanges}>
<c-quantic-timeframe period="next" unit="year"></c-quantic-timeframe>
<c-quantic-timeframe amount="2" unit="week"></c-quantic-timeframe>
<c-quantic-timeframe unit="month"></c-quantic-timeframe>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export default class ExampleQuanticTimeframeFacet extends LightningElement {
description: 'Whether the facet is initially collapsed.',
defaultValue: false,
},
{
attribute: 'generateAutomaticRanges',
label: 'Generate automatic ranges',
description:
'Whether to generate automatic ranges for the facet in addition to the manually defined ranges.',
defaultValue: false,
},
{
attribute: 'useCase',
label: 'Use Case',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,28 @@ describe('c-quantic-timeframe-facet', () => {
);
});

it('should build the facet controller with generateAutomaticRanges set to true when the generateAutomaticRanges property is set to true', async () => {
createTestComponent({
...defaultOptions,
generateAutomaticRanges: true,
});
await flushPromises();

expect(functionsMocks.buildDateFacet).toHaveBeenCalledTimes(1);
expect(functionsMocks.buildDateFacet).toHaveBeenCalledWith(
exampleEngine,
expect.objectContaining({
options: expect.objectContaining({
field: defaultOptions.field,
facetId: defaultOptions.facetId,
generateAutomaticRanges: true,
sortCriteria: 'descending',
injectionDepth: defaultOptions.injectionDepth,
}),
})
);
});

it('should register the facet to the quantic store', async () => {
const expectedFacetType = 'dateFacets';
const element = createTestComponent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {api, LightningElement, track} from 'lwc';
* @category Search
* @category Insight Panel
* @example
* <c-quantic-timeframe-facet engine-id={engineId} field="Date" label="Indexed Date" is-collapsed with-date-picker>
* <c-quantic-timeframe-facet engine-id={engineId} field="Date" label="Indexed Date" is-collapsed with-date-picker generate-automatic-ranges>
* <c-quantic-timeframe period="past" unit="year" amount="10" label="Past decade"></c-quantic-timeframe>
* </c-quantic-timeframe-facet>
*/
Expand Down Expand Up @@ -156,6 +156,13 @@ export default class QuanticTimeframeFacet extends LightningElement {
* @type {DependsOn}
*/
@api dependsOn;
/**
* Whether to generate automatic ranges for the facet in addition to the manually defined `c-quantic-timeframe` ranges.
* @api
* @type {boolean}
* @defaultValue `false`
*/
@api generateAutomaticRanges = false;

static attributes = [
'facetId',
Expand All @@ -165,6 +172,7 @@ export default class QuanticTimeframeFacet extends LightningElement {
'noFilterFacetCount',
'injectionDepth',
'dependsOn',
'generateAutomaticRanges',
];

/** @type {DateFacetState} */
Expand Down Expand Up @@ -476,7 +484,7 @@ export default class QuanticTimeframeFacet extends LightningElement {
options: {
field: this.field,
currentValues: this.currentValues,
generateAutomaticRanges: false,
generateAutomaticRanges: this.generateAutomaticRanges,
sortCriteria: 'descending',
filterFacetCount: !this.noFilterFacetCount,
injectionDepth: Number(this.injectionDepth),
Expand Down
Loading