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 const dataExplorerActions = unionize({
10 CLEAR: ofType<{ id: string }>(),
11 RESET_PAGINATION: ofType<{ id: string }>(),
12 REQUEST_ITEMS: ofType<{ id: string, criteriaChanged?: boolean }>(),
13 SET_FETCH_MODE: ofType<({ id: string, fetchMode: DataTableFetchMode })>(),
14 SET_COLUMNS: ofType<{ id: string, columns: DataColumns<any> }>(),
15 SET_FILTERS: ofType<{ id: string, columnName: string, filters: DataTableFilters }>(),
16 SET_ITEMS: ofType<{ id: string, items: any[], page: number, rowsPerPage: number, itemsAvailable: number }>(),
17 APPEND_ITEMS: ofType<{ id: string, items: any[], page: number, rowsPerPage: number, itemsAvailable: number }>(),
18 SET_PAGE: ofType<{ id: string, page: number }>(),
19 SET_ROWS_PER_PAGE: ofType<{ id: string, rowsPerPage: number }>(),
20 TOGGLE_COLUMN: ofType<{ id: string, columnName: string }>(),
21 TOGGLE_SORT: ofType<{ id: string, columnName: string }>(),
22 SET_EXPLORER_SEARCH_VALUE: ofType<{ id: string, searchValue: string }>(),
25 export type DataExplorerAction = UnionOf<typeof dataExplorerActions>;
27 export const bindDataExplorerActions = (id: string) => ({
29 dataExplorerActions.CLEAR({ id }),
30 RESET_PAGINATION: () =>
31 dataExplorerActions.RESET_PAGINATION({ id }),
32 REQUEST_ITEMS: (criteriaChanged?: boolean) =>
33 dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged }),
34 SET_FETCH_MODE: (payload: { fetchMode: DataTableFetchMode }) =>
35 dataExplorerActions.SET_FETCH_MODE({ ...payload, id }),
36 SET_COLUMNS: (payload: { columns: DataColumns<any> }) =>
37 dataExplorerActions.SET_COLUMNS({ ...payload, id }),
38 SET_FILTERS: (payload: { columnName: string, filters: DataTableFilters }) =>
39 dataExplorerActions.SET_FILTERS({ ...payload, id }),
40 SET_ITEMS: (payload: { items: any[], page: number, rowsPerPage: number, itemsAvailable: number }) =>
41 dataExplorerActions.SET_ITEMS({ ...payload, id }),
42 APPEND_ITEMS: (payload: { items: any[], page: number, rowsPerPage: number, itemsAvailable: number }) =>
43 dataExplorerActions.APPEND_ITEMS({ ...payload, id }),
44 SET_PAGE: (payload: { page: number }) =>
45 dataExplorerActions.SET_PAGE({ ...payload, id }),
46 SET_ROWS_PER_PAGE: (payload: { rowsPerPage: number }) =>
47 dataExplorerActions.SET_ROWS_PER_PAGE({ ...payload, id }),
48 TOGGLE_COLUMN: (payload: { columnName: string }) =>
49 dataExplorerActions.TOGGLE_COLUMN({ ...payload, id }),
50 TOGGLE_SORT: (payload: { columnName: string }) =>
51 dataExplorerActions.TOGGLE_SORT({ ...payload, id }),
52 SET_EXPLORER_SEARCH_VALUE: (payload: { searchValue: string }) =>
53 dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ ...payload, id }),