Add progress indicator for services
authorDaniel Kos <daniel.kos@contractors.roche.com>
Sun, 16 Sep 2018 19:55:57 +0000 (21:55 +0200)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Sun, 16 Sep 2018 19:56:57 +0000 (21:56 +0200)
Feature #14186

Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos@contractors.roche.com>

34 files changed:
package.json
src/index.tsx
src/services/api/api-progress.ts [new file with mode: 0644]
src/services/api/url-builder.test.ts [new file with mode: 0644]
src/services/api/url-builder.ts
src/services/auth-service/auth-service.ts
src/services/collection-service/collection-service.ts
src/services/common-service/common-resource-service.test.ts
src/services/common-service/common-resource-service.ts
src/services/common-service/trashable-resource-service.ts
src/services/container-request-service/container-request-service.ts
src/services/container-service/container-service.ts
src/services/favorite-service/favorite-service.ts
src/services/groups-service/groups-service.test.ts
src/services/groups-service/groups-service.ts
src/services/keep-service/keep-service.ts
src/services/link-service/link-service.ts
src/services/log-service/log-service.ts
src/services/project-service/project-service.test.ts
src/services/services.ts
src/services/user-service/user-service.ts
src/store/auth/auth-actions.test.ts
src/store/auth/auth-reducer.test.ts
src/store/progress-indicator/progress-indicator-actions.ts
src/store/progress-indicator/progress-indicator-reducer.ts
src/store/progress-indicator/with-progress.ts
src/store/side-panel-tree/side-panel-tree-actions.ts
src/views-components/main-app-bar/main-app-bar.tsx
src/views-components/progress/content-progress.tsx
src/views-components/progress/side-panel-progress.tsx
src/views-components/side-panel/side-panel.tsx
src/views/workbench/workbench.tsx
tslint.json
yarn.lock

index 84d1510f5660226cf8a1f7abac8a1ca20a2c0509..dd16eea932fdce1151b53295346ed7cf0345ef0f 100644 (file)
@@ -24,7 +24,8 @@
     "react-transition-group": "2.4.0",
     "redux": "4.0.0",
     "redux-thunk": "2.3.0",
