21535: added timeouts to test spec Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados.git] / services / workbench2 / src / store / token-dialog / token-dialog-actions.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { dialogActions } from "store/dialog/dialog-actions";
6 import { getProperty } from 'store/properties/properties';
7 import { propertiesActions } from 'store/properties/properties-actions';
8 import { RootState } from 'store/store';
9
10 export const TOKEN_DIALOG_NAME = 'tokenDialog';
11 const API_HOST_PROPERTY_NAME = 'apiHost';
12
13 export interface TokenDialogData {
14     token: string;
15     tokenExpiration?: Date;
16     apiHost: string;
17     canCreateNewTokens: boolean;
18 }
19
20 export const setTokenDialogApiHost = (apiHost: string) =>
21     propertiesActions.SET_PROPERTY({ key: API_HOST_PROPERTY_NAME, value: apiHost });
22
23 export const getTokenDialogData = (state: RootState): TokenDialogData => {
24     const loginCluster = state.auth.config.clusterConfig.Login.LoginCluster;
25     const canCreateNewTokens = !(loginCluster !== "" && state.auth.homeCluster !== loginCluster);
26
27     return {
28         apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
29         token: state.auth.extraApiToken || state.auth.apiToken || '',
30         tokenExpiration: state.auth.extraApiToken
31             ? state.auth.extraApiTokenExpiration
32             : state.auth.apiTokenExpiration,
33         canCreateNewTokens,
34     };
35 };
36
37 export const openTokenDialog = dialogActions.OPEN_DIALOG({ id: TOKEN_DIALOG_NAME, data: {} });