X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/d88f3e92dcbf4810fab55f098d7d4296107aa6ab..f470b41502497ccc4b37872cc921d71e57a37986:/src/store/data-explorer/data-explorer-reducer.ts diff --git a/src/store/data-explorer/data-explorer-reducer.ts b/src/store/data-explorer/data-explorer-reducer.ts index 613bf278..7705a891 100644 --- a/src/store/data-explorer/data-explorer-reducer.ts +++ b/src/store/data-explorer/data-explorer-reducer.ts @@ -2,12 +2,18 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { DataColumn, toggleSortDirection, resetSortDirection, SortDirection } from "~/components/data-table/data-column"; -import { dataExplorerActions, DataExplorerAction } from "./data-explorer-action"; -import { DataColumns } from "~/components/data-table/data-table"; +import { + DataColumn, + resetSortDirection, + SortDirection, + toggleSortDirection +} from "~/components/data-table/data-column"; +import { DataExplorerAction, dataExplorerActions, DataTableRequestState } from "./data-explorer-action"; +import { DataColumns, DataTableFetchMode } from "~/components/data-table/data-table"; import { DataTableFilters } from "~/components/data-table-filters/data-table-filters-tree"; export interface DataExplorer { + fetchMode: DataTableFetchMode; columns: DataColumns; items: any[]; itemsAvailable: number; @@ -16,25 +22,34 @@ export interface DataExplorer { rowsPerPageOptions: number[]; searchValue: string; working?: boolean; + requestState: DataTableRequestState; } export const initialDataExplorer: DataExplorer = { + fetchMode: DataTableFetchMode.PAGINATED, columns: [], items: [], itemsAvailable: 0, page: 0, - rowsPerPage: 10, - rowsPerPageOptions: [5, 10, 25, 50], - searchValue: "" + rowsPerPage: 50, + rowsPerPageOptions: [50, 100, 200, 500], + searchValue: "", + requestState: DataTableRequestState.IDLE }; export type DataExplorerState = Record; export const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorerAction) => dataExplorerActions.match(action, { + CLEAR: ({ id }) => + update(state, id, explorer => ({ ...explorer, page: 0, itemsAvailable: 0, items: [] })), + RESET_PAGINATION: ({ id }) => update(state, id, explorer => ({ ...explorer, page: 0 })), + SET_FETCH_MODE: ({ id, fetchMode }) => + update(state, id, explorer => ({ ...explorer, fetchMode })), + SET_COLUMNS: ({ id, columns }) => update(state, id, setColumns(columns)), @@ -44,6 +59,15 @@ export const dataExplorerReducer = (state: DataExplorerState = {}, action: DataE SET_ITEMS: ({ id, items, itemsAvailable, page, rowsPerPage }) => update(state, id, explorer => ({ ...explorer, items, itemsAvailable, page, rowsPerPage })), + APPEND_ITEMS: ({ id, items, itemsAvailable, page, rowsPerPage }) => + update(state, id, explorer => ({ + ...explorer, + items: state[id].items.concat(items), + itemsAvailable: state[id].itemsAvailable + itemsAvailable, + page, + rowsPerPage + })), + SET_PAGE: ({ id, page }) => update(state, id, explorer => ({ ...explorer, page })), @@ -53,6 +77,9 @@ export const dataExplorerReducer = (state: DataExplorerState = {}, action: DataE SET_EXPLORER_SEARCH_VALUE: ({ id, searchValue }) => update(state, id, explorer => ({ ...explorer, searchValue })), + SET_REQUEST_STATE: ({ id, requestState }) => + update(state, id, explorer => ({ ...explorer, requestState })), + TOGGLE_SORT: ({ id, columnName }) => update(state, id, mapColumns(toggleSort(columnName))),