import * as ReactDOM from 'react-dom';
import { Provider } from "react-redux";
import Workbench from './views/workbench/workbench';
-import ProjectList from './views-components/project-list/project-list';
import './index.css';
import { Route } from "react-router";
import createBrowserHistory from "history/createBrowserHistory";
import { ConnectedRouter } from "react-router-redux";
import ApiToken from "./views-components/api-token/api-token";
import authActions from "./store/auth/auth-action";
-import { authService, projectService } from "./services/services";
+import { authService } from "./services/services";
+import { getProjectList } from "./store/project/project-action";
const history = createBrowserHistory();
store.dispatch(authActions.INIT());
const rootUuid = authService.getRootUuid();
-store.dispatch<any>(projectService.getProjectList(rootUuid));
+store.dispatch<any>(getProjectList(rootUuid));
const App = () =>
<Provider store={store}>
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";
export const API_TOKEN_KEY = 'apiToken';
export const USER_EMAIL_KEY = 'userEmail';
window.location.assign(`${API_HOST}/logout?return_to=${currentUrl}`);
}
- public getUserDetails = () => (dispatch: Dispatch): Promise<void> => {
- dispatch(actions.USER_DETAILS_REQUEST());
+ public getUserDetails = (): Promise<User> => {
return serverApi
.get<UserDetailsResponse>('/users/current')
- .then(resp => {
- dispatch(actions.USER_DETAILS_SUCCESS(resp.data));
- });
+ .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
+ }));
}
public getRootUuid() {
// SPDX-License-Identifier: AGPL-3.0
import { serverApi } from "../../common/api/server-api";
-import { Dispatch } from "redux";
-import actions from "../../store/collection/collection-action";
-import UrlBuilder from "../../common/api/url-builder";
import FilterBuilder, { FilterField } from "../../common/api/filter-builder";
import { ArvadosResource } from "../response";
import { Collection } from "../../models/collection";
}
export default class CollectionService {
- public getCollectionList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Collection[]> => {
- dispatch(actions.COLLECTIONS_REQUEST());
+ public getCollectionList = (parentUuid?: string): Promise<Collection[]> => {
if (parentUuid) {
const fb = new FilterBuilder();
fb.addLike(FilterField.OWNER_UUID, parentUuid);
ownerUuid: g.owner_uuid,
kind: g.kind
} as Collection));
- dispatch(actions.COLLECTIONS_SUCCESS({collections}));
return collections;
});
} else {
- dispatch(actions.COLLECTIONS_SUCCESS({collections: []}));
return Promise.resolve([]);
}
}
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";
import { ArvadosResource } from "../response";
}
export default class ProjectService {
- public getProjectList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Project[]> => {
- dispatch(actions.PROJECTS_REQUEST(parentUuid));
+ public getProjectList = (parentUuid?: string): Promise<Project[]> => {
if (parentUuid) {
const fb = new FilterBuilder();
fb.addLike(FilterField.OWNER_UUID, parentUuid);
ownerUuid: g.owner_uuid,
kind: g.kind
} as Project));
- dispatch(actions.PROJECTS_SUCCESS({projects, parentItemId: parentUuid}));
return projects;
});
} else {
- dispatch(actions.PROJECTS_SUCCESS({projects: [], parentItemId: parentUuid}));
return Promise.resolve([]);
}
}
// SPDX-License-Identifier: AGPL-3.0
import { ofType, default as unionize, UnionOf } from "unionize";
-import { UserDetailsResponse } from "../../services/auth-service/auth-service";
+import { Dispatch } from "redux";
+import { authService } from "../../services/services";
+import { User } from "../../models/user";
const actions = unionize({
SAVE_API_TOKEN: ofType<string>(),
LOGOUT: {},
INIT: {},
USER_DETAILS_REQUEST: {},
- USER_DETAILS_SUCCESS: ofType<UserDetailsResponse>()
+ USER_DETAILS_SUCCESS: ofType<User>()
}, {
tag: 'type',
value: 'payload'
});
+export const getUserDetails = () => (dispatch: Dispatch): Promise<User> => {
+ dispatch(actions.USER_DETAILS_REQUEST());
+ return authService.getUserDetails().then(details => {
+ dispatch(actions.USER_DETAILS_SUCCESS(details));
+ return details;
+ });
+};
+
+
export type AuthAction = UnionOf<typeof actions>;
export default actions;
it('should set user details on success fetch', () => {
const initialState = undefined;
- const userDetails = {
+ const user = {
email: "test@test.com",
- first_name: "John",
- last_name: "Doe",
+ firstName: "John",
+ lastName: "Doe",
uuid: "uuid",
- owner_uuid: "ownerUuid",
- is_admin: true
+ ownerUuid: "ownerUuid"
};
- const state = authReducer(initialState, actions.USER_DETAILS_SUCCESS(userDetails));
+ const state = authReducer(initialState, actions.USER_DETAILS_SUCCESS(user));
expect(state).toEqual({
apiToken: undefined,
user: {
import { User } from "../../models/user";
import { authService } from "../../services/services";
import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/api/server-api";
-import { UserDetailsResponse } from "../../services/auth-service/auth-service";
export interface AuthState {
user?: User;
authService.logout();
return {...state, apiToken: undefined};
},
- USER_DETAILS_SUCCESS: (ud: UserDetailsResponse) => {
- const user = {
- email: ud.email,
- firstName: ud.first_name,
- lastName: ud.last_name,
- uuid: ud.uuid,
- ownerUuid: ud.owner_uuid
- };
+ USER_DETAILS_SUCCESS: (user: User) => {
authService.saveUser(user);
return {...state, user};
},
import { Collection } from "../../models/collection";
import { default as unionize, ofType, UnionOf } from "unionize";
+import { Dispatch } from "redux";
+import { collectionService } from "../../services/services";
const actions = unionize({
CREATE_COLLECTION: ofType<Collection>(),
value: 'payload'
});
+export const getCollectionList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Collection[]> => {
+ dispatch(actions.COLLECTIONS_REQUEST());
+ return collectionService.getCollectionList(parentUuid).then(collections => {
+ dispatch(actions.COLLECTIONS_SUCCESS({collections}));
+ return collections;
+ });
+};
+
export type CollectionAction = UnionOf<typeof actions>;
export default actions;
import { Project } from "../../models/project";
import { default as unionize, ofType, UnionOf } from "unionize";
+import { projectService } from "../../services/services";
+import { Dispatch } from "redux";
const actions = unionize({
CREATE_PROJECT: ofType<Project>(),
value: 'payload'
});
+export const getProjectList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Project[]> => {
+ dispatch(actions.PROJECTS_REQUEST());
+ return projectService.getProjectList(parentUuid).then(projects => {
+ dispatch(actions.PROJECTS_SUCCESS({projects, parentItemId: parentUuid}));
+ return projects;
+ });
+};
+
export type ProjectAction = UnionOf<typeof actions>;
export default actions;
import { Redirect, RouteProps } from "react-router";
import * as React from "react";
import { connect, DispatchProp } from "react-redux";
-import authActions from "../../store/auth/auth-action";
-import { authService, projectService } from "../../services/services";
+import authActions, { getUserDetails } from "../../store/auth/auth-action";
+import { authService } from "../../services/services";
+import { getProjectList } from "../../store/project/project-action";
interface ApiTokenProps {
}
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<any>(authService.getUserDetails()).then(() => {
+ this.props.dispatch<any>(getUserDetails()).then(() => {
const rootUuid = authService.getRootUuid();
- this.props.dispatch(projectService.getProjectList(rootUuid));
+ this.props.dispatch(getProjectList(rootUuid));
});
}
render() {
import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItem } from '../../views-components/main-app-bar/main-app-bar';
import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
import { push } from 'react-router-redux';
-import projectActions from "../../store/project/project-action";
+import projectActions, { getProjectList } from "../../store/project/project-action";
import ProjectTree from '../../views-components/project-tree/project-tree';
import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
import { Project } from "../../models/project";
-import { projectService } from '../../services/services';
import { getTreePath } from '../../store/project/project-reducer';
import DataExplorer from '../data-explorer/data-explorer';
if (status === TreeItemStatus.Loaded) {
this.openProjectItem(itemId);
} else {
- this.props.dispatch<any>(projectService.getProjectList(itemId))
+ this.props.dispatch<any>(getProjectList(itemId))
.then(() => this.openProjectItem(itemId));
}
}