-    "unionize": "2.1.2"
+    "unionize": "2.1.2",
+    "uuid": "3.3.2"
   },
   "scripts": {
     "start": "react-scripts-ts start",
@@ -47,6 +48,7 @@
     "@types/react-router-redux": "5.0.15",
     "@types/redux-devtools": "3.0.44",
     "@types/redux-form": "7.4.5",
+    "@types/uuid": "3.4.4",
     "axios-mock-adapter": "1.15.0",
     "enzyme": "3.4.4",
     "enzyme-adapter-react-16": "1.2.0",
index a07068549679799b9dade5aa11dfae115df05e1c..2fb236d011bd118c2f3918861b0628a7295a7c5b 100644 (file)
@@ -38,7 +38,6 @@ import { addRouteChangeHandlers } from './routes/route-change-handlers';
 import { setCurrentTokenDialogApiHost } from '~/store/current-token-dialog/current-token-dialog-actions';
 import { processResourceActionSet } from './views-components/context-menu/action-sets/process-resource-action-set';
 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
-import { ProgressIndicatorData } from '~/store/progress-indicator/progress-indicator-reducer';
 
 const getBuildNumber = () => "BN-" + (process.env.REACT_APP_BUILD_NUMBER || "dev");
 const getGitCommit = () => "GIT-" + (process.env.REACT_APP_GIT_COMMIT || "latest").substr(0, 7);
@@ -63,13 +62,14 @@ addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
 fetchConfig()
     .then(({ config, apiHost }) => {
         const history = createBrowserHistory();
-        const services = createServices(config);
+        const services = createServices(config, (id, working) => {
+            store.dispatch(progressIndicatorActions.TOGGLE({ id, working }));
+        });
         const store = configureStore(history, services);
 
         store.subscribe(initListener(history, store, services, config));
         store.dispatch(initAuth());
         store.dispatch(setCurrentTokenDialogApiHost(apiHost));
-        store.dispatch(progressIndicatorActions.START_SUBMIT({ id: ProgressIndicatorData.SIDE_PANEL_PROGRESS }));
 
         const TokenComponent = (props: any) => <ApiToken authService={services.authService} {...props} />;
         const WorkbenchComponent = (props: any) => <Workbench authService={services.authService} buildInfo={buildInfo} {...props} />;
diff --git a/src/services/api/api-progress.ts b/src/services/api/api-progress.ts
new file mode 100644 (file)
index 0000000..14dc584
--- /dev/null
@@ -0,0 +1,5 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export type ProgressFn = (id: string, working: boolean) => void;
diff --git a/src/services/api/url-builder.test.ts b/src/services/api/url-builder.test.ts
new file mode 100644 (file)
index 0000000..2b48940
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { OrderBuilder } from "./order-builder";
+import { joinUrls } from "~/services/api/url-builder";
+
+describe("UrlBuilder", () => {
+    it("should join urls properly 1", () => {
+        expect(joinUrls('http://localhost:3000', '/main')).toEqual('http://localhost:3000/main');
+    });
+    it("should join urls properly 2", () => {
+        expect(joinUrls('http://localhost:3000/', '/main')).toEqual('http://localhost:3000/main');
+    });
+    it("should join urls properly 3", () => {
+        expect(joinUrls('http://localhost:3000//', '/main')).toEqual('http://localhost:3000/main');
+    });
+    it("should join urls properly 4", () => {
+        expect(joinUrls('http://localhost:3000', '//main')).toEqual('http://localhost:3000/main');
+    });
+    it("should join urls properly 5", () => {
+        expect(joinUrls('http://localhost:3000///', 'main')).toEqual('http://localhost:3000/main');
+    });
+    it("should join urls properly 6", () => {
+        expect(joinUrls('http://localhost:3000///', '//main')).toEqual('http://localhost:3000/main');
+    });
+    it("should join urls properly 7", () => {
+        expect(joinUrls(undefined, '//main')).toEqual('/main');
+    });
+    it("should join urls properly 8", () => {
+        expect(joinUrls(undefined, 'main')).toEqual('/main');
+    });
+    it("should join urls properly 9", () => {
+        expect(joinUrls('http://localhost:3000///', undefined)).toEqual('http://localhost:3000');
+    });
+});
index 0587c837371dbe0ef242885f0bce6a4a5c2e9c4b..32039a50c23f2a12e1c2c7fdbfe690c4cceecee6 100644 (file)
@@ -24,3 +24,24 @@ export class UrlBuilder {
         return this.url + this.query;
     }
 }
+
+export function joinUrls(url0?: string, url1?: string) {
+    let u0 = "";
+    if (url0) {
+        let idx0 = url0.length - 1;
+        while (url0[idx0] === '/') { --idx0; }
+        u0 = url0.substr(0, idx0 + 1);
+    }
+    let u1 = "";
+    if (url1) {
+        let idx1 = 0;
+        while (url1[idx1] === '/') { ++idx1; }
+        u1 = url1.substr(idx1);
+    }
+    let url = u0;
+    if (u1.length > 0) {
+        url += '/';
+    }
+    url += u1;
+    return url;
+}
index 57915f70578f04be4afd19ef8d6de2543b1cdf3b..89545c1f2166e942276475cbe659b40b9e259c66 100644 (file)
@@ -4,6 +4,8 @@
 
 import { User } from "~/models/user";
 import { AxiosInstance } from "axios";
+import { ProgressFn } from "~/services/api/api-progress";
+import * as uuid from "uuid/v4";
 
 export const API_TOKEN_KEY = 'apiToken';
 export const USER_EMAIL_KEY = 'userEmail';
@@ -25,7 +27,8 @@ export class AuthService {
 
     constructor(
         protected apiClient: AxiosInstance,
-        protected baseUrl: string) { }
+        protected baseUrl: string,
+        protected progressFn: ProgressFn) { }
 
     public saveApiToken(token: string) {
         localStorage.setItem(API_TOKEN_KEY, token);
@@ -86,15 +89,24 @@ export class AuthService {
     }
 
     public getUserDetails = (): Promise<User> => {
+        const reqId = uuid();
+        this.progressFn(reqId, true);
         return this.apiClient
             .get<UserDetailsResponse>('/users/current')
-            .then(resp => ({
-                email: resp.data.email,
-                firstName: resp.data.first_name,
-                lastName: resp.data.last_name,
-                uuid: resp.data.uuid,
-                ownerUuid: resp.data.owner_uuid
-            }));
+            .then(resp => {
+                this.progressFn(reqId, false);
+                return {
+                    email: resp.data.email,
+                    firstName: resp.data.first_name,
+                    lastName: resp.data.last_name,
+                    uuid: resp.data.uuid,
+                    ownerUuid: resp.data.owner_uuid
+                };
+            })
+            .catch(e => {
+                this.progressFn(reqId, false);
+                throw e;
+            });
     }
 
     public getRootUuid() {
index 6e6f2a97d439748a3fb96d9741cff45aa965e073..6a60ebf33d02b3857367eb0d4d87268ccb5deacd 100644 (file)
@@ -11,12 +11,13 @@ import { mapTreeValues } from "~/models/tree";
 import { parseFilesResponse } from "./collection-service-files-response";
 import { fileToArrayBuffer } from "~/common/file";
 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
 export class CollectionService extends TrashableResourceService<CollectionResource> {
-    constructor(serverApi: AxiosInstance, private webdavClient: WebDAV, private authService: AuthService) {
-        super(serverApi, "collections");
+    constructor(serverApi: AxiosInstance, private webdavClient: WebDAV, private authService: AuthService, progressFn: ProgressFn) {
+        super(serverApi, "collections", progressFn);
     }
 
     async files(uuid: string) {
index d67d5dbf403ab66ea59c6267dce0d0fa90dacd9c..385485dbca623a18ce0ee06898eba9dec39a7489 100644 (file)
@@ -6,11 +6,13 @@ import { CommonResourceService } from "./common-resource-service";
 import axios, { AxiosInstance } from "axios";
 import MockAdapter from "axios-mock-adapter";
 import { Resource } from "src/models/resource";
+import { ProgressFn } from "~/services/api/api-progress";
 
-export const mockResourceService = <R extends Resource, C extends CommonResourceService<R>>(Service: new (client: AxiosInstance) => C) => {
+export const mockResourceService = <R extends Resource, C extends CommonResourceService<R>>(
+    Service: new (client: AxiosInstance, progressFn: ProgressFn) => C) => {
     const axiosInstance = axios.create();
     const axiosMock = new MockAdapter(axiosInstance);
-    const service = new Service(axiosInstance);
+    const service = new Service(axiosInstance, (id, working) => {});
     Object.keys(service).map(key => service[key] = jest.fn());
     return service;
 };
@@ -18,6 +20,7 @@ export const mockResourceService = <R extends Resource, C extends CommonResource
 describe("CommonResourceService", () => {
     const axiosInstance = axios.create();
     const axiosMock = new MockAdapter(axiosInstance);
+    const progressFn = (id: string, working: boolean) => {};
 
     beforeEach(() => {
         axiosMock.reset();
@@ -28,14 +31,14 @@ describe("CommonResourceService", () => {
             .onPost("/resource/")
             .reply(200, { owner_uuid: "ownerUuidValue" });
 
-        const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+        const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn);
         const resource = await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
         expect(resource).toEqual({ ownerUuid: "ownerUuidValue" });
     });
 
     it("#create maps request params to snake case", async () => {
         axiosInstance.post = jest.fn(() => Promise.resolve({data: {}}));
-        const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+        const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn);
         await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
         expect(axiosInstance.post).toHaveBeenCalledWith("/resource/", {owner_uuid: "ownerUuidValue"});
     });
@@ -45,7 +48,7 @@ describe("CommonResourceService", () => {
             .onDelete("/resource/uuid")
             .reply(200, { deleted_at: "now" });
 
-        const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+        const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn);
         const resource = await commonResourceService.delete("uuid");
         expect(resource).toEqual({ deletedAt: "now" });
     });
@@ -55,7 +58,7 @@ describe("CommonResourceService", () => {
             .onGet("/resource/uuid")
             .reply(200, { modified_at: "now" });
 
-        const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+        const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn);
         const resource = await commonResourceService.get("uuid");
         expect(resource).toEqual({ modifiedAt: "now" });
     });
@@ -73,7 +76,7 @@ describe("CommonResourceService", () => {
                 items_available: 20
             });
 
-        const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+        const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn);
         const resource = await commonResourceService.list({ limit: 10, offset: 1 });
         expect(resource).toEqual({
             kind: "kind",
index 09e034f5f8b6022e762c902b5d7d4e0cb99411a4..0ad6fbce1f3df525f4fd139af33e4a9c91c75fd6 100644 (file)
@@ -5,6 +5,8 @@
 import * as _ from "lodash";
 import { AxiosInstance, AxiosPromise } from "axios";
 import { Resource } from "src/models/resource";
+import * as uuid from "uuid/v4";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export interface ListArguments {
     limit?: number;
@@ -60,36 +62,53 @@ export class CommonResourceService<T extends Resource> {
             }
         }
 
-    static defaultResponse<R>(promise: AxiosPromise<R>): Promise<R> {
+    static defaultResponse<R>(promise: AxiosPromise<R>, progressFn: ProgressFn): Promise<R> {
+        const reqId = uuid();
+        progressFn(reqId, true);
         return promise
+            .then(data => {
+                progressFn(reqId, false);
+                return data;
+            })
             .then(CommonResourceService.mapResponseKeys)
-            .catch(({ response }) => Promise.reject<Errors>(CommonResourceService.mapResponseKeys(response)));
+            .catch(({ response }) => {
+                progressFn(reqId, false);
+                Promise.reject<Errors>(CommonResourceService.mapResponseKeys(response));
+            });
     }
 
     protected serverApi: AxiosInstance;
     protected resourceType: string;
+    protected progressFn: ProgressFn;
 
-    constructor(serverApi: AxiosInstance, resourceType: string) {
+    constructor(serverApi: AxiosInstance, resourceType: string, onProgress: ProgressFn) {
         this.serverApi = serverApi;
         this.resourceType = '/' + resourceType + '/';
+        this.progressFn = onProgress;
     }
 
     create(data?: Partial<T> | any) {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .post<T>(this.resourceType, data && CommonResourceService.mapKeys(_.snakeCase)(data)));
+                .post<T>(this.resourceType, data && CommonResourceService.mapKeys(_.snakeCase)(data)),
+            this.progressFn
+        );
     }
 
     delete(uuid: string): Promise<T> {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .delete(this.resourceType + uuid));
+                .delete(this.resourceType + uuid),
+            this.progressFn
+        );
     }
 
     get(uuid: string) {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .get<T>(this.resourceType + uuid));
+                .get<T>(this.resourceType + uuid),
+            this.progressFn
+        );
     }
 
     list(args: ListArguments = {}): Promise<ListResults<T>> {
@@ -103,14 +122,17 @@ export class CommonResourceService<T extends Resource> {
             this.serverApi
                 .get(this.resourceType, {
                     params: CommonResourceService.mapKeys(_.snakeCase)(params)
-                }));
+                }),
+            this.progressFn
+        );
     }
 
     update(uuid: string, data: Partial<T>) {
         return CommonResourceService.defaultResponse(
             this.serverApi
-                .put<T>(this.resourceType + uuid, data && CommonResourceService.mapKeys(_.snakeCase)(data)));
-
+                .put<T>(this.resourceType + uuid, data && CommonResourceService.mapKeys(_.snakeCase)(data)),
+            this.progressFn
+        );
     }
 }
 
