[ARVADOS-WORKBENCH2] updated: 1.1.4-618-g5d2d4c9

Git user git at public.curoverse.com
Sat Aug 18 17:37:32 EDT 2018


Summary of changes:
 src/components/data-explorer/data-explorer.tsx     |  4 ++
 src/store/data-explorer/data-explorer-reducer.ts   | 16 +++++-
 .../data-explorer/data-explorer.tsx                | 64 +++++++++++-----------
 3 files changed, 52 insertions(+), 32 deletions(-)

       via  5d2d4c926ba82b3147c7a315e1b5c8a49b71e9d2 (commit)
      from  24034b05e619fefd6015db12be27c812e9b4393d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 5d2d4c926ba82b3147c7a315e1b5c8a49b71e9d2
Author: Daniel Kos <daniel.kos at contractors.roche.com>
Date:   Sat Aug 18 23:37:20 2018 +0200

    Improve setting data explorer columns
    
    Feature #13986
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos at contractors.roche.com>

diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx
index 681caa9..1a26d59 100644
--- a/src/components/data-explorer/data-explorer.tsx
+++ b/src/components/data-explorer/data-explorer.tsx
@@ -51,6 +51,7 @@ interface DataExplorerDataProps<T> {
 }
 
 interface DataExplorerActionProps<T> {
+    onSetColumns: (columns: DataColumns<T>) => void;
     onSearch: (value: string) => void;
     onRowClick: (item: T) => void;
     onRowDoubleClick: (item: T) => void;
@@ -67,6 +68,9 @@ type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T
 
 export const DataExplorer = withStyles(styles)(
     class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
+        componentDidMount() {
+            this.props.onSetColumns(this.props.columns);
+        }
         render() {
             const {
                 columns, onContextMenu, onFiltersChange, onSortToggle, extractKey,
diff --git a/src/store/data-explorer/data-explorer-reducer.ts b/src/store/data-explorer/data-explorer-reducer.ts
index 175cd0b..cc80024 100644
--- a/src/store/data-explorer/data-explorer-reducer.ts
+++ b/src/store/data-explorer/data-explorer-reducer.ts
@@ -67,9 +67,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<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) =>
-        ({ ...dataExplorer, columns });
+        ({ ...dataExplorer, columns: canUpdateColumns(dataExplorer.columns, columns) ? columns : dataExplorer.columns });
 
 const mapColumns = (mapFn: (column: DataColumn<any>) => DataColumn<any>) =>
     (dataExplorer: DataExplorer) =>
diff --git a/src/views-components/data-explorer/data-explorer.tsx b/src/views-components/data-explorer/data-explorer.tsx
index 68eeb3c..d548f60 100644
--- a/src/views-components/data-explorer/data-explorer.tsx
+++ b/src/views-components/data-explorer/data-explorer.tsx
@@ -21,48 +21,50 @@ interface Props {
     extractKey?: (item: any) => React.Key;
 }
 
-const mapStateToProps = (state: RootState, { id }: Props) =>
-    getDataExplorer(state.dataExplorer, id);
+const mapStateToProps = (state: RootState, { id, columns }: Props) => {
+    const s = getDataExplorer(state.dataExplorer, id);
+    if (s.columns.length === 0) {
+        s.columns = columns;
+    }
+    return s;
+};
 
 const mapDispatchToProps = () => {
-    let prevColumns: DataColumns<any>;
-    return (dispatch: Dispatch, { id, columns, onRowClick, onRowDoubleClick, onContextMenu }: Props) => {
-        if (columns !== prevColumns) {
-            prevColumns = columns;
+    return (dispatch: Dispatch, { id, columns, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
+        onSetColumns: (columns: DataColumns<any>) => {
             dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
-        }
-        return {
-            onSearch: (searchValue: string) => {
-                dispatch(dataExplorerActions.SET_SEARCH_VALUE({ id, searchValue }));
-            },
+        },
+
+        onSearch: (searchValue: string) => {
+            dispatch(dataExplorerActions.SET_SEARCH_VALUE({ id, searchValue }));
+        },
 
-            onColumnToggle: (column: DataColumn<any>) => {
-                dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
-            },
+        onColumnToggle: (column: DataColumn<any>) => {
+            dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
+        },
 
-            onSortToggle: (column: DataColumn<any>) => {
-                dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
-            },
+        onSortToggle: (column: DataColumn<any>) => {
+            dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
+        },
 
-            onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
-                dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
-            },
+        onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
+            dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
+        },
 
-            onChangePage: (page: number) => {
-                dispatch(dataExplorerActions.SET_PAGE({ id, page }));
-            },
+        onChangePage: (page: number) => {
+            dispatch(dataExplorerActions.SET_PAGE({ id, page }));
+        },
 
-            onChangeRowsPerPage: (rowsPerPage: number) => {
-                dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
-            },
+        onChangeRowsPerPage: (rowsPerPage: number) => {
+            dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
+        },
 
-            onRowClick,
+        onRowClick,
 
-            onRowDoubleClick,
+        onRowDoubleClick,
 
-            onContextMenu,
-        };
-    };
+        onContextMenu,
+    });
 };
 
 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps())(DataExplorerComponent);

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list