The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Update API keys admin page UI (#75170)
Andrei Chernykh3d0713ce21c4
diff --git a/e2e/support/helpers/e2e-api-key-helpers.ts b/e2e/support/helpers/e2e-api-key-helpers.tsindex 825457268b0..86fe489dc80 100644--- a/e2e/support/helpers/e2e-api-key-helpers.ts+++ b/e2e/support/helpers/e2e-api-key-helpers.ts@@ -9,11 +9,11 @@ export const tryToCreateApiKeyViaModal = ({group: string | RegExp;}) => {cy.findByTestId("api-keys-settings-header")- .button(/create api key/i)+ .button(/create an api key/i).click();H.modal().within(() => {cy.findByLabelText(/Key name/).type(name);- cy.findByLabelText(/group/).click();+ cy.findByLabelText(/group/i).click();});H.selectDropdown()diff --git a/e2e/test/scenarios/admin-2/api-keys.cy.spec.ts b/e2e/test/scenarios/admin-2/api-keys.cy.spec.tsindex 7f6d30a4aa0..47aa3cd2960 100644--- a/e2e/test/scenarios/admin-2/api-keys.cy.spec.ts+++ b/e2e/test/scenarios/admin-2/api-keys.cy.spec.ts@@ -80,7 +80,7 @@ describe("scenarios > admin > settings > API keys", () => {H.tryToCreateApiKeyViaModal({ name, group });cy.wait("@getKeys");- cy.findByLabelText("Copy and save the API key").findByLabelText(+ cy.findByLabelText("Copy and save this API key").findByLabelText(/the api key/i,);@@ -109,15 +109,16 @@ describe("scenarios > admin > settings > API keys", () => {cy.findByTestId("api-keys-table").contains("Test API Key One")- .closest("tr")- .icon("trash")+ .closest('[role="row"]')+ .findByLabelText("API key actions").click();+ cy.findByRole("menuitem", { name: /delete/i }).click();H.modal().button("Delete API key").click();cy.wait("@deleteKey");cy.wait("@getKeys");- cy.findByTestId("empty-table-warning").findByText("No API keys here yet");+ cy.findByTestId("empty-table-warning").findByText("No API keys yet");});it("should allow editing an API key", () => {@@ -128,13 +129,18 @@ describe("scenarios > admin > settings > API keys", () => {.should("include.text", "Development API Key").and("include.text", "All Users");- cy.findByTestId("api-keys-table").icon("pencil").click();+ cy.findByTestId("api-keys-table")+ .contains("Development API Key")+ .closest('[role="row"]')+ .findByLabelText("API key actions")+ .click();+ cy.findByRole("menuitem", { name: /edit/i }).click();cy.findByLabelText(/Key name/).clear().type("Different key name");- cy.findByLabelText(/group/).click();+ cy.findByLabelText(/group/i).click();cy.findByRole("listbox").findByText("collection").click();cy.button("Save").click();@@ -144,7 +150,7 @@ describe("scenarios > admin > settings > API keys", () => {cy.findByTestId("api-keys-table").should("not.contain", "Development API Key").contains("Different key name")- .closest("tr")+ .closest('[role="row"]').should("contain", "collection");});@@ -154,9 +160,10 @@ describe("scenarios > admin > settings > API keys", () => {visitApiKeySettings();cy.findByTestId("api-keys-table").contains("Personal API Key")- .closest("tr")- .icon("pencil")+ .closest('[role="row"]')+ .findByLabelText("API key actions").click();+ cy.findByRole("menuitem", { name: /edit/i }).click();cy.button("Regenerate API key").click();cy.button("Regenerate").click();cy.wait("@regenerateKey");diff --git a/e2e/test/scenarios/admin-2/settings.cy.spec.js b/e2e/test/scenarios/admin-2/settings.cy.spec.jsindex 54a0d63daaf..bd86934c709 100644--- a/e2e/test/scenarios/admin-2/settings.cy.spec.js+++ b/e2e/test/scenarios/admin-2/settings.cy.spec.js@@ -1284,7 +1284,7 @@ describe("admin > settings > nav", () => {cy.findByTestId("admin-layout-sidebar").findByText(/api keys/i).click();- cy.findByTestId("admin-layout-content").findByText(/No API keys here yet/i);+ cy.findByTestId("admin-layout-content").findByText(/No API keys yet/i);cy.url().should("include", "/admin/settings/authentication/api-keys");});});diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.module.css b/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.module.cssnew file mode 100644index 00000000000..471027466dc--- /dev/null+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.module.css@@ -0,0 +1,6 @@+/* The form Input theme defaults descriptions to text-primary; the design+ calls for the muted text-secondary. !important beats the theme's+ equal-specificity .description rule regardless of bundle order. */+.groupDescription {+ color: var(--mb-color-text-secondary) !important;+}diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.tsxindex a851bd8c8fc..6181aa5c152 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/CreateApiKeyModal.tsx@@ -10,9 +10,10 @@ import {FormSubmitButton,FormTextInput,} from "metabase/forms";-import { Button, Group, Modal, Stack, Text } from "metabase/ui";+import { Button, Group, Modal, Paper, Stack, Text } from "metabase/ui";import type { CreateApiKeyRequest } from "metabase-types/api";+import S from "./CreateApiKeyModal.module.css";import { SecretKeyModal } from "./SecretKeyModal";import { API_KEY_VALIDATION_SCHEMA } from "./utils";@@ -36,7 +37,8 @@ export const CreateApiKeyModal = ({ onClose }: { onClose: () => void }) => {if (response.isUninitialized || response.isLoading || response.isError) {return (<Modal- size="30rem"+ size="40rem"+ padding="xl"openedonClose={onClose}title={t`Create a new API key`}@@ -47,24 +49,31 @@ export const CreateApiKeyModal = ({ onClose }: { onClose: () => void }) => {onSubmit={handleSubmit}><Form data-testid="create-api-key-modal">- <Stack gap="md">+ <Stack gap="xl"><FormTextInputname="name"label={t`Key name`}- size="sm"+ placeholder={t`Something to help you remember what this is for`}requiredmaxLength={250}/><FormGroupWidgetname="group_id"- label={t`Which group should this key belong to? The key will have the same permissions granted to that group.`}- size="sm"+ label={t`Group this key should belong to`}+ description={t`The key will have the same permissions that the group does.`}+ classNames={{ description: S.groupDescription }}required/>- <Text- my="sm"- size="sm"- >{t`We don't version the Metabase API. We rarely change API endpoints, and almost never remove them, but if you write code that relies on the API, there's a chance you might have to update your code in the future.`}</Text>+ {/* TODO: swap for the planned metabase/ui Alert variant once it lands. */}+ <Paper+ bg="background-secondary"+ radius="md"+ px="md"+ py="sm"+ shadow="none"+ >+ <Text c="text-secondary">{t`We don't version the Metabase API. We rarely change API endpoints, and almost never remove them, but if you write code that relies on the API, there's a chance you might have to update your code in the future.`}</Text>+ </Paper><FormErrorMessage /><Group justify="flex-end"><Button onClick={onClose}>{t`Cancel`}</Button>diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.module.css b/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.module.cssnew file mode 100644index 00000000000..471027466dc--- /dev/null+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.module.css@@ -0,0 +1,6 @@+/* The form Input theme defaults descriptions to text-primary; the design+ calls for the muted text-secondary. !important beats the theme's+ equal-specificity .description rule regardless of bundle order. */+.groupDescription {+ color: var(--mb-color-text-secondary) !important;+}diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsxindex b68a146397a..9fcfd4fd5fd 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/EditApiKeyModal.tsx@@ -13,10 +13,11 @@ import {FormSubmitButton,FormTextInput,} from "metabase/forms";-import { Button, Group, Modal, Stack, Text } from "metabase/ui";+import { Button, Group, Modal, Paper, Stack, Text } from "metabase/ui";import { getThemeOverrides } from "metabase/ui/theme";import type { ApiKey, UpdateApiKeyRequest } from "metabase-types/api";+import S from "./EditApiKeyModal.module.css";import { SecretKeyModal } from "./SecretKeyModal";import { API_KEY_VALIDATION_SCHEMA } from "./utils";@@ -42,37 +43,41 @@ const RegenerateKeyModal = ({return (<Modal- size="30rem"+ size="40rem"+ padding="xl"openedonClose={() => setModal("edit")}title={t`Regenerate API key`}><FormProvider initialValues={{}} onSubmit={handleRegenerate}><Form>- <Stack gap="lg">+ <Stack gap="xl"><Stack gap="xs"><Textcomponent="label"+ c="text-secondary"fw="bold"- color="text-tertiary"- size="sm">{t`Key name`}</Text>- <Text fw="bold" size="sm">- {apiKey.name}- </Text>+ <Text>{apiKey.name}</Text></Stack><Stack gap="xs"><Textcomponent="label"+ c="text-secondary"fw="bold"- color="text-tertiary"- size="sm">{t`Group`}</Text>- <Text fw="bold" size="sm">- {apiKey.group.name}- </Text>+ <Text>{apiKey.group.name}</Text></Stack>- <Text>{t`Metabase will replace the existing API key with a new key. You won't be able to recover the old key.`}</Text>+ {/* TODO: swap for the planned metabase/ui Alert variant once it lands. */}+ <Paper+ bg="background-secondary"+ radius="md"+ px="md"+ py="sm"+ shadow="none"+ >+ <Text c="text-secondary">{t`Metabase will replace the existing API key with a new key. You won't be able to recover the old key.`}</Text>+ </Paper><FormErrorMessage /><Group justify="flex-end"><Button@@ -127,7 +132,7 @@ export const EditApiKeyModal = ({if (modal === "edit") {return (<Modal- size="30rem"+ size="40rem"padding="xl"openedonClose={onClose}@@ -140,33 +145,28 @@ export const EditApiKeyModal = ({>{({ dirty }) => (<Form>- <Stack gap="md">- <FormTextInput- name="name"- label={t`Key name`}- size="sm"- required- withAsterisk={false}- />+ <Stack gap="xl">+ <FormTextInput name="name" label={t`Key name`} required /><FormGroupWidgetname="group_id"- label={t`Which group should this key belong to? The key will have the same permissions granted to that group.`}- size="sm"+ label={t`Group this key should belong to`}+ description={t`The key will have the same permissions that the group does.`}+ classNames={{ description: S.groupDescription }}/><FormTextInputname="masked_key"label={t`API Key`}- size="sm"styles={{input: {- color: `black !important`,+ // override the disabled-gray so the masked key stays readable in both themes+ color: "var(--mb-color-text-primary) !important",fontFamily: fontFamilyMonospace as string,},}}disabled/><FormErrorMessage />- <Group justify="space-between" mt="lg">+ <Group justify="space-between"><ButtononClick={() => setModal("regenerate")}>{t`Regenerate API key`}</Button>diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.module.css b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.module.cssnew file mode 100644index 00000000000..d39a7ec2df3--- /dev/null+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.module.css@@ -0,0 +1,16 @@+/* Match the API keys design: 16px horizontal cell padding (no gap), 48px rows.+ !important overrides TreeTable's inline cell padding and Mantine's flex gap. */+.cell {+ padding: 0 1rem !important;+ gap: 0 !important;+}++/* Pin the actions ("...") menu to the right edge of the table. */+.cell:last-child {+ justify-content: flex-end !important;+}++.row {+ min-height: 3rem;+ cursor: pointer;+}diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsxindex 1923dc3e04f..7639dd59235 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.tsx@@ -1,22 +1,27 @@-import { useMemo, useState } from "react";+import type { Row } from "@tanstack/react-table";+import { useCallback, useMemo, useState } from "react";import { t } from "ttag";-import {- SettingsPageWrapper,- SettingsSection,-} from "metabase/admin/components/SettingsSection";+import ApiKeysEmptyIllustration from "assets/img/api-keys-empty.svg?component";+import { SettingsPageWrapper } from "metabase/admin/components/SettingsSection";import { useListApiKeysQuery } from "metabase/api";import { DelayedLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper/DelayedLoadingAndErrorWrapper";-import { ClientSortableTable } from "metabase/common/components/Table";-import CS from "metabase/css/core/index.css";import {+ ActionIcon,+ Box,Button,+ Card,+ Center,Ellipsified,Group,Icon,+ Menu,Stack,Text,Title,+ TreeTable,+ type TreeTableColumnDef,+ useTreeTableInstance,} from "metabase/ui";import { getThemeOverrides } from "metabase/ui/theme";import { formatDateTimeWithUnit } from "metabase/visualizations/lib/formatting/date";@@ -25,125 +30,193 @@ import type { ApiKey } from "metabase-types/api";import { CreateApiKeyModal } from "./CreateApiKeyModal";import { DeleteApiKeyModal } from "./DeleteApiKeyModal";import { EditApiKeyModal } from "./EditApiKeyModal";-import type { FlatApiKey } from "./utils";-import { flattenApiKey, formatMaskedKey } from "./utils";+import S from "./ManageApiKeys.module.css";+import { formatMaskedKey } from "./utils";const { fontFamilyMonospace } = getThemeOverrides();type Modal = null | "create" | "edit" | "delete";-function EmptyTableWarning({ onCreate }: { onCreate: () => void }) {+const getNodeId = (apiKey: ApiKey) => String(apiKey.id);++// TODO: replace with the shared `metabase/common/components/EmptyState` once it's migrated off Emotion (UXW-3641).+function EmptyState() {return (- <Stack- mt="xl"- align="center"- justify="center"- gap="sm"- data-testid="empty-table-warning"- >- <Title order={2}>{t`No API keys here yet`}</Title>- <Text mb="md">- {t`You can create an API key to make API calls programmatically.`}- </Text>- <Button key="create-key-button" variant="filled" onClick={onCreate}>- {t`Create API key`}- </Button>- </Stack>+ <Center mih="20rem" data-testid="empty-table-warning">+ <Stack align="center" gap="sm">+ <Box c="text-primary" lh={0}>+ <ApiKeysEmptyIllustration aria-hidden />+ </Box>+ <Text+ c="text-tertiary"+ size="sm"+ ta="center"+ >{t`No API keys yet`}</Text>+ </Stack>+ </Center>+ );+}++function ApiKeyActionsMenu({+ apiKey,+ onEdit,+ onDelete,+}: {+ apiKey: ApiKey;+ onEdit: (apiKey: ApiKey) => void;+ onDelete: (apiKey: ApiKey) => void;+}) {+ return (+ <Menu shadow="md" position="bottom-end">+ <Menu.Target>+ <ActionIcon+ variant="subtle"+ aria-label={t`API key actions`}+ onClick={(e) => e.stopPropagation()}+ >+ <Icon name="ellipsis" />+ </ActionIcon>+ </Menu.Target>+ <Menu.Dropdown onClick={(e) => e.stopPropagation()}>+ <Menu.Item+ leftSection={<Icon name="pencil" />}+ onClick={() => onEdit(apiKey)}+ >+ {t`Edit`}+ </Menu.Item>+ <Menu.Item+ leftSection={<Icon name="trash" />}+ onClick={() => onDelete(apiKey)}+ >+ {t`Delete`}+ </Menu.Item>+ </Menu.Dropdown>+ </Menu>+ );+}++function useApiKeyColumns({+ onEdit,+ onDelete,+}: {+ onEdit: (apiKey: ApiKey) => void;+ onDelete: (apiKey: ApiKey) => void;+}): TreeTableColumnDef<ApiKey>[] {+ return useMemo(+ () => [+ {+ id: "name",+ header: t`Key name`,+ minWidth: 140,+ enableSorting: true,+ accessorFn: (apiKey) => apiKey.name,+ cell: ({ row }) => <Ellipsified>{row.original.name}</Ellipsified>,+ },+ {+ id: "group_name",+ header: t`Group`,+ minWidth: 130,+ enableSorting: true,+ accessorFn: (apiKey) => apiKey.group.name,+ cell: ({ row }) => <Ellipsified>{row.original.group.name}</Ellipsified>,+ },+ {+ id: "masked_key",+ header: t`Key`,+ minWidth: 130,+ enableSorting: false,+ accessorFn: (apiKey) => apiKey.masked_key,+ cell: ({ row }) => (+ <Text ff={fontFamilyMonospace as string}>+ {formatMaskedKey(row.original.masked_key)}+ </Text>+ ),+ },+ {+ id: "updated_by_name",+ header: t`Last modified by`,+ minWidth: 130,+ enableSorting: true,+ accessorFn: (apiKey) => apiKey.updated_by?.common_name ?? "",+ cell: ({ row }) => (+ <Ellipsified>+ {row.original.updated_by?.common_name ?? ""}+ </Ellipsified>+ ),+ },+ {+ id: "updated_at",+ header: t`Last modified on`,+ width: 200,+ enableSorting: true,+ sortDescFirst: true,+ accessorFn: (apiKey) => apiKey.updated_at,+ cell: ({ row }) =>+ formatDateTimeWithUnit(row.original.updated_at, "minute"),+ },+ {+ id: "actions",+ header: "",+ width: 64,+ enableSorting: false,+ cell: ({ row }) => (+ <ApiKeyActionsMenu+ apiKey={row.original}+ onEdit={onEdit}+ onDelete={onDelete}+ />+ ),+ },+ ],+ [onEdit, onDelete],);}function ApiKeysTable({apiKeys,- setActiveApiKey,- setModal,- loading,- error,+ onEdit,+ onDelete,}: {- apiKeys?: ApiKey[];- setActiveApiKey: (apiKey: ApiKey) => void;- setModal: (modal: Modal) => void;- loading: boolean;- error?: unknown;+ apiKeys: ApiKey[];+ onEdit: (apiKey: ApiKey) => void;+ onDelete: (apiKey: ApiKey) => void;}) {- const flatApiKeys = useMemo(() => apiKeys?.map(flattenApiKey), [apiKeys]);-- if (loading || error) {- return <DelayedLoadingAndErrorWrapper loading={loading} error={error} />;- }+ const columns = useApiKeyColumns({ onEdit, onDelete });+ const instance = useTreeTableInstance<ApiKey>({+ data: apiKeys,+ columns,+ getNodeId,+ defaultRowHeight: 48,+ });- if (apiKeys?.length === 0 || !apiKeys || !flatApiKeys) {- return <EmptyTableWarning onCreate={() => setModal("create")} />;- }+ const getRowProps = useCallback(+ (row: Row<ApiKey>) => ({+ "data-testid": `api-key-row-${row.original.id}`,+ "aria-label": row.original.name,+ }),+ [],+ );- const columns = [- { key: "name", name: t`Key name` },- { key: "group_name", name: t`Group` },- { key: "masked_key", name: t`Key` },- { key: "updated_by_name", name: t`Last modified by` },- { key: "updated_at", name: t`Last modified on` },- { key: "actions", name: "", sortable: false },- ];+ const handleRowClick = useCallback(+ (row: Row<ApiKey>) => onEdit(row.original),+ [onEdit],+ );return (- <ClientSortableTable- data-testid="api-keys-table"- columns={columns}- rows={flatApiKeys}- rowRenderer={(row) => (- <ApiKeyRow- apiKey={row}- setActiveApiKey={setActiveApiKey}- setModal={setModal}- />- )}- />+ <Box data-testid="api-keys-table">+ <TreeTable+ instance={instance}+ hierarchical={false}+ headerVariant="pill"+ ariaLabel={t`API keys`}+ getRowProps={getRowProps}+ onRowClick={handleRowClick}+ classNames={{ cell: S.cell, row: S.row }}+ />+ </Box>);}-const ApiKeyRow = ({- apiKey,- setActiveApiKey,- setModal,-}: {- apiKey: FlatApiKey;- setActiveApiKey: (apiKey: ApiKey) => void;- setModal: (modal: Modal) => void;-}) => (- <tr>- <td className={CS.textBold} style={{ maxWidth: 400 }}>- <Ellipsified>{apiKey.name}</Ellipsified>- </td>- <td>{apiKey.group.name}</td>- <td>- <Text ff={fontFamilyMonospace as string}>- {formatMaskedKey(apiKey.masked_key)}- </Text>- </td>- <td>{apiKey.updated_by.common_name}</td>- <td>{formatDateTimeWithUnit(apiKey.updated_at, "minute")}</td>- <td>- <Group gap="md" py="md">- <Icon- name="pencil"- className={CS.cursorPointer}- onClick={() => {- setActiveApiKey(apiKey);- setModal("edit");- }}- />- <Icon- name="trash"- className={CS.cursorPointer}- onClick={() => {- setActiveApiKey(apiKey);- setModal("delete");- }}- />- </Group>- </td>- </tr>-);-export const ManageApiKeys = () => {const [modal, setModal] = useState<Modal>(null);const [activeApiKey, setActiveApiKey] = useState<null | ApiKey>(null);@@ -152,44 +225,62 @@ export const ManageApiKeys = () => {const sortedApiKeys = useMemo(() => {if (!apiKeys) {- return;+ return [];}return [...apiKeys].sort((a, b) => a.name.localeCompare(b.name));}, [apiKeys]);const handleClose = () => setModal(null);+ const handleEdit = useCallback((apiKey: ApiKey) => {+ setActiveApiKey(apiKey);+ setModal("edit");+ }, []);+ const handleDelete = useCallback((apiKey: ApiKey) => {+ setActiveApiKey(apiKey);+ setModal("delete");+ }, []);++ const hasKeys = sortedApiKeys.length > 0;+ const showLoadingOrError = isLoading || Boolean(error);return (- <SettingsPageWrapper title={t`API keys`}>- <SettingsSection>- <ApiKeyModals- onClose={handleClose}- modal={modal}- activeApiKey={activeApiKey}- />- <Stack gap="lg">- <Group- justify="space-between"- align="center"- data-testid="api-keys-settings-header"- >- <Text c="text-secondary">- {t`Allow users to use API keys to authenticate their API calls.`}- </Text>- <Button- variant="filled"- onClick={() => setModal("create")}- >{t`Create API key`}</Button>- </Group>+ <SettingsPageWrapper>+ <ApiKeyModals+ onClose={handleClose}+ modal={modal}+ activeApiKey={activeApiKey}+ />+ <Group+ justify="space-between"+ align="flex-start"+ gap="xl"+ data-testid="api-keys-settings-header"+ >+ <Box>+ <Title order={1}>{t`API keys`}</Title>+ <Text c="text-secondary" maw="40rem">+ {t`Create API keys to let users authenticate API calls or make them programmatically.`}+ </Text>+ </Box>+ <Button variant="filled" onClick={() => setModal("create")}>+ {t`Create an API key`}+ </Button>+ </Group>+ <Card withBorder radius="md" p={0} style={{ overflow: "hidden" }}>+ {showLoadingOrError ? (+ <Box p="xl" mih="20rem">+ <DelayedLoadingAndErrorWrapper loading={isLoading} error={error} />+ </Box>+ ) : hasKeys ? (<ApiKeysTable- loading={isLoading}- error={error}apiKeys={sortedApiKeys}- setActiveApiKey={setActiveApiKey}- setModal={setModal}+ onEdit={handleEdit}+ onDelete={handleDelete}/>- </Stack>- </SettingsSection>+ ) : (+ <EmptyState />+ )}+ </Card></SettingsPageWrapper>);};diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.unit.spec.tsxindex 341f23f0045..d583f6f7e82 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.unit.spec.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/ManageApiKeys.unit.spec.tsx@@ -6,6 +6,7 @@ import {setupGroupsEndpoint,} from "__support__/server-mocks";import {+ mockGetBoundingClientRect,renderWithProviders,screen,waitFor,@@ -62,6 +63,8 @@ const testApiKeys: ApiKey[] = [async function setup({ apiKeys }: { apiKeys?: ApiKey[] } = { apiKeys: undefined },) {+ // TreeTable virtualizes rows, so the container needs a measurable size+ mockGetBoundingClientRect({ width: 800, height: 600 });setupGroupsEndpoint(GROUPS);setupApiKeyEndpoints(apiKeys ?? testApiKeys);renderWithProviders(<ManageApiKeys />);@@ -73,6 +76,11 @@ async function setup(});}+async function openRowMenu(rowName: RegExp) {+ const row = await screen.findByRole("row", { name: rowName });+ await userEvent.click(within(row).getByLabelText("API key actions"));+}+describe("ManageApiKeys", () => {it("should render the component", async () => {await setup();@@ -82,13 +90,10 @@ describe("ManageApiKeys", () => {it("should render component empty state", async () => {await setup({ apiKeys: [] });expect(screen.getByText("API keys")).toBeInTheDocument();- expect(screen.getByText("No API keys here yet")).toBeInTheDocument();+ expect(screen.getByText("No API keys yet")).toBeInTheDocument();expect(- screen.getByText(- "You can create an API key to make API calls programmatically.",- ),+ screen.getByRole("button", { name: "Create an API key" }),).toBeInTheDocument();- expect(screen.getAllByText("Create API key")).toHaveLength(2);});it("should load API keys from api", async () => {@@ -98,16 +103,22 @@ describe("ManageApiKeys", () => {it("should create a new API key", async () => {await setup();- await userEvent.click(screen.getByText("Create API key"));+ await userEvent.click(+ screen.getByRole("button", { name: "Create an API key" }),+ );expect(await screen.findByText("Create a new API key")).toBeInTheDocument();await userEvent.type(screen.getByLabelText(/Key name/), "New key");- await userEvent.click(await screen.findByLabelText(/which group/i));+ await userEvent.click(+ await screen.findByLabelText(/group this key should belong to/i),+ );await userEvent.click(await screen.findByText("flamingos"));// Blur the selectawait userEvent.click(await screen.findByText(/We don't version/));expect(- await screen.findByRole("textbox", { name: /which group/i }),+ await screen.findByRole("textbox", {+ name: /group this key should belong to/i,+ }),).not.toHaveAttribute("data-error");const createButton = screen.getByRole("button", { name: "Create" });@@ -115,7 +126,7 @@ describe("ManageApiKeys", () => {await userEvent.click(createButton);expect(- await screen.findByText("Copy and save the API key"),+ await screen.findByText("Copy and save this API key"),).toBeInTheDocument();const calls = fetchMock.callHistory.calls("path:/api/api-key", {method: "POST",@@ -140,12 +151,9 @@ describe("ManageApiKeys", () => {const REGEN_URL = "path:/api/api-key/1/regenerate";fetchMock.put(REGEN_URL, { unmasked_key: "mb_regenerated" });+ await openRowMenu(/development api key/i);await userEvent.click(- within(- await screen.findByRole("row", {- name: /development api key/i,- }),- ).getByRole("img", { name: /pencil/i }),+ await screen.findByRole("menuitem", { name: /edit/i }),);await screen.findByText("Edit API key");await userEvent.click(@@ -155,7 +163,7 @@ describe("ManageApiKeys", () => {await screen.findByRole("button", { name: "Regenerate" }),);- await screen.findByText("Copy and save the API key");+ await screen.findByText("Copy and save this API key");expect(fetchMock.callHistory.called(REGEN_URL, { method: "PUT" }),).toBeTruthy();@@ -171,20 +179,19 @@ describe("ManageApiKeys", () => {const EDIT_URL = "path:/api/api-key/1";fetchMock.put(EDIT_URL, 200);+ await openRowMenu(/development api key/i);await userEvent.click(- within(- await screen.findByRole("row", {- name: /development api key/i,- }),- ).getByRole("img", { name: /pencil/i }),+ await screen.findByRole("menuitem", { name: /edit/i }),);await screen.findByText("Edit API key");- const group = await screen.findByLabelText(/which group/i);+ const group = await screen.findByLabelText(+ /group this key should belong to/i,+ );await userEvent.click(group);await userEvent.click(await screen.findByText("flamingos"));- const keyName = screen.getByLabelText("Key name");+ const keyName = screen.getByLabelText(/Key name/);await userEvent.clear(keyName);await userEvent.type(keyName, "My Key");@@ -203,17 +210,31 @@ describe("ManageApiKeys", () => {});});+ it("should open the edit modal when a row is clicked", async () => {+ await setup();+ await userEvent.click(+ await screen.findByRole("row", { name: /development api key/i }),+ );+ expect(await screen.findByText("Edit API key")).toBeInTheDocument();+ });++ it("should not open the edit modal when opening the actions menu", async () => {+ await setup();+ await openRowMenu(/development api key/i);+ expect(+ await screen.findByRole("menuitem", { name: /edit/i }),+ ).toBeInTheDocument();+ expect(screen.queryByText("Edit API key")).not.toBeInTheDocument();+ });+it("should delete API key", async () => {await setup();const DELETE_URL = "path:/api/api-key/1";fetchMock.delete(DELETE_URL, 200);+ await openRowMenu(/development api key/i);await userEvent.click(- within(- await screen.findByRole("row", {- name: /development api key/i,- }),- ).getByRole("img", { name: /trash/i }),+ await screen.findByRole("menuitem", { name: /delete/i }),);await userEvent.click(await screen.findByRole("button", { name: "Delete API key" }),diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.module.css b/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.module.cssnew file mode 100644index 00000000000..81e1f5efd8f--- /dev/null+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.module.css@@ -0,0 +1,13 @@+/* The API key field is a read-only, borderless code block. These override+ Mantine/Metabase's default input styles, hence the raised specificity. */+.keyInput[data-variant] {+ height: auto;+ min-height: unset;+ /* room on the right for the copy button (rightSection) */+ padding: 0.5rem 2.5rem 0.5rem 1rem;+ border: none;+ border-radius: var(--mantine-radius-md);+ line-height: 1.25rem;+ background-color: var(--mb-color-background-secondary);+ font-family: var(--mantine-font-family-monospace);+}diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.tsx b/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.tsxindex be7c99a406c..9596bde8580 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.tsx+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/SecretKeyModal.tsx@@ -1,11 +1,19 @@import { t } from "ttag";-import { CopyTextInput } from "metabase/common/components/CopyTextInput";-import CS from "metabase/css/core/index.css";-import { Button, Flex, Group, Icon, Modal, Stack, Text } from "metabase/ui";-import { getThemeOverrides } from "metabase/ui/theme";-import { color } from "metabase/ui/utils/colors";-const { fontFamilyMonospace } = getThemeOverrides();+import {+ ActionIcon,+ Button,+ CopyButton,+ Group,+ Icon,+ Modal,+ Stack,+ Text,+ TextInput,+ Tooltip,+} from "metabase/ui";++import S from "./SecretKeyModal.module.css";export const SecretKeyModal = ({secretKey,@@ -15,39 +23,36 @@ export const SecretKeyModal = ({onClose: () => void;}) => (<Modal- size="30rem"+ size="40rem"openedonClose={onClose}- title={t`Copy and save the API key`}+ title={t`Copy and save this API key`}data-testid="secret-key-modal">- <Stack gap="xl" data-testid="secret-key-modal">- <CopyTextInput- label={t`The API key`}- size="sm"+ <Stack gap="lg">+ <Text c="text-secondary">{t`Store this key somewhere safe. For security reasons, we can't show it to you again.`}</Text>+ <TextInput+ aria-label={t`The API key`}value={secretKey}readOnly- disabled- styles={{- input: {- // This color prop is needed to override disabled input color styles- color: color("text-primary"),- fontFamily: fontFamilyMonospace as string,- },- }}+ classNames={{ input: S.keyInput }}+ rightSectionPointerEvents="all"+ rightSection={+ <CopyButton value={secretKey} timeout={2000}>+ {({ copied, copy }) => (+ <Tooltip label={t`Copied!`} opened={copied}>+ <ActionIcon+ variant="subtle"+ aria-label={t`Copy`}+ onClick={copy}+ >+ <Icon name="copy" />+ </ActionIcon>+ </Tooltip>+ )}+ </CopyButton>+ }/>- <Flex direction="row" gap="md">- <Icon- name="info"- size={22}- className={CS.textMedium}- style={{ marginTop: "-4px" }}- />- <Text- size="sm"- color="text-secondary"- >{t`Please copy this key and save it somewhere safe. For security reasons, we can't show it to you again.`}</Text>- </Flex><Group justify="flex-end"><Button onClick={onClose} variant="filled">{t`Done`}</Button></Group>diff --git a/frontend/src/metabase/admin/settings/components/ApiKeys/utils.ts b/frontend/src/metabase/admin/settings/components/ApiKeys/utils.tsindex ac5b7995740..9f0d4933f79 100644--- a/frontend/src/metabase/admin/settings/components/ApiKeys/utils.ts+++ b/frontend/src/metabase/admin/settings/components/ApiKeys/utils.ts@@ -1,8 +1,6 @@import { t } from "ttag";import * as Yup from "yup";-import type { ApiKey } from "metabase-types/api";-export function formatMaskedKey(maskedKey: string) {return maskedKey.substring(0, 7) + "...";}@@ -14,14 +12,3 @@ export const API_KEY_VALIDATION_SCHEMA = Yup.object({.typeError(t`Group is a required field`).required(),});--export type FlatApiKey = ApiKey & {- group_name: string;- updated_by_name: string;-};--export const flattenApiKey = (apiKey: ApiKey): FlatApiKey => ({- ...apiKey,- group_name: apiKey.group.name,- updated_by_name: apiKey.updated_by?.common_name || "",-});diff --git a/frontend/src/metabase/admin/settings/tests/setup.tsx b/frontend/src/metabase/admin/settings/tests/setup.tsxindex 8f81db84f7c..173c1119862 100644--- a/frontend/src/metabase/admin/settings/tests/setup.tsx+++ b/frontend/src/metabase/admin/settings/tests/setup.tsx@@ -59,7 +59,7 @@ export const ossRoutes: RouteMap = {ldap: { path: "/authentication/ldap", testPattern: /Server Settings/i },apiKeys: {path: "/authentication/api-keys",- testPattern: /Allow users to use API keys/i,+ testPattern: /Create API keys to let users authenticate/i,},maps: { path: "/maps", testPattern: /Map tile server URL/i },localization: { path: "/localization", testPattern: /Instance language/i },diff --git a/resources/frontend_client/app/assets/img/api-keys-empty.svg b/resources/frontend_client/app/assets/img/api-keys-empty.svgnew file mode 100644index 00000000000..99396bf569e--- /dev/null+++ b/resources/frontend_client/app/assets/img/api-keys-empty.svg@@ -0,0 +1,18 @@+<svg xmlns="http://www.w3.org/2000/svg" width="96" height="96" viewBox="0 0 96 96" fill="none">+ <circle cx="48" cy="48" r="48" fill="currentColor" fill-opacity="0.05"/>+ <g filter="url(#filter0_d_9_27)">+ <path d="M64.7334 28.6039C65.5256 27.7986 66.8098 27.7988 67.6021 28.6039C68.3943 29.4093 68.3943 30.7147 67.6021 31.52L65.4307 33.7273L69.4062 37.7686L69.5462 37.927C70.195 38.7367 70.148 39.93 69.4062 40.6847L63.0957 47.1024C62.3529 47.8575 61.177 47.9029 60.3802 47.242L60.2244 47.1024L56.2489 43.0611L51.5893 47.7952C52.1044 48.5278 52.5415 49.3161 52.8863 50.1501C53.4966 51.6268 53.8135 53.2127 53.8188 54.8144C53.824 56.416 53.5185 58.0033 52.918 59.484C52.3176 60.9644 51.4352 62.3097 50.3214 63.442C49.2073 64.5746 47.8819 65.4711 46.4252 66.0816C44.9691 66.6917 43.4093 67.0051 41.8343 66.9999C40.2589 66.9946 38.6986 66.6723 37.2461 66.0521C35.7935 65.4317 34.4749 64.5257 33.3684 63.3856L33.3551 63.3695C31.179 61.0791 29.9732 58.0093 30.0005 54.8251C30.028 51.6414 31.2857 48.5965 33.5004 46.3452C35.7152 44.0939 38.7103 42.8152 41.8422 42.7873C44.3002 42.7655 46.6862 43.5188 48.689 44.9113L64.7334 28.6039ZM41.8792 46.9118C39.8108 46.93 37.8318 47.7745 36.3691 49.2613C34.9064 50.7483 34.0758 52.7599 34.0578 54.8627C34.04 56.9583 34.8302 58.9774 36.2581 60.4883L36.8313 61.0226C37.4293 61.5277 38.0984 61.9426 38.8177 62.2498C39.7768 62.6593 40.8073 62.8719 41.8475 62.8754C42.8877 62.8788 43.9183 62.6716 44.88 62.2686C45.8418 61.8654 46.7171 61.2737 47.4528 60.5259C48.1882 59.7781 48.7706 58.8881 49.1671 57.9104C49.5634 56.9329 49.7649 55.8851 49.7614 54.8278C49.7579 53.7702 49.5489 52.7229 49.146 51.7479C48.746 50.7804 48.1616 49.9039 47.429 49.1647L46.8479 48.6464C45.4415 47.5132 43.6892 46.896 41.8792 46.9118ZM59.1176 40.1423L61.6587 42.7255L65.1032 39.2266L62.5621 36.6435L59.1176 40.1423Z" fill="white" shape-rendering="crispEdges"/>+ <path d="M64.7334 28.6039C65.5256 27.7986 66.8098 27.7988 67.6021 28.6039C68.3943 29.4093 68.3943 30.7147 67.6021 31.52L65.4307 33.7273L69.4062 37.7686L69.5462 37.927C70.195 38.7367 70.148 39.93 69.4062 40.6847L63.0957 47.1024C62.3529 47.8575 61.177 47.9029 60.3802 47.242L60.2244 47.1024L56.2489 43.0611L51.5893 47.7952C52.1044 48.5278 52.5415 49.3161 52.8863 50.1501C53.4966 51.6268 53.8135 53.2127 53.8188 54.8144C53.824 56.416 53.5185 58.0033 52.918 59.484C52.3176 60.9644 51.4352 62.3097 50.3214 63.442C49.2073 64.5746 47.8819 65.4711 46.4252 66.0816C44.9691 66.6917 43.4093 67.0051 41.8343 66.9999C40.2589 66.9946 38.6986 66.6723 37.2461 66.0521C35.7935 65.4317 34.4749 64.5257 33.3684 63.3856L33.3551 63.3695C31.179 61.0791 29.9732 58.0093 30.0005 54.8251C30.028 51.6414 31.2857 48.5965 33.5004 46.3452C35.7152 44.0939 38.7103 42.8152 41.8422 42.7873C44.3002 42.7655 46.6862 43.5188 48.689 44.9113L64.7334 28.6039ZM41.8792 46.9118C39.8108 46.93 37.8318 47.7745 36.3691 49.2613C34.9064 50.7483 34.0758 52.7599 34.0578 54.8627C34.04 56.9583 34.8302 58.9774 36.2581 60.4883L36.8313 61.0226C37.4293 61.5277 38.0984 61.9426 38.8177 62.2498C39.7768 62.6593 40.8073 62.8719 41.8475 62.8754C42.8877 62.8788 43.9183 62.6716 44.88 62.2686C45.8418 61.8654 46.7171 61.2737 47.4528 60.5259C48.1882 59.7781 48.7706 58.8881 49.1671 57.9104C49.5634 56.9329 49.7649 55.8851 49.7614 54.8278C49.7579 53.7702 49.5489 52.7229 49.146 51.7479C48.746 50.7804 48.1616 49.9039 47.429 49.1647L46.8479 48.6464C45.4415 47.5132 43.6892 46.896 41.8792 46.9118ZM59.1176 40.1423L61.6587 42.7255L65.1032 39.2266L62.5621 36.6435L59.1176 40.1423Z" stroke="currentColor" stroke-opacity="0.14" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" shape-rendering="crispEdges"/>+ </g>+ <defs>+ <filter id="filter0_d_9_27" x="29.25" y="27.25" width="42.5" height="41.5" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>+ <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>+ <feOffset dx="1" dy="1"/>+ <feComposite in2="hardAlpha" operator="out"/>+ <feColorMatrix type="matrix" values="0 0 0 0 0.892879 0 0 0 0 0.892879 0 0 0 0 0.892879 0 0 0 1 0"/>+ <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_9_27"/>+ <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_9_27" result="shape"/>+ </filter>+ </defs>+</svg>