[ARVADOS-WORKBENCH2] created: 1.1.4-1-gb863f7a

Git user git at public.curoverse.com
Tue Jun 12 15:09:53 EDT 2018


        at  b863f7aaab7112a32c7f9b1e7a0299c4266df2f5 (commit)


commit b863f7aaab7112a32c7f9b1e7a0299c4266df2f5
Author: Daniel Kos <daniel.kos at contractors.roche.com>
Date:   Tue Jun 12 09:13:59 2018 +0200

    Replaced getting top project list with more generic version
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos at contractors.roche.com>

diff --git a/src/common/api/filter-builder.ts b/src/common/api/filter-builder.ts
new file mode 100644
index 0000000..c4c29b4
--- /dev/null
+++ b/src/common/api/filter-builder.ts
@@ -0,0 +1,34 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export enum FilterField {
+    UUID = "uuid"
+}
+
+export default class FilterBuilder {
+    private filters = "";
+
+    private addCondition(field: FilterField, cond: string, value?: string) {
+        if (value) {
+            this.filters += `["${field}","${cond}","${value}"]`;
+        }
+        return this;
+    }
+
+    public addEqual(field: FilterField, value?: string) {
+        return this.addCondition(field, "=", value);
+    }
+
+    public addLike(field: FilterField, value?: string) {
+        return this.addCondition(field, "like", value);
+    }
+
+    public addILike(field: FilterField, value?: string) {
+        return this.addCondition(field, "ilike", value);
+    }
+
+    public get() {
+        return "[" + this.filters + "]";
+    }
+}
diff --git a/src/common/server-api.ts b/src/common/api/server-api.ts
similarity index 100%
rename from src/common/server-api.ts
rename to src/common/api/server-api.ts
diff --git a/src/common/api/url-builder.ts b/src/common/api/url-builder.ts
new file mode 100644
index 0000000..e5786a2
--- /dev/null
+++ b/src/common/api/url-builder.ts
@@ -0,0 +1,26 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export default class UrlBuilder {
+	private url: string = "";
+	private query: string = "";
+
+	constructor(host: string) {
+		this.url = host;
+	}
+
+	public addParam(param: string, value: string) {
+		if (this.query.length === 0) {
+			this.query += "?";
+		} else {
+			this.query += "&";
+		}
+		this.query += `${param}=${value}`;
+		return this;
+	}
+
+	public get() {
+		return this.url + this.query;
+	}
+}
diff --git a/src/components/api-token/api-token.tsx b/src/components/api-token/api-token.tsx
index 34e2d64..87da39b 100644
--- a/src/components/api-token/api-token.tsx
+++ b/src/components/api-token/api-token.tsx
@@ -24,7 +24,7 @@ class ApiToken extends React.Component<ApiTokenProps & RouteProps & DispatchProp
         const apiToken = ApiToken.getUrlParameter(search, 'api_token');
         this.props.dispatch(authActions.SAVE_API_TOKEN(apiToken));
         this.props.dispatch(authService.getUserDetails());
