Create my account view
authorPawel Kromplewski <pawel.kromplewski@contractors.roche.com>
Thu, 29 Nov 2018 12:47:09 +0000 (13:47 +0100)
committerPawel Kromplewski <pawel.kromplewski@contractors.roche.com>
Thu, 29 Nov 2018 12:47:09 +0000 (13:47 +0100)
Feature #14452

Arvados-DCO-1.1-Signed-off-by: Pawel Kromplewski <pawel.kromplewski@contractors.roche.com>

13 files changed:
src/models/user.ts
src/routes/route-change-handlers.ts
src/routes/routes.ts
src/services/auth-service/auth-service.ts
src/store/auth/auth-action.ts
src/store/auth/auth-reducer.test.ts
src/store/my-account/my-account-panel-actions.ts [new file with mode: 0644]
src/store/navigation/navigation-action.ts
src/store/workbench/workbench-actions.ts
src/views-components/main-app-bar/account-menu.tsx
src/views/my-account-panel/my-account-panel-root.tsx [new file with mode: 0644]
src/views/my-account-panel/my-account-panel.tsx [new file with mode: 0644]
src/views/workbench/workbench.tsx

index c2f21e582798dacd5597872696ff7fc1685d62e7..eed135a21cf816133dc14deb4a656cce21953553 100644 (file)
@@ -4,12 +4,24 @@
 
 import { Resource, ResourceKind } from '~/models/resource';
 
+export type userPrefs = {
+    profile?: {
+        organization?: string,
+        organization_email?: string,
+        lab?: string,
+        website_url?: string,
+        role?: string
+    }
+};
+
 export interface User {
     email: string;
     firstName: string;
     lastName: string;
     uuid: string;
     ownerUuid: string;
+    identityUrl: string;
+    prefs: userPrefs;
 }
 
 export const getUserFullname = (user?: User) => {
index c7f3555bcf79db6f64448b330cb4132392a913cb..f2aed2db48f0411b7ba3ebcffeb2ad60483d6169 100644 (file)
@@ -4,8 +4,8 @@
 
 import { History, Location } from 'history';
 import { RootStore } from '~/store/store';
-import { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute, matchSearchResultsRoute, matchSshKeysRoute, matchRepositoriesRoute } from './routes';
-import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog, loadSshKeys, loadRepositories } from '~/store/workbench/workbench-actions';
+import { matchProcessRoute, matchProcessLogRoute, matchProjectRoute, matchCollectionRoute, matchFavoritesRoute, matchTrashRoute, matchRootRoute, matchSharedWithMeRoute, matchRunProcessRoute, matchWorkflowRoute, matchSearchResultsRoute, matchSshKeysRoute, matchRepositoriesRoute, matchMyAccountRoute } from './routes';
+import { loadProject, loadCollection, loadFavorites, loadTrash, loadProcess, loadProcessLog, loadSshKeys, loadRepositories, loadMyAccount } from '~/store/workbench/workbench-actions';
 import { navigateToRootProject } from '~/store/navigation/navigation-action';
 import { loadSharedWithMe, loadRunProcess, loadWorkflow, loadSearchResults } from '~//store/workbench/workbench-actions';
 
@@ -29,6 +29,7 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
     const runProcessMatch = matchRunProcessRoute(pathname);
     const workflowMatch = matchWorkflowRoute(pathname);
     const sshKeysMatch = matchSshKeysRoute(pathname);
+    const myAccountMatch = matchMyAccountRoute(pathname);
 
     if (projectMatch) {
         store.dispatch(loadProject(projectMatch.params.id));
@@ -56,5 +57,7 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => {
         store.dispatch(loadRepositories);
     } else if (sshKeysMatch) {
         store.dispatch(loadSshKeys);
+    } else if (myAccountMatch) {
+        store.dispatch(loadMyAccount);
     }
 };
