[ARVADOS-WORKBENCH2] updated: 1.1.4-466-g79a2e3e
Git user
git at public.curoverse.com
Tue Jul 31 08:51:49 EDT 2018
Summary of changes:
src/components/file-tree/file-tree-item.tsx | 15 +++-
.../collection-panel-files-actions.ts | 4 +-
.../collection-panel-files-state.test.ts | 69 +++++++++++++++++
.../collection-panel-files-state.ts | 87 ++++++++++++++++++++--
.../collections-panel-files-reducer.ts | 75 ++++---------------
.../collection-panel-files.ts | 34 +++++----
6 files changed, 198 insertions(+), 86 deletions(-)
create mode 100644 src/store/collection-panel/collection-panel-files/collection-panel-files-state.test.ts
via 79a2e3e107a55d8081647b9bf81369aa7e5ad2ac (commit)
via c3cfdfd215a3c6dd547e1358f3e8d24b55665e9d (commit)
via 76e8c0fe945a04cbf0f2cc6d7cab82d2585d639a (commit)
via 1f6bacd062a8ee17a6631fab64b890f2f6d335ab (commit)
from 3120740061c64645fe8a2015c075add657563921 (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 79a2e3e107a55d8081647b9bf81369aa7e5ad2ac
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Tue Jul 31 14:41:33 2018 +0200
Update collection-panel-container to handle new state structure
Feature #13855
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/views-components/collection-panel-files/collection-panel-files.ts b/src/views-components/collection-panel-files/collection-panel-files.ts
index 86953a0..0542ce9 100644
--- a/src/views-components/collection-panel-files/collection-panel-files.ts
+++ b/src/views-components/collection-panel-files/collection-panel-files.ts
@@ -6,7 +6,7 @@ import { connect } from "react-redux";
import { CollectionPanelFiles as Component, CollectionPanelFilesProps } from "../../components/collection-panel-files/collection-panel-files";
import { RootState } from "../../store/store";
import { TreeItemStatus, TreeItem } from "../../components/tree/tree";
-import { CollectionPanelFile } from "../../store/collection-panel/collection-panel-files/collection-panel-files-state";
+import { CollectionPanelItem } from "../../store/collection-panel/collection-panel-files/collection-panel-files-state";
import { FileTreeData } from "../../components/file-tree/file-tree-data";
import { Dispatch } from "redux";
import { collectionPanelFilesAction } from "../../store/collection-panel/collection-panel-files/collection-panel-files-actions";
@@ -15,13 +15,17 @@ import { ContextMenuKind } from "../context-menu/context-menu";
const mapStateToProps = (state: RootState): Pick<CollectionPanelFilesProps, "items"> => ({
items: state.collectionPanelFiles
- .filter(f => f.parentId === undefined)
- .map(fileToTreeItem(state.collectionPanelFiles))
+ .filter(item => item.parentId === '')
+ .map(collectionItemToTreeItem(state.collectionPanelFiles))
});
const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
- onCollapseToggle: (id) => dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id })),
- onSelectionToggle: (event, item) => dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id })),
+ onCollapseToggle: (id) => {
+ dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id }));
+ },
+ onSelectionToggle: (event, item) => {
+ dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id }));
+ },
onItemMenuOpen: (event, item) => {
event.preventDefault();
dispatch(contextMenuActions.OPEN_CONTEXT_MENU({
@@ -39,20 +43,20 @@ const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps,
export const CollectionPanelFiles = connect(mapStateToProps, mapDispatchToProps)(Component);
-const fileToTreeItem = (files: CollectionPanelFile[]) => (file: CollectionPanelFile): TreeItem<FileTreeData> => {
+const collectionItemToTreeItem = (items: CollectionPanelItem[]) => (item: CollectionPanelItem): TreeItem<FileTreeData> => {
return {
active: false,
data: {
- name: file.name,
- size: file.size,
- type: file.type
+ name: item.name,
+ size: item.type === 'file' ? item.size : undefined,
+ type: item.type
},
- id: file.id,
- items: files
- .filter(f => f.parentId === file.id)
- .map(fileToTreeItem(files)),
- open: !file.collapsed,
- selected: file.selected,
+ id: item.id,
+ items: items
+ .filter(i => i.parentId === item.id)
+ .map(collectionItemToTreeItem(items)),
+ open: item.type === 'directory' ? !item.collapsed : false,
+ selected: item.selected,
status: TreeItemStatus.LOADED
};
};
commit c3cfdfd215a3c6dd547e1358f3e8d24b55665e9d
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Tue Jul 31 14:39:14 2018 +0200
Update collection panel actions and reducer to work with updated state structure
Feature #13855
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
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
index caaa426..90fcf3e 100644
--- 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
@@ -3,10 +3,10 @@
// SPDX-License-Identifier: AGPL-3.0
import { default as unionize, ofType, UnionOf } from "unionize";
-import { CollectionPanelFilesState, CollectionPanelFile } from "./collection-panel-files-state";
+import { KeepManifest } from "../../../models/keep-manifest";
export const collectionPanelFilesAction = unionize({
- SET_COLLECTION_FILES: ofType<{ files: CollectionPanelFilesState }>(),
+ SET_COLLECTION_FILES: ofType<{ manifest: KeepManifest }>(),
TOGGLE_COLLECTION_FILE_COLLAPSE: ofType<{ id: string }>(),
TOGGLE_COLLECTION_FILE_SELECTION: ofType<{ id: string }>(),
SELECT_ALL_COLLECTION_FILES: ofType<{}>(),
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
index 408779c..d4f3bad 100644
--- 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
@@ -2,74 +2,25 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import { CollectionPanelFilesState, CollectionPanelFile } from "./collection-panel-files-state";
+import { CollectionPanelFilesState, CollectionPanelFile, CollectionPanelDirectory, CollectionPanelItem, mapManifestToItems } from "./collection-panel-files-state";
import { CollectionPanelFilesAction, collectionPanelFilesAction } from "./collection-panel-files-actions";
-import { stat } from "fs";
-const initialState: CollectionPanelFilesState = [{
- collapsed: true,
- id: 'Directory 1',
- name: 'Directory 1',
- selected: false,
- type: 'directory',
-}, {
- parentId: 'Directory 1',
- collapsed: true,
- id: 'Directory 1.1',
- name: 'Directory 1.1',
- selected: false,
- type: 'directory',
-}, {
- parentId: 'Directory 1',
- collapsed: true,
- id: 'File 1.1',
- name: 'File 1.1',
- selected: false,
- type: 'file',
-}, {
- collapsed: true,
- id: 'Directory 2',
- name: 'Directory 2',
- selected: false,
- type: 'directory',
-}, {
- parentId: 'Directory 2',
- collapsed: true,
- id: 'Directory 2.1',
- name: 'Directory 2.1',
- selected: false,
- type: 'directory',
-}, {
- parentId: 'Directory 2.1',
- collapsed: true,
- id: 'Directory 2.1.1',
- name: 'Directory 2.1.1',
- selected: false,
- type: 'directory',
-}, {
- parentId: 'Directory 2.1.1',
- collapsed: true,
- id: 'Directory 2.1.1.1',
- name: 'Directory 2.1.1.1',
- selected: false,
- type: 'directory',
-}];
-
-export const collectionPanelFilesReducer = (state: CollectionPanelFilesState = initialState, action: CollectionPanelFilesAction) => {
+export const collectionPanelFilesReducer = (state: CollectionPanelFilesState = [], action: CollectionPanelFilesAction) => {
return collectionPanelFilesAction.match(action, {
- SET_COLLECTION_FILES: data => data.files,
+ SET_COLLECTION_FILES: ({manifest}) => mapManifestToItems(manifest),
TOGGLE_COLLECTION_FILE_COLLAPSE: data => toggleCollapsed(state, data.id),
TOGGLE_COLLECTION_FILE_SELECTION: data => toggleSelected(state, data.id),
- SELECT_ALL_COLLECTION_FILES: () => state.map(file => ({...file, selected: true})),
- UNSELECT_ALL_COLLECTION_FILES: () => state.map(file => ({...file, selected: false})),
+ SELECT_ALL_COLLECTION_FILES: () => state.map(file => ({ ...file, selected: true })),
+ UNSELECT_ALL_COLLECTION_FILES: () => state.map(file => ({ ...file, selected: false })),
default: () => state
});
};
const toggleCollapsed = (state: CollectionPanelFilesState, id: string) =>
- state.map(file => file.id === id
- ? { ...file, collapsed: !file.collapsed }
- : file);
+ state.map((item: CollectionPanelItem) =>
+ item.type === 'directory' && item.id === id
+ ? { ...item, collapsed: !item.collapsed }
+ : item);
const toggleSelected = (state: CollectionPanelFilesState, id: string) =>
toggleAncestors(toggleDescendants(state, id), id);
@@ -83,7 +34,7 @@ const toggleDescendants = (state: CollectionPanelFilesState, id: string) => {
return state;
};
-const toggleAncestors = (state: CollectionPanelFilesState, id: string): CollectionPanelFile[] => {
+const toggleAncestors = (state: CollectionPanelFilesState, id: string): CollectionPanelItem[] => {
const file = state.find(f => f.id === id);
if (file) {
const selected = state
@@ -97,10 +48,10 @@ const toggleAncestors = (state: CollectionPanelFilesState, id: string): Collecti
return state;
};
-const getDescendants = (state: CollectionPanelFilesState) => ({ id }: { id: string }): CollectionPanelFile[] => {
- const root = state.find(f => f.id === id);
+const getDescendants = (state: CollectionPanelFilesState) => ({ id }: { id: string }): CollectionPanelItem[] => {
+ const root = state.find(item => item.id === id);
if (root) {
- return [root].concat(...state.filter(f => f.parentId === id).map(getDescendants(state)));
+ return [root].concat(...state.filter(item => item.parentId === id).map(getDescendants(state)));
} else { return []; }
};
commit 76e8c0fe945a04cbf0f2cc6d7cab82d2585d639a
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Tue Jul 31 14:38:15 2018 +0200
Add collection-panel manifest map utils
Feature #13855
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-state.test.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.test.ts
new file mode 100644
index 0000000..3550bc5
--- /dev/null
+++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.test.ts
@@ -0,0 +1,69 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { parseKeepManifestText } from "../../../models/keep-manifest";
+import { mapManifestToFiles, mapManifestToDirectories } from './collection-panel-files-state';
+
+test('mapManifestToFiles', () => {
+ const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n./c d41d8cd98f00b204e9800998ecf8427e+0 0:0:d`;
+ const manifest = parseKeepManifestText(manifestText);
+ const files = mapManifestToFiles(manifest);
+ expect(files).toEqual([{
+ parentId: '',
+ id: '/a',
+ name: 'a',
+ size: 0,
+ selected: false,
+ type: 'file'
+ }, {
+ parentId: '',
+ id: '/b',
+ name: 'b',
+ size: 0,
+ selected: false,
+ type: 'file'
+ }, {
+ parentId: '',
+ id: '/output.txt',
+ name: 'output.txt',
+ size: 33,
+ selected: false,
+ type: 'file'
+ }, {
+ parentId: '/c',
+ id: '/c/d',
+ name: 'd',
+ size: 0,
+ selected: false,
+ type: 'file'
+ },]);
+});
+
+test('mapManifestToDirectories', () => {
+ const manifestText = `./c/user/results 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt\n`;
+ const manifest = parseKeepManifestText(manifestText);
+ const directories = mapManifestToDirectories(manifest);
+ expect(directories).toEqual([{
+ parentId: "",
+ id: '/c',
+ name: 'c',
+ collapsed: true,
+ selected: false,
+ type: 'directory'
+ }, {
+ parentId: '/c',
+ id: '/c/user',
+ name: 'user',
+ collapsed: true,
+ selected: false,
+ type: 'directory'
+ }, {
+ parentId: '/c/user',
+ id: '/c/user/results',
+ name: 'results',
+ collapsed: true,
+ selected: false,
+ type: 'directory'
+ },]);
+});
\ 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
index 953f4c0..6af2550 100644
--- 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
@@ -2,14 +2,91 @@
//
// SPDX-License-Identifier: AGPL-3.0
-export type CollectionPanelFilesState = Array<CollectionPanelFile>;
+import { uniqBy } from 'lodash';
+import { KeepManifestStream, KeepManifestStreamFile, KeepManifest } from "../../../models/keep-manifest";
-export interface CollectionPanelFile {
+export type CollectionPanelFilesState = Array<CollectionPanelItem>;
+
+export type CollectionPanelItem = CollectionPanelDirectory | CollectionPanelFile;
+
+export interface CollectionPanelDirectory {
parentId?: string;
id: string;
name: string;
- size?: number;
collapsed: boolean;
selected: boolean;
- type: string;
-}
\ No newline at end of file
+ type: 'directory';
+}
+
+export interface CollectionPanelFile {
+ parentId?: string;
+ id: string;
+ name: string;
+ selected: boolean;
+ size: number;
+ type: 'file';
+}
+
+export const mapManifestToItems = (manifest: KeepManifest): CollectionPanelItem[] => ([
+ ...mapManifestToDirectories(manifest),
+ ...mapManifestToFiles(manifest)
+]);
+
+export const mapManifestToDirectories = (manifest: KeepManifest): CollectionPanelDirectory[] =>
+ uniqBy(
+ manifest
+ .map(mapStreamDirectory)
+ .map(splitDirectory)
+ .reduce((all, splitted) => ([...all, ...splitted]), []),
+ directory => directory.id);
+
+export const mapManifestToFiles = (manifest: KeepManifest): CollectionPanelFile[] =>
+ manifest
+ .map(stream => stream.files.map(mapStreamFile(stream)))
+ .reduce((all, current) => ([...all, ...current]), []);
+
+const splitDirectory = (directory: CollectionPanelDirectory): CollectionPanelDirectory[] => {
+ return directory.name
+ .split('/')
+ .slice(1)
+ .map(mapPathComponentToDirectory);
+};
+
+const mapPathComponentToDirectory = (component: string, index: number, components: string[]): CollectionPanelDirectory =>
+ createDirectory({
+ parentId: index === 0 ? '' : joinPathComponents(components, index),
+ id: joinPathComponents(components, index + 1),
+ name: component,
+ });
+
+const joinPathComponents = (components: string[], index: number) =>
+ `/${components.slice(0, index).join('/')}`;
+
+const mapStreamDirectory = (stream: KeepManifestStream): CollectionPanelDirectory =>
+ createDirectory({
+ parentId: '',
+ id: stream.name,
+ name: stream.name,
+ });
+
+const mapStreamFile = (stream: KeepManifestStream) =>
+ (file: KeepManifestStreamFile): CollectionPanelFile =>
+ createFile({
+ parentId: stream.name,
+ id: `${stream.name}/${file.name}`,
+ name: file.name,
+ size: file.size,
+ });
+
+const createDirectory = (data: { parentId: string, id: string, name: string }): CollectionPanelDirectory => ({
+ ...data,
+ collapsed: true,
+ selected: false,
+ type: 'directory'
+});
+
+const createFile = (data: { parentId: string, id: string, name: string, size: number }): CollectionPanelFile => ({
+ ...data,
+ selected: false,
+ type: 'file'
+});
\ No newline at end of file
commit 1f6bacd062a8ee17a6631fab64b890f2f6d335ab
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Tue Jul 31 14:35:36 2018 +0200
Add function for getting correct file tree item icon
Feature #13855
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/components/file-tree/file-tree-item.tsx b/src/components/file-tree/file-tree-item.tsx
index 71e37f1..bbea443 100644
--- a/src/components/file-tree/file-tree-item.tsx
+++ b/src/components/file-tree/file-tree-item.tsx
@@ -4,7 +4,7 @@
import * as React from "react";
import { TreeItem } from "../tree/tree";
-import { ProjectIcon, MoreOptionsIcon } from "../icon/icon";
+import { ProjectIcon, MoreOptionsIcon, DefaultIcon, CollectionIcon } from "../icon/icon";
import { Typography, IconButton, StyleRulesCallback, withStyles, WithStyles } from "@material-ui/core";
import { formatFileSize } from "../../common/formatters";
import { ListItemTextIcon } from "../list-item-text-icon/list-item-text-icon";
@@ -40,7 +40,7 @@ export const FileTreeItem = withStyles(fileTreeItemStyle)(
const { classes, item } = this.props;
return <div className={classes.root}>
<ListItemTextIcon
- icon={ProjectIcon}
+ icon={getIcon(item)}
name={item.data.name} />
<div className={classes.spacer} />
<Typography
@@ -59,3 +59,14 @@ export const FileTreeItem = withStyles(fileTreeItemStyle)(
}
});
+const getIcon = (item: TreeItem<FileTreeData>) => {
+ switch(item.data.type){
+ case 'directory':
+ return ProjectIcon;
+ case 'file':
+ return CollectionIcon;
+ default:
+ return DefaultIcon;
+ }
+};
+
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list