From: Michal Klobukowski Date: Fri, 27 Jul 2018 11:56:46 +0000 (+0200) Subject: Create collection-panel-files actions and reducer X-Git-Tag: 1.2.0~16^2~33 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/28f13ae4d15f4f80ff3834d6a7422b4259672a20 Create collection-panel-files actions and reducer Feature #13855 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts new file mode 100644 index 00000000..6997f088 --- /dev/null +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts @@ -0,0 +1,14 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { default as unionize, ofType, UnionOf } from "unionize"; +import { CollectionPanelFilesState, CollectionPanelFile } from "./collection-panel-files-state"; + +export const collectionPanelFilesAction = unionize({ + SET_COLLECTION_FILES: ofType<{ files: CollectionPanelFilesState }>(), + TOGGLE_COLLECTION_FILE_COLLAPSE: ofType<{ id: string }>(), + TOGGLE_COLLECTION_FILE_SELECTION: ofType<{ id: string }>() +}, { tag: 'type', value: 'payload' }); + +export type CollectionPanelFilesAction = UnionOf; \ No newline at end of file diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts new file mode 100644 index 00000000..8869fd30 --- /dev/null +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts @@ -0,0 +1,15 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +export type CollectionPanelFilesState = Array; + +export interface CollectionPanelFile { + parentId: string; + id: string; + name: string; + size: number; + collapsed: boolean; + selected: boolean; + type: string; +} \ No newline at end of file diff --git a/src/store/collection-panel/collection-panel-files/collections-panel-files-reducer.ts b/src/store/collection-panel/collection-panel-files/collections-panel-files-reducer.ts new file mode 100644 index 00000000..8a294e78 --- /dev/null +++ b/src/store/collection-panel/collection-panel-files/collections-panel-files-reducer.ts @@ -0,0 +1,20 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { CollectionPanelFilesState } from "./collection-panel-files-state"; +import { CollectionPanelFilesAction, collectionPanelFilesAction } from "./collection-panel-files-actions"; + +export const collectionPanelFilesReducer = (state: CollectionPanelFilesState = [], action: CollectionPanelFilesAction) => { + return collectionPanelFilesAction.match(action, { + SET_COLLECTION_FILES: data => data.files, + TOGGLE_COLLECTION_FILE_COLLAPSE: data => toggle(state, data.id, "collapsed"), + TOGGLE_COLLECTION_FILE_SELECTION: data => toggle(state, data.id, "selected"), + default: () => state + }); +}; + +const toggle = (state: CollectionPanelFilesState, id: string, key: "collapsed" | "selected") => + state.map(file => file.id === id + ? { ...file, [key]: !file[key] } + : file); \ No newline at end of file