Skip to content

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

[GHY-4747] Show a note on a transform's tags when no enabled job runs them (#85731)

Tyler Plude66e5e46e6434
diff --git a/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.tsx b/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.tsx
index f077e3dce87..db2a9219f88 100644
--- a/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.tsx
+++ b/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.tsx
@@ -7,6 +7,7 @@ import {
skipToken,
useCancelCurrentTransformRunMutation,
useListDagRunTransformRunsQuery,
+ useListTransformJobsQuery,
useRunTransformDagMutation,
useRunTransformMutation,
useUpdateTransformMutation,
@@ -26,6 +27,7 @@ import {
Icon,
Menu,
Stack,
+ Text,
} from "metabase/ui";
import * as Urls from "metabase/urls";
import { isResourceNotFoundError } from "metabase/utils/errors";
@@ -363,12 +365,42 @@ function TagSection({ transform, readOnly }: TagSectionProps) {
};
return (
- <Box flex={1}>
+ <Stack flex={1} gap="sm">
<TagMultiSelect
onChange={handleTagListChange}
readOnly={readOnly}
tagIds={transform.tag_ids ?? []}
/>
- </Box>
+ <NoActiveJobNote tagIds={transform.tag_ids ?? []} />
+ </Stack>
+ );
+}
+
+type NoActiveJobNoteProps = {
+ tagIds: TransformTagId[];
+};
+
+function NoActiveJobNote({ tagIds }: NoActiveJobNoteProps) {
+ const hasTags = tagIds.length > 0;
+ const { data: jobs } = useListTransformJobsQuery(hasTags ? {} : skipToken);
+
+ if (!hasTags || jobs == null) {
+ return null;
+ }
+
+ const hasActiveJob = jobs.some(
+ (job) => job.active && job.tag_ids?.some((tagId) => tagIds.includes(tagId)),
+ );
+ if (hasActiveJob) {
+ return null;
+ }
+
+ return (
+ <Text c="text-secondary" size="sm" data-testid="no-active-job-note">
+ {t`No enabled job runs these tags.`}{" "}
+ <Anchor component={Link} to={Urls.transformJobList()} lh="inherit">
+ {t`Go to jobs`}
+ </Anchor>
+ </Text>
);
}
diff --git a/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.unit.spec.tsx b/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.unit.spec.tsx
index 79a18ef9569..2e4ef9d9f2a 100644
--- a/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.unit.spec.tsx
+++ b/frontend/src/metabase/transforms/pages/TransformRunPage/RunSection/RunSection.unit.spec.tsx
@@ -4,6 +4,7 @@ import fetchMock from "fetch-mock";
import {
setupListDagRunTransformRunsEndpoint,
setupListDagTransformsEndpoint,
+ setupListTransformJobsEndpoint,
setupListTransformTagsEndpoint,
setupRunTransformDagEndpoint,
} from "__support__/server-mocks";
@@ -12,10 +13,12 @@ import { UndoListing } from "metabase/common/components/UndoListing";
import type {
RunTransformDagResponse,
Transform,
+ TransformJob,
TransformRunForJobRun,
} from "metabase-types/api";
import {
createMockTransform,
+ createMockTransformJob,
createMockTransformRun,
createMockTransformRunForJobRun,
} from "metabase-types/api/mocks";
@@ -37,10 +40,14 @@ function setup({
transform,
runDagResponse,
dagMembers = DEFAULT_DAG_MEMBERS,
+ jobs = [],
+ noTitle,
}: {
transform?: Transform;
runDagResponse?: RunTransformDagResponse;
dagMembers?: TransformRunForJobRun[];
+ jobs?: TransformJob[];
+ noTitle?: boolean;
} = {}) {
const testTransform =
transform ?? createMockTransform({ id: TRANSFORM_ID, last_run: null });
@@ -53,10 +60,11 @@ function setup({
]);
setupRunTransformDagEndpoint(TRANSFORM_ID, runDagResponse);
setupListDagRunTransformRunsEndpoint(DAG_RUN_ID, dagMembers);
+ setupListTransformJobsEndpoint(jobs);
renderWithProviders(
<>
- <RunSection transform={testTransform} />
+ <RunSection transform={testTransform} noTitle={noTitle} />
<UndoListing />
</>,
);
@@ -171,3 +179,85 @@ describe("RunSection DAG run flow", () => {
).not.toBeInTheDocument();
});
});
+
+describe("RunSection no active job note", () => {
+ const TAG_ID = 5;
+ const OTHER_TAG_ID = 6;
+ const NOTE_TEXT = "No enabled job runs these tags.";
+
+ const taggedTransform = createMockTransform({
+ id: TRANSFORM_ID,
+ last_run: null,
+ tag_ids: [TAG_ID],
+ });
+
+ async function waitForJobsRequest() {
+ await waitFor(() => {
+ expect(fetchMock.callHistory.called("path:/api/transform-job")).toBe(
+ true,
+ );
+ });
+ }
+
+ it("shows the note with a jobs link when no active job has any of the transform's tags", async () => {
+ setup({
+ transform: taggedTransform,
+ jobs: [
+ createMockTransformJob({ id: 1, active: false, tag_ids: [TAG_ID] }),
+ createMockTransformJob({
+ id: 2,
+ active: true,
+ tag_ids: [OTHER_TAG_ID],
+ }),
+ ],
+ });
+
+ expect(await screen.findByText(NOTE_TEXT)).toBeInTheDocument();
+ expect(screen.getByRole("link", { name: "Go to jobs" })).toHaveAttribute(
+ "href",
+ "/data-studio/transforms/jobs",
+ );
+ });
+
+ it("shows the note when the section renders without a title", async () => {
+ setup({
+ transform: taggedTransform,
+ jobs: [
+ createMockTransformJob({ id: 1, active: false, tag_ids: [TAG_ID] }),
+ ],
+ noTitle: true,
+ });
+
+ expect(await screen.findByText(NOTE_TEXT)).toBeInTheDocument();
+ });
+
+ it("hides the note when an active job has one of the transform's tags", async () => {
+ setup({
+ transform: taggedTransform,
+ jobs: [
+ createMockTransformJob({
+ id: 1,
+ active: true,
+ tag_ids: [OTHER_TAG_ID, TAG_ID],
+ }),
+ ],
+ });
+ await waitForJobsRequest();
+
+ expect(screen.queryByText(NOTE_TEXT)).not.toBeInTheDocument();
+ });
+
+ it("hides the note and does not fetch jobs when the transform has no tags", async () => {
+ setup({
+ transform: createMockTransform({
+ id: TRANSFORM_ID,
+ last_run: null,
+ tag_ids: [],
+ }),
+ });
+ await screen.findByText("This transform hasn't been run before.");
+
+ expect(screen.queryByText(NOTE_TEXT)).not.toBeInTheDocument();
+ expect(fetchMock.callHistory.called("path:/api/transform-job")).toBe(false);
+ });
+});