From f7a90615d80967d63669231c4a4b00e4f96e9864 Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Thu, 8 Aug 2024 18:28:21 -0400 Subject: [PATCH] feat(atomic): add tab support for atomic-sort-dropdown (#4222) This PR allows atomic-sort-dropdown to be visible/hidden based on the currently active tab in the tab manager. https://coveord.atlassian.net/browse/CDX-1554 --------- Co-authored-by: GitHub Actions Bot <> Co-authored-by: Alex Prudhomme <78121423+alexprudhomme@users.noreply.github.com> --- .../src/lib/stencil-generated/components.ts | 4 +- packages/atomic/src/components.d.ts | 16 ++ .../atomic-refine-modal.tsx | 20 ++- .../search/atomic-search-interface/store.ts | 1 + .../atomic-sort-dropdown.tsx | 59 ++++-- .../atomic-sort-expression.tsx | 33 ++++ .../atomic-tab-manager.new.stories.tsx | 29 +++ .../e2e/atomic-tab-manager.e2e.ts | 169 ++++++++++++------ .../atomic-tab-manager/e2e/page-object.ts | 23 +++ packages/atomic/src/pages/examples/tabs.html | 21 ++- 10 files changed, 306 insertions(+), 69 deletions(-) diff --git a/packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/components.ts b/packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/components.ts index 9edae2ad224..759a27e5b19 100644 --- a/packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/components.ts +++ b/packages/atomic-angular/projects/atomic-angular/src/lib/stencil-generated/components.ts @@ -2202,14 +2202,14 @@ export declare interface AtomicSortDropdown extends Components.AtomicSortDropdow @ProxyCmp({ - inputs: ['expression', 'label'] + inputs: ['expression', 'label', 'tabsExcluded', 'tabsIncluded'] }) @Component({ selector: 'atomic-sort-expression', changeDetection: ChangeDetectionStrategy.OnPush, template: '', // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property - inputs: ['expression', 'label'], + inputs: ['expression', 'label', 'tabsExcluded', 'tabsIncluded'], }) export class AtomicSortExpression { protected el: HTMLElement; diff --git a/packages/atomic/src/components.d.ts b/packages/atomic/src/components.d.ts index 244806e18f0..d6961586dd2 100644 --- a/packages/atomic/src/components.d.ts +++ b/packages/atomic/src/components.d.ts @@ -3349,6 +3349,14 @@ export namespace Components { * The non-localized label to display for this expression. */ "label": string; + /** + * The tabs on which the sort expression must not be displayed. This property should not be used at the same time as `tabs-included`. Set this property as a stringified JSON array, e.g., ```html ``` If you don't set this property, the sort expression can be displayed on any tab. Otherwise, the sort expression won't be displayed on any of the specified tabs. + */ + "tabsExcluded": string[] | string; + /** + * The tabs on which the sort expression can be displayed. This property should not be used at the same time as `tabs-excluded`. Set this property as a stringified JSON array, e.g., ```html ``` If you don't set this property, the sort expression can be displayed on any tab. Otherwise, the sort expression can only be displayed on the specified tabs. + */ + "tabsIncluded": string[] | string; } interface AtomicTab { /** @@ -8886,6 +8894,14 @@ declare namespace LocalJSX { * The non-localized label to display for this expression. */ "label": string; + /** + * The tabs on which the sort expression must not be displayed. This property should not be used at the same time as `tabs-included`. Set this property as a stringified JSON array, e.g., ```html ``` If you don't set this property, the sort expression can be displayed on any tab. Otherwise, the sort expression won't be displayed on any of the specified tabs. + */ + "tabsExcluded"?: string[] | string; + /** + * The tabs on which the sort expression can be displayed. This property should not be used at the same time as `tabs-excluded`. Set this property as a stringified JSON array, e.g., ```html ``` If you don't set this property, the sort expression can be displayed on any tab. Otherwise, the sort expression can only be displayed on the specified tabs. + */ + "tabsIncluded"?: string[] | string; } interface AtomicTab { /** diff --git a/packages/atomic/src/components/search/atomic-refine-modal/atomic-refine-modal.tsx b/packages/atomic/src/components/search/atomic-refine-modal/atomic-refine-modal.tsx index 04fa87001e7..2dd82fe3c0f 100644 --- a/packages/atomic/src/components/search/atomic-refine-modal/atomic-refine-modal.tsx +++ b/packages/atomic/src/components/search/atomic-refine-modal/atomic-refine-modal.tsx @@ -13,6 +13,9 @@ import { SearchStatus, FacetManager, buildFacetManager, + TabManager, + TabManagerState, + buildTabManager, } from '@coveo/headless'; import {Component, h, State, Prop, Element, Watch} from '@stencil/core'; import { @@ -20,6 +23,7 @@ import { InitializableComponent, InitializeBindings, } from '../../../utils/initialization-utils'; +import {shouldDisplayOnCurrentTab} from '../../../utils/tab-utils'; import {sortByDocumentPosition} from '../../../utils/utils'; import {findSection} from '../../common/atomic-layout-section/sections'; import { @@ -95,6 +99,10 @@ export class AtomicRefineModal implements InitializableComponent { @State() public facetManagerState!: FacetManagerState; @State() @BindStateToController('sort') public sortState!: SortState; + public tabManager!: TabManager; + @BindStateToController('tabManager') + @State() + public tabManagerState!: TabManagerState; @State() public error!: Error; @Prop({mutable: true}) openButton?: HTMLElement; @@ -126,6 +134,7 @@ export class AtomicRefineModal implements InitializableComponent { this.querySummary = buildQuerySummary(this.bindings.engine); this.searchStatus = buildSearchStatus(this.bindings.engine); this.facetManager = buildFacetManager(this.bindings.engine); + this.tabManager = buildTabManager(this.bindings.engine); this.watchEnabled(this.isOpen); } @@ -229,7 +238,16 @@ export class AtomicRefineModal implements InitializableComponent { option && this.sort.sortBy(option.criteria); } - private buildOption({expression, criteria, label}: SortDropdownOption) { + private buildOption({expression, criteria, label, tabs}: SortDropdownOption) { + if ( + !shouldDisplayOnCurrentTab( + [...tabs.included], + [...tabs.excluded], + this.tabManagerState?.activeTab + ) + ) { + return; + } return (