Merge branch 'master'
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 25 Jun 2018 13:34:30 +0000 (15:34 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Mon, 25 Jun 2018 13:34:30 +0000 (15:34 +0200)
Feature #13678

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/index.tsx
src/store/data-explorer/data-explorer-action.ts [new file with mode: 0644]
src/store/data-explorer/data-explorer-reducer.test.tsx [new file with mode: 0644]
src/store/data-explorer/data-explorer-reducer.ts [new file with mode: 0644]
src/store/store.ts
src/views-components/data-explorer/data-explorer.tsx [new file with mode: 0644]
src/views-components/project-explorer/project-explorer.tsx
src/views/project-panel/project-panel.tsx
src/views/workbench/workbench.tsx

index ba395e8b785ab49dd6255427ff90382b43ff6191..580487846f05f9074068b20761c3b81579768f5b 100644 (file)
@@ -18,17 +18,7 @@ import { getProjectList } from "./store/project/project-action";
 
 const history = createBrowserHistory();
 
-const store = configureStore({
-    projects: [
-    ],
-    router: {
-        location: null
-    },
-    auth: {
-        user: undefined
-    },
-    sidePanel: []
-}, history);
+const store = configureStore(history);
 
 store.dispatch(authActions.INIT());
 const rootUuid = authService.getRootUuid();
diff --git a/src/store/data-explorer/data-explorer-action.ts b/src/store/data-explorer/data-explorer-action.ts
new file mode 100644 (file)
index 0000000..7035999
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { default as unionize, ofType, UnionOf } from "unionize";
+import { SortDirection, DataColumn } from "../../components/data-table/data-column";
+import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
+
+type WithId<T> = T & { id: string };
+
+const actions = unionize({
+    SET_COLUMNS: ofType<WithId<{ columns: Array<DataColumn<any>> }>>(),
+    SET_FILTERS: ofType<WithId<{columnName: string, filters: DataTableFilterItem[]}>>(),
+    SET_ITEMS: ofType<WithId<{items: any[]}>>(),
+    SET_PAGE: ofType<WithId<{page: number}>>(),
+    SET_ROWS_PER_PAGE: ofType<WithId<{rowsPerPage: number}>>(),
+    TOGGLE_COLUMN: ofType<WithId<{ columnName: string }>>(),
+    TOGGLE_SORT: ofType<WithId<{ columnName: string }>>(),
+    SET_SEARCH_VALUE: ofType<WithId<{searchValue: string}>>()
+}, { tag: "type", value: "payload" });
+
+export type DataExplorerAction = UnionOf<typeof actions>;
+
+export default actions;
+
+
+
+
diff --git a/src/store/data-explorer/data-explorer-reducer.test.tsx b/src/store/data-explorer/data-explorer-reducer.test.tsx
new file mode 100644 (file)
index 0000000..2a9e56c
--- /dev/null
@@ -0,0 +1,73 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import dataExplorerReducer, { initialDataExplorer } from "./data-explorer-reducer";
+import actions from "./data-explorer-action";
+import { DataColumn } from "../../components/data-table/data-column";
+import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
+
+describe('data-explorer-reducer', () => {
+    it('should set columns', () => {
+        const columns: Array<DataColumn<any>> = [{
+            name: "Column 1",
+            render: jest.fn(),
+            selected: true
+        }];
+        const state = dataExplorerReducer(undefined,
+            actions.SET_COLUMNS({ id: "Data explorer", columns }));
+        expect(state["Data explorer"].columns).toEqual(columns);
+    });
+
+    it('should toggle sorting', () => {
+        const columns: Array<DataColumn<any>> = [{
+            name: "Column 1",
+            render: jest.fn(),
+            selected: true,
+            sortDirection: "asc"
+        }, {
+            name: "Column 2",
+            render: jest.fn(),
+            selected: true,
+            sortDirection: "none",
+        }];
+        const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
+            actions.TOGGLE_SORT({ id: "Data explorer", columnName: "Column 2" }));
+        expect(state["Data explorer"].columns[0].sortDirection).toEqual("none");
+        expect(state["Data explorer"].columns[1].sortDirection).toEqual("asc");
+    });
+
+    it('should set filters', () => {
+        const columns: Array<DataColumn<any>> = [{
+            name: "Column 1",
+            render: jest.fn(),
+            selected: true,
+        }];
+
+        const filters: DataTableFilterItem[] = [{
+            name: "Filter 1",
+            selected: true
+        }];
+        const state = dataExplorerReducer({ "Data explorer": { ...initialDataExplorer, columns } },
+            actions.SET_FILTERS({ id: "Data explorer", columnName: "Column 1", filters }));
+        expect(state["Data explorer"].columns[0].filters).toEqual(filters);
+    });
+
+    it('should set items', () => {
+        const state = dataExplorerReducer({ "Data explorer": undefined },
+            actions.SET_ITEMS({ id: "Data explorer", items: ["Item 1", "Item 2"] }));
+        expect(state["Data explorer"].items).toEqual(["Item 1", "Item 2"]);
+    });
+
+    it('should set page', () => {
+        const state = dataExplorerReducer({ "Data explorer": undefined },
+            actions.SET_PAGE({ id: "Data explorer", page: 2 }));
+        expect(state["Data explorer"].page).toEqual(2);
+    });
+    
+    it('should set rows per page', () => {
+        const state = dataExplorerReducer({ "Data explorer": undefined },
+            actions.SET_ROWS_PER_PAGE({ id: "Data explorer", rowsPerPage: 5 }));
+        expect(state["Data explorer"].rowsPerPage).toEqual(5);
+    });
+});
diff --git a/src/store/data-explorer/data-explorer-reducer.ts b/src/store/data-explorer/data-explorer-reducer.ts
new file mode 100644 (file)
index 0000000..af1eb46
--- /dev/null
@@ -0,0 +1,67 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// 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";
+
+interface DataExplorer {
+    columns: Array<DataColumn<any>>;
+    items: any[];
+    page: number;
+    rowsPerPage: number;
+    searchValue: string;
+}
+
+export const initialDataExplorer: DataExplorer = {
+    columns: [],
+    items: [],
+    page: 0,
+    rowsPerPage: 0,
+    searchValue: ""
+};
+
+export type DataExplorerState = Record<string, DataExplorer | undefined>;
+
+const dataExplorerReducer = (state: DataExplorerState = {}, action: DataExplorerAction) =>
+    actions.match(action, {
+        SET_COLUMNS: ({ id, columns }) => update(state, id, setColumns(columns)),
+        SET_FILTERS: ({ id, columnName, filters }) => update(state, id, mapColumns(setFilters(columnName, filters))),
+        SET_ITEMS: ({ id, items }) => update(state, id, explorer => ({ ...explorer, items })),
+        SET_PAGE: ({ id, page }) => update(state, id, explorer => ({ ...explorer, page })),
+        SET_ROWS_PER_PAGE: ({ id, rowsPerPage }) => update(state, id, explorer => ({ ...explorer, rowsPerPage })),
+        TOGGLE_SORT: ({ id, columnName }) => update(state, id, mapColumns(toggleSort(columnName))),
+        TOGGLE_COLUMN: ({ id, columnName }) => update(state, id, mapColumns(toggleColumn(columnName))),
+        default: () => state
+    });
+
+export default dataExplorerReducer;
+
+export const get = (state: DataExplorerState, id: string) => state[id] || initialDataExplorer;
+
+const update = (state: DataExplorerState, id: string, updateFn: (dataExplorer: DataExplorer) => DataExplorer) =>
+    ({ ...state, [id]: updateFn(get(state, id)) });
+
+const setColumns = (columns: Array<DataColumn<any>>) =>
+    (dataExplorer: DataExplorer) =>
+        ({ ...dataExplorer, columns });
+
+const mapColumns = (mapFn: (column: DataColumn<any>) => DataColumn<any>) =>
+    (dataExplorer: DataExplorer) =>
+        ({ ...dataExplorer, columns: dataExplorer.columns.map(mapFn) });
+
+const toggleSort = (columnName: string) =>
+    (column: DataColumn<any>) => column.name === columnName
+        ? toggleSortDirection(column)
+        : resetSortDirection(column);
+
+const toggleColumn = (columnName: string) =>
+    (column: DataColumn<any>) => column.name === columnName
+        ? { ...column, selected: !column.selected }
+        : column;
+
+const setFilters = (columnName: string, filters: DataTableFilterItem[]) =>
+    (column: DataColumn<any>) => column.name === columnName
+        ? { ...column, filters }
+        : column;
index 6089caf35cdf409d77ceb5ede5ced2ebc4083967..7092c1d9e80c9740d22f73f308e21b999ae894f9 100644 (file)
@@ -11,6 +11,7 @@ import projectsReducer, { ProjectState } from "./project/project-reducer";
 import sidePanelReducer, { SidePanelState } from './side-panel/side-panel-reducer';
 import authReducer, { AuthState } from "./auth/auth-reducer";
 import collectionsReducer from "./collection/collection-reducer";
