projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
17109: Handles keep-web's inline wildcard urls correctly.
[arvados-workbench2.git]
/
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 0622f0ff2ee990964f1a13e440f00f5b6a925322..7705a891d8f23e34bf40b96d355ccf0cee4d3bce 100644
(file)
--- a/
src/store/data-explorer/data-explorer-reducer.ts
+++ b/
src/store/data-explorer/data-explorer-reducer.ts
@@
-2,38
+2,54
@@
//
// SPDX-License-Identifier: AGPL-3.0
//
// SPDX-License-Identifier: AGPL-3.0
-import { DataColumn, toggleSortDirection, resetSortDirection } from "../../components/data-table/data-column";
-import actions, { DataExplorerAction } from "./data-explorer-action";
-import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
-import { DataColumns } from "../../components/data-table/data-table";
-
-interface DataExplorer {
+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<any>;
items: any[];
itemsAvailable: number;
page: number;
rowsPerPage: number;
columns: DataColumns<any>;
items: any[];
itemsAvailable: number;
page: number;
rowsPerPage: number;
- rowsPerPageOptions
?
: number[];
+ rowsPerPageOptions: number[];
searchValue: string;
searchValue: string;
+ working?: boolean;
+ requestState: DataTableRequestState;
}
export const initialDataExplorer: DataExplorer = {
}
export const initialDataExplorer: DataExplorer = {
+ fetchMode: DataTableFetchMode.PAGINATED,
columns: [],
items: [],
itemsAvailable: 0,
page: 0,
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<string, DataExplorer | undefined>;
+export type DataExplorerState = Record<string, DataExplorer>;
+
+export const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorerAction) =>
+ dataExplorerActions.match(action, {
+ CLEAR: ({ id }) =>
+ update(state, id, explorer => ({ ...explorer, page: 0, itemsAvailable: 0, items: [] })),
-const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorerAction) =>
- actions.match(action, {
RESET_PAGINATION: ({ id }) =>
update(state, id, explorer => ({ ...explorer, page: 0 })),
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)),
SET_COLUMNS: ({ id, columns }) =>
update(state, id, setColumns(columns)),
@@
-43,12
+59,27
@@
const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorer
SET_ITEMS: ({ id, items, itemsAvailable, page, rowsPerPage }) =>
update(state, id, explorer => ({ ...explorer, items, itemsAvailable, page, rowsPerPage })),
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 })),
SET_ROWS_PER_PAGE: ({ id, rowsPerPage }) =>
update(state, id, explorer => ({ ...explorer, rowsPerPage })),
SET_PAGE: ({ id, page }) =>
update(state, id, explorer => ({ ...explorer, page })),
SET_ROWS_PER_PAGE: ({ id, rowsPerPage }) =>
update(state, id, explorer => ({ ...explorer, rowsPerPage })),
+ 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))),
TOGGLE_SORT: ({ id, columnName }) =>
update(state, id, mapColumns(toggleSort(columnName))),
@@
-58,17
+89,32
@@
const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorer
default: () => state
});
default: () => state
});
-export default dataExplorerReducer;
-
export const getDataExplorer = (state: DataExplorerState, id: string) =>
state[id] || initialDataExplorer;
export const getDataExplorer = (state: DataExplorerState, id: string) =>
state[id] || initialDataExplorer;
+export const getSortColumn = (dataExplorer: DataExplorer) => dataExplorer.columns.find((c: any) =>
+ !!c.sortDirection && c.sortDirection !== SortDirection.NONE);
+
const update = (state: DataExplorerState, id: string, updateFn: (dataExplorer: DataExplorer) => DataExplorer) =>
({ ...state, [id]: updateFn(getDataExplorer(state, id)) });
const update = (state: DataExplorerState, id: string, updateFn: (dataExplorer: DataExplorer) => DataExplorer) =>
({ ...state, [id]: updateFn(getDataExplorer(state, id)) });
+const canUpdateColumns = (prevColumns: DataColumns<any>, nextColumns: DataColumns<any>) => {
+ 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<any>) =>
(dataExplorer: DataExplorer) =>
const setColumns = (columns: DataColumns<any>) =>
(dataExplorer: DataExplorer) =>
- ({ ...dataExplorer, columns });
+ ({ ...dataExplorer, columns
: canUpdateColumns(dataExplorer.columns, columns) ? columns : dataExplorer.columns
});
const mapColumns = (mapFn: (column: DataColumn<any>) => DataColumn<any>) =>
(dataExplorer: DataExplorer) =>
const mapColumns = (mapFn: (column: DataColumn<any>) => DataColumn<any>) =>
(dataExplorer: DataExplorer) =>
@@
-84,7
+130,7
@@
const toggleColumn = (columnName: string) =>
? { ...column, selected: !column.selected }
: column;
? { ...column, selected: !column.selected }
: column;
-const setFilters = (columnName: string, filters: DataTableFilter
Item[]
) =>
+const setFilters = (columnName: string, filters: DataTableFilter
s
) =>
(column: DataColumn<any>) => column.name === columnName
? { ...column, filters }
: column;
(column: DataColumn<any>) => column.name === columnName
? { ...column, filters }
: column;