Skip to content

Commit

Permalink
fix(atomic): Facets don't update correctly in the refine modal when c…
Browse files Browse the repository at this point in the history
…hanging tabs (#4280)

This PR ensures that the facets in the refine modal are shown/hidden
based on which tab is open. Prior to this fix, the refine modal would
show the facets of the previous active tab, not the current one.

https://coveord.atlassian.net/browse/CDX-1586
  • Loading branch information
fpbrault authored Aug 26, 2024
1 parent 19cabeb commit 221e1bc
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 263 deletions.
2 changes: 1 addition & 1 deletion packages/atomic/cypress/e2e/breadbox.cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('Breadbox Test Suites', () => {
});

describe('when excluding from a standard facet', () => {
const selectionIndex = 2;
const selectionIndex = 1;

function setupFacetWithMultipleExcludedValues() {
new TestFixture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ import {
TabManager,
buildTabManager,
} from '@coveo/headless';
import {Component, h, State, Prop, Element, Fragment} from '@stencil/core';
import {
Component,
h,
State,
Prop,
Element,
Fragment,
Watch,
} from '@stencil/core';
import {
AriaLiveRegion,
FocusTargetController,
Expand Down Expand Up @@ -340,17 +348,26 @@ export class AtomicCategoryFacet implements InitializableComponent {
);
}

@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
}
}

public componentShouldUpdate(
next: unknown,
prev: unknown,
propName: keyof AtomicCategoryFacet
) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
if (
this.isCategoryFacetState(prev, propName) &&
this.isCategoryFacetState(next, propName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TabManager,
TabManagerState,
} from '@coveo/headless';
import {Component, h, State, Prop, VNode, Element} from '@stencil/core';
import {Component, h, State, Prop, VNode, Element, Watch} from '@stencil/core';
import {
AriaLiveRegion,
FocusTargetController,
Expand Down Expand Up @@ -348,17 +348,26 @@ export class AtomicColorFacet implements InitializableComponent {
);
}

@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
}
}

public componentShouldUpdate(
next: unknown,
prev: unknown,
propName: keyof AtomicColorFacet
) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
if (propName === 'facetState' && prev && this.withSearch) {
return shouldUpdateFacetSearchComponent(
(next as FacetState).facetSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Element,
VNode,
Fragment,
Watch,
} from '@stencil/core';
import {
AriaLiveRegion,
Expand Down Expand Up @@ -317,17 +318,26 @@ export class AtomicFacet implements InitializableComponent {
this.facetConditionsManager?.stopWatching();
}

@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
}
}

public componentShouldUpdate(
next: unknown,
prev: unknown,
next: FacetState,
prev: FacetState,
propName: keyof AtomicFacet
) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
if (
this.isFacetState(prev, propName) &&
this.isFacetState(next, propName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
TabManager,
TabManagerState,
} from '@coveo/headless';
import {Component, Element, h, Listen, Prop, State} from '@stencil/core';
import {Component, Element, h, Listen, Prop, State, Watch} from '@stencil/core';
import {FocusTargetController} from '../../../../utils/accessibility-utils';
import {
BindStateToController,
Expand Down Expand Up @@ -265,13 +265,19 @@ export class AtomicNumericFacet implements InitializableComponent {
this.tabManager = buildTabManager(this.bindings.engine);
}

public componentShouldUpdate(): void {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facetForRange
);
@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facetForRange
);
}
}

private initializeFacetForInput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TabManager,
TabManagerState,
} from '@coveo/headless';
import {Component, h, State, Prop, VNode, Element} from '@stencil/core';
import {Component, h, State, Prop, VNode, Element, Watch} from '@stencil/core';
import Star from '../../../../images/star.svg';
import {FocusTargetController} from '../../../../utils/accessibility-utils';
import {
Expand Down Expand Up @@ -271,13 +271,19 @@ export class AtomicRatingFacet implements InitializableComponent {
this.dependenciesManager?.stopWatching();
}

public componentShouldUpdate(): void {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
}
}

private get isHidden() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TabManager,
TabManagerState,
} from '@coveo/headless';
import {Component, h, State, Prop, VNode, Element} from '@stencil/core';
import {Component, h, State, Prop, VNode, Element, Watch} from '@stencil/core';
import Star from '../../../../images/star.svg';
import {FocusTargetController} from '../../../../utils/accessibility-utils';
import {
Expand Down Expand Up @@ -214,16 +214,20 @@ export class AtomicRatingRangeFacet implements InitializableComponent {
this.initializeFacet();
this.initializeDependenciesManager();
}

public componentShouldUpdate(): void {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
}
}

public disconnectedCallback() {
if (this.host.isConnected) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
TabManager,
TabManagerState,
} from '@coveo/headless';
import {Component, h, Prop, State, VNode} from '@stencil/core';
import {Component, h, Prop, State, VNode, Watch} from '@stencil/core';
import {getFieldValueCaption} from '../../../../utils/field-utils';
import {
BindStateToController,
Expand Down Expand Up @@ -215,13 +215,19 @@ export class AtomicSegmentedFacet implements InitializableComponent {
);
}

public componentShouldUpdate(): void {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facet
);
}
}

disconnectedCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TabManager,
TabManagerState,
} from '@coveo/headless';
import {Component, Element, h, Listen, Prop, State} from '@stencil/core';
import {Component, Element, h, Listen, Prop, State, Watch} from '@stencil/core';
import {FocusTargetController} from '../../../../utils/accessibility-utils';
import {
BindStateToController,
Expand Down Expand Up @@ -256,13 +256,19 @@ export class AtomicTimeframeFacet implements InitializableComponent {
this.tabManager = buildTabManager(this.bindings.engine);
}

public componentShouldUpdate(): void {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facetForDateRange
);
@Watch('tabManagerState')
watchTabManagerState(
newValue: {activeTab: string},
oldValue: {activeTab: string}
) {
if (newValue?.activeTab !== oldValue?.activeTab) {
updateFacetVisibilityForActiveTab(
[...this.tabsIncluded],
[...this.tabsExcluded],
this.tabManagerState?.activeTab,
this.facetForDateRange
);
}
}

public disconnectedCallback() {
Expand Down
Loading

0 comments on commit 221e1bc

Please sign in to comment.