+import dataExplorerReducer, { DataExplorerState } from './data-explorer/data-explorer-reducer';
 
 const composeEnhancers =
     (process.env.NODE_ENV === 'development' &&
@@ -21,6 +22,7 @@ export interface RootState {
     auth: AuthState;
     projects: ProjectState;
     router: RouterState;
+    dataExplorer: DataExplorerState;
     sidePanel: SidePanelState;
 }
 
@@ -29,15 +31,16 @@ const rootReducer = combineReducers({
     projects: projectsReducer,
     collections: collectionsReducer,
     router: routerReducer,
+    dataExplorer: dataExplorerReducer,
     sidePanel: sidePanelReducer
 });
 
 
-export default function configureStore(initialState: RootState, history: History) {
+export default function configureStore(history: History) {
     const middlewares: Middleware[] = [
         routerMiddleware(history),
         thunkMiddleware
     ];
     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
-    return createStore(rootReducer, initialState!, enhancer);
+    return createStore(rootReducer, enhancer);
 }
diff --git a/src/views-components/data-explorer/data-explorer.tsx b/src/views-components/data-explorer/data-explorer.tsx
new file mode 100644 (file)
index 0000000..f00664f
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { connect } from "react-redux";
+import { RootState } from "../../store/store";
+import DataExplorer from "../../components/data-explorer/data-explorer";
+import { get } from "../../store/data-explorer/data-explorer-reducer";
+
+export default connect((state: RootState, props: { id: string }) => get(state.dataExplorer, props.id))(DataExplorer);
index 4931c09a5149b67c1b3f5b300a6bf3b8798da093..7fff08a33162d91247bc150a86f620550bb7a03b 100644 (file)
@@ -6,79 +6,15 @@ import * as React from 'react';
 import { ProjectExplorerItem } from './project-explorer-item';
 import { Grid, Typography } from '@material-ui/core';
 import { formatDate, formatFileSize } from '../../common/formatters';
-import DataExplorer from '../../components/data-explorer/data-explorer';
+import DataExplorer from '../data-explorer/data-explorer';
 import { DataColumn, toggleSortDirection, resetSortDirection } from '../../components/data-table/data-column';
 import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
 import { ContextMenuAction } from '../../components/context-menu/context-menu';
+import { DispatchProp, connect } from 'react-redux';
+import actions from "../../store/data-explorer/data-explorer-action";
 
-export interface ProjectExplorerContextActions {
-    onAddToFavourite: (item: ProjectExplorerItem) => void;
-    onCopy: (item: ProjectExplorerItem) => void;
-    onDownload: (item: ProjectExplorerItem) => void;
-    onMoveTo: (item: ProjectExplorerItem) => void;
-    onRemove: (item: ProjectExplorerItem) => void;
-    onRename: (item: ProjectExplorerItem) => void;
-    onShare: (item: ProjectExplorerItem) => void;
-}
-
-interface ProjectExplorerProps {
-    items: ProjectExplorerItem[];
-}
-
-interface ProjectExplorerState {
-    columns: Array<DataColumn<ProjectExplorerItem>>;
-    searchValue: string;
-    page: number;
-    rowsPerPage: number;
-}
-
-class ProjectExplorer extends React.Component<ProjectExplorerProps, ProjectExplorerState> {
-    state: ProjectExplorerState = {
-        searchValue: "",
-        page: 0,
-        rowsPerPage: 10,
-        columns: [{
-            name: "Name",
-            selected: true,
-            sortDirection: "asc",
-            render: renderName
-        }, {
-            name: "Status",
-            selected: true,
-            filters: [{
-                name: "In progress",
-                selected: true
-            }, {
-                name: "Complete",
-                selected: true
-            }],
-            render: renderStatus
-        }, {
-            name: "Type",
-            selected: true,
-            filters: [{
-                name: "Collection",
-                selected: true
-            }, {
-                name: "Group",
-                selected: true
-            }],
-            render: item => renderType(item.type)
-        }, {
-            name: "Owner",
-            selected: true,
-            render: item => renderOwner(item.owner)
-        }, {
-            name: "File size",
-            selected: true,
-            sortDirection: "none",
-            render: item => renderFileSize(item.fileSize)
-        }, {
-            name: "Last modified",
-            selected: true,
-            render: item => renderDate(item.lastModified)
-        }]
-    };
+export const PROJECT_EXPLORER_ID = "projectExplorer";
+class ProjectExplorer extends React.Component<DispatchProp> {
 
     contextMenuActions = [[{
         icon: "fas fa-users fa-fw",
@@ -106,12 +42,8 @@ class ProjectExplorer extends React.Component<ProjectExplorerProps, ProjectExplo
 
     render() {
         return <DataExplorer
-            items={this.props.items}
-            columns={this.state.columns}
+            id={PROJECT_EXPLORER_ID}
             contextActions={this.contextMenuActions}
-            searchValue={this.state.searchValue}
-            page={this.state.page}
-            rowsPerPage={this.state.rowsPerPage}
             onColumnToggle={this.toggleColumn}
             onFiltersChange={this.changeFilters}
             onRowClick={console.log}
@@ -122,34 +54,20 @@ class ProjectExplorer extends React.Component<ProjectExplorerProps, ProjectExplo
             onChangeRowsPerPage={this.changeRowsPerPage} />;
     }
 
+    componentDidMount() {
+        this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_EXPLORER_ID, columns }));
+    }
+
     toggleColumn = (toggledColumn: DataColumn<ProjectExplorerItem>) => {
-        this.setState({
-            columns: this.state.columns.map(column =>
-                column.name === toggledColumn.name
-                    ? { ...column, selected: !column.selected }
-                    : column
-            )
-        });
+        this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_EXPLORER_ID, columnName: toggledColumn.name }));
     }
 
     toggleSort = (toggledColumn: DataColumn<ProjectExplorerItem>) => {
-        this.setState({
-            columns: this.state.columns.map(column =>
-                column.name === toggledColumn.name
-                    ? toggleSortDirection(column)
-                    : resetSortDirection(column)
-            )
-        });
+        this.props.dispatch(actions.TOGGLE_SORT({ id: PROJECT_EXPLORER_ID, columnName: toggledColumn.name }));
     }
 
     changeFilters = (filters: DataTableFilterItem[], updatedColumn: DataColumn<ProjectExplorerItem>) => {
-        this.setState({
-            columns: this.state.columns.map(column =>
-                column.name === updatedColumn.name
-                    ? { ...column, filters }
-                    : column
-            )
-        });
+        this.props.dispatch(actions.SET_FILTERS({ id: PROJECT_EXPLORER_ID, columnName: updatedColumn.name, filters }));
     }
 
     executeAction = (action: ContextMenuAction, item: ProjectExplorerItem) => {
@@ -157,15 +75,15 @@ class ProjectExplorer extends React.Component<ProjectExplorerProps, ProjectExplo
     }
 
     search = (searchValue: string) => {
-        this.setState({ searchValue });
+        this.props.dispatch(actions.SET_SEARCH_VALUE({ id: PROJECT_EXPLORER_ID, searchValue }));
     }
 
     changePage = (page: number) => {
-        this.setState({ page });
+        this.props.dispatch(actions.SET_PAGE({ id: PROJECT_EXPLORER_ID, page }));
     }
 
     changeRowsPerPage = (rowsPerPage: number) => {
-        this.setState({ rowsPerPage });
+        this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_EXPLORER_ID, rowsPerPage }));
     }
 }
 
