18484: Improves CollectionService.get() to support "select". 18484-collection-manifest-fix
authorLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 30 Nov 2021 14:02:03 +0000 (11:02 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 30 Nov 2021 14:02:03 +0000 (11:02 -0300)
Updates related code, also adds the "include_old_versions" param so that
it works with snapshots.
Adds tests.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/services/collection-service/collection-service.test.ts
src/services/collection-service/collection-service.ts
src/services/common-service/common-service.ts
src/store/advanced-tab/advanced-tab.tsx
src/store/collections/collection-partial-copy-actions.ts
src/store/collections/collection-version-actions.ts

index 1b0130c72915bf3d132f8844a239f56960072bc5..b759fd1a46d9cb622e9567196887667d71e6a9ab 100644 (file)
@@ -41,7 +41,24 @@ describe('collection-service', () => {
                 '/collections', {
                     params: {
                         filters: `[["uuid","=","zzzzz-4zz18-0123456789abcde"]]`,
-                        order: undefined
+                        include_old_versions: true,
+                    },
+                }
+            );
+        });
+
+        it('should be able to request specific fields', async () => {
+            serverApi.get = jest.fn(() => Promise.resolve(
+                { data: { items: [{}] } }
+            ));
+            const uuid = 'zzzzz-4zz18-0123456789abcde'
+            await collectionService.get(uuid, undefined, ['manifestText']);
+            expect(serverApi.get).toHaveBeenCalledWith(
+                '/collections', {
+                    params: {
+                        filters: `[["uuid","=","zzzzz-4zz18-0123456789abcde"]]`,
+                        include_old_versions: true,
+                        select: `["manifest_text"]`
                     },
                 }
             );
index 43041ccd91cc2e3103a54860ad0930e826a50e0b..b6272650debf07034f2c3f336880d94e2814a42a 100644 (file)
@@ -12,6 +12,7 @@ import { TrashableResourceService } from "services/common-service/trashable-reso
 import { ApiActions } from "services/api/api-actions";
 import { customEncodeURI } from "common/url";
 import { FilterBuilder } from "services/api/filter-builder";
+import { ListArguments } from "services/common-service/common-service";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
@@ -29,11 +30,15 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         ]);
     }
 
-    async get(uuid: string, showErrors?: boolean) {
+    async get(uuid: string, showErrors?: boolean, select?: string[]) {
         super.validateUuid(uuid);
         // We use a filtered list request to avoid getting the manifest text
         const filters = new FilterBuilder().addEqual('uuid', uuid).getFilters();
-        const lst = await super.list({filters}, showErrors);
+        const listArgs: ListArguments = {filters, includeOldVersions: true};
+        if (select) {
+            listArgs.select = select;
+        }
+        const lst = await super.list(listArgs, showErrors);
         return lst.items[0];
     }
 
index b5dd1a08b2d726d3c294c7f6077e38f1443ffe86..f66fad74b701c07d079d56bf087375a049e18a1d 100644 (file)
@@ -125,11 +125,13 @@ export class CommonService<T> {
     }
 
     list(args: ListArguments = {}, showErrors?: boolean): Promise<ListResults<T>> {
-        const { filters, order, ...other } = args;
+        const { filters, select, ...other } = args;
         const params = {
             ...CommonService.mapKeys(snakeCase)(other),
             filters: filters ? `[${filters}]` : undefined,
-            order: order ? order : undefined
+            select: select
+                ? `[${select.map(snakeCase).map(s => `"${s}"`).join(', ')}]`
+                : undefined
         };
 
         if (QueryString.stringify(params).length <= 1500) {
index 0f8bf3cb5e010b288fe912971d5d03109b96d6ba..25d90195d7028a079423ce5ed2eb73b5d9150d80 100644 (file)
@@ -411,7 +411,7 @@ const containerRequestApiResponse = (apiResponse: ContainerRequestResource) => {
 
 const collectionApiResponse = (apiResponse: CollectionResource) => {
     const { uuid, ownerUuid, createdAt, modifiedAt, modifiedByClientUuid, modifiedByUserUuid, name, description, properties, portableDataHash, replicationDesired,
-        replicationConfirmedAt, replicationConfirmed, manifestText, deleteAt, trashAt, isTrashed, storageClassesDesired,
+        replicationConfirmedAt, replicationConfirmed, deleteAt, trashAt, isTrashed, storageClassesDesired,
         storageClassesConfirmed, storageClassesConfirmedAt, currentVersionUuid, version, preserveVersion, fileCount, fileSizeTotal } = apiResponse;
     const response = `
 "uuid": "${uuid}",
@@ -424,7 +424,6 @@ const collectionApiResponse = (apiResponse: CollectionResource) => {
 "replication_desired": ${stringify(replicationDesired)},
 "replication_confirmed_at": ${stringify(replicationConfirmedAt)},
 "replication_confirmed": ${stringify(replicationConfirmed)},
-"manifest_text": ${stringify(manifestText)},
 "name": ${stringify(name)},
 "description": ${stringify(description)},
 "properties": ${stringifyObject(properties)},
index 49900f2c288d80d739f5d11f131f9cd17a88dba2..d898c50043d85acc39cbb88d5299ed2251226a6b 100644 (file)
@@ -114,7 +114,7 @@ export const copyCollectionPartialToSelectedCollection = ({ collectionUuid }: Co
         const currentCollection = state.collectionPanel.item;
 
         if (currentCollection && !currentCollection.manifestText) {
-            const fetchedCurrentCollection = await services.collectionService.get(currentCollection.uuid);
+            const fetchedCurrentCollection = await services.collectionService.get(currentCollection.uuid, undefined, ['manifestText']);
             currentCollection.manifestText = fetchedCurrentCollection.manifestText;
             currentCollection.unsignedManifestText = fetchedCurrentCollection.unsignedManifestText;
         }
index c0a58432d7f6be7c4e5412ec5f5f72658d190c13..7d2511eda24d90368df29716c94157e090aeb10a 100644 (file)
@@ -9,6 +9,8 @@ import { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions";
 import { resourcesActions } from "../resources/resources-actions";
 import { navigateTo } from "../navigation/navigation-action";
 import { dialogActions } from "../dialog/dialog-actions";
+import { getResource } from "store/resources/resources";
+import { CollectionResource } from "models/collection";
 
 export const COLLECTION_RESTORE_VERSION_DIALOG = 'collectionRestoreVersionDialog';
 
@@ -28,9 +30,15 @@ export const openRestoreCollectionVersionDialog = (uuid: string) =>
 export const restoreVersion = (resourceUuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         try {
-            // Request que entire record because stored old versions usually
-            // don't include the manifest_text field.
-            const oldVersion = await services.collectionService.get(resourceUuid);
+            // Request the manifest text because stored old versions usually
+            // don't include them.
+            let oldVersion = getResource<CollectionResource>(resourceUuid)(getState().resources);
+            if (!oldVersion) {
+                oldVersion = await services.collectionService.get(resourceUuid);
+            }
+            const oldVersionManifest = await services.collectionService.get(resourceUuid, undefined, ['manifestText']);
+            oldVersion.manifestText = oldVersionManifest.manifestText;
+
             const { uuid, version, ...rest} = oldVersion;
             const headVersion = await services.collectionService.update(
                 oldVersion.currentVersionUuid,