Refactor to apply global navigation actions
[arvados-workbench2.git] / src / models / resource.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export interface Resource {
6     uuid: string;
7     ownerUuid: string;
8     createdAt: string;
9     modifiedByClientUuid: string;
10     modifiedByUserUuid: string;
11     modifiedAt: string;
12     href: string;
13     kind: string;
14     etag: string;
15 }
16
17 export enum ResourceKind {
18     COLLECTION = "arvados#collection",
19     CONTAINER_REQUEST = "arvados#containerRequest",
20     GROUP = "arvados#group",
21     PROCESS = "arvados#containerRequest",
22     PROJECT = "arvados#group",
23     WORKFLOW = "arvados#workflow",
24     USER = "arvados#user",
25 }
26
27 export enum ResourceObjectType {
28     USER = 'tpzed',
29     GROUP = 'j7d0g',
30     COLLECTION = '4zz18'
31 }
32
33 export const RESOURCE_UUID_PATTERN = '.{5}-.{5}-.{15}';
34 export const RESOURCE_UUID_REGEX = new RegExp(RESOURCE_UUID_PATTERN);
35
36 export const isResourceUuid = (uuid: string) =>
37     RESOURCE_UUID_REGEX.test(uuid);
38
39 export const extractUuidObjectType = (uuid: string) => {
40     const match = RESOURCE_UUID_REGEX.exec(uuid);
41     return match
42         ? match[0].split('-')[1]
43         : undefined;
44 };
45
46 export const extractUuidKind = (uuid: string = '') => {
47     const objectType = extractUuidObjectType(uuid);
48     switch (objectType) {
49         case ResourceObjectType.USER:
50             return ResourceKind.USER;
51         case ResourceObjectType.GROUP:
52             return ResourceKind.GROUP;
53         case ResourceObjectType.COLLECTION:
54             return ResourceKind.COLLECTION;
55         default:
56             return undefined;
57     }
58 };