index 23e7366e9f69537aa0905e1a982c02943d3fb8bd..92e02734806a5b2716453d3a6905ba9de5b1be4d 100644 (file)
@@ -6,27 +6,32 @@ import * as _ from "lodash";
 import { AxiosInstance } from "axios";
 import { TrashableResource } from "src/models/resource";
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export class TrashableResourceService<T extends TrashableResource> extends CommonResourceService<T> {
 
-    constructor(serverApi: AxiosInstance, resourceType: string) {
-        super(serverApi, resourceType);
+    constructor(serverApi: AxiosInstance, resourceType: string, progressFn: ProgressFn) {
+        super(serverApi, resourceType, progressFn);
     }
 
     trash(uuid: string): Promise<T> {
-        return this.serverApi
-            .post(this.resourceType + `${uuid}/trash`)
-            .then(CommonResourceService.mapResponseKeys);
+        return CommonResourceService.defaultResponse(
+            this.serverApi
+                .post(this.resourceType + `${uuid}/trash`),
+            this.progressFn
+        );
     }
 
     untrash(uuid: string): Promise<T> {
         const params = {
             ensure_unique_name: true
         };
-        return this.serverApi
-            .post(this.resourceType + `${uuid}/untrash`, {
-                params: CommonResourceService.mapKeys(_.snakeCase)(params)
-            })
-            .then(CommonResourceService.mapResponseKeys);
+        return CommonResourceService.defaultResponse(
+            this.serverApi
+                .post(this.resourceType + `${uuid}/untrash`, {
+                    params: CommonResourceService.mapKeys(_.snakeCase)(params)
+                }),
+            this.progressFn
+        );
     }
 }
index 01805ff903ee4396da0ae64dc283045da2119c98..6ee44d25e7c2b300d1f6be9b1d43adb0f623c619 100644 (file)
@@ -4,10 +4,11 @@
 
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
 import { AxiosInstance } from "axios";
-import { ContainerRequestResource } from '../../models/container-request';
+import { ContainerRequestResource } from '~/models/container-request';
+import { ProgressFn } from "~/services/api/api-progress";
 
 export class ContainerRequestService extends CommonResourceService<ContainerRequestResource> {
-    constructor(serverApi: AxiosInstance) {
-        super(serverApi, "container_requests");
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {
+        super(serverApi, "container_requests", progressFn);
     }
 }
index 0ace1f60af6a1e72fbf674727493209796a5f360..2f5b71276fd45ef96f561f232eb02a6a2a51cebb 100644 (file)
@@ -4,10 +4,11 @@
 
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
 import { AxiosInstance } from "axios";
-import { ContainerResource } from '../../models/container';
+import { ContainerResource } from '~/models/container';
+import { ProgressFn } from "~/services/api/api-progress";
 
 export class ContainerService extends CommonResourceService<ContainerResource> {
-    constructor(serverApi: AxiosInstance) {
-        super(serverApi, "containers");
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {
+        super(serverApi, "containers", progressFn);
     }
 }
index 4601054315fab0a196c1fa4de6c12056558e4a57..92b0713dbcc6ee2ce8b0eb0939d4cb928710676b 100644 (file)
@@ -19,7 +19,7 @@ export interface FavoriteListArguments {
 export class FavoriteService {
     constructor(
         private linkService: LinkService,
-        private groupsService: GroupsService
+        private groupsService: GroupsService,
     ) {}
 
     create(data: { userUuid: string; resource: { uuid: string; name: string } }) {
index e1157f4b177e5ca18c9764c9bb249cf1467d7074..d88b3c50683ea878ed96cc3494ba4f67b420d6fe 100644 (file)
@@ -27,7 +27,7 @@ describe("GroupsService", () => {
                 items_available: 20
             });
 
-        const groupsService = new GroupsService(axios);
+        const groupsService = new GroupsService(axios, (id, working) => {});
         const resource = await groupsService.contents("1", { limit: 10, offset: 1 });
         expect(resource).toEqual({
             kind: "kind",
index b285e9285518505cf6e459d357ba72ee58acec05..fe337ef14eee9049cb26acf29e617ea1fa5ecd88 100644 (file)
@@ -10,6 +10,7 @@ import { ProjectResource } from "~/models/project";
 import { ProcessResource } from "~/models/process";
 import { TrashableResource } from "~/models/resource";
 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export interface ContentsArguments {
     limit?: number;
@@ -27,8 +28,8 @@ export type GroupContentsResource =
 
 export class GroupsService<T extends TrashableResource = TrashableResource> extends TrashableResourceService<T> {
 
-    constructor(serverApi: AxiosInstance) {
-        super(serverApi, "groups");
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {
+        super(serverApi, "groups", progressFn);
     }
 
     contents(uuid: string, args: ContentsArguments = {}): Promise<ListResults<GroupContentsResource>> {
@@ -38,11 +39,13 @@ export class GroupsService<T extends TrashableResource = TrashableResource> exte
             filters: filters ? `[${filters}]` : undefined,
             order: order ? order : undefined
         };
-        return this.serverApi
-            .get(this.resourceType + `${uuid}/contents`, {
-                params: CommonResourceService.mapKeys(_.snakeCase)(params)
-            })
-            .then(CommonResourceService.mapResponseKeys);
+        return CommonResourceService.defaultResponse(
+            this.serverApi
+                .get(this.resourceType + `${uuid}/contents`, {
+                    params: CommonResourceService.mapKeys(_.snakeCase)(params)
+                }),
+            this.progressFn
+        );
     }
 }
 
index 77d06d933d37ba334e5205a70adde87d127d83d4..f28629f1bbe8a8c1e501f65bc0c1fe9286aa86ec 100644 (file)
@@ -5,9 +5,10 @@
 import { CommonResourceService } from "~/services/common-service/common-resource-service";\r
 import { AxiosInstance } from "axios";\r
 import { KeepResource } from "~/models/keep";\r
+import { ProgressFn } from "~/services/api/api-progress";\r
 \r
 export class KeepService extends CommonResourceService<KeepResource> {\r
-    constructor(serverApi: AxiosInstance) {\r
-        super(serverApi, "keep_services");\r
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {\r
+        super(serverApi, "keep_services", progressFn);\r
     }\r
 }\r
index c77def5f8c2eb461b8533ded52b6ae522cdc03e4..67c1a870ec5b7b95440a41b6fafef7a384ea7a42 100644 (file)
@@ -5,9 +5,10 @@
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
 import { LinkResource } from "~/models/link";
 import { AxiosInstance } from "axios";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export class LinkService extends CommonResourceService<LinkResource> {
-    constructor(serverApi: AxiosInstance) {
-        super(serverApi, "links");
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {
+        super(serverApi, "links", progressFn);
     }
 }
index 8f6c66c8a2ddbf24f9e02fb0fe84874036b23f6c..7f78d95834d496f5ad7c82eadee94050c5fcad67 100644 (file)
@@ -5,9 +5,10 @@
 import { AxiosInstance } from "axios";
 import { LogResource } from '~/models/log';
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export class LogService extends CommonResourceService<LogResource> {
-    constructor(serverApi: AxiosInstance) {
-        super(serverApi, "logs");
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {
+        super(serverApi, "logs", progressFn);
     }
 }
index 11c2f61f3d87f5d9f7190726fc22d658d078f73d..5647ded8beb60b25a4c86835867b6456344b9401 100644 (file)
@@ -11,7 +11,7 @@ describe("CommonResourceService", () => {
 
     it(`#create has groupClass set to "project"`, async () => {
         axiosInstance.post = jest.fn(() => Promise.resolve({ data: {} }));
-        const projectService = new ProjectService(axiosInstance);
+        const projectService = new ProjectService(axiosInstance, (id, working) => {});
         const resource = await projectService.create({ name: "nameValue" });
         expect(axiosInstance.post).toHaveBeenCalledWith("/groups/", {
             name: "nameValue",
@@ -21,7 +21,7 @@ describe("CommonResourceService", () => {
 
     it("#list has groupClass filter set by default", async () => {
         axiosInstance.get = jest.fn(() => Promise.resolve({ data: {} }));
-        const projectService = new ProjectService(axiosInstance);
+        const projectService = new ProjectService(axiosInstance, (id, working) => {});
         const resource = await projectService.list();
         expect(axiosInstance.get).toHaveBeenCalledWith("/groups/", {
             params: {
index 53721dd301b64399d77775c3ec09b65240a6c564..bd73c745d8e30a0a9747c8948c2696a1193f170f 100644 (file)
@@ -12,8 +12,8 @@ import { CollectionService } from "./collection-service/collection-service";
 import { TagService } from "./tag-service/tag-service";
 import { CollectionFilesService } from "./collection-files-service/collection-files-service";
 import { KeepService } from "./keep-service/keep-service";
-import { WebDAV } from "../common/webdav";
-import { Config } from "../common/config";
+import { WebDAV } from "~/common/webdav";
+import { Config } from "~/common/config";
 import { UserService } from './user-service/user-service';
 import { AncestorService } from "~/services/ancestors-service/ancestors-service";
 import { ResourceKind } from "~/models/resource";
@@ -23,25 +23,25 @@ import { LogService } from './log-service/log-service';
 
 export type ServiceRepository = ReturnType<typeof createServices>;
 
-export const createServices = (config: Config) => {
+export const createServices = (config: Config, progressFn: (id: string, working: boolean) => void) => {
     const apiClient = Axios.create();
     apiClient.defaults.baseURL = config.baseUrl;
 
     const webdavClient = new WebDAV();
     webdavClient.defaults.baseURL = config.keepWebServiceUrl;
 
-    const containerRequestService = new ContainerRequestService(apiClient);
-    const containerService = new ContainerService(apiClient);
-    const groupsService = new GroupsService(apiClient);
-    const keepService = new KeepService(apiClient);
-    const linkService = new LinkService(apiClient);
-    const logService = new LogService(apiClient);
-    const projectService = new ProjectService(apiClient);
-    const userService = new UserService(apiClient);
-    
+    const containerRequestService = new ContainerRequestService(apiClient, progressFn);
+    const containerService = new ContainerService(apiClient, progressFn);
+    const groupsService = new GroupsService(apiClient, progressFn);
+    const keepService = new KeepService(apiClient, progressFn);
+    const linkService = new LinkService(apiClient, progressFn);
+    const logService = new LogService(apiClient, progressFn);
+    const projectService = new ProjectService(apiClient, progressFn);
+    const userService = new UserService(apiClient, progressFn);
+
     const ancestorsService = new AncestorService(groupsService, userService);
-    const authService = new AuthService(apiClient, config.rootUrl);
-    const collectionService = new CollectionService(apiClient, webdavClient, authService);
+    const authService = new AuthService(apiClient, config.rootUrl, progressFn);
+    const collectionService = new CollectionService(apiClient, webdavClient, authService, progressFn);
     const collectionFilesService = new CollectionFilesService(collectionService);
     const favoriteService = new FavoriteService(linkService, groupsService);
     const tagService = new TagService(linkService);
@@ -77,4 +77,4 @@ export const getResourceService = (kind?: ResourceKind) => (serviceRepository: S
         default:
             return undefined;
     }
-};
\ No newline at end of file
+};
index 31cc4bbbbce8820b357dcab978a2efc2f8fb381f..cd8b6a47c0bf8ca6e5cabfb685dd9b473f8f512d 100644 (file)
@@ -5,9 +5,10 @@
 import { AxiosInstance } from "axios";
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
 import { UserResource } from "~/models/user";
+import { ProgressFn } from "~/services/api/api-progress";
 
 export class UserService extends CommonResourceService<UserResource> {
-    constructor(serverApi: AxiosInstance) {
-        super(serverApi, "users");
+    constructor(serverApi: AxiosInstance, progressFn: ProgressFn) {
+        super(serverApi, "users", progressFn);
     }
 }
index 4ac48a0be2afa021ab220f553847eccde259871d..46d28354e99a84adc0136a722a41ad09fb3b8e5f 100644 (file)
@@ -22,11 +22,12 @@ import { mockConfig } from '~/common/config';
 describe('auth-actions', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
     let store: RootStore;
+    const progressFn = (id: string, working: boolean) => {};
 
     beforeEach(() => {
-        store = configureStore(createBrowserHistory(), createServices(mockConfig({})));
+        store = configureStore(createBrowserHistory(), createServices(mockConfig({}), progressFn));
         localStorage.clear();
-        reducer = authReducer(createServices(mockConfig({})));
+        reducer = authReducer(createServices(mockConfig({}), progressFn));
     });
 
     it('should initialise state with user and api token from local storage', () => {
index 2b1920a61db9fc47e32fb543341a2010ccd59d63..c8e2ccb1e9af4845b28b7bdcb1ab2334340ea20f 100644 (file)
@@ -11,10 +11,11 @@ import { mockConfig } from '~/common/config';
 
 describe('auth-reducer', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
+    const progressFn = (id: string, working: boolean) => {};
 
     beforeAll(() => {
         localStorage.clear();
-        reducer = authReducer(createServices(mockConfig({})));
+        reducer = authReducer(createServices(mockConfig({}), progressFn));
     });
 
     it('should correctly initialise state', () => {
index 5f824e401a57b1f360800b3d898312f374229a4a..3712e41b6899578d1b41e8151620c82eba83b831 100644 (file)
@@ -5,8 +5,9 @@
 import { unionize, ofType, UnionOf } from "~/common/unionize";
 
 export const progressIndicatorActions = unionize({
-    START_SUBMIT: ofType<{ id: string }>(),
-    STOP_SUBMIT: ofType<{ id: string }>()
+    START: ofType<string>(),
+    STOP: ofType<string>(),
+    TOGGLE: ofType<{ id: string, working: boolean }>()
 });
 
-export type ProgressIndicatorAction = UnionOf<typeof progressIndicatorActions>;
\ No newline at end of file
+export type ProgressIndicatorAction = UnionOf<typeof progressIndicatorActions>;
index daacdb76d0f1d73984a64a0c392d927a7ca4f69b..190ad13f54b40a3494ae29b69747f9a58481ec75 100644 (file)
@@ -3,45 +3,25 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { ProgressIndicatorAction, progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
-import { Dispatch } from 'redux';
-import { RootState } from '~/store/store';
-import { ServiceRepository } from '~/services/services';
 
 export interface ProgressIndicatorState {
-    'sidePanelProgress': { started: boolean };
-    'contentProgress': { started: boolean };
-    // 'workbenchProgress': { started: boolean };
+    [key: string]: {
+        working: boolean
+    };
 }
 
 const initialState: ProgressIndicatorState = {
-    'sidePanelProgress': { started: false },
-    'contentProgress': { started: false },
-    // 'workbenchProgress': { started: false }
 };
 
-export enum ProgressIndicatorData {
-    SIDE_PANEL_PROGRESS = 'sidePanelProgress',
-    CONTENT_PROGRESS = 'contentProgress',
-    // WORKBENCH_PROGRESS = 'workbenchProgress',
-}
-
 export const progressIndicatorReducer = (state: ProgressIndicatorState = initialState, action: ProgressIndicatorAction) => {
     return progressIndicatorActions.match(action, {
-        START_SUBMIT: ({ id }) => ({ ...state, [id]: { started: true } }),
-        STOP_SUBMIT: ({ id }) => ({
-            ...state,
-            [id]: state[id] ? { ...state[id], started: false } : { started: false }
-        }),
+        START: id => ({ ...state, [id]: { working: true } }),
+        STOP: id => ({ ...state, [id]: { working: false } }),
+        TOGGLE: ({ id, working }) => ({ ...state, [id]: { working }}),
         default: () => state,
     });
 };
 
-// export const getProgress = () =>
-//     (dispatch: Dispatch, getState: () => RootState) => {
-//         const progress = getState().progressIndicator;
-//         if (progress.sidePanelProgress.started || progress.contentProgress.started) {
-//             dispatch(progressIndicatorActions.START_SUBMIT({ id: ProgressIndicatorData.WORKBENCH_PROGRESS }));
-//         } else {
-//             dispatch(progressIndicatorActions.STOP_SUBMIT({ id: ProgressIndicatorData.WORKBENCH_PROGRESS }));
-//         }
-//     };
+export function isSystemWorking(state: ProgressIndicatorState): boolean {
+    return Object.keys(state).reduce((working, k) => working ? true : state[k].working, false);
+}
index b91c05df25a582b2d2422724f508115fee68dfd3..976f7575a65ba890a84d764861fc94042fe387b8 100644 (file)
@@ -1,20 +1,20 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
+// // Copyright (C) The Arvados Authors. All rights reserved.
+// //
+// // SPDX-License-Identifier: AGPL-3.0
 //
-// SPDX-License-Identifier: AGPL-3.0
-
-import * as React from 'react';
-import { connect } from 'react-redux';
-import { RootState } from '~/store/store';
-
-export type WithProgressStateProps = {
-    started: boolean;
-};
-
-export const withProgress = (id: string) =>
-    (component: React.ComponentType<WithProgressStateProps>) =>
-        connect(mapStateToProps(id))(component);
-
-export const mapStateToProps = (id: string) => (state: RootState): WithProgressStateProps => {
-    const progress = state.progressIndicator[id];
-    return progress;
-};
\ No newline at end of file
+// import * as React from 'react';
+// import { connect } from 'react-redux';
+// import { RootState } from '~/store/store';
+//
+// export type WithProgressStateProps = {
+//     started: boolean;
+// };
+//
+// export const withProgress = (id: string) =>
+//     (component: React.ComponentType<WithProgressStateProps>) =>
+//         connect(mapStateToProps(id))(component);
+//
+// export const mapStateToProps = (id: string) => (state: RootState): WithProgressStateProps => {
+//     const progress = state.progressIndicator[id];
+//     return progress;
+// };
index c7ad91bd93cb03567c1b38458e5229252a35b706..561df1d7ed5a2f4e6dd8391a953c0a90222ea106 100644 (file)
@@ -14,7 +14,6 @@ import { TreeItemStatus } from "~/components/tree/tree";
 import { getNodeAncestors, getNodeValue, getNodeAncestorsIds, getNode } from '~/models/tree';
 import { ProjectResource } from '~/models/project';
 import { progressIndicatorActions } from '../progress-indicator/progress-indicator-actions';
-import { ProgressIndicatorData } from '~/store/progress-indicator/progress-indicator-reducer';
 
 export enum SidePanelTreeCategory {
     PROJECTS = 'Projects',
@@ -101,7 +100,6 @@ export const activateSidePanelTreeItem = (nodeId: string) =>
         if (!isSidePanelTreeCategory(nodeId)) {
             await dispatch<any>(activateSidePanelTreeProject(nodeId));
         }
-        dispatch(progressIndicatorActions.STOP_SUBMIT({ id: ProgressIndicatorData.SIDE_PANEL_PROGRESS }));
     };
 
 export const activateSidePanelTreeProject = (nodeId: string) =>
index ec2a511a1e89faf2e0261911dbe8e5b679d1882d..93cf4968e99e5bd1475258fa23b5f3ed35fe8003 100644 (file)
@@ -13,6 +13,7 @@ import { NotificationsMenu } from "~/views-components/main-app-bar/notifications
 import { AccountMenu } from "~/views-components/main-app-bar/account-menu";
 import { AnonymousMenu } from "~/views-components/main-app-bar/anonymous-menu";
 import { HelpMenu } from './help-menu';
+import { ReactNode } from "react";
 
 type CssRules = 'toolbar' | 'link';
 
@@ -31,6 +32,7 @@ interface MainAppBarDataProps {
     searchDebounce?: number;
     user?: User;
     buildInfo?: string;
+    children?: ReactNode;
 }
 
 export interface MainAppBarActionProps {
@@ -41,7 +43,7 @@ export type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps & With
 
 export const MainAppBar = withStyles(styles)(
     (props: MainAppBarProps) => {
-        return <AppBar position="static">
+        return <AppBar position="absolute">
             <Toolbar className={props.classes.toolbar}>
                 <Grid container justify="space-between">
                     <Grid container item xs={3} direction="column" justify="center">
@@ -80,6 +82,7 @@ export const MainAppBar = withStyles(styles)(
                     </Grid>
                 </Grid>
             </Toolbar>
+            {props.children}
         </AppBar>;
     }
 );
index 0d291f42e23138f3f80788f41c255414dd67ab12..fa2cad58772f5a124cc5e8877fbcd5693c978713 100644 (file)
@@ -1,13 +1,13 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
+// // Copyright (C) The Arvados Authors. All rights reserved.
+// //
+// // SPDX-License-Identifier: AGPL-3.0
 //
-// SPDX-License-Identifier: AGPL-3.0
-
-import * as React from 'react';
-import { CircularProgress } from '@material-ui/core';
-import { withProgress } from '~/store/progress-indicator/with-progress';
-import { WithProgressStateProps } from '~/store/progress-indicator/with-progress';
-import { ProgressIndicatorData } from '~/store/progress-indicator/progress-indicator-reducer';
-
-export const ContentProgress = withProgress(ProgressIndicatorData.CONTENT_PROGRESS)((props: WithProgressStateProps) => 
-    props.started ? <CircularProgress /> : null
-);
+// import * as React from 'react';
+// import { CircularProgress } from '@material-ui/core';
+// import { withProgress } from '~/store/progress-indicator/with-progress';
+// import { WithProgressStateProps } from '~/store/progress-indicator/with-progress';
+// import { ProgressIndicatorData } from '~/store/progress-indicator/progress-indicator-reducer';
+//
+// export const ContentProgress = withProgress(ProgressIndicatorData.CONTENT_PROGRESS)((props: WithProgressStateProps) =>
+//     props.started ? <CircularProgress /> : null
+// );
index b3bc0db8d357693c0af0110d8e99e768976068c1..2d832a574b4d136647bd03142be5429d6bb81a90 100644 (file)
@@ -1,13 +1,13 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
+// // Copyright (C) The Arvados Authors. All rights reserved.
+// //
+// // SPDX-License-Identifier: AGPL-3.0
 //
-// SPDX-License-Identifier: AGPL-3.0
-
-import * as React from 'react';
-import { CircularProgress } from '@material-ui/core';
-import { withProgress } from '~/store/progress-indicator/with-progress';
-import { WithProgressStateProps } from '~/store/progress-indicator/with-progress';
-import { ProgressIndicatorData } from '~/store/progress-indicator/progress-indicator-reducer';
-
-export const SidePanelProgress = withProgress(ProgressIndicatorData.SIDE_PANEL_PROGRESS)((props: WithProgressStateProps) =>
-    props.started ? <span style={{ display: 'flex', justifyContent: 'center', marginTop: "40px" }}><CircularProgress /></span> : null
-);
+// import * as React from 'react';
+// import { CircularProgress } from '@material-ui/core';
+// import { withProgress } from '~/store/progress-indicator/with-progress';
+// import { WithProgressStateProps } from '~/store/progress-indicator/with-progress';
+// import { ProgressIndicatorData } from '~/store/progress-indicator/progress-indicator-reducer';
+//
+// export const SidePanelProgress = withProgress(ProgressIndicatorData.SIDE_PANEL_PROGRESS)((props: WithProgressStateProps) =>
+//     props.started ? <span style={{ display: 'flex', justifyContent: 'center', marginTop: "40px" }}><CircularProgress /></span> : null
+// );
index 780ecc7fbe77685a6d6c83f002fb46dbc9787610..739e9eac1139ee62b3b38eeb3b8988cea5cc3bb2 100644 (file)
@@ -12,7 +12,6 @@ import { navigateFromSidePanel } from '../../store/side-panel/side-panel-action'
 import { Grid } from '@material-ui/core';
 import { SidePanelButton } from '~/views-components/side-panel-button/side-panel-button';
 import { RootState } from '~/store/store';
-import { SidePanelProgress } from '~/views-components/progress/side-panel-progress';
 
 const DRAWER_WITDH = 240;
 
@@ -35,7 +34,6 @@ const mapDispatchToProps = (dispatch: Dispatch): SidePanelTreeProps => ({
 });
 
 const mapStateToProps = (state: RootState) => ({
-    sidePanelProgress: state.progressIndicator.sidePanelProgress.started
 });
 
 export const SidePanel = compose(
@@ -44,5 +42,5 @@ export const SidePanel = compose(
 )(({ classes, ...props }: WithStyles<CssRules> & SidePanelTreeProps) =>
     <Grid item xs>
         <SidePanelButton />
-        {props.sidePanelProgress ? <SidePanelProgress /> : <SidePanelTree {...props} />}
-    </Grid>);
\ No newline at end of file
+        <SidePanelTree {...props} />
+    </Grid>);
index c5cb983ab7d5daca7372c150025982f1711c0c40..c22dde25f2a80be37775c27f19e701f3ad43a028 100644 (file)
@@ -43,6 +43,7 @@ import { TrashPanel } from "~/views/trash-panel/trash-panel";
 import { MainContentBar } from '~/views-components/main-content-bar/main-content-bar';
 import { Grid, LinearProgress } from '@material-ui/core';
 import { ProcessCommandDialog } from '~/views-components/process-command-dialog/process-command-dialog';
+import { isSystemWorking } from "~/store/progress-indicator/progress-indicator-reducer";
 
 type CssRules = 'root' | 'asidePanel' | 'contentWrapper' | 'content' | 'appBar';
 
@@ -50,7 +51,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
         overflow: 'hidden',
         width: '100vw',
-        height: '100vh'
+        height: '100vh',
+        paddingTop: theme.spacing.unit * 8
     },
     asidePanel: {
         maxWidth: '240px',
@@ -74,8 +76,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 interface WorkbenchDataProps {
     user?: User;
     currentToken?: string;
-    loadingSidePanel: boolean;
-    loadingContent: boolean;
+    working: boolean;
 }
 
 interface WorkbenchGeneralProps {
@@ -94,8 +95,7 @@ export const Workbench = withStyles(styles)(
         (state: RootState) => ({
             user: state.auth.user,
             currentToken: state.auth.apiToken,
-            loadingSidePanel: state.progressIndicator.sidePanelProgress.started,
-            loadingContent: state.progressIndicator.contentProgress.started
+            working: isSystemWorking(state.progressIndicator)
         })
     )(
         class extends React.Component<WorkbenchProps, WorkbenchState> {
@@ -105,15 +105,14 @@ export const Workbench = withStyles(styles)(
             render() {
                 const { classes } = this.props;
                 return <>
+                    <MainAppBar
+                        searchText={this.state.searchText}
+                        user={this.props.user}
+                        onSearch={this.onSearch}
+                        buildInfo={this.props.buildInfo}>
+                        {this.props.working ? <LinearProgress color="secondary" /> : null}
+                    </MainAppBar>
                     <Grid container direction="column" className={classes.root}>
-                        <Grid className={classes.appBar}>
-                            <MainAppBar
-                                searchText={this.state.searchText}
-                                user={this.props.user}
-                                onSearch={this.onSearch}
-                                buildInfo={this.props.buildInfo} />
-                        </Grid>
-                        {this.props.loadingContent || this.props.loadingSidePanel ? <LinearProgress color="secondary" /> : null}
                         {this.props.user &&
                             <Grid container item xs alignItems="stretch" wrap="nowrap">
                                 <Grid container item xs component='aside' direction='column' className={classes.asidePanel}>
index 85b43690d37e54ae7d2d4c3dd1f80dffb527abd9..f9b81ca95bf0e83a0f2d7b19866624d9eef5887d 100644 (file)
@@ -14,7 +14,8 @@
     "no-shadowed-variable": false,
     "semicolon": true,
     "array-type": false,
-    "interface-over-type-literal": false
+    "interface-over-type-literal": false,
+    "no-empty": false
   },
   "linterOptions": {
     "exclude": [
index 359927100d4493eca58c01ca52ccc458a55361eb..45c879fd84f5f8d224c08ea3ca7f78f739707c57 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
     "@types/react" "*"
     redux "^3.6.0 || ^4.0.0"
 
+"@types/uuid@3.4.4":
+  version "3.4.4"
+  resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.4.4.tgz#7af69360fa65ef0decb41fd150bf4ca5c0cefdf5"
+  dependencies:
+    "@types/node" "*"
+
 abab@^1.0.4:
   version "1.0.4"
   resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
@@ -7808,14 +7814,14 @@ utils-merge@1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
 
+uuid@3.3.2, uuid@^3.1.0:
+  version "3.3.2"
+  resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
+
 uuid@^2.0.2:
   version "2.0.3"
   resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
 
-uuid@^3.1.0:
-  version "3.3.2"
-  resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
-
 validate-npm-package-license@^3.0.1:
   version "3.0.3"
   resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz#81643bcbef1bdfecd4623793dc4648948ba98338"