X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3cb71e5a3dadfaa307dc948f8933e6ca3af4df60..4b961d16b8f8ef8afbd13697a79fe4684acd0416:/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..0fa32905 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 } 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; @@ -19,6 +25,7 @@ export interface DataExplorer { } export const initialDataExplorer: DataExplorer = { + fetchMode: DataTableFetchMode.PAGINATED, columns: [], items: [], itemsAvailable: 0, @@ -32,9 +39,15 @@ 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 +57,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 })),