@@ -221,4 +139,46 @@ const renderStatus = (item: ProjectExplorerItem) =>
         {item.status || "-"}
     </Typography>;
 
-export default ProjectExplorer;
+const columns: Array<DataColumn<ProjectExplorerItem>> = [{
+    name: "Name",
+    selected: true,
+    sortDirection: "asc",
+    render: renderName
+}, {
+    name: "Status",
+    selected: true,
+    filters: [{
+        name: "In progress",
+        selected: true
+    }, {
+        name: "Complete",
+        selected: true
+    }],
+    render: renderStatus
+}, {
+    name: "Type",
+    selected: true,
+    filters: [{
+        name: "Collection",
+        selected: true
+    }, {
+        name: "Group",
+        selected: true
+    }],
+    render: item => renderType(item.type)
+}, {
+    name: "Owner",
+    selected: true,
+    render: item => renderOwner(item.owner)
+}, {
+    name: "File size",
+    selected: true,
+    sortDirection: "none",
+    render: item => renderFileSize(item.fileSize)
+}, {
+    name: "Last modified",
+    selected: true,
+    render: item => renderDate(item.lastModified)
+}];
+
+export default connect()(ProjectExplorer);
index f9e6c8b8e2c0b7f50ce690d0a445de582f71460c..afc6ce0ff353d773826d13bbb1394e094f8dd45e 100644 (file)
@@ -6,9 +6,8 @@ import * as React from 'react';
 import { RouteComponentProps } from 'react-router-dom';
 import { DispatchProp, connect } from 'react-redux';
 import { ProjectState, findTreeItem } from '../../store/project/project-reducer';
