[ARVADOS-WORKBENCH2] updated: 3664cf869c1bdb38e62ffd35d16dee0c12af7c59
Git user
git at public.curoverse.com
Sun Jun 10 13:56:27 EDT 2018
Summary of changes:
src/components/api-token/api-token.tsx | 6 ++--
src/index.tsx | 7 ++--
src/models/project.ts | 4 +++
src/services/auth-service/auth-service.ts | 22 +++++++++++-
src/services/project-service/project-service.ts | 48 +++++++++++++++++++++++++
src/services/services.ts | 2 ++
src/store/auth/auth-action.ts | 23 +-----------
src/store/auth/auth-reducer.ts | 6 +++-
src/store/project/project-action.ts | 4 ++-
src/store/project/project-reducer.test.ts | 39 ++++++++++++++++++++
src/store/project/project-reducer.ts | 6 +++-
11 files changed, 135 insertions(+), 32 deletions(-)
create mode 100644 src/services/project-service/project-service.ts
create mode 100644 src/store/project/project-reducer.test.ts
via 3664cf869c1bdb38e62ffd35d16dee0c12af7c59 (commit)
from a5984c9693267f41237746af6b37d8402effdc39 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3664cf869c1bdb38e62ffd35d16dee0c12af7c59
Author: Daniel Kos <daniel.kos at contractors.roche.com>
Date: Sun Jun 10 19:49:24 2018 +0200
Added basic functionality related to reading groups
Feature #13545
Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos at contractors.roche.com>
diff --git a/src/components/api-token/api-token.tsx b/src/components/api-token/api-token.tsx
index daebe9b..34e2d64 100644
--- a/src/components/api-token/api-token.tsx
+++ b/src/components/api-token/api-token.tsx
@@ -5,7 +5,8 @@
import { Redirect, RouteProps } from "react-router";
import * as React from "react";
import { connect, DispatchProp } from "react-redux";
-import authActions, { getUserDetails } from "../../store/auth/auth-action";
+import authActions from "../../store/auth/auth-action";
+import { authService, projectService } from "../../services/services";
interface ApiTokenProps {
}
@@ -22,7 +23,8 @@ class ApiToken extends React.Component<ApiTokenProps & RouteProps & DispatchProp
const search = this.props.location ? this.props.location.search : "";
const apiToken = ApiToken.getUrlParameter(search, 'api_token');
this.props.dispatch(authActions.SAVE_API_TOKEN(apiToken));
- this.props.dispatch(getUserDetails());
+ this.props.dispatch(authService.getUserDetails());
+ this.props.dispatch(projectService.getTopProjectList());
}
render() {
return <Redirect to="/"/>
diff --git a/src/index.tsx b/src/index.tsx
index cb868eb..67de95f 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -8,19 +8,17 @@ import { Provider } from "react-redux";
import Workbench from './views/workbench/workbench';
import ProjectList from './components/project-list/project-list';
import './index.css';
-import { Redirect, Route, RouteProps, Router, RouterProps } from "react-router";
+import { Route } from "react-router";
import createBrowserHistory from "history/createBrowserHistory";
import configureStore from "./store/store";
import { ConnectedRouter } from "react-router-redux";
import ApiToken from "./components/api-token/api-token";
import authActions from "./store/auth/auth-action";
+import { projectService } from "./services/services";
const history = createBrowserHistory();
const store = configureStore({
projects: [
- { name: 'Mouse genome', createdAt: '2018-05-01' },
- { name: 'Human body', createdAt: '2018-05-01' },
- { name: 'Secret operation', createdAt: '2018-05-01' }
],
router: {
location: null
@@ -31,6 +29,7 @@ const store = configureStore({
}, history);
store.dispatch(authActions.INIT());
+store.dispatch<any>(projectService.getTopProjectList());
const App = () =>
<Provider store={store}>
diff --git a/src/models/project.ts b/src/models/project.ts
index 2534ddc..83862c9 100644
--- a/src/models/project.ts
+++ b/src/models/project.ts
@@ -5,4 +5,8 @@
export interface Project {
name: string;
createdAt: string;
+ modifiedAt: string;
+ uuid: string;
+ ownerUuid: string;
+ href: string
}
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 4b213fb..80d13e3 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -2,14 +2,23 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import { API_HOST } from "../../common/server-api";
+import { API_HOST, serverApi } from "../../common/server-api";
import { User } from "../../models/user";
+import { Dispatch } from "redux";
+import actions from "../../store/auth/auth-action";
export const API_TOKEN_KEY = 'apiToken';
export const USER_EMAIL_KEY = 'userEmail';
export const USER_FIRST_NAME_KEY = 'userFirstName';
export const USER_LAST_NAME_KEY = 'userLastName';
+export interface UserDetailsResponse {
+ email: string;
+ first_name: string;
+ last_name: string;
+ is_admin: boolean;
+}
+
export default class AuthService {
public saveApiToken(token: string) {
@@ -54,4 +63,15 @@ export default class AuthService {
const currentUrl = `${window.location.protocol}//${window.location.host}`;
window.location.assign(`${API_HOST}/logout?return_to=${currentUrl}`);
}
+
+ public getUserDetails = () => (dispatch: Dispatch) => {
+ dispatch(actions.USER_DETAILS_REQUEST());
+ serverApi
+ .get<UserDetailsResponse>('/users/current')
+ .then(resp => {
+ dispatch(actions.USER_DETAILS_SUCCESS(resp.data));
+ })
+ // .catch(err => {
+ // });
+ };
}
diff --git a/src/services/project-service/project-service.ts b/src/services/project-service/project-service.ts
new file mode 100644
index 0000000..f35ca9c
--- /dev/null
+++ b/src/services/project-service/project-service.ts
@@ -0,0 +1,48 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { serverApi } from "../../common/server-api";
+import { Dispatch } from "redux";
+import actions from "../../store/project/project-action";
+import { Project } from "../../models/project";
+
+interface GroupsResponse {
+ offset: number;
+ limit: number;
+ items: Array<{
+ href: string;
+ kind: string;
+ etag: string;
+ uuid: string;
+ owner_uuid: string;
+ created_at: string;
+ modified_by_client_uuid: string;
+ modified_by_user_uuid: string;
+ modified_at: string;
+ name: string;
+ group_class: string;
+ description: string;
+ writable_by: string[];
+ delete_at: string;
+ trash_at: string;
+ is_trashed: boolean;
+ }>;
+}
+
+export default class ProjectService {
+ public getTopProjectList = () => (dispatch: Dispatch) => {
+ dispatch(actions.TOP_PROJECTS_REQUEST());
+ serverApi.get<GroupsResponse>('/groups').then(groups => {
+ const projects = groups.data.items.map(g => ({
+ name: g.name,
+ createdAt: g.created_at,
+ modifiedAt: g.modified_at,
+ href: g.href,
+ uuid: g.uuid,
+ ownerUuid: g.owner_uuid
+ } as Project));
+ dispatch(actions.TOP_PROJECTS_SUCCESS(projects));
+ });
+ }
+}
diff --git a/src/services/services.ts b/src/services/services.ts
index 2a903b4..ea72001 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -3,5 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0
import AuthService from "./auth-service/auth-service";
+import ProjectService from "./project-service/project-service";
export const authService = new AuthService();
+export const projectService = new ProjectService();
diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts
index dbf9a0f..e18c78b 100644
--- a/src/store/auth/auth-action.ts
+++ b/src/store/auth/auth-action.ts
@@ -2,16 +2,8 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import { serverApi } from "../../common/server-api";
import { ofType, default as unionize, UnionOf } from "unionize";
-import { Dispatch } from "redux";
-
-export interface UserDetailsResponse {
- email: string;
- first_name: string;
- last_name: string;
- is_admin: boolean;
-}
+import { UserDetailsResponse } from "../../services/auth-service/auth-service";
const actions = unionize({
SAVE_API_TOKEN: ofType<string>(),
@@ -27,16 +19,3 @@ const actions = unionize({
export type AuthAction = UnionOf<typeof actions>;
export default actions;
-
-export const getUserDetails = () => (dispatch: Dispatch) => {
- dispatch(actions.USER_DETAILS_REQUEST());
- serverApi
- .get<UserDetailsResponse>('/users/current')
- .then(resp => {
- dispatch(actions.USER_DETAILS_SUCCESS(resp.data));
- })
- // .catch(err => {
- // });
-};
-
-
diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts
index c5a4856..3fad4cf 100644
--- a/src/store/auth/auth-reducer.ts
+++ b/src/store/auth/auth-reducer.ts
@@ -2,10 +2,11 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import actions, { AuthAction, UserDetailsResponse } from "./auth-action";
+import actions, { AuthAction } from "./auth-action";
import { User } from "../../models/user";
import { authService } from "../../services/services";
import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/server-api";
+import { UserDetailsResponse } from "../../services/auth-service/auth-service";
export interface AuthState {
user?: User;
@@ -22,6 +23,9 @@ const authReducer = (state: AuthState = {}, action: AuthAction) => {
INIT: () => {
const user = authService.getUser();
const token = authService.getApiToken();
+ if (token) {
+ setServerApiAuthorizationHeader(token);
+ }
return {user, apiToken: token};
},
LOGIN: () => {
diff --git a/src/store/project/project-action.ts b/src/store/project/project-action.ts
index 8d57d2b..7c91cc5 100644
--- a/src/store/project/project-action.ts
+++ b/src/store/project/project-action.ts
@@ -7,7 +7,9 @@ import { default as unionize, ofType, UnionOf } from "unionize";
const actions = unionize({
CREATE_PROJECT: ofType<Project>(),
- REMOVE_PROJECT: ofType<string>()
+ REMOVE_PROJECT: ofType<string>(),
+ TOP_PROJECTS_REQUEST: {},
+ TOP_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
new file mode 100644
index 0000000..e5f5c27
--- /dev/null
+++ b/src/store/project/project-reducer.test.ts
@@ -0,0 +1,39 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import projectsReducer from "./project-reducer";
+import actions from "./project-action";
+
+describe('project-reducer', () => {
+ it('should add new project to the list', () => {
+ const initialState = undefined;
+ const project = {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123'
+ };
+
+ const state = projectsReducer(initialState, actions.CREATE_PROJECT(project));
+ expect(state).toEqual([project]);
+ });
+
+ it('should load projects', () => {
+ const initialState = undefined;
+ const project = {
+ name: 'test',
+ href: 'href',
+ createdAt: '2018-01-01',
+ modifiedAt: '2018-01-01',
+ ownerUuid: 'owner-test123',
+ uuid: 'test123'
+ };
+
+ const topProjects = [project, project];
+ const state = projectsReducer(initialState, actions.TOP_PROJECTS_SUCCESS(topProjects));
+ expect(state).toEqual(topProjects);
+ });
+});
diff --git a/src/store/project/project-reducer.ts b/src/store/project/project-reducer.ts
index de11d51..64e7925 100644
--- a/src/store/project/project-reducer.ts
+++ b/src/store/project/project-reducer.ts
@@ -9,8 +9,12 @@ export type ProjectState = Project[];
const projectsReducer = (state: ProjectState = [], action: ProjectAction) => {
return actions.match(action, {
- CREATE_PROJECT: (project) => [...state, project],
+ CREATE_PROJECT: project => [...state, project],
REMOVE_PROJECT: () => state,
+ TOP_PROJECTS_REQUEST: () => state,
+ TOP_PROJECTS_SUCCESS: projects => {
+ return projects;
+ },
default: () => state
});
};
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list