From f571c46495129063f6aeeee8ac77cdc74050441b Mon Sep 17 00:00:00 2001 From: Vardan Torosyan Date: Thu, 21 Jul 2022 18:56:20 +0200 Subject: [PATCH] Service accounts: Add a confirm modal for migration actions (#52604) * Service accounts: Add a confirm modal for migration actions * Handle the error case when migrating fails, reload page afterwards so that the tab disappears --- .../features/api-keys/APIKeysMigratedCard.tsx | 27 ++++++++---- public/app/features/api-keys/ApiKeysPage.tsx | 11 ++++- public/app/features/api-keys/ApiKeysTable.tsx | 2 +- .../api-keys/MigrateToServiceAccountsCard.tsx | 43 +++++++++++++------ .../ServiceAccountsListPage.tsx | 2 +- 5 files changed, 60 insertions(+), 25 deletions(-) diff --git a/public/app/features/api-keys/APIKeysMigratedCard.tsx b/public/app/features/api-keys/APIKeysMigratedCard.tsx index 8198154a64f..c2bfba21093 100644 --- a/public/app/features/api-keys/APIKeysMigratedCard.tsx +++ b/public/app/features/api-keys/APIKeysMigratedCard.tsx @@ -1,27 +1,36 @@ import { css } from '@emotion/css'; -import React from 'react'; +import React, { useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; -import { Alert, LinkButton, useStyles2 } from '@grafana/ui'; +import { Alert, ConfirmModal, useStyles2, Button } from '@grafana/ui'; interface Props { onHideApiKeys: () => void; } export const APIKeysMigratedCard = ({ onHideApiKeys }: Props): JSX.Element => { + const [isModalOpen, setIsModalOpen] = useState(false); const styles = useStyles2(getStyles); return ( - +
- We have upgraded your API keys into more powerful Service accounts and tokens. All your keys are safe and - working - you will find them inside respective service accounts. Keys are now called tokens. + We have migrated API keys into Grafana service accounts. All API keys are safe and continue working as they used + to, you can find them inside the respective service account.
- - Go to service accounts tab and never show API keys tab again - - Go to service accounts tab + + setIsModalOpen(false)} + /> + View service accounts page
); diff --git a/public/app/features/api-keys/ApiKeysPage.tsx b/public/app/features/api-keys/ApiKeysPage.tsx index 5e738b09316..79fdb6f985a 100644 --- a/public/app/features/api-keys/ApiKeysPage.tsx +++ b/public/app/features/api-keys/ApiKeysPage.tsx @@ -3,6 +3,7 @@ import { connect, ConnectedProps } from 'react-redux'; // Utils import { rangeUtil } from '@grafana/data'; +import { locationService } from '@grafana/runtime'; import { InlineField, InlineSwitch, VerticalGroup } from '@grafana/ui'; import appEvents from 'app/core/app_events'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; @@ -142,8 +143,14 @@ export class ApiKeysPageUnconnected extends PureComponent { }; onHideApiKeys = async () => { - await this.props.hideApiKeys(); - window.location.reload(); + try { + await this.props.hideApiKeys(); + let serviceAccountsUrl = '/org/serviceaccounts'; + locationService.push(serviceAccountsUrl); + window.location.reload(); + } catch (err) { + console.error(err); + } }; render() { diff --git a/public/app/features/api-keys/ApiKeysTable.tsx b/public/app/features/api-keys/ApiKeysTable.tsx index cc920eeb494..3748624a5b2 100644 --- a/public/app/features/api-keys/ApiKeysTable.tsx +++ b/public/app/features/api-keys/ApiKeysTable.tsx @@ -50,7 +50,7 @@ export const ApiKeysTable: FC = ({ apiKeys, timeZone, onDelete, onMigrate void; @@ -10,22 +10,41 @@ interface Props { } export const MigrateToServiceAccountsCard = ({ onMigrate, disabled }: Props): JSX.Element => { + const [isModalOpen, setIsModalOpen] = useState(false); const styles = useStyles2(getStyles); + const docsLink = ( + + here. + + ); + const migrationBoxDesc = ( + Are you sure you want to migrate all API keys to service accounts? Find out more {docsLink} + ); + return ( - +
- Service accounts give you more control. API keys will be automatically migrated into tokens inside respective - service accounts. The current API keys will still work, but will be called tokens and you will find them in the - detail view of a respective service account. + Each API key will be automatically migrated into a service account with a token. The service account will be + created with the same permission as the API Key and current API Keys will continue to work as they were.
- {!disabled && ( - - )} - Read more about Service accounts and how to turn them on + + setIsModalOpen(false)} + />
); diff --git a/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx b/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx index c569f4d79c3..aeb50c52c30 100644 --- a/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx @@ -219,7 +219,7 @@ export const ServiceAccountsListPageUnconnected = ({