-        this.props.dispatch(projectService.getTopProjectList());
+        this.props.dispatch(projectService.getProjectList());
     }
     render() {
         return <Redirect to="/"/>
diff --git a/src/index.tsx b/src/index.tsx
index 67de95f..0cb67f1 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -29,7 +29,7 @@ const store = configureStore({
 }, history);
 
 store.dispatch(authActions.INIT());
-store.dispatch<any>(projectService.getTopProjectList());
+store.dispatch<any>(projectService.getProjectList());
 
 const App = () =>
     <Provider store={store}>
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 80d13e3..da593c2 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { API_HOST, serverApi } from "../../common/server-api";
+import { API_HOST, serverApi } from "../../common/api/server-api";
 import { User } from "../../models/user";
 import { Dispatch } from "redux";
 import actions from "../../store/auth/auth-action";
diff --git a/src/services/project-service/project-service.ts b/src/services/project-service/project-service.ts
index f35ca9c..87272d4 100644
--- a/src/services/project-service/project-service.ts
+++ b/src/services/project-service/project-service.ts
@@ -2,10 +2,12 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { serverApi } from "../../common/server-api";
+import { serverApi } from "../../common/api/server-api";
 import { Dispatch } from "redux";
 import actions from "../../store/project/project-action";
 import { Project } from "../../models/project";
+import UrlBuilder from "../../common/api/url-builder";
+import FilterBuilder, { FilterField } from "../../common/api/filter-builder";
 
 interface GroupsResponse {
     offset: number;
@@ -31,9 +33,15 @@ interface GroupsResponse {
 }
 
 export default class ProjectService {
-    public getTopProjectList = () => (dispatch: Dispatch) => {
-        dispatch(actions.TOP_PROJECTS_REQUEST());
-        serverApi.get<GroupsResponse>('/groups').then(groups => {
+    public getProjectList = (parentUuid?: string) => (dispatch: Dispatch) => {
+        dispatch(actions.PROJECTS_REQUEST());
+
+        const ub = new UrlBuilder('/groups');
+        const fb = new FilterBuilder();
+        fb.addEqual(FilterField.UUID, parentUuid);
+        const url = ub.addParam('filter', fb.get()).get();
+
+        serverApi.get<GroupsResponse>(url).then(groups => {
             const projects = groups.data.items.map(g => ({
                 name: g.name,
                 createdAt: g.created_at,
@@ -42,7 +50,7 @@ export default class ProjectService {
                 uuid: g.uuid,
                 ownerUuid: g.owner_uuid
             } as Project));
-            dispatch(actions.TOP_PROJECTS_SUCCESS(projects));
+            dispatch(actions.PROJECTS_SUCCESS(projects));
         });
-    }
+    };
 }
diff --git a/src/store/auth/auth-reducer.test.ts b/src/store/auth/auth-reducer.test.ts
index f2e20ba..17bd421 100644
--- a/src/store/auth/auth-reducer.test.ts
+++ b/src/store/auth/auth-reducer.test.ts
@@ -10,7 +10,7 @@ import {
     USER_FIRST_NAME_KEY,
     USER_LAST_NAME_KEY
 } from "../../services/auth-service/auth-service";
-import { API_HOST } from "../../common/server-api";
+import { API_HOST } from "../../common/api/server-api";
 
 import 'jest-localstorage-mock';
 
diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts
index 3fad4cf..57a17ae 100644
--- a/src/store/auth/auth-reducer.ts
+++ b/src/store/auth/auth-reducer.ts
@@ -5,7 +5,7 @@
 import actions, { AuthAction } from "./auth-action";
 import { User } from "../../models/user";
 import { authService } from "../../services/services";
-import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/server-api";
+import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/api/server-api";
 import { UserDetailsResponse } from "../../services/auth-service/auth-service";
 
 export interface AuthState {
diff --git a/src/store/project/project-action.ts b/src/store/project/project-action.ts
index 7c91cc5..c88edb6 100644
--- a/src/store/project/project-action.ts
+++ b/src/store/project/project-action.ts
@@ -8,8 +8,8 @@ import { default as unionize, ofType, UnionOf } from "unionize";
 const actions = unionize({
     CREATE_PROJECT: ofType<Project>(),
     REMOVE_PROJECT: ofType<string>(),
-    TOP_PROJECTS_REQUEST: {},
-    TOP_PROJECTS_SUCCESS: ofType<Project[]>()
+    PROJECTS_REQUEST: {},
+    PROJECTS_SUCCESS: ofType<Project[]>()
 }, {
     tag: 'type',
     value: 'payload'
diff --git a/src/store/project/project-reducer.test.ts b/src/store/project/project-reducer.test.ts
index e5f5c27..0bcf942 100644
--- a/src/store/project/project-reducer.test.ts
+++ b/src/store/project/project-reducer.test.ts
@@ -32,8 +32,8 @@ describe('project-reducer', () => {
             uuid: 'test123'
         };
 
-        const topProjects = [project, project];
-        const state = projectsReducer(initialState, actions.TOP_PROJECTS_SUCCESS(topProjects));
-        expect(state).toEqual(topProjects);
+        const projects = [project, project];
+        const state = projectsReducer(initialState, actions.PROJECTS_SUCCESS(projects));
+        expect(state).toEqual(projects);
     });
 });
diff --git a/src/store/project/project-reducer.ts b/src/store/project/project-reducer.ts
index 64e7925..477cb1e 100644
--- a/src/store/project/project-reducer.ts
+++ b/src/store/project/project-reducer.ts
@@ -11,8 +11,8 @@ const projectsReducer = (state: ProjectState = [], action: ProjectAction) => {
     return actions.match(action, {
         CREATE_PROJECT: project => [...state, project],
         REMOVE_PROJECT: () => state,
-        TOP_PROJECTS_REQUEST: () => state,
-        TOP_PROJECTS_SUCCESS: projects => {
+        PROJECTS_REQUEST: () => state,
+        PROJECTS_SUCCESS: projects => {
             return projects;
         },
         default: () => state

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list