index c9c2ae20e1eff73e55ae7d76b6e52aa3c2658f00..988b4cb4a8427eba202d287d8a678e42095c1b96 100644 (file)
@@ -21,7 +21,8 @@ export const Routes = {
     RUN_PROCESS: '/run-process',
     WORKFLOWS: '/workflows',
     SEARCH_RESULTS: '/search-results',
-    SSH_KEYS: `/ssh-keys`
+    SSH_KEYS: `/ssh-keys`,
+    MY_ACCOUNT: '/my-account'
 };
 
 export const getResourceUrl = (uuid: string) => {
@@ -84,3 +85,6 @@ export const matchRepositoriesRoute = (route: string) =>
     
 export const matchSshKeysRoute = (route: string) =>
     matchPath(route, { path: Routes.SSH_KEYS });
+
+export const matchMyAccountRoute = (route: string) =>
+    matchPath(route, { path: Routes.MY_ACCOUNT });
index 50760bb4d8493b5384b1564ca6e936c00001b40e..d4e81e42ee76c88bec04814e70953cd7bcbfa335 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { User } from "~/models/user";
+import { User, userPrefs } from "~/models/user";
 import { AxiosInstance } from "axios";
 import { ApiActions, ProgressFn } from "~/services/api/api-actions";
 import * as uuid from "uuid/v4";
@@ -13,6 +13,8 @@ export const USER_FIRST_NAME_KEY = 'userFirstName';
 export const USER_LAST_NAME_KEY = 'userLastName';
 export const USER_UUID_KEY = 'userUuid';
 export const USER_OWNER_UUID_KEY = 'userOwnerUuid';
+export const USER_IDENTITY_URL = 'identityUrl';
+export const USER_PREFS = 'prefs';
 
 export interface UserDetailsResponse {
     email: string;
@@ -21,6 +23,8 @@ export interface UserDetailsResponse {
     uuid: string;
     owner_uuid: string;
     is_admin: boolean;
+    identity_url: string;
+    prefs: userPrefs;
 }
 
 export class AuthService {
@@ -56,9 +60,10 @@ export class AuthService {
         const lastName = localStorage.getItem(USER_LAST_NAME_KEY);
         const uuid = localStorage.getItem(USER_UUID_KEY);
         const ownerUuid = localStorage.getItem(USER_OWNER_UUID_KEY);
-
-        return email && firstName && lastName && uuid && ownerUuid
-            ? { email, firstName, lastName, uuid, ownerUuid }
+        const identityUrl = localStorage.getItem(USER_IDENTITY_URL);
+        const prefs = JSON.parse(localStorage.getItem(USER_PREFS) || '{"profile": {}}');
+        return email && firstName && lastName && uuid && ownerUuid && identityUrl && prefs
+            ? { email, firstName, lastName, uuid, ownerUuid, identityUrl, prefs }
             : undefined;
     }
 
@@ -68,6 +73,8 @@ export class AuthService {
         localStorage.setItem(USER_LAST_NAME_KEY, user.lastName);
         localStorage.setItem(USER_UUID_KEY, user.uuid);
         localStorage.setItem(USER_OWNER_UUID_KEY, user.ownerUuid);
+        localStorage.setItem(USER_IDENTITY_URL, user.identityUrl);
+        localStorage.setItem(USER_PREFS, JSON.stringify(user.prefs));
     }
 
     public removeUser() {
@@ -76,6 +83,8 @@ export class AuthService {
         localStorage.removeItem(USER_LAST_NAME_KEY);
         localStorage.removeItem(USER_UUID_KEY);
         localStorage.removeItem(USER_OWNER_UUID_KEY);
+        localStorage.removeItem(USER_IDENTITY_URL);
+        localStorage.removeItem(USER_PREFS);
     }
 
     public login() {
@@ -95,12 +104,16 @@ export class AuthService {
             .get<UserDetailsResponse>('/users/current')
             .then(resp => {
                 this.actions.progressFn(reqId, false);
+                const prefs = resp.data.prefs.profile ? resp.data.prefs : { profile: {}};
+                console.log(resp.data);
                 return {
                     email: resp.data.email,
                     firstName: resp.data.first_name,
                     lastName: resp.data.last_name,
                     uuid: resp.data.uuid,
-                    ownerUuid: resp.data.owner_uuid
+                    ownerUuid: resp.data.owner_uuid,
+                    identityUrl: resp.data.identity_url,
+                    prefs
                 };
             })
             .catch(e => {
index 28559b1a7ac126feac5adfb7c15170fa2f28295d..a2046f33732350fabb9775f246d3b39553e8e560 100644 (file)
@@ -161,5 +161,4 @@ export const loadSshKeysPanel = () =>
         }
     };
 
-
 export type AuthAction = UnionOf<typeof authActions>;
index 25ce2c1122d7b9688eb71193ddb1be1ce3ec5649..592191caec493503bcce69174c78f81fdedefee4 100644 (file)
@@ -29,7 +29,9 @@ describe('auth-reducer', () => {
             firstName: "John",
             lastName: "Doe",
             uuid: "uuid",
-            ownerUuid: "ownerUuid"
+            ownerUuid: "ownerUuid",
+            identityUrl: "identityUrl",
+            prefs: {}
         };
         const state = reducer(initialState, authActions.INIT({ user, token: "token" }));
         expect(state).toEqual({
@@ -57,7 +59,9 @@ describe('auth-reducer', () => {
             firstName: "John",
             lastName: "Doe",
             uuid: "uuid",
-            ownerUuid: "ownerUuid"
+            ownerUuid: "ownerUuid",
+            identityUrl: "identityUrl",
+            prefs: {}
         };
 
         const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
diff --git a/src/store/my-account/my-account-panel-actions.ts b/src/store/my-account/my-account-panel-actions.ts
new file mode 100644 (file)
index 0000000..cb1584c
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { Dispatch } from "redux";
+import { RootState } from "~/store/store";
+import { ServiceRepository } from "~/services/services";
+import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
+
+export const loadMyAccountPanel = () =>
+    async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+        try {
+            dispatch(setBreadcrumbs([{ label: 'User profile'}]));
+        } catch (e) {
+            return;
+        }
+    };
\ No newline at end of file
index fc08f3ac495403949d4aa2fc6f32a82e18db3bba..0b6713bf04cb0d685b59e85f0327bb04a2256c56 100644 (file)
@@ -65,3 +65,5 @@ export const navigateToSearchResults = push(Routes.SEARCH_RESULTS);
 export const navigateToRepositories = push(Routes.REPOSITORIES);
 
 export const navigateToSshKeys= push(Routes.SSH_KEYS);
+
+export const navigateToMyAccount = push(Routes.MY_ACCOUNT);
index 5e33661cfff12f9c0442de7f09011f3381e7a1a0..dc54e4b861c1c235e888e5fea1f2d2ee547e8d21 100644 (file)
@@ -40,6 +40,7 @@ import { loadSharedWithMePanel } from '~/store/shared-with-me-panel/shared-with-
 import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
 import { loadSshKeysPanel } from '~/store/auth/auth-action';
+import { loadMyAccountPanel } from '~/store/my-account/my-account-panel-actions';
 import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
 import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer';
@@ -403,6 +404,11 @@ export const loadSshKeys = handleFirstTimeLoad(
         await dispatch(loadSshKeysPanel());
     });
 
+export const loadMyAccount = handleFirstTimeLoad(
+    async (dispatch: Dispatch<any>) => {
+        await dispatch(loadMyAccountPanel());
+    });
+
 const finishLoadingProject = (project: GroupContentsResource | string) =>
     async (dispatch: Dispatch<any>) => {
         const uuid = typeof project === 'string' ? project : project.uuid;
index f00c678e15c573abe0572c6e729bafd887edff3d..b93bfcfbedecf90de608d3acb2eb90ab62d26c7e 100644 (file)
@@ -12,7 +12,7 @@ import { logout } from '~/store/auth/auth-action';
 import { RootState } from "~/store/store";
 import { openCurrentTokenDialog } from '~/store/current-token-dialog/current-token-dialog-actions';
 import { openRepositoriesPanel } from "~/store/repositories/repositories-actions";
-import { navigateToSshKeys } from '~/store/navigation/navigation-action';
+import { navigateToSshKeys, navigateToMyAccount } from '~/store/navigation/navigation-action';
 
 interface AccountMenuProps {
     user?: User;
@@ -35,7 +35,7 @@ export const AccountMenu = connect(mapStateToProps)(
                 <MenuItem onClick={() => dispatch(openRepositoriesPanel())}>Repositories</MenuItem>
                 <MenuItem onClick={() => dispatch(openCurrentTokenDialog)}>Current token</MenuItem>
                 <MenuItem onClick={() => dispatch(navigateToSshKeys)}>Ssh Keys</MenuItem>
-                <MenuItem>My account</MenuItem>
+                <MenuItem onClick={() => dispatch(navigateToMyAccount)}>My account</MenuItem>
                 <MenuItem onClick={() => dispatch(logout())}>Logout</MenuItem>
             </DropdownMenu>
             : null);
diff --git a/src/views/my-account-panel/my-account-panel-root.tsx b/src/views/my-account-panel/my-account-panel-root.tsx
new file mode 100644 (file)
index 0000000..c12f01a
--- /dev/null
@@ -0,0 +1,119 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { StyleRulesCallback, WithStyles, withStyles, Card, CardContent, TextField, Button, Typography, Grid, Table, TableHead, TableRow, TableCell, TableBody, Tooltip, IconButton } from '@material-ui/core';
+import { ArvadosTheme } from '~/common/custom-theme';
+import { User } from "~/models/user";
+
+type CssRules = 'root' | 'gridItem' | 'title';
+
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    root: {
+        width: '100%',
+        overflow: 'auto'
+    },
+    gridItem: {
+        minHeight: 45,
+        marginBottom: 20
+    },
+    title: {
+        marginBottom: theme.spacing.unit * 3,
+        color: theme.palette.grey["600"]
+    }
+});
+
+export interface MyAccountPanelRootActionProps {}
+
+export interface MyAccountPanelRootDataProps {
+    user?: User;
+}
+
+type MyAccountPanelRootProps = MyAccountPanelRootActionProps & MyAccountPanelRootDataProps & WithStyles<CssRules>;
+
+export const MyAccountPanelRoot = withStyles(styles)(
+    ({ classes, user }: MyAccountPanelRootProps) => {
+        console.log(user);
+        return <Card className={classes.root}>
+            <CardContent>
+                <Typography variant="title" className={classes.title}>User profile</Typography>
+                <Grid container direction="row" spacing={24}>
+                    <Grid item xs={6}>
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="E-mail"
+                                name="email"
+                                fullWidth
+                                value={user!.email}
+                                disabled
+                            />
+                        </Grid>
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="First name"
+                                name="firstName"
+                                fullWidth
+                                value={user!.firstName}
+                                disabled
+                            />
+                        </Grid>
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="Identity URL"
+                                name="identityUrl"
+                                fullWidth
+                                value={user!.identityUrl}
+                                disabled
+                            />
+                        </Grid>
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="Organization"
+                                name="organization"
+                                value={user!.prefs.profile!.organization}
+                                fullWidth
+                            />
+                        </Grid>
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="Website"
+                                name="website"
+                                value={user!.prefs.profile!.website_url}
+                                fullWidth
+                            />
+                        </Grid>
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="Role"
+                                name="role"
+                                value={user!.prefs.profile!.role}
+                                fullWidth
+                            />
+                        </Grid>
+                    </Grid>
+                    <Grid item xs={6}>
+                        <Grid item className={classes.gridItem} />
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="Last name"
+                                name="lastName"
+                                fullWidth
+                                value={user!.lastName}
+                                disabled
+                            />
+                        </Grid>
+                        <Grid item className={classes.gridItem} />
+                        <Grid item className={classes.gridItem}>
+                            <TextField
+                                label="E-mail at Organization"
+                                name="organizationEmail"
+                                value={user!.prefs.profile!.organization_email}
+                                fullWidth
+                            />
+                        </Grid>
+                    </Grid>
+                </Grid>
+            </CardContent>
+        </Card>;}
+);
\ No newline at end of file
diff --git a/src/views/my-account-panel/my-account-panel.tsx b/src/views/my-account-panel/my-account-panel.tsx
new file mode 100644 (file)
index 0000000..508a4c7
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { RootState } from '~/store/store';
+import { Dispatch } from 'redux';
+import { connect } from 'react-redux';
+import { MyAccountPanelRoot, MyAccountPanelRootDataProps, MyAccountPanelRootActionProps } from '~/views/my-account-panel/my-account-panel-root';
+
+const mapStateToProps = (state: RootState): MyAccountPanelRootDataProps => ({
+    user: state.auth.user
+});
+
+const mapDispatchToProps = (dispatch: Dispatch): MyAccountPanelRootActionProps => ({
+
+});
+
+export const MyAccountPanel = connect(mapStateToProps, mapDispatchToProps)(MyAccountPanelRoot);
\ No newline at end of file
index 84c8e24c99dc0959ce9c34961d83d1e390478315..8542e6ca36a278a54e59c395ea63c4900e6c9ce0 100644 (file)
@@ -45,6 +45,7 @@ import SplitterLayout from 'react-splitter-layout';
 import { WorkflowPanel } from '~/views/workflow-panel/workflow-panel';
 import { SearchResultsPanel } from '~/views/search-results-panel/search-results-panel';
 import { SshKeyPanel } from '~/views/ssh-key-panel/ssh-key-panel';
+import { MyAccountPanel } from '~/views/my-account-panel/my-account-panel';
 import { SharingDialog } from '~/views-components/sharing-dialog/sharing-dialog';
 import { AdvancedTabDialog } from '~/views-components/advanced-tab-dialog/advanced-tab-dialog';
 import { ProcessInputDialog } from '~/views-components/process-input-dialog/process-input-dialog';
@@ -129,6 +130,7 @@ export const WorkbenchPanel =
                                 <Route path={Routes.SEARCH_RESULTS} component={SearchResultsPanel} />
                                 <Route path={Routes.REPOSITORIES} component={RepositoriesPanel} />
                                 <Route path={Routes.SSH_KEYS} component={SshKeyPanel} />
+                                <Route path={Routes.MY_ACCOUNT} component={MyAccountPanel} />
                             </Switch>
                         </Grid>
                     </Grid>