X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/bccb9ca5151f041d8c8b73098a3e1874023e3efa..f80a908d033729d3fb63e2611e3bd11d94fa2a65:/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 c112454b..141d1a9f 100644 --- a/src/store/data-explorer/data-explorer-reducer.ts +++ b/src/store/data-explorer/data-explorer-reducer.ts @@ -2,19 +2,20 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { DataColumn, toggleSortDirection, resetSortDirection } from "../../components/data-table/data-column"; +import { DataColumn, toggleSortDirection, resetSortDirection } from "~/components/data-table/data-column"; import { dataExplorerActions, DataExplorerAction } from "./data-explorer-action"; -import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters"; -import { DataColumns } from "../../components/data-table/data-table"; +import { DataTableFilterItem } from "~/components/data-table-filters/data-table-filters"; +import { DataColumns } from "~/components/data-table/data-table"; -interface DataExplorer { +export interface DataExplorer { columns: DataColumns; items: any[]; itemsAvailable: number; page: number; rowsPerPage: number; - rowsPerPageOptions?: number[]; + rowsPerPageOptions: number[]; searchValue: string; + working?: boolean; } export const initialDataExplorer: DataExplorer = { @@ -27,7 +28,7 @@ export const initialDataExplorer: DataExplorer = { searchValue: "" }; -export type DataExplorerState = Record; +export type DataExplorerState = Record; export const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorerAction) => dataExplorerActions.match(action, { @@ -49,7 +50,7 @@ export const dataExplorerReducer = (state: DataExplorerState = {}, action: DataE SET_ROWS_PER_PAGE: ({ id, rowsPerPage }) => update(state, id, explorer => ({ ...explorer, rowsPerPage })), - SET_SEARCH_VALUE: ({ id, searchValue }) => + SET_EXPLORER_SEARCH_VALUE: ({ id, searchValue }) => update(state, id, explorer => ({ ...explorer, searchValue })), TOGGLE_SORT: ({ id, columnName }) => @@ -67,9 +68,23 @@ export const getDataExplorer = (state: DataExplorerState, id: string) => const update = (state: DataExplorerState, id: string, updateFn: (dataExplorer: DataExplorer) => DataExplorer) => ({ ...state, [id]: updateFn(getDataExplorer(state, id)) }); +const canUpdateColumns = (prevColumns: DataColumns, nextColumns: DataColumns) => { + if (prevColumns.length !== nextColumns.length) { + return true; + } + for (let i = 0; i < nextColumns.length; i++) { + const pc = prevColumns[i]; + const nc = nextColumns[i]; + if (pc.key !== nc.key || pc.name !== nc.name) { + return true; + } + } + return false; +}; + const setColumns = (columns: DataColumns) => (dataExplorer: DataExplorer) => - ({ ...dataExplorer, columns }); + ({ ...dataExplorer, columns: canUpdateColumns(dataExplorer.columns, columns) ? columns : dataExplorer.columns }); const mapColumns = (mapFn: (column: DataColumn) => DataColumn) => (dataExplorer: DataExplorer) =>