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 RESET_ITEMS_AVAILABLE: ofType<{ id: string }>(),
19 REQUEST_ITEMS: ofType<{ id: string; criteriaChanged?: boolean, background?: boolean }>(),
20 REQUEST_STATE: ofType<{ id: string; criteriaChanged?: boolean }>(),
21 SET_FETCH_MODE: ofType<{ id: string; fetchMode: DataTableFetchMode }>(),
22 SET_COLUMNS: ofType<{ id: string; columns: DataColumns<any, any> }>(),
23 SET_FILTERS: ofType<{ id: string; columnName: string; filters: DataTableFilters }>(),
24 SET_ITEMS: ofType<{ id: string; items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }>(),
25 APPEND_ITEMS: ofType<{ id: string; items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }>(),
26 SET_PAGE: ofType<{ id: string; page: number }>(),
27 SET_ROWS_PER_PAGE: ofType<{ id: string; rowsPerPage: number }>(),
28 TOGGLE_COLUMN: ofType<{ id: string; columnName: string }>(),
29 TOGGLE_SORT: ofType<{ id: string; columnName: string }>(),
30 SET_EXPLORER_SEARCH_VALUE: ofType<{ id: string; searchValue: string }>(),
31 RESET_EXPLORER_SEARCH_VALUE: ofType<{ id: string }>(),
32 SET_REQUEST_STATE: ofType<{ id: string; requestState: DataTableRequestState }>(),
33 SET_IS_NOT_FOUND: ofType<{ id: string; isNotFound: boolean }>(),
36 export type DataExplorerAction = UnionOf<typeof dataExplorerActions>;
38 export const bindDataExplorerActions = (id: string) => ({
39 CLEAR: () => dataExplorerActions.CLEAR({ id }),
40 RESET_PAGINATION: () => dataExplorerActions.RESET_PAGINATION({ id }),
41 RESET_ITEMS_AVAILABLE: () => dataExplorerActions.RESET_ITEMS_AVAILABLE({ id }),
42 REQUEST_ITEMS: (criteriaChanged?: boolean, background?: boolean) => dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged, background }),
43 SET_FETCH_MODE: (payload: { fetchMode: DataTableFetchMode }) => dataExplorerActions.SET_FETCH_MODE({ ...payload, id }),
44 SET_COLUMNS: (payload: { columns: DataColumns<any, any> }) => dataExplorerActions.SET_COLUMNS({ ...payload, id }),
45 SET_FILTERS: (payload: { columnName: string; filters: DataTableFilters }) => dataExplorerActions.SET_FILTERS({ ...payload, id }),
46 SET_ITEMS: (payload: { items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }) =>
47 dataExplorerActions.SET_ITEMS({ ...payload, id }),
48 APPEND_ITEMS: (payload: { items: any[]; page: number; rowsPerPage: number; itemsAvailable: number }) =>
49 dataExplorerActions.APPEND_ITEMS({ ...payload, id }),
50 SET_PAGE: (payload: { page: number }) => dataExplorerActions.SET_PAGE({ ...payload, id }),
51 SET_ROWS_PER_PAGE: (payload: { rowsPerPage: number }) => dataExplorerActions.SET_ROWS_PER_PAGE({ ...payload, id }),
52 TOGGLE_COLUMN: (payload: { columnName: string }) => dataExplorerActions.TOGGLE_COLUMN({ ...payload, id }),
53 TOGGLE_SORT: (payload: { columnName: string }) => dataExplorerActions.TOGGLE_SORT({ ...payload, id }),
54 SET_EXPLORER_SEARCH_VALUE: (payload: { searchValue: string }) => dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ ...payload, id }),
55 RESET_EXPLORER_SEARCH_VALUE: () => dataExplorerActions.RESET_EXPLORER_SEARCH_VALUE({ id }),
56 SET_REQUEST_STATE: (payload: { requestState: DataTableRequestState }) => dataExplorerActions.SET_REQUEST_STATE({ ...payload, id }),
57 SET_IS_NOT_FOUND: (payload: { isNotFound: boolean }) => dataExplorerActions.SET_IS_NOT_FOUND({ ...payload, id }),
60 export type BoundDataExplorerActions = ReturnType<typeof bindDataExplorerActions>;