19231: Add smaller page sizes (10 and 20 items) to load faster
[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 }>(),
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> }>(),
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     SET_REQUEST_STATE: ofType<{ id: string, requestState: DataTableRequestState }>(),
31 });
32
33 export type DataExplorerAction = UnionOf<typeof dataExplorerActions>;
34
35 export const bindDataExplorerActions = (id: string) => ({
36     CLEAR: () =>
37         dataExplorerActions.CLEAR({ id }),
38     RESET_PAGINATION: () =>
39         dataExplorerActions.RESET_PAGINATION({ id }),
40     REQUEST_ITEMS: (criteriaChanged?: boolean) =>
41         dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged }),
42     SET_FETCH_MODE: (payload: { fetchMode: DataTableFetchMode }) =>
43         dataExplorerActions.SET_FETCH_MODE({ ...payload, id }),
44     SET_COLUMNS: (payload: { columns: DataColumns<any> }) =>
45         dataExplorerActions.SET_COLUMNS({ ...payload, id }),
46     SET_FILTERS: (payload: { columnName: string, filters: DataTableFilters }) =>
47         dataExplorerActions.SET_FILTERS({ ...payload, id }),
48     SET_ITEMS: (payload: { items: any[], page: number, rowsPerPage: number, itemsAvailable: number }) =>
49         dataExplorerActions.SET_ITEMS({ ...payload, id }),
50     APPEND_ITEMS: (payload: { items: any[], page: number, rowsPerPage: number, itemsAvailable: number }) =>
51         dataExplorerActions.APPEND_ITEMS({ ...payload, id }),
52     SET_PAGE: (payload: { page: number }) =>
53         dataExplorerActions.SET_PAGE({ ...payload, id }),
54     SET_ROWS_PER_PAGE: (payload: { rowsPerPage: number }) =>
55         dataExplorerActions.SET_ROWS_PER_PAGE({ ...payload, id }),
56     TOGGLE_COLUMN: (payload: { columnName: string }) =>
57         dataExplorerActions.TOGGLE_COLUMN({ ...payload, id }),
58     TOGGLE_SORT: (payload: { columnName: string }) =>
59         dataExplorerActions.TOGGLE_SORT({ ...payload, id }),
60     SET_EXPLORER_SEARCH_VALUE: (payload: { searchValue: string }) =>
61         dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ ...payload, id }),
62     SET_REQUEST_STATE: (payload: { requestState: DataTableRequestState }) =>
63         dataExplorerActions.SET_REQUEST_STATE({ ...payload, id })
64 });