Refactor to apply global navigation actions
[arvados-workbench2.git] / src / models / resource.ts
index 39b4e915cad26f9b4919e38a8c25aadd6e077512..ff95c1a9b8df59872d6819dccdbcfb2b8ee92441 100644 (file)
@@ -1,9 +1,58 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 export interface Resource {
-    name: string;
-    createdAt: string;
-    modifiedAt: string;
     uuid: string;
     ownerUuid: string;
+    createdAt: string;
+    modifiedByClientUuid: string;
+    modifiedByUserUuid: string;
+    modifiedAt: string;
     href: string;
     kind: string;
+    etag: string;
+}
+
+export enum ResourceKind {
+    COLLECTION = "arvados#collection",
+    CONTAINER_REQUEST = "arvados#containerRequest",
+    GROUP = "arvados#group",
+    PROCESS = "arvados#containerRequest",
+    PROJECT = "arvados#group",
+    WORKFLOW = "arvados#workflow",
+    USER = "arvados#user",
+}
+
+export enum ResourceObjectType {
+    USER = 'tpzed',
+    GROUP = 'j7d0g',
+    COLLECTION = '4zz18'
 }
+
+export const RESOURCE_UUID_PATTERN = '.{5}-.{5}-.{15}';
+export const RESOURCE_UUID_REGEX = new RegExp(RESOURCE_UUID_PATTERN);
+
+export const isResourceUuid = (uuid: string) =>
+    RESOURCE_UUID_REGEX.test(uuid);
+
+export const extractUuidObjectType = (uuid: string) => {
+    const match = RESOURCE_UUID_REGEX.exec(uuid);
+    return match
+        ? match[0].split('-')[1]
+        : undefined;
+};
+
+export const extractUuidKind = (uuid: string = '') => {
+    const objectType = extractUuidObjectType(uuid);
+    switch (objectType) {
+        case ResourceObjectType.USER:
+            return ResourceKind.USER;
+        case ResourceObjectType.GROUP:
+            return ResourceKind.GROUP;
+        case ResourceObjectType.COLLECTION:
+            return ResourceKind.COLLECTION;
+        default:
+            return undefined;
+    }
+};