Implement sorting in projet-panel
[arvados-workbench2.git] / src / views / project-panel / project-panel-selectors.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { TreeItem } from "../../components/tree/tree";
6 import { Project } from "../../models/project";
7 import { findTreeItem } from "../../store/project/project-reducer";
8 import { ResourceKind } from "../../models/resource";
9 import { Collection } from "../../models/collection";
10 import { getResourceUrl } from "../../store/navigation/navigation-action";
11 import { ProjectExplorerItem } from "../../views-components/project-explorer/project-explorer-item";
12
13 export const projectExplorerItems = (projects: Array<TreeItem<Project>>, treeItemId: string, collections: Array<Collection>): ProjectExplorerItem[] => {
14     const dataItems: ProjectExplorerItem[] = [];
15
16     const treeItem = findTreeItem(projects, treeItemId);
17     if (treeItem) {
18         dataItems.push({
19             name: "..",
20             url: getResourceUrl(treeItem.data),
21             kind: ResourceKind.LEVEL_UP,
22             owner: treeItem.data.ownerUuid,
23             uuid: treeItem.data.uuid,
24             lastModified: treeItem.data.modifiedAt
25         });
26
27         if (treeItem.items) {
28             treeItem.items.forEach(p => {
29                 const item = {
30                     name: p.data.name,
31                     kind: ResourceKind.PROJECT,
32                     url: getResourceUrl(treeItem.data),
33                     owner: p.data.ownerUuid,
34                     uuid: p.data.uuid,
35                     lastModified: p.data.modifiedAt
36                 } as ProjectExplorerItem;
37
38                 dataItems.push(item);
39             });
40         }
41     }
42
43     collections.forEach(c => {
44         const item = {
45             name: c.name,
46             kind: ResourceKind.COLLECTION,
47             url: getResourceUrl(c),
48             owner: c.ownerUuid,
49             uuid: c.uuid,
50             lastModified: c.modifiedAt
51         } as ProjectExplorerItem;
52
53         dataItems.push(item);
54     });
55
56     return dataItems;
57 };
58