18881: Fixes the "non-status" indication on objects that aren't processes.
[arvados-workbench2.git] / src / store / token-dialog / token-dialog-actions.tsx
index 656f532b5a5908a8f11a3892794822a74ef3337a..6d07fa0ac12c1ea7d2178ebb9aba65557edfe37c 100644 (file)
@@ -2,25 +2,36 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { dialogActions } from "~/store/dialog/dialog-actions";
-import { getProperty } from '~/store/properties/properties';
-import { propertiesActions } from '~/store/properties/properties-actions';
-import { RootState } from '~/store/store';
+import { dialogActions } from "store/dialog/dialog-actions";
+import { getProperty } from 'store/properties/properties';
+import { propertiesActions } from 'store/properties/properties-actions';
+import { RootState } from 'store/store';
 
 export const TOKEN_DIALOG_NAME = 'tokenDialog';
 const API_HOST_PROPERTY_NAME = 'apiHost';
 
 export interface TokenDialogData {
     token: string;
+    tokenExpiration?: Date;
     apiHost: string;
+    canCreateNewTokens: boolean;
 }
 
 export const setTokenDialogApiHost = (apiHost: string) =>
     propertiesActions.SET_PROPERTY({ key: API_HOST_PROPERTY_NAME, value: apiHost });
 
-export const getTokenDialogData = (state: RootState): TokenDialogData => ({
-    apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
-    token: state.auth.extraApiToken || state.auth.apiToken || '',
-});
+export const getTokenDialogData = (state: RootState): TokenDialogData => {
+    const loginCluster = state.auth.config.clusterConfig.Login.LoginCluster;
+    const canCreateNewTokens = !(loginCluster !== "" && state.auth.homeCluster !== loginCluster);
+
+    return {
+        apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
+        token: state.auth.extraApiToken || state.auth.apiToken || '',
+        tokenExpiration: state.auth.extraApiToken
+            ? state.auth.extraApiTokenExpiration
+            : state.auth.apiTokenExpiration,
+        canCreateNewTokens,
+    };
+};
 
 export const openTokenDialog = dialogActions.OPEN_DIALOG({ id: TOKEN_DIALOG_NAME, data: {} });