Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / data-explorer / data-explorer-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize, ofType, UnionOf } from "common/unionize";
6 import { DataColumns, DataTableFetchMode } from "components/data-table/data-table";
7 import { DataTableFilters } from "components/data-table-filters/data-table-filters-tree";
8
9 export enum DataTableRequestState {
10     IDLE,
11     PENDING,
12     NEED_REFRESH,
13 }
14
15 export const dataExplorerActions = unionize({
16     CLEAR: ofType<{ id: string }>(),
17     RESET_PAGINATION: ofType<{ id: string }>(),
18     REQUEST_ITEMS: ofType<{ id: string; criteriaChanged?: boolean, background?: boolean }>(),
19     REQUEST_STATE: ofType<{ id: string; criteriaChanged?: boolean }>(),
20     SET_FETCH_MODE: ofType<{ id: string; fetchMode: DataTableFetchMode }>(),
21     SET_COLUMNS: ofType<{ id: string; columns: DataColumns<any, any> }>(),
22     SET_FILTERS: ofType<{ id: string; columnName: string; filters: DataTableFilters }>(),
23     SET_ITEMS: ofType<{ id: string; items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }>(),
24     APPEND_ITEMS: ofType<{ id: string; items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }>(),
25     SET_PAGE: ofType<{ id: string; page: number }>(),
26     SET_ROWS_PER_PAGE: ofType<{ id: string; rowsPerPage: number }>(),
27     TOGGLE_COLUMN: ofType<{ id: string; columnName: string }>(),
28     TOGGLE_SORT: ofType<{ id: string; columnName: string }>(),
29     SET_EXPLORER_SEARCH_VALUE: ofType<{ id: string; searchValue: string }>(),
30     RESET_EXPLORER_SEARCH_VALUE: ofType<{ id: string }>(),
31     SET_REQUEST_STATE: ofType<{ id: string; requestState: DataTableRequestState }>(),
32 });
33
34 export type DataExplorerAction = UnionOf<typeof dataExplorerActions>;
35
36 export const bindDataExplorerActions = (id: string) => ({
37     CLEAR: () => dataExplorerActions.CLEAR({ id }),
38     RESET_PAGINATION: () => dataExplorerActions.RESET_PAGINATION({ id }),
39     REQUEST_ITEMS: (criteriaChanged?: boolean, background?: boolean) => dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged, background }),
40     SET_FETCH_MODE: (payload: { fetchMode: DataTableFetchMode }) => dataExplorerActions.SET_FETCH_MODE({ ...payload, id }),
41     SET_COLUMNS: (payload: { columns: DataColumns<any, any> }) => dataExplorerActions.SET_COLUMNS({ ...payload, id }),
42     SET_FILTERS: (payload: { columnName: string; filters: DataTableFilters }) => dataExplorerActions.SET_FILTERS({ ...payload, id }),
43     SET_ITEMS: (payload: { items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }) =>
44         dataExplorerActions.SET_ITEMS({ ...payload, id }),
45     APPEND_ITEMS: (payload: { items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }) =>
46         dataExplorerActions.APPEND_ITEMS({ ...payload, id }),
47     SET_PAGE: (payload: { page: number }) => dataExplorerActions.SET_PAGE({ ...payload, id }),
48     SET_ROWS_PER_PAGE: (payload: { rowsPerPage: number }) => dataExplorerActions.SET_ROWS_PER_PAGE({ ...payload, id }),
49     TOGGLE_COLUMN: (payload: { columnName: string }) => dataExplorerActions.TOGGLE_COLUMN({ ...payload, id }),
50     TOGGLE_SORT: (payload: { columnName: string }) => dataExplorerActions.TOGGLE_SORT({ ...payload, id }),
51     SET_EXPLORER_SEARCH_VALUE: (payload: { searchValue: string }) => dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ ...payload, id }),
52     RESET_EXPLORER_SEARCH_VALUE: () => dataExplorerActions.RESET_EXPLORER_SEARCH_VALUE({ id }),
53     SET_REQUEST_STATE: (payload: { requestState: DataTableRequestState }) => dataExplorerActions.SET_REQUEST_STATE({ ...payload, id }),
54 });