From 64fcf842a75ade29706401a47759deab406f0dfd Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Mon, 27 Aug 2018 18:16:30 +0200 Subject: [PATCH] Clean up old project store Feature #14102 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/store/project/project-action.ts | 38 ----- src/store/project/project-reducer.test.ts | 165 ------------------- src/store/project/project-reducer.ts | 154 ----------------- src/store/projects/project-update-actions.ts | 4 - src/store/store.ts | 2 - src/views/favorite-panel/favorite-panel.tsx | 5 +- src/views/workbench/workbench.tsx | 6 - 7 files changed, 2 insertions(+), 372 deletions(-) delete mode 100644 src/store/project/project-action.ts delete mode 100644 src/store/project/project-reducer.test.ts delete mode 100644 src/store/project/project-reducer.ts diff --git a/src/store/project/project-action.ts b/src/store/project/project-action.ts deleted file mode 100644 index 4f03ae1c..00000000 --- a/src/store/project/project-action.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import { unionize, ofType, UnionOf } from '~/common/unionize'; -import { ProjectResource } from "~/models/project"; -import { Dispatch } from "redux"; -import { FilterBuilder } from "~/common/api/filter-builder"; -import { RootState } from "../store"; -import { updateFavorites } from "../favorites/favorites-actions"; -import { ServiceRepository } from "~/services/services"; -import { resourcesActions } from '~/store/resources/resources-actions'; - -export const projectActions = unionize({ - REMOVE_PROJECT: ofType(), - PROJECTS_REQUEST: ofType(), - PROJECTS_SUCCESS: ofType<{ projects: ProjectResource[], parentItemId?: string }>(), - TOGGLE_PROJECT_TREE_ITEM_OPEN: ofType(), - TOGGLE_PROJECT_TREE_ITEM_ACTIVE: ofType(), - RESET_PROJECT_TREE_ACTIVITY: ofType() -}); - -export const getProjectList = (parentUuid: string = '') => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(projectActions.PROJECTS_REQUEST(parentUuid)); - return services.projectService.list({ - filters: new FilterBuilder() - .addEqual("ownerUuid", parentUuid) - .getFilters() - }).then(({ items: projects }) => { - dispatch(projectActions.PROJECTS_SUCCESS({ projects, parentItemId: parentUuid })); - dispatch(updateFavorites(projects.map(project => project.uuid))); - dispatch(resourcesActions.SET_RESOURCES(projects)); - return projects; - }); - }; - -export type ProjectAction = UnionOf; diff --git a/src/store/project/project-reducer.test.ts b/src/store/project/project-reducer.test.ts deleted file mode 100644 index 56a62534..00000000 --- a/src/store/project/project-reducer.test.ts +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import { projectsReducer, getTreePath } from "./project-reducer"; -import { projectActions } from "./project-action"; -import { TreeItem, TreeItemStatus } from "~/components/tree/tree"; -import { mockProjectResource } from "~/models/test-utils"; - -describe('project-reducer', () => { - - it('should load projects', () => { - const initialState = undefined; - - const projects = [mockProjectResource({ uuid: "1" }), mockProjectResource({ uuid: "2" })]; - const state = projectsReducer(initialState, projectActions.PROJECTS_SUCCESS({ projects, parentItemId: undefined })); - expect(state).toEqual({ - items: [{ - active: false, - open: false, - id: "1", - items: [], - data: mockProjectResource({ uuid: "1" }), - status: TreeItemStatus.INITIAL - }, { - active: false, - open: false, - id: "2", - items: [], - data: mockProjectResource({ uuid: "2" }), - status: TreeItemStatus.INITIAL - } - ], - currentItemId: "" - }); - }); - - it('should remove activity on projects list', () => { - const initialState = { - items: [{ - data: mockProjectResource(), - id: "1", - open: true, - active: true, - status: TreeItemStatus.PENDING - }], - currentItemId: "1" - }; - const project = { - items: [{ - data: mockProjectResource(), - id: "1", - open: true, - active: false, - status: TreeItemStatus.PENDING - }], - currentItemId: "" - }; - - const state = projectsReducer(initialState, projectActions.RESET_PROJECT_TREE_ACTIVITY(initialState.items[0].id)); - expect(state).toEqual(project); - }); - - it('should toggle project tree item activity', () => { - const initialState = { - items: [{ - data: mockProjectResource(), - id: "1", - open: true, - active: false, - status: TreeItemStatus.PENDING - }], - currentItemId: "1" - }; - const project = { - items: [{ - data: mockProjectResource(), - id: "1", - open: true, - active: true, - status: TreeItemStatus.PENDING, - }], - currentItemId: "1" - }; - - const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState.items[0].id)); - expect(state).toEqual(project); - }); - - - it('should close project tree item ', () => { - const initialState = { - items: [{ - data: mockProjectResource(), - id: "1", - open: true, - active: false, - status: TreeItemStatus.PENDING, - }], - currentItemId: "1" - }; - const project = { - items: [{ - data: mockProjectResource(), - id: "1", - open: false, - active: false, - status: TreeItemStatus.PENDING, - }], - currentItemId: "1" - }; - - const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState.items[0].id)); - expect(state).toEqual(project); - }); -}); - -describe("findTreeBranch", () => { - const createTreeItem = (id: string, items?: Array>): TreeItem => ({ - id, - items, - active: false, - data: "", - open: false, - status: TreeItemStatus.INITIAL - }); - - it("should return an array that matches path to the given item", () => { - const tree: Array> = [ - createTreeItem("1", [ - createTreeItem("1.1", [ - createTreeItem("1.1.1"), - createTreeItem("1.1.2") - ]) - ]), - createTreeItem("2", [ - createTreeItem("2.1", [ - createTreeItem("2.1.1"), - createTreeItem("2.1.2") - ]) - ]) - ]; - const branch = getTreePath(tree, "2.1.1"); - expect(branch.map(item => item.id)).toEqual(["2", "2.1", "2.1.1"]); - }); - - it("should return empty array if item is not found", () => { - const tree: Array> = [ - createTreeItem("1", [ - createTreeItem("1.1", [ - createTreeItem("1.1.1"), - createTreeItem("1.1.2") - ]) - ]), - createTreeItem("2", [ - createTreeItem("2.1", [ - createTreeItem("2.1.1"), - createTreeItem("2.1.2") - ]) - ]) - ]; - expect(getTreePath(tree, "3")).toHaveLength(0); - }); - -}); diff --git a/src/store/project/project-reducer.ts b/src/store/project/project-reducer.ts deleted file mode 100644 index 452f6be3..00000000 --- a/src/store/project/project-reducer.ts +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (C) The Arvados Authors. All rights reserved. -// -// SPDX-License-Identifier: AGPL-3.0 - -import * as _ from "lodash"; - -import { projectActions, ProjectAction } from "./project-action"; -import { TreeItem, TreeItemStatus } from "~/components/tree/tree"; -import { ProjectResource } from "~/models/project"; - -export type ProjectState = { - items: Array>, - currentItemId: string -}; - -interface ProjectUpdater { - opened: boolean; - uuid: string; -} - -export function findTreeItem(tree: Array>, itemId: string): TreeItem | undefined { - let item; - for (const t of tree) { - item = t.id === itemId - ? t - : findTreeItem(t.items ? t.items : [], itemId); - if (item) { - break; - } - } - return item; -} - -export function getActiveTreeItem(tree: Array>): TreeItem | undefined { - let item; - for (const t of tree) { - item = t.active - ? t - : getActiveTreeItem(t.items ? t.items : []); - if (item) { - break; - } - } - return item; -} - -export function getTreePath(tree: Array>, itemId: string): Array> { - for (const item of tree) { - if (item.id === itemId) { - return [item]; - } else { - const branch = getTreePath(item.items || [], itemId); - if (branch.length > 0) { - return [item, ...branch]; - } - } - } - return []; -} - -function resetTreeActivity(tree: Array>) { - for (const t of tree) { - t.active = false; - resetTreeActivity(t.items ? t.items : []); - } -} - -function updateProjectTree(tree: Array>, projects: ProjectResource[], parentItemId?: string): Array> { - let treeItem; - if (parentItemId) { - treeItem = findTreeItem(tree, parentItemId); - if (treeItem) { - treeItem.status = TreeItemStatus.LOADED; - } - } - const items = projects.map(p => ({ - id: p.uuid, - open: false, - active: false, - status: TreeItemStatus.INITIAL, - data: p, - items: [] - } as TreeItem)); - - if (treeItem) { - treeItem.items = items; - return tree; - } - - return items; -} - -const initialState: ProjectState = { - items: [], - currentItemId: "" -}; - - -export const projectsReducer = (state: ProjectState = initialState, action: ProjectAction) => { - return projectActions.match(action, { - REMOVE_PROJECT: () => state, - PROJECTS_REQUEST: itemId => { - const items = _.cloneDeep(state.items); - const item = findTreeItem(items, itemId); - if (item) { - item.status = TreeItemStatus.PENDING; - state.items = items; - } - return { ...state, items }; - }, - PROJECTS_SUCCESS: ({ projects, parentItemId }) => { - const items = _.cloneDeep(state.items); - return { - ...state, - items: updateProjectTree(items, projects, parentItemId) - }; - }, - TOGGLE_PROJECT_TREE_ITEM_OPEN: itemId => { - const items = _.cloneDeep(state.items); - const item = findTreeItem(items, itemId); - if (item) { - item.open = !item.open; - } - return { - ...state, - items, - currentItemId: itemId - }; - }, - TOGGLE_PROJECT_TREE_ITEM_ACTIVE: itemId => { - const items = _.cloneDeep(state.items); - resetTreeActivity(items); - const item = findTreeItem(items, itemId); - if (item) { - item.active = true; - } - return { - ...state, - items, - currentItemId: itemId - }; - }, - RESET_PROJECT_TREE_ACTIVITY: () => { - const items = _.cloneDeep(state.items); - resetTreeActivity(items); - return { - ...state, - items, - currentItemId: "" - }; - }, - default: () => state - }); -}; diff --git a/src/store/projects/project-update-actions.ts b/src/store/projects/project-update-actions.ts index 7a4ed89a..39b97b24 100644 --- a/src/store/projects/project-update-actions.ts +++ b/src/store/projects/project-update-actions.ts @@ -5,15 +5,11 @@ import { Dispatch } from "redux"; import { initialize, startSubmit, stopSubmit } from 'redux-form'; import { RootState } from "~/store/store"; -import { loadDetailsPanel } from "~/store/details-panel/details-panel-action"; import { dialogActions } from "~/store/dialog/dialog-actions"; -import { snackbarActions } from "~/store/snackbar/snackbar-actions"; import { ContextMenuResource } from '~/store/context-menu/context-menu-reducer'; import { getCommonResourceServiceError, CommonResourceServiceError } from "~/common/api/common-resource-service"; import { ServiceRepository } from "~/services/services"; import { ProjectResource } from '~/models/project'; -import { getProjectList } from '~/store/project/project-action'; -import { projectPanelActions } from '~/store/project-panel/project-panel-action'; export interface ProjectUpdateFormDialogData { uuid: string; diff --git a/src/store/store.ts b/src/store/store.ts index 0e548c58..abfe187c 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -7,7 +7,6 @@ import { routerMiddleware, routerReducer } from "react-router-redux"; import thunkMiddleware from 'redux-thunk'; import { History } from "history"; -import { projectsReducer } from "./project/project-reducer"; import { authReducer } from "./auth/auth-reducer"; import { dataExplorerReducer } from './data-explorer/data-explorer-reducer'; import { detailsPanelReducer } from './details-panel/details-panel-reducer'; @@ -61,7 +60,6 @@ export function configureStore(history: History, services: ServiceRepository): R const createRootReducer = (services: ServiceRepository) => combineReducers({ auth: authReducer(services), - projects: projectsReducer, collections: collectionsReducer, router: routerReducer, dataExplorer: dataExplorerReducer, diff --git a/src/views/favorite-panel/favorite-panel.tsx b/src/views/favorite-panel/favorite-panel.tsx index 3fd33aef..f02c906a 100644 --- a/src/views/favorite-panel/favorite-panel.tsx +++ b/src/views/favorite-panel/favorite-panel.tsx @@ -8,14 +8,13 @@ import { DataExplorer } from "~/views-components/data-explorer/data-explorer"; import { DispatchProp, connect } from 'react-redux'; import { DataColumns } from '~/components/data-table/data-table'; import { RouteComponentProps } from 'react-router'; -import { RootState } from '~/store/store'; import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters'; import { ContainerRequestState } from '~/models/container-request'; import { SortDirection } from '~/components/data-table/data-column'; import { ResourceKind } from '~/models/resource'; import { resourceLabel } from '~/common/labels'; import { ArvadosTheme } from '~/common/custom-theme'; -import { FAVORITE_PANEL_ID, loadFavoritePanel } from "~/store/favorite-panel/favorite-panel-action"; +import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action"; import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner, ResourceName } from '~/views-components/data-explorer/renderers'; import { FavoriteIcon } from '~/components/icon/icon'; import { Dispatch } from 'redux'; @@ -172,7 +171,7 @@ type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & Di & WithStyles & RouteComponentProps<{ id: string }>; export const FavoritePanel = withStyles(styles)( - connect((state: RootState) => ({ currentItemId: state.projects.currentItemId }), mapDispatchToProps)( + connect(undefined, mapDispatchToProps)( class extends React.Component { render() { return = (theme: ArvadosTheme) => ({ }); interface WorkbenchDataProps { - projects: Array>; - currentProjectId: string; user?: User; currentToken?: string; } @@ -109,8 +105,6 @@ interface WorkbenchState { export const Workbench = withStyles(styles)( connect( (state: RootState) => ({ - projects: state.projects.items, - currentProjectId: state.projects.currentItemId, user: state.auth.user, currentToken: state.auth.apiToken, }) -- 2.30.2