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(atomic): add atomic-tab-manager component #4196

Merged
merged 25 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ce13d7c
create tab-manager controller
fpbrault Jul 16, 2024
e86bcdb
remove clearFiltersOnTabChange from registerTab action
fpbrault Jul 17, 2024
94dee8c
remove triggersearch
fpbrault Jul 17, 2024
4ae52e5
rework atomic-tab-manager
fpbrault Jul 16, 2024
b1c830f
remove unused arrayprop
fpbrault Jul 16, 2024
15f74a4
add tabs page example
fpbrault Jul 16, 2024
8aaf0d5
remove triggersearch
fpbrault Jul 17, 2024
60ec970
use tailwind for styling of tab button
fpbrault Jul 18, 2024
199510f
Add generated files
Jul 18, 2024
c29829d
add parts for tab buttons
fpbrault Jul 18, 2024
0fba424
create tab-manager controller
fpbrault Jul 16, 2024
e8b8966
remove clearFiltersOnTabChange from registerTab action
fpbrault Jul 17, 2024
3b59bfb
remove triggersearch
fpbrault Jul 17, 2024
7086575
Merge branch 'CDX-1582' into CDX-1580
fpbrault Jul 19, 2024
01c3edf
clean up core tab manager
fpbrault Jul 23, 2024
addea59
use prepareForSearchWithQuery to clear filters
fpbrault Jul 23, 2024
b31c3f1
Merge branch 'CDX-1582' into CDX-1580
fpbrault Jul 23, 2024
080b6d3
create tab-manager controller
fpbrault Jul 16, 2024
50d6a79
remove clearFiltersOnTabChange from registerTab action
fpbrault Jul 17, 2024
6e9b573
remove triggersearch
fpbrault Jul 17, 2024
6a1dc6f
clean up core tab manager
fpbrault Jul 23, 2024
2d13740
use prepareForSearchWithQuery to clear filters
fpbrault Jul 23, 2024
66e3965
Merge branch 'CDX-1582' into CDX-1580
fpbrault Jul 23, 2024
529e2f3
Merge branch 'master' into CDX-1580
fpbrault Jul 23, 2024
b90c016
Merge branch 'master' into CDX-1580
fpbrault Jul 25, 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
@@ -1,4 +1,3 @@
import {configuration} from '../../../app/common-reducers';
import {tabSetReducer as tabSet} from '../../../features/tab-set/tab-set-slice';
import {
buildMockSearchEngine,
Expand All @@ -21,9 +20,25 @@ describe('Core Tab Manager', () => {
initTabManager();
});

it('returns the current active tab', () => {
expect(engine.state.tabSet).toEqual({});

const tabId = '1';
const expectedTabSet = {
[tabId]: {
id: tabId,
expression: 'test',
isActive: true,
},
};

engine.state.tabSet = expectedTabSet;

expect(engine.state.tabSet).toEqual(expectedTabSet);
});

it('adds the correct reducers to engine', () => {
expect(engine.addReducers).toHaveBeenCalledWith({
configuration,
tabSet,
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {configuration} from '../../../app/common-reducers';
import {createSelector} from '@reduxjs/toolkit';
import {CoreEngine} from '../../../app/engine';
import {tabSetReducer as tabSet} from '../../../features/tab-set/tab-set-slice';
import {ConfigurationSection, TabSection} from '../../../state/state-sections';
import {TabSection} from '../../../state/state-sections';
import {loadReducerError} from '../../../utils/errors';
import {
buildController,
Expand All @@ -23,10 +23,7 @@ export interface TabManagerState {
}

/**
* Creates a `TabManager` controller instance.
*
* @param engine - The headless engine.
* @returns A `TabManager` controller instance.
* @internal
*/
export function buildCoreTabManager(engine: CoreEngine): TabManager {
if (!loadTabReducers(engine)) {
Expand All @@ -35,26 +32,24 @@ export function buildCoreTabManager(engine: CoreEngine): TabManager {

const controller = buildController(engine);

const getCurrentTab = () => {
return (
Object.values(engine.state.tabSet ?? {}).find((tab) => tab.isActive)
?.id ?? ''
);
};
const currentTab = createSelector(
(state: typeof engine.state) => state.tabSet,
(state) => {
const activeTab = Object.values(state).find((tab) => tab.isActive);
return activeTab?.id ?? '';
}
);
fpbrault marked this conversation as resolved.
Show resolved Hide resolved

return {
...controller,

get state() {
const activeTab = getCurrentTab();
return {activeTab};
return {activeTab: currentTab(engine.state)};
},
};
}

function loadTabReducers(
engine: CoreEngine
): engine is CoreEngine<ConfigurationSection & TabSection> {
engine.addReducers({configuration, tabSet});
function loadTabReducers(engine: CoreEngine): engine is CoreEngine<TabSection> {
engine.addReducers({tabSet});
return true;
}
15 changes: 7 additions & 8 deletions packages/headless/src/controllers/core/tab/headless-core-tab.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {BooleanValue, Schema} from '@coveo/bueno';
import {configuration} from '../../../app/common-reducers';
import {CoreEngine} from '../../../app/engine';
import {
deselectAllBreadcrumbs,
deselectAllNonBreadcrumbs,
} from '../../../features/breadcrumb/breadcrumb-actions';
import {getConfigurationInitialState} from '../../../features/configuration/configuration-state';
import {updateQuery} from '../../../features/query/query-actions';
import {prepareForSearchWithQuery} from '../../../features/search/search-actions';
import {
registerTab,
updateActiveTab,
Expand Down Expand Up @@ -136,9 +132,12 @@ export function buildCoreTab(engine: CoreEngine, props: TabProps): Tab {

select() {
if (props.options.clearFiltersOnTabChange) {
dispatch(deselectAllBreadcrumbs());
dispatch(deselectAllNonBreadcrumbs());
dispatch(updateQuery({q: ''}));
dispatch(
prepareForSearchWithQuery({
q: '',
clearFilters: true,
})
);
}
dispatch(updateActiveTab(id));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import {

export type {TabManager, TabManagerState};

/**
* Creates a `Tab Manager` controller instance.
*
* @param engine - The headless engine.
* @param props - The configurable `Tab Manager` properties.
* @returns A `Tab Manager` controller instance.
*/
export function buildTabManager(engine: SearchEngine): TabManager {
const tabManager = buildCoreTabManager(engine);

Expand Down
Loading