From cedcd977ec9b5af0953e3358f79292613cafb775 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Thu, 7 Dec 2023 14:20:13 +0000 Subject: [PATCH] Service accounts: Add skeleton loader (#79224) * use emotion object syntax * move create button to be a page action * create and use skeleton --- .betterer.results | 20 --- .../ServiceAccountsListPage.tsx | 149 ++++++++++-------- .../components/ServiceAccountsListItem.tsx | 111 +++++++++---- 3 files changed, 161 insertions(+), 119 deletions(-) diff --git a/.betterer.results b/.betterer.results index b33c8a5678c..b8eba4d816f 100644 --- a/.betterer.results +++ b/.betterer.results @@ -4308,18 +4308,6 @@ exports[`better eslint`] = { "public/app/features/search/utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/serviceaccounts/ServiceAccountsListPage.tsx:5381": [ - [0, 0, 0, "Styles should be written using objects.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"], - [0, 0, 0, "Styles should be written using objects.", "2"], - [0, 0, 0, "Styles should be written using objects.", "3"], - [0, 0, 0, "Styles should be written using objects.", "4"], - [0, 0, 0, "Styles should be written using objects.", "5"], - [0, 0, 0, "Styles should be written using objects.", "6"], - [0, 0, 0, "Styles should be written using objects.", "7"], - [0, 0, 0, "Styles should be written using objects.", "8"], - [0, 0, 0, "Styles should be written using objects.", "9"] - ], "public/app/features/serviceaccounts/components/CreateTokenModal.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"], @@ -4341,14 +4329,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "5"], [0, 0, 0, "Styles should be written using objects.", "6"] ], - "public/app/features/serviceaccounts/components/ServiceAccountsListItem.tsx:5381": [ - [0, 0, 0, "Styles should be written using objects.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"], - [0, 0, 0, "Styles should be written using objects.", "2"], - [0, 0, 0, "Styles should be written using objects.", "3"], - [0, 0, 0, "Styles should be written using objects.", "4"], - [0, 0, 0, "Styles should be written using objects.", "5"] - ], "public/app/features/serviceaccounts/state/reducers.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], diff --git a/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx b/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx index 79411995351..46737866d50 100644 --- a/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx +++ b/public/app/features/serviceaccounts/ServiceAccountsListPage.tsx @@ -16,7 +16,6 @@ import { } from '@grafana/ui'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import { Page } from 'app/core/components/Page/Page'; -import PageLoader from 'app/core/components/PageLoader/PageLoader'; import config from 'app/core/config'; import { contextSrv } from 'app/core/core'; import { StoreState, ServiceAccountDTO, AccessControlAction, ServiceAccountStateFilter } from 'app/types'; @@ -190,7 +189,19 @@ export const ServiceAccountsListPageUnconnected = ({ ); return ( - + + {!noServiceAccountsCreated && contextSrv.hasPermission(AccessControlAction.ServiceAccountsCreate) && ( + + Add service account + + )} + + } + >
@@ -207,13 +218,7 @@ export const ServiceAccountsListPageUnconnected = ({ value={serviceAccountStateFilter} className={styles.filter} /> - {!noServiceAccountsCreated && contextSrv.hasPermission(AccessControlAction.ServiceAccountsCreate) && ( - - Add service account - - )}
- {isLoading && } {!isLoading && noServiceAccountsCreated && ( <> )} - {!isLoading && serviceAccounts.length !== 0 && ( + {(isLoading || serviceAccounts.length !== 0) && ( <>
@@ -245,18 +250,26 @@ export const ServiceAccountsListPageUnconnected = ({ - {serviceAccounts.map((serviceAccount: ServiceAccountDTO) => ( - - ))} + {isLoading ? ( + <> + + + + + ) : ( + serviceAccounts.map((serviceAccount) => ( + + )) + )}
@@ -307,55 +320,55 @@ export const ServiceAccountsListPageUnconnected = ({ export const getStyles = (theme: GrafanaTheme2) => { return { - table: css` - margin-top: ${theme.spacing(3)}; - `, - filter: css` - margin: 0 ${theme.spacing(1)}; - `, - row: css` - display: flex; - align-items: center; - height: 100% !important; + table: css({ + marginTop: theme.spacing(3), + }), + filter: css({ + margin: `0 ${theme.spacing(1)}`, + }), + row: css({ + display: 'flex', + alignItems: 'center', + height: '100% !important', - a { - padding: ${theme.spacing(0.5)} 0 !important; - } - `, - unitTooltip: css` - display: flex; - flex-direction: column; - `, - unitItem: css` - cursor: pointer; - padding: ${theme.spacing(0.5)} 0; - margin-right: ${theme.spacing(1)}; - `, - disabled: css` - color: ${theme.colors.text.disabled}; - `, - link: css` - color: inherit; - cursor: pointer; - text-decoration: underline; - `, - pageHeader: css` - display: flex; - margin-bottom: ${theme.spacing(2)}; - `, - apiKeyInfoLabel: css` - margin-left: ${theme.spacing(1)}; - line-height: 2.2; - flex-grow: 1; - color: ${theme.colors.text.secondary}; + a: { + padding: `${theme.spacing(0.5)} 0 !important`, + }, + }), + unitTooltip: css({ + display: 'flex', + flexDirection: 'column', + }), + unitItem: css({ + cursor: 'pointer', + padding: theme.spacing(0.5, 0), + marginRight: theme.spacing(1), + }), + disabled: css({ + color: theme.colors.text.disabled, + }), + link: css({ + color: 'inherit', + cursor: 'pointer', + textDecoration: 'underline', + }), + pageHeader: css({ + display: 'flex', + marginBottom: theme.spacing(2), + }), + apiKeyInfoLabel: css({ + marginLeft: theme.spacing(1), + lineHeight: 2.2, + flexGrow: 1, + color: theme.colors.text.secondary, - span { - padding: ${theme.spacing(0.5)}; - } - `, - filterDelimiter: css` - flex-grow: 1; - `, + span: { + padding: theme.spacing(0.5), + }, + }), + filterDelimiter: css({ + flexGrow: 1, + }), }; }; diff --git a/public/app/features/serviceaccounts/components/ServiceAccountsListItem.tsx b/public/app/features/serviceaccounts/components/ServiceAccountsListItem.tsx index 3031d76f2e6..ed78f6da724 100644 --- a/public/app/features/serviceaccounts/components/ServiceAccountsListItem.tsx +++ b/public/app/features/serviceaccounts/components/ServiceAccountsListItem.tsx @@ -1,8 +1,9 @@ import { css, cx } from '@emotion/css'; import React, { memo } from 'react'; +import Skeleton from 'react-loading-skeleton'; import { GrafanaTheme2, OrgRole } from '@grafana/data'; -import { Button, HorizontalGroup, Icon, IconButton, useStyles2 } from '@grafana/ui'; +import { Button, Icon, IconButton, Stack, useStyles2 } from '@grafana/ui'; import { UserRolePicker } from 'app/core/components/RolePicker/UserRolePicker'; import { contextSrv } from 'app/core/core'; import { OrgRolePicker } from 'app/features/admin/OrgRolePicker'; @@ -22,7 +23,7 @@ const getServiceAccountsAriaLabel = (name: string) => { return `Edit service account's ${name} details`; }; -const ServiceAccountListItem = memo( +const ServiceAccountListItemComponent = memo( ({ serviceAccount, onRoleChange, @@ -113,7 +114,7 @@ const ServiceAccountListItem = memo( {!serviceAccount.isExternal && ( - + {contextSrv.hasPermission(AccessControlAction.ServiceAccountsWrite) && !serviceAccount.tokens && (