search-results-view
[arvados-workbench2.git] / src / store / search-bar / search-bar-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { searchBarActions, SearchBarActions } from '~/store/search-bar/search-bar-actions';
6 import { GroupContentsResource } from '~/services/groups-service/groups-service';
7
8 interface SearchBar {
9     currentView: string;
10     open: boolean;
11     searchResults: GroupContentsResource[];
12     searchValue: string;
13     savedQueries: string[];
14 }
15
16 export enum SearchView {
17     BASIC = 'basic',
18     ADVANCED = 'advanced',
19     AUTOCOMPLETE = 'autocomplete'
20 }
21
22 const initialState: SearchBar = {
23     currentView: SearchView.BASIC,
24     open: false,
25     searchResults: [],
26     searchValue: '',
27     savedQueries: []
28 };
29
30 export const searchBarReducer = (state = initialState, action: SearchBarActions): SearchBar =>
31     searchBarActions.match(action, {
32         SET_CURRENT_VIEW: currentView => ({ ...state, currentView }),
33         OPEN_SEARCH_VIEW: () => ({ ...state, open: true }),
34         CLOSE_SEARCH_VIEW: () => ({ ...state, open: false }),
35         SET_SEARCH_RESULTS: (searchResults) => ({ ...state, searchResults }),
36         SET_SEARCH_VALUE: (searchValue) => ({ ...state, searchValue }),
37         SET_SAVED_QUERIES: savedQueries => ({ ...state, savedQueries }),
38         default: () => state
39     });