Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-2931: Make Alerts Management tabs visible by default (#79166)

Stas Gavrylova7691ffcbf4d
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationDetailSidebar/SidebarHeader.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationDetailSidebar/SidebarHeader.tsx
index 3e4bd88682b..8840c2947fc 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationDetailSidebar/SidebarHeader.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationDetailSidebar/SidebarHeader.tsx
@@ -39,6 +39,8 @@ export const SidebarHeader = ({
}: SidebarHeaderProps) => {
const cardName = notification?.payload?.card?.name ?? t`Untitled question`;
const dispatch = useDispatch();
+ const isEditDisabled =
+ notification == null || isQuestionLoading || isBulkLoading;
const handleCopyLink = async () => {
const url = `${window.location.origin}${Urls.monitorNotificationDetail(notificationId)}`;
@@ -113,8 +115,8 @@ export const SidebarHeader = ({
aria-label={t`Edit`}
size="lg"
c="icon-primary"
- disabled={isQuestionLoading || isBulkLoading}
- onClick={!isQuestionLoading ? onEdit : undefined}
+ disabled={isEditDisabled}
+ onClick={!isEditDisabled ? onEdit : undefined}
>
{isQuestionLoading ? <Loader size="sm" /> : <Icon name="pencil" />}
</ActionIcon>
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.tsx
index 755027425f3..f621abe609a 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.tsx
@@ -49,7 +49,7 @@ import {
SORT_COLUMN_VALUES,
} from "./constants";
import type { RouteParams } from "./types";
-import { buildListParams, urlStateConfig } from "./utils";
+import { buildListParams, getTabCount, urlStateConfig } from "./utils";
export const NotificationsAdminPage = () => {
const location = useLocation();
@@ -77,9 +77,18 @@ export const NotificationsAdminPage = () => {
const selectedCount = selectedNotifications.length;
const {
- data: failingData,
+ currentData: allCountData,
+ error: allCountError,
+ isFetching: isAllCountFetching,
+ } = useAdminListNotificationsQuery({
+ limit: 1,
+ offset: 0,
+ active: urlState.active ?? undefined,
+ });
+ const {
+ currentData: failingData,
error: failingError,
- isLoading: isFailingLoading,
+ isFetching: isFailingFetching,
} = useAdminListNotificationsQuery({
limit: 1,
offset: 0,
@@ -87,34 +96,19 @@ export const NotificationsAdminPage = () => {
last_check_status: "failing",
});
const {
- data: ownerlessData,
+ currentData: ownerlessData,
error: ownerlessError,
- isLoading: isOwnerlessLoading,
+ isFetching: isOwnerlessFetching,
} = useAdminListNotificationsQuery({
limit: 1,
offset: 0,
active: urlState.active ?? undefined,
creatorless: true,
});
+ const allCount = allCountData?.total ?? 0;
const failingCount = failingData?.total ?? 0;
const ownerlessCount = ownerlessData?.total ?? 0;
- useEffect(() => {
- if (
- (urlState.tab === "failing" && failingData && failingCount === 0) ||
- (urlState.tab === "ownerless" && ownerlessData && ownerlessCount === 0)
- ) {
- patchUrlState({ tab: "all", page: 0 });
- }
- }, [
- urlState.tab,
- failingData,
- failingCount,
- ownerlessData,
- ownerlessCount,
- patchUrlState,
- ]);
-
const [bulkAction, { isLoading: isBulkLoading }] =
useBulkNotificationActionMutation();
@@ -282,8 +276,18 @@ export const NotificationsAdminPage = () => {
);
const isSidebarOpen = notificationId !== undefined;
- const isPageLoading = isLoading || isFailingLoading || isOwnerlessLoading;
const countError = failingError ?? ownerlessError;
+ const allTabCount = getTabCount(isAllCountFetching, allCountError, allCount);
+ const failingTabCount = getTabCount(
+ isFailingFetching,
+ failingError,
+ failingCount,
+ );
+ const ownerlessTabCount = getTabCount(
+ isOwnerlessFetching,
+ ownerlessError,
+ ownerlessCount,
+ );
const { prevNotificationId, nextNotificationId, notificationSummary } =
useMemo(() => {
@@ -312,10 +316,8 @@ export const NotificationsAdminPage = () => {
};
}, [notificationId, notifications]);
- if (isPageLoading || countError) {
- return (
- <LoadingAndErrorWrapper loading={isPageLoading} error={countError} />
- );
+ if (countError) {
+ return <LoadingAndErrorWrapper error={countError} />;
}
return (
@@ -326,8 +328,9 @@ export const NotificationsAdminPage = () => {
<NotificationsTabs
tab={urlState.tab}
- failingCount={failingCount}
- ownerlessCount={ownerlessCount}
+ allCount={allTabCount}
+ failingCount={failingTabCount}
+ ownerlessCount={ownerlessTabCount}
onChange={(patch) => patchUrlState({ ...patch, page: 0 })}
/>
@@ -354,21 +357,29 @@ export const NotificationsAdminPage = () => {
onRowClick={handleRowClick}
/>
- <Flex justify="end">
- <PaginationControls
- page={urlState.page}
- pageSize={PAGE_SIZE}
- itemsLength={notifications.length}
- total={total}
- showTotal
- onPreviousPage={() =>
- patchUrlState({ page: urlState.page - 1 }, { immediate: true })
- }
- onNextPage={() =>
- patchUrlState({ page: urlState.page + 1 }, { immediate: true })
- }
- />
- </Flex>
+ {!isLoading && error === undefined && (
+ <Flex justify="end">
+ <PaginationControls
+ page={urlState.page}
+ pageSize={PAGE_SIZE}
+ itemsLength={notifications.length}
+ total={total}
+ showTotal
+ onPreviousPage={() =>
+ patchUrlState(
+ { page: urlState.page - 1 },
+ { immediate: true },
+ )
+ }
+ onNextPage={() =>
+ patchUrlState(
+ { page: urlState.page + 1 },
+ { immediate: true },
+ )
+ }
+ />
+ </Flex>
+ )}
</MonitorMain>
{isSidebarOpen && (
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.unit.spec.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.unit.spec.tsx
index 625f187342e..056196d8e9f 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.unit.spec.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/NotificationsAdminPage.unit.spec.tsx
@@ -18,7 +18,6 @@ import {
renderWithProviders,
screen,
waitFor,
- waitForLoaderToBeRemoved,
within,
} from "__support__/ui";
import { URL_UPDATE_DEBOUNCE_DELAY } from "metabase/common/hooks/use-url-state";
@@ -130,6 +129,7 @@ const multiHandlerNotification = createMockAdminNotification({
type SetupOpts = {
notifications?: AdminNotification[];
total?: number;
+ allCount?: number;
failingCount?: number;
ownerlessCount?: number;
users?: UserListResult[];
@@ -138,11 +138,13 @@ type SetupOpts = {
detailDelay?: number;
detailErrorId?: NotificationId;
failingCountError?: boolean;
+ allCountError?: boolean;
};
const setup = ({
notifications = [notification1],
total = notifications.length,
+ allCount = total,
failingCount = 0,
ownerlessCount = 0,
users = [],
@@ -151,6 +153,7 @@ const setup = ({
detailDelay,
detailErrorId,
failingCountError = false,
+ allCountError = false,
}: SetupOpts = {}) => {
fetchMock.get("path:/api/notification/admin", (call) => {
const params = new URL(call.url).searchParams;
@@ -165,6 +168,15 @@ const setup = ({
if (params.get("limit") === "1" && params.get("creatorless") === "true") {
return { data: [], total: ownerlessCount, limit: 1, offset: 0 };
}
+ if (
+ params.get("limit") === "1" &&
+ !params.has("last_check_status") &&
+ !params.has("creatorless")
+ ) {
+ return allCountError
+ ? { status: 500, body: { message: "All count failed" } }
+ : { data: [], total: allCount, limit: 1, offset: 0 };
+ }
return { data: notifications, total, limit: PAGE_SIZE, offset: 0 };
});
@@ -214,6 +226,16 @@ const getListCalls = () =>
new URL(call.url).searchParams.get("limit") === String(PAGE_SIZE),
);
+const getAllCountCalls = () =>
+ fetchMock.callHistory.calls("path:/api/notification/admin").filter((call) => {
+ const params = new URL(call.url).searchParams;
+ return (
+ params.get("limit") === "1" &&
+ !params.has("last_check_status") &&
+ !params.has("creatorless")
+ );
+ });
+
const getFailingCountCalls = () =>
fetchMock.callHistory.calls("path:/api/notification/admin").filter((call) => {
const params = new URL(call.url).searchParams;
@@ -228,6 +250,10 @@ const getBulkPosts = async () =>
request.url.includes("/api/notification/admin/bulk"),
);
+// Tabs, filters, and the table skeleton render immediately (no page-blocking
+// loader), so tests wait for the real grid to replace the skeleton instead.
+const waitForTableToLoad = () => screen.findByRole("treegrid");
+
describe("NotificationsAdminPage", () => {
beforeEach(() => {
jest.useFakeTimers({ advanceTimers: true });
@@ -240,18 +266,42 @@ describe("NotificationsAdminPage", () => {
});
describe("rendering", () => {
- it("shows a loader and then renders the table", async () => {
+ it("shows tabs, filters, and a grid skeleton immediately, then renders the table", async () => {
setup();
- expect(screen.getByTestId("loading-indicator")).toBeInTheDocument();
- await waitForLoaderToBeRemoved();
+
+ expect(
+ screen.getByTestId("notifications-admin-tabs"),
+ ).toBeInTheDocument();
expect(
- screen.getByTestId("notifications-admin-table"),
+ screen.getByPlaceholderText(/Search by question or owner/),
).toBeInTheDocument();
+ expect(screen.getByTestId("notifications-admin-table")).toHaveAttribute(
+ "aria-busy",
+ "true",
+ );
+ expect(screen.queryByRole("treegrid")).not.toBeInTheDocument();
+
+ await waitForTableToLoad();
+ expect(screen.getByTestId("notifications-admin-table")).toHaveAttribute(
+ "aria-busy",
+ "false",
+ );
+ });
+
+ it("hides pagination until the grid has loaded", async () => {
+ setup({ notifications: [notification1, notification2], total: 120 });
+
+ expect(screen.queryByTestId("pagination-total")).not.toBeInTheDocument();
+
+ await waitForTableToLoad();
+ expect(await screen.findByTestId("pagination-total")).toHaveTextContent(
+ "120",
+ );
});
it("renders a row per notification with its owner and question", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row1 = await screen.findByTestId("notification-row-1");
const row2 = await screen.findByTestId("notification-row-2");
@@ -263,7 +313,7 @@ describe("NotificationsAdminPage", () => {
it("counts webhook handlers as configured channels", async () => {
setup({ notifications: [webhookNotification] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row = await screen.findByTestId("notification-row-99");
expect(within(row).getByText("Webhook Alert")).toBeInTheDocument();
@@ -278,7 +328,7 @@ describe("NotificationsAdminPage", () => {
it("merges multiple handlers across and within channels", async () => {
setup({ notifications: [multiHandlerNotification] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row = await screen.findByTestId("notification-row-50");
expect(within(row).getByText("Multi Channel Alert")).toBeInTheDocument();
@@ -298,24 +348,34 @@ describe("NotificationsAdminPage", () => {
it("shows an empty state when there are no notifications", async () => {
setup({ notifications: [] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
expect(await screen.findByText("No alerts")).toBeInTheDocument();
});
});
describe("tabs", () => {
- it("hides the tabs when there are no failing or ownerless alerts", async () => {
+ it("shows tabs with a loading placeholder before counts resolve", async () => {
setup({ failingCount: 0, ownerlessCount: 0 });
- await waitForLoaderToBeRemoved();
- expect(
- screen.queryByTestId("notifications-admin-tabs"),
- ).not.toBeInTheDocument();
+
+ const failingTab = screen.getByTestId("notifications-admin-tab-failing");
+ const ownerlessTab = screen.getByTestId(
+ "notifications-admin-tab-ownerless",
+ );
+ expect(within(failingTab).queryByText(/\d/)).not.toBeInTheDocument();
+ expect(within(ownerlessTab).queryByText(/\d/)).not.toBeInTheDocument();
+
+ await waitForTableToLoad();
+ expect(within(failingTab).getByText("0")).toBeInTheDocument();
+ expect(within(ownerlessTab).getByText("0")).toBeInTheDocument();
});
- it("renders failing and ownerless tabs with their counts", async () => {
- setup({ failingCount: 2, ownerlessCount: 3 });
- await waitForLoaderToBeRemoved();
+ it("always shows all three tabs, even when a tab has no alerts", async () => {
+ setup({ failingCount: 0, ownerlessCount: 0 });
+ await waitForTableToLoad();
+ expect(
+ screen.getByTestId("notifications-admin-tab-all"),
+ ).toBeInTheDocument();
expect(
screen.getByTestId("notifications-admin-tab-failing"),
).toBeInTheDocument();
@@ -324,9 +384,36 @@ describe("NotificationsAdminPage", () => {
).toBeInTheDocument();
});
+ it("renders failing and ownerless tabs with their counts", async () => {
+ setup({ failingCount: 2, ownerlessCount: 3 });
+ await waitForTableToLoad();
+
+ const failingTab = screen.getByTestId("notifications-admin-tab-failing");
+ const ownerlessTab = screen.getByTestId(
+ "notifications-admin-tab-ownerless",
+ );
+ expect(within(failingTab).getByText("2")).toBeInTheDocument();
+ expect(within(ownerlessTab).getByText("3")).toBeInTheDocument();
+ });
+
+ it("keeps the All tab's true total after switching to a filtered tab", async () => {
+ setup({ allCount: 137, failingCount: 9, ownerlessCount: 33 });
+ await waitForTableToLoad();
+
+ const allTab = screen.getByTestId("notifications-admin-tab-all");
+ expect(within(allTab).getByText("137")).toBeInTheDocument();
+
+ await userEvent.click(
+ screen.getByTestId("notifications-admin-tab-failing"),
+ );
+ await waitForTableToLoad();
+
+ expect(within(allTab).getByText("137")).toBeInTheDocument();
+ });
+
it("pushes the selected tab to the URL", async () => {
const { history } = setup({ failingCount: 2 });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(
screen.getByTestId("notifications-admin-tab-failing"),
@@ -340,21 +427,47 @@ describe("NotificationsAdminPage", () => {
});
});
- it("redirects away from an empty failing tab", async () => {
+ it("does not redirect away from a failing tab with no alerts", async () => {
const { history } = setup({
failingCount: 0,
initialRoute: `${PATHNAME}?tab=failing`,
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
- await waitFor(() => {
- expect(history?.getCurrentLocation().search).not.toContain("failing");
+ expect(history?.getCurrentLocation().search).toContain("tab=failing");
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-failing")).getByText(
+ "0",
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("does not redirect away from an ownerless tab with no alerts", async () => {
+ const { history } = setup({
+ ownerlessCount: 0,
+ initialRoute: `${PATHNAME}?tab=ownerless`,
});
+ await waitForTableToLoad();
+
+ expect(history?.getCurrentLocation().search).toContain("tab=ownerless");
+ expect(
+ within(
+ screen.getByTestId("notifications-admin-tab-ownerless"),
+ ).getByText("0"),
+ ).toBeInTheDocument();
+ });
+
+ it("counts all alerts with the active filter applied", async () => {
+ setup({ initialRoute: `${PATHNAME}?active=false` });
+ await waitForTableToLoad();
+
+ const [countCall] = getAllCountCalls();
+ expect(new URL(countCall.url).searchParams.get("active")).toBe("false");
});
it("counts inactive failing alerts when the status filter includes them", async () => {
setup({ initialRoute: `${PATHNAME}?active=all` });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const [countCall] = getFailingCountCalls();
expect(new URL(countCall.url).searchParams.get("active")).toBeNull();
@@ -365,12 +478,29 @@ describe("NotificationsAdminPage", () => {
expect(await screen.findByText("Count failed")).toBeInTheDocument();
});
+
+ it("keeps the page usable when only the all-count request fails", async () => {
+ setup({ allCountError: true, failingCount: 2 });
+ await waitForTableToLoad();
+
+ expect(screen.queryByText("All count failed")).not.toBeInTheDocument();
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-all")).queryByText(
+ /\d/,
+ ),
+ ).not.toBeInTheDocument();
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-failing")).getByText(
+ "2",
+ ),
+ ).toBeInTheDocument();
+ });
});
describe("search, sorting and pagination", () => {
it("pushes the search query to the URL", async () => {
const { history } = setup();
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.type(
screen.getByPlaceholderText(/Search by question or owner/),
@@ -396,7 +526,7 @@ describe("NotificationsAdminPage", () => {
it("pushes sorting changes to the URL and refetches", async () => {
const { history } = setup();
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(screen.getByRole("columnheader", { name: "ID" }));
@@ -421,7 +551,7 @@ describe("NotificationsAdminPage", () => {
notifications: [notification1, notification2],
total: 120,
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
expect(await screen.findByTestId("pagination-total")).toHaveTextContent(
"120",
@@ -450,7 +580,7 @@ describe("NotificationsAdminPage", () => {
describe("selection and bulk actions", () => {
it("shows the bulk action bar when a row is selected", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row1 = await screen.findByTestId("notification-row-1");
await userEvent.click(within(row1).getByRole("checkbox"));
@@ -467,7 +597,7 @@ describe("NotificationsAdminPage", () => {
it("selects every row with the header checkbox", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(
screen.getByRole("checkbox", { name: "Select all" }),
@@ -480,7 +610,7 @@ describe("NotificationsAdminPage", () => {
it("selects the keyboard-highlighted row via space", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
screen.getByRole("treegrid", { name: "Notifications" }).focus();
await userEvent.keyboard("{ArrowDown} ");
@@ -493,7 +623,7 @@ describe("NotificationsAdminPage", () => {
it("clears the selection with the Clear button", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row1 = await screen.findByTestId("notification-row-1");
await userEvent.click(within(row1).getByRole("checkbox"));
@@ -513,7 +643,7 @@ describe("NotificationsAdminPage", () => {
notifications: [notification1, notification2],
total: 120,
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row1 = await screen.findByTestId("notification-row-1");
await userEvent.click(within(row1).getByRole("checkbox"));
@@ -528,7 +658,7 @@ describe("NotificationsAdminPage", () => {
it("removes selected alerts after confirmation", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(
screen.getByRole("checkbox", { name: "Select all" }),
@@ -567,7 +697,7 @@ describe("NotificationsAdminPage", () => {
notifications: [notification1, notification2],
users: [newOwner],
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(
screen.getByRole("checkbox", { name: "Select all" }),
@@ -609,7 +739,7 @@ describe("NotificationsAdminPage", () => {
describe("detail sidebar", () => {
it("opens the sidebar on row click and closes it again", async () => {
const { history } = setup({ notifications: [notification1] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
@@ -638,7 +768,7 @@ describe("NotificationsAdminPage", () => {
const { history } = setup({
notifications: [notification1, notification2],
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
expect(history?.getCurrentLocation().pathname).toBe(`${PATHNAME}/1`);
@@ -667,7 +797,7 @@ describe("NotificationsAdminPage", () => {
it("deletes the open alert from the sidebar menu", async () => {
const { history } = setup({ notifications: [notification1] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
expect(await screen.findByText("Alert 1")).toBeInTheDocument();
@@ -700,7 +830,7 @@ describe("NotificationsAdminPage", () => {
it("copies the alert link to the clipboard from the sidebar menu", async () => {
setup({ notifications: [notification1] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
expect(await screen.findByText("Alert 1")).toBeInTheDocument();
@@ -723,7 +853,7 @@ describe("NotificationsAdminPage", () => {
it("keeps the edit action disabled until the question has loaded", async () => {
setup({ notifications: [notification1], cardDelay: 10_000 });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
expect(await screen.findByText("Alert 1")).toBeInTheDocument();
@@ -739,9 +869,28 @@ describe("NotificationsAdminPage", () => {
});
});
+ it("keeps the edit action disabled while a directly-linked alert is still loading", async () => {
+ setup({
+ notifications: [notification1],
+ initialRoute: `${PATHNAME}/1`,
+ cardDelay: 10_000,
+ });
+ await waitForTableToLoad();
+
+ expect(screen.getByRole("button", { name: "Edit" })).toBeDisabled();
+
+ act(() => {
+ jest.advanceTimersByTime(10_000);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByRole("button", { name: "Edit" })).toBeEnabled();
+ });
+ });
+
it("points the run-history 'View all' links at the card runs, including today", async () => {
setup({ notifications: [notification1] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
expect(await screen.findByText("Alert 1")).toBeInTheDocument();
@@ -759,7 +908,7 @@ describe("NotificationsAdminPage", () => {
it("shows loaders in the history sections while the alert detail loads", async () => {
setup({ notifications: [notification1], detailDelay: 10_000 });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(await screen.findByTestId("notification-row-1"));
@@ -796,7 +945,7 @@ describe("NotificationsAdminPage", () => {
describe("change owner modal", () => {
it("preselects the owner when a single alert is selected", async () => {
setup({ notifications: [notification1, notification2] });
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
const row1 = await screen.findByTestId("notification-row-1");
await userEvent.click(within(row1).getByRole("checkbox"));
@@ -831,7 +980,7 @@ describe("NotificationsAdminPage", () => {
notifications: [notification1, notification2],
users: [newOwner],
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(
screen.getByRole("checkbox", { name: "Select all" }),
@@ -885,7 +1034,7 @@ describe("NotificationsAdminPage", () => {
notifications: [notification1, notification2],
users: [newOwner],
});
- await waitForLoaderToBeRemoved();
+ await waitForTableToLoad();
await userEvent.click(
screen.getByRole("checkbox", { name: "Select all" }),
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/types.ts b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/types.ts
index 3a1375cf82e..c2a6ccbc94a 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/types.ts
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/types.ts
@@ -12,6 +12,11 @@ export type RouteParams = {
export type NotificationsTab = "all" | "failing" | "ownerless";
+export type TabCountState =
+ | { status: "loading" }
+ | { status: "error" }
+ | { status: "loaded"; value: number };
+
export type NotificationsUrlState = {
page: number;
active: boolean | null;
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/utils.ts b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/utils.ts
index 16a64b55a41..7e9453e3d63 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/utils.ts
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsAdminPage/utils.ts
@@ -30,7 +30,11 @@ import {
TAB_FILTERS,
TAB_VALUES,
} from "./constants";
-import type { NotificationsTab, NotificationsUrlState } from "./types";
+import type {
+ NotificationsTab,
+ NotificationsUrlState,
+ TabCountState,
+} from "./types";
const parsePage = (param: QueryParam): number => {
const value = getFirstParamValue(param);
@@ -199,6 +203,20 @@ export const buildListParams = (
};
};
+export const getTabCount = (
+ isLoading: boolean,
+ error: unknown,
+ value: number,
+): TabCountState => {
+ if (isLoading) {
+ return { status: "loading" };
+ }
+ if (error !== undefined) {
+ return { status: "error" };
+ }
+ return { status: "loaded", value };
+};
+
export const getChannelLabel = (channel: NotificationChannelType): string =>
match(channel)
.with("channel/email", () => t`Email`)
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsTable/NotificationsTable.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationsTable/NotificationsTable.tsx
index 92f367caaa1..39ae48faec5 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsTable/NotificationsTable.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsTable/NotificationsTable.tsx
@@ -22,6 +22,7 @@ import {
Text,
Tooltip,
TreeTable,
+ TreeTableSkeleton,
useTreeTableInstance,
} from "metabase/ui";
import { EMPTY_CELL_PLACEHOLDER } from "metabase/utils/constants";
@@ -84,7 +85,7 @@ export const NotificationsTable = ({
accessorFn: (notification) => notification.id,
cell: ({ row }) => (
<Flex justify="center">
- <Badge variant="outline" size="sm" miw={29}>
+ <Badge variant="light" color="brand" size="xs" miw={29}>
{row.original.id}
</Badge>
</Flex>
@@ -229,7 +230,7 @@ export const NotificationsTable = ({
[],
);
- if (isLoading || error !== undefined) {
+ if (error !== undefined) {
return (
<Card
flex="0 1 auto"
@@ -238,7 +239,7 @@ export const NotificationsTable = ({
p="lg"
data-testid="notifications-admin-table"
>
- <LoadingAndErrorWrapper loading={isLoading} error={error} />
+ <LoadingAndErrorWrapper error={error} />
</Card>
);
}
@@ -249,19 +250,27 @@ export const NotificationsTable = ({
mih={0}
p={0}
withBorder
+ aria-busy={isLoading}
data-testid="notifications-admin-table"
>
- <TreeTable
- instance={instance}
- hierarchical={false}
- showCheckboxes
- onHeaderCheckboxClick={() => instance.table.toggleAllRowsSelected()}
- headerCheckboxAriaLabel={t`Select all`}
- ariaLabel={t`Notifications`}
- onRowClick={handleRowActivate}
- getRowProps={getRowProps}
- emptyState={<MonitorEmptyState label={t`No alerts`} />}
- />
+ {isLoading ? (
+ <TreeTableSkeleton
+ showCheckboxes
+ columnWidths={[0.06, 0.28, 0.18, 0.16, 0.16, 0.16]}
+ />
+ ) : (
+ <TreeTable
+ instance={instance}
+ hierarchical={false}
+ showCheckboxes
+ onHeaderCheckboxClick={() => instance.table.toggleAllRowsSelected()}
+ headerCheckboxAriaLabel={t`Select all`}
+ ariaLabel={t`Notifications`}
+ onRowClick={handleRowActivate}
+ getRowProps={getRowProps}
+ emptyState={<MonitorEmptyState label={t`No alerts`} />}
+ />
+ )}
</Card>
);
};
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx
index fa4f7843826..eafdafa500c 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.tsx
@@ -1,11 +1,13 @@
+import { match } from "ts-pattern";
import { t } from "ttag";
-import { Icon, Tabs } from "metabase/ui";
+import { Badge, Icon, Skeleton, Tabs } from "metabase/ui";
import type { IconName } from "metabase-types/api";
import type {
NotificationsTab,
NotificationsUrlState,
+ TabCountState,
} from "../NotificationsAdminPage/types";
import { trackAlertsManagementTabClicked } from "../analytics";
@@ -13,8 +15,9 @@ import S from "./NotificationsTabs.module.css";
type Props = {
tab: NotificationsTab;
- failingCount: number;
- ownerlessCount: number;
+ allCount: TabCountState;
+ failingCount: TabCountState;
+ ownerlessCount: TabCountState;
onChange: (patch: Partial<NotificationsUrlState>) => void;
};
@@ -22,33 +25,60 @@ type TabConfig = {
value: NotificationsTab;
icon: IconName;
label: string;
+ count: TabCountState;
patch: Partial<NotificationsUrlState>;
};
+const TabCountBadge = ({
+ count,
+ isActive,
+}: {
+ count: TabCountState;
+ isActive: boolean;
+}) =>
+ match(count)
+ .with({ status: "loading" }, () => (
+ <Skeleton
+ h={16}
+ miw="1.5rem"
+ radius="xl"
+ data-testid="tab-count-skeleton"
+ />
+ ))
+ .with({ status: "loaded" }, ({ value }) =>
+ isActive ? (
+ <Badge variant="filled" size="xs" color="brand" c="white">
+ {value}
+ </Badge>
+ ) : (
+ <Badge variant="light" size="xs" color="neutral">
+ {value}
+ </Badge>
+ ),
+ )
+ .with({ status: "error" }, () => null)
+ .exhaustive();
+
export const NotificationsTabs = ({
tab,
+ allCount,
failingCount,
ownerlessCount,
onChange,
}: Props) => {
- if (failingCount === 0 && ownerlessCount === 0) {
- return null;
- }
-
const tabs: TabConfig[] = [
{
value: "all",
icon: "alert",
label: t`All alerts`,
+ count: allCount,
patch: { tab: "all" },
},
- ];
-
- if (failingCount > 0) {
- tabs.push({
+ {
value: "failing",
icon: "warning_round",
label: t`Failing`,
+ count: failingCount,
// The Failing tab filters on last_check, and abandoned / query-failed runs have no last_send
// (the default sort), so they'd sort to the bottom. Default this tab to last_check so the
// alerts it exists to surface land at the top.
@@ -58,17 +88,15 @@ export const NotificationsTabs = ({
sort_column: "last_check",
sort_direction: "desc",
},
- });
- }
-
- if (ownerlessCount > 0) {
- tabs.push({
+ },
+ {
value: "ownerless",
icon: "ghost",
label: t`Ownerless`,
+ count: ownerlessCount,
patch: { tab: "ownerless", creator_active: null },
- });
- }
+ },
+ ];
const handleTabChange = (value: NotificationsTab | null) => {
const next = tabs.find((config) => config.value === value);
@@ -98,6 +126,12 @@ export const NotificationsTabs = ({
key={config.value}
value={config.value}
leftSection={<Icon name={config.icon} size={16} />}
+ rightSection={
+ <TabCountBadge
+ count={config.count}
+ isActive={config.value === tab}
+ />
+ }
data-testid={`notifications-admin-tab-${config.value}`}
>
{config.label}
diff --git a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.unit.spec.tsx b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.unit.spec.tsx
index 4cf2ec16b22..e4683fd4737 100644
--- a/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.unit.spec.tsx
+++ b/frontend/src/metabase/monitor/tools/notifications/NotificationsTabs/NotificationsTabs.unit.spec.tsx
@@ -1,6 +1,6 @@
import userEvent from "@testing-library/user-event";
-import { renderWithProviders, screen } from "__support__/ui";
+import { renderWithProviders, screen, within } from "__support__/ui";
import { NotificationsTabs } from "./NotificationsTabs";
@@ -14,8 +14,9 @@ describe("NotificationsTabs", () => {
renderWithProviders(
<NotificationsTabs
tab="all"
- failingCount={3}
- ownerlessCount={0}
+ allCount={{ status: "loaded", value: 3 }}
+ failingCount={{ status: "loaded", value: 3 }}
+ ownerlessCount={{ status: "loaded", value: 0 }}
onChange={onChange}
/>,
);
@@ -30,4 +31,90 @@ describe("NotificationsTabs", () => {
}),
);
});
+
+ it("always renders all three tabs, even when a tab's count is zero", () => {
+ renderWithProviders(
+ <NotificationsTabs
+ tab="all"
+ allCount={{ status: "loaded", value: 5 }}
+ failingCount={{ status: "loaded", value: 0 }}
+ ownerlessCount={{ status: "loaded", value: 0 }}
+ onChange={jest.fn()}
+ />,
+ );
+
+ expect(
+ screen.getByTestId("notifications-admin-tab-all"),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByTestId("notifications-admin-tab-failing"),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByTestId("notifications-admin-tab-ownerless"),
+ ).toBeInTheDocument();
+ });
+
+ it("shows the resolved count next to each tab", () => {
+ renderWithProviders(
+ <NotificationsTabs
+ tab="all"
+ allCount={{ status: "loaded", value: 5 }}
+ failingCount={{ status: "loaded", value: 2 }}
+ ownerlessCount={{ status: "loaded", value: 0 }}
+ onChange={jest.fn()}
+ />,
+ );
+
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-failing")).getByText(
+ "2",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-ownerless")).getByText(
+ "0",
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("drops the badge when a count fails to load", () => {
+ renderWithProviders(
+ <NotificationsTabs
+ tab="all"
+ allCount={{ status: "error" }}
+ failingCount={{ status: "loaded", value: 2 }}
+ ownerlessCount={{ status: "loaded", value: 0 }}
+ onChange={jest.fn()}
+ />,
+ );
+
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-all")).queryByText(
+ /\d/,
+ ),
+ ).not.toBeInTheDocument();
+ expect(
+ within(screen.getByTestId("notifications-admin-tab-failing")).getByText(
+ "2",
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("shows a loading placeholder instead of a count while it resolves", () => {
+ renderWithProviders(
+ <NotificationsTabs
+ tab="all"
+ allCount={{ status: "loading" }}
+ failingCount={{ status: "loading" }}
+ ownerlessCount={{ status: "loading" }}
+ onChange={jest.fn()}
+ />,
+ );
+
+ const failingTab = screen.getByTestId("notifications-admin-tab-failing");
+ expect(
+ within(failingTab).getByTestId("tab-count-skeleton"),
+ ).toBeInTheDocument();
+ expect(within(failingTab).queryByText(/\d/)).not.toBeInTheDocument();
+ });
});