-import ProjectExplorer from '../../views-components/project-explorer/project-explorer';
 import { RootState } from '../../store/store';
-import { mapProjectTreeItem } from './project-panel-selectors';
+import ProjectExplorer from '../../views-components/project-explorer/project-explorer';
 
 interface ProjectPanelDataProps {
     projects: ProjectState;
@@ -19,10 +18,8 @@ type ProjectPanelProps = ProjectPanelDataProps & RouteComponentProps<{ name: str
 class ProjectPanel extends React.Component<ProjectPanelProps> {
 
     render() {
-        const project = findTreeItem(this.props.projects, this.props.match.params.name);
-        const projectItems = project && project.items || [];
         return (
-            <ProjectExplorer items={projectItems.map(mapProjectTreeItem)} />
+            <ProjectExplorer />
         );
     }
 }
index 4f9843cb0a3e952786ef3489de8ac29b477796ee..a05d4db564623155cf31468f461f295f883241fe 100644 (file)
@@ -8,6 +8,7 @@ import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
 import { Route, Switch } from "react-router";
 import authActions from "../../store/auth/auth-action";
+import dataExplorerActions from "../../store/data-explorer/data-explorer-action";
 import { User } from "../../models/user";
 import { RootState } from "../../store/store";
 import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../views-components/main-app-bar/main-app-bar';
@@ -17,8 +18,10 @@ import projectActions, { getProjectList } from "../../store/project/project-acti
 import ProjectTree from '../../views-components/project-tree/project-tree';
 import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
 import { Project } from "../../models/project";
-import { getTreePath } from '../../store/project/project-reducer';
+import { getTreePath, findTreeItem } from '../../store/project/project-reducer';
 import ProjectPanel from '../project-panel/project-panel';
+import { PROJECT_EXPLORER_ID } from '../../views-components/project-explorer/project-explorer';
+import { ProjectExplorerItem } from '../../views-components/project-explorer/project-explorer-item';
 import sidePanelActions from '../../store/side-panel/side-panel-action';
 import { projectService } from '../../services/services';
 import SidePanel, { SidePanelItem } from '../../components/side-panel/side-panel';
@@ -189,6 +192,18 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
         });
         this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(itemId));
         this.props.dispatch(push(`/project/${itemId}`));
+
+        const project = findTreeItem(this.props.projects, itemId);
+        const items: ProjectExplorerItem[] = project && project.items
+            ? project.items.map(({ data }) => ({
+                uuid: data.uuid,
+                name: data.name,
+                type: data.kind,
+                owner: data.ownerUuid,
+                lastModified: data.modifiedAt
+            }))
+            : [];
+        this.props.dispatch(dataExplorerActions.SET_ITEMS({ id: PROJECT_EXPLORER_ID, items }));
     }
 
     render() {