1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
9 export enum DataTableRequestState {
15 export const dataExplorerActions = unionize({
16 CLEAR: ofType<{ id: string }>(),
17 RESET_PAGINATION: ofType<{ id: string }>(),
18 REQUEST_ITEMS: ofType<{ id: string, criteriaChanged?: 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 }>(),
34 export type DataExplorerAction = UnionOf<typeof dataExplorerActions>;
36 export const bindDataExplorerActions = (id: string) => ({
38 dataExplorerActions.CLEAR({ id }),
39 RESET_PAGINATION: () =>
40 dataExplorerActions.RESET_PAGINATION({ id }),
41 REQUEST_ITEMS: (criteriaChanged?: boolean) =>
42 dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged }),
43 SET_FETCH_MODE: (payload: { fetchMode: DataTableFetchMode }) =>
44 dataExplorerActions.SET_FETCH_MODE({ ...payload, id }),
45 SET_COLUMNS: (payload: { columns: DataColumns<any, any> }) =>
46 dataExplorerActions.SET_COLUMNS({ ...payload, id }),
47 SET_FILTERS: (payload: { columnName: string, filters: DataTableFilters }) =>
48 dataExplorerActions.SET_FILTERS({ ...payload, id }),
49 SET_ITEMS: (payload: { items: any[], page: number, rowsPerPage: number, itemsAvailable: number }) =>
50 dataExplorerActions.SET_ITEMS({ ...payload, id }),
51 APPEND_ITEMS: (payload: { items: any[], page: number, rowsPerPage: number, itemsAvailable: number }) =>
52 dataExplorerActions.APPEND_ITEMS({ ...payload, id }),
53 SET_PAGE: (payload: { page: number }) =>
54 dataExplorerActions.SET_PAGE({ ...payload, id }),
55 SET_ROWS_PER_PAGE: (payload: { rowsPerPage: number }) =>
56 dataExplorerActions.SET_ROWS_PER_PAGE({ ...payload, id }),
57 TOGGLE_COLUMN: (payload: { columnName: string }) =>
58 dataExplorerActions.TOGGLE_COLUMN({ ...payload, id }),
59 TOGGLE_SORT: (payload: { columnName: string }) =>
60 dataExplorerActions.TOGGLE_SORT({ ...payload, id }),
61 SET_EXPLORER_SEARCH_VALUE: (payload: { searchValue: string }) =>
62 dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ ...payload, id }),
63 RESET_EXPLORER_SEARCH_VALUE: () =>
64 dataExplorerActions.RESET_EXPLORER_SEARCH_VALUE({ id }),
65 SET_REQUEST_STATE: (payload: { requestState: DataTableRequestState }) =>
66 dataExplorerActions.SET_REQUEST_STATE({ ...payload, id })