From: Peter Amstutz Date: Mon, 4 Nov 2019 21:34:39 +0000 (-0500) Subject: 15736: Add delete button to site manager X-Git-Tag: 2.0.0~30^2~4 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/ceb4f50aeca2bb6b0354a7bd96a599b4a14147fe?ds=sidebyside;hp=d6538e3ec3a545258ff9073ef88501fe2c75a4f0 15736: Add delete button to site manager * Add delete button to remove sessions from site manager * Adjust error handling flow in validateSession to ensure that failures still are marked as finished validating * Fix tests --- diff --git a/src/store/auth/auth-action-session.ts b/src/store/auth/auth-action-session.ts index 9190dc1a..2a9733f0 100644 --- a/src/store/auth/auth-action-session.ts +++ b/src/store/auth/auth-action-session.ts @@ -139,28 +139,27 @@ export const validateSession = (session: Session, activeSession: Session) => session.loggedIn = true; }; - const info = await getRemoteHostInfo(session.remoteHost); - if (!info) { - throw new Error(`Could not get config for ${session.remoteHost}`); - } - let fail: Error | null = null; - try { - const { user, token } = await validateCluster(info, session.token); - setupSession(info.baseUrl, user, token); - } catch (e) { - fail = new Error(`Getting current user for ${session.remoteHost}: ${e.message}`); + const info = await getRemoteHostInfo(session.remoteHost); + if (info !== null) { try { - const { user, token } = await validateCluster(info, activeSession.token); + const { user, token } = await validateCluster(info, session.token); setupSession(info.baseUrl, user, token); - fail = null; } catch (e) { - if (e.message === invalidV2Token) { - fail = new Error(`Getting current user for ${session.remoteHost}: ${e.message}`); + fail = new Error(`Getting current user for ${session.remoteHost}: ${e.message}`); + try { + const { user, token } = await validateCluster(info, activeSession.token); + setupSession(info.baseUrl, user, token); + fail = null; + } catch (e2) { + if (e.message === invalidV2Token) { + fail = new Error(`Getting current user for ${session.remoteHost}: ${e2.message}`); + } } } + } else { + fail = new Error(`Could not get config for ${session.remoteHost}`); } - session.status = SessionStatus.VALIDATED; dispatch(authActions.UPDATE_SESSION(session)); @@ -259,6 +258,13 @@ export const addSession = (remoteHost: string, token?: string, sendToLogin?: boo return Promise.reject(new Error("Could not validate cluster")); }; + +export const removeSession = (clusterId: string) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + await dispatch(authActions.REMOVE_SESSION(clusterId)); + services.authService.saveSessions(getState().auth.sessions); + }; + export const toggleSession = (session: Session) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const s: Session = { ...session }; diff --git a/src/store/auth/auth-action.test.ts b/src/store/auth/auth-action.test.ts index 801d9e33..a543fc18 100644 --- a/src/store/auth/auth-action.test.ts +++ b/src/store/auth/auth-action.test.ts @@ -90,7 +90,8 @@ describe('auth-actions', () => { "remoteHost": "https://zzzzz.arvadosapi.com", "status": 2, "token": "token", - "username": "John Doe" + "name": "John Doe" + "uuid": "zzzzz-tpzed-abcefg", }, { "active": false, "baseUrl": "", @@ -100,7 +101,8 @@ describe('auth-actions', () => { "remoteHost": "xc59z.arvadosapi.com", "status": 1, "token": "", - "username": "" + "name": "", + "uuid": "", }], user: { email: "test@test.com", diff --git a/src/views/site-manager-panel/site-manager-panel-root.tsx b/src/views/site-manager-panel/site-manager-panel-root.tsx index f4022111..bc2303da 100644 --- a/src/views/site-manager-panel/site-manager-panel-root.tsx +++ b/src/views/site-manager-panel/site-manager-panel-root.tsx @@ -8,6 +8,7 @@ import { CardContent, CircularProgress, Grid, + IconButton, StyleRulesCallback, Table, TableBody, @@ -28,6 +29,7 @@ import { addSession } from "~/store/auth/auth-action-session"; import { SITE_MANAGER_REMOTE_HOST_VALIDATION } from "~/validators/validators"; import { Config } from '~/common/config'; import { ResourceCluster } from '~/views-components/data-explorer/renderers'; +import { TrashIcon } from "~/components/icon/icon"; type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' | 'remoteSiteInfo' | 'buttonAdd' | 'buttonLoggedIn' | 'buttonLoggedOut' | @@ -86,6 +88,7 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ export interface SiteManagerPanelRootActionProps { toggleSession: (session: Session) => void; + removeSession: (session: Session) => void; } export interface SiteManagerPanelRootDataProps { @@ -117,7 +120,7 @@ export const SiteManagerPanelRoot = compose( } }), withStyles(styles)) - (({ classes, sessions, handleSubmit, toggleSession, remoteHostsConfig }: SiteManagerPanelRootProps) => + (({ classes, sessions, handleSubmit, toggleSession, removeSession, remoteHostsConfig }: SiteManagerPanelRootProps) => @@ -136,6 +139,7 @@ export const SiteManagerPanelRoot = compose( Email UUID Status + Actions @@ -156,6 +160,9 @@ export const SiteManagerPanelRoot = compose( {validating ? "Validating" : (session.loggedIn ? "Logged in" : "Logged out")} + removeSession(session)}> + + ; })} diff --git a/src/views/site-manager-panel/site-manager-panel.tsx b/src/views/site-manager-panel/site-manager-panel.tsx index 0f48565d..59897f2c 100644 --- a/src/views/site-manager-panel/site-manager-panel.tsx +++ b/src/views/site-manager-panel/site-manager-panel.tsx @@ -10,7 +10,7 @@ import { SiteManagerPanelRootDataProps } from "~/views/site-manager-panel/site-manager-panel-root"; import { Session } from "~/models/session"; -import { toggleSession } from "~/store/auth/auth-action-session"; +import { toggleSession, removeSession } from "~/store/auth/auth-action-session"; const mapStateToProps = (state: RootState): SiteManagerPanelRootDataProps => { return { @@ -22,7 +22,10 @@ const mapStateToProps = (state: RootState): SiteManagerPanelRootDataProps => { const mapDispatchToProps = (dispatch: Dispatch): SiteManagerPanelRootActionProps => ({ toggleSession: (session: Session) => { dispatch(toggleSession(session)); - } + }, + removeSession: (session: Session) => { + dispatch(removeSession(session.clusterId)); + }, }); export const SiteManagerPanel = connect(mapStateToProps, mapDispatchToProps)(SiteManagerPanelRoot);