add react-highlight-word and change autocomplete list
[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 }
14
15 export enum SearchView {
16     BASIC = 'basic',
17     ADVANCED = 'advanced',
18     AUTOCOMPLETE = 'autocomplete'
19 }
20
21 const initialState: SearchBar = {
22     currentView: SearchView.BASIC,
23     open: false,
24     searchResults: [],
25     searchValue: ''
26 };
27
28 export const searchBarReducer = (state = initialState, action: SearchBarActions): SearchBar =>
29     searchBarActions.match(action, {
30         SET_CURRENT_VIEW: currentView => ({ ...state, currentView }),
31         OPEN_SEARCH_VIEW: () => ({ ...state, open: true }),
32         CLOSE_SEARCH_VIEW: () => ({ ...state, open: false }),
33         SET_SEARCH_RESULTS: (searchResults) => ({ ...state, searchResults }),
34         SET_SEARCH_VALUE: (searchValue) => ({ ...state, searchValue }),
35         default: () => state
36     });