Skip to content

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

Render transform job details before the transform plan loads (#75499)

Oleh K09c574b988d9
diff --git a/frontend/src/metabase/transforms/components/JobEditor/JobEditor.tsx b/frontend/src/metabase/transforms/components/JobEditor/JobEditor.tsx
index 2ef4c4271d2..66da5ad6282 100644
--- a/frontend/src/metabase/transforms/components/JobEditor/JobEditor.tsx
+++ b/frontend/src/metabase/transforms/components/JobEditor/JobEditor.tsx
@@ -27,6 +27,7 @@ type JobEditorProps = {
menu?: ReactNode;
actions?: ReactNode;
readOnly?: boolean;
+ isCheckingPermissions?: boolean;
onNameChange: (name: string) => void;
onScheduleChange: (
schedule: string,
@@ -40,6 +41,7 @@ export function JobEditor({
menu,
actions,
readOnly,
+ isCheckingPermissions,
onNameChange,
onScheduleChange,
onTagListChange,
@@ -86,6 +88,7 @@ export function JobEditor({
<ScheduleSection
job={job}
readOnly={readOnly}
+ isCheckingPermissions={isCheckingPermissions}
onScheduleChange={onScheduleChange}
/>
<TagSection
diff --git a/frontend/src/metabase/transforms/components/JobEditor/ScheduleSection/ScheduleSection.tsx b/frontend/src/metabase/transforms/components/JobEditor/ScheduleSection/ScheduleSection.tsx
index 9c63056588c..8733b13c56b 100644
--- a/frontend/src/metabase/transforms/components/JobEditor/ScheduleSection/ScheduleSection.tsx
+++ b/frontend/src/metabase/transforms/components/JobEditor/ScheduleSection/ScheduleSection.tsx
@@ -21,6 +21,7 @@ import type { TransformJobInfo } from "../types";
type ScheduleSectionProps = {
job: TransformJobInfo;
readOnly?: boolean;
+ isCheckingPermissions?: boolean;
onScheduleChange: (
schedule: string,
uiDisplayType: ScheduleDisplayType,
@@ -30,6 +31,7 @@ type ScheduleSectionProps = {
export function ScheduleSection({
job,
readOnly,
+ isCheckingPermissions,
onScheduleChange,
}: ScheduleSectionProps) {
return (
@@ -48,7 +50,11 @@ export function ScheduleSection({
run={job?.last_run ?? null}
neverRunMessage={t`This job hasn’t been run before.`}
/>
- <RunButtonSection job={job} readOnly={readOnly} />
+ <RunButtonSection
+ job={job}
+ readOnly={readOnly}
+ isCheckingPermissions={isCheckingPermissions}
+ />
</Group>
</TitleSection>
);
@@ -115,15 +121,23 @@ function ScheduleWidget({ job, onChangeSchedule }: ScheduleWidgetProps) {
type RunButtonSectionProps = {
job: TransformJobInfo;
readOnly?: boolean;
+ isCheckingPermissions?: boolean;
};
-function RunButtonSection({ job, readOnly }: RunButtonSectionProps) {
+function RunButtonSection({
+ job,
+ readOnly,
+ isCheckingPermissions,
+}: RunButtonSectionProps) {
const [runJob] = useRunTransformJobMutation();
const { sendErrorToast } = useMetadataToasts();
const isSaved = job.id != null;
const hasTags = job.tag_ids?.length !== 0;
const tooltipLabel = (() => {
+ if (isCheckingPermissions) {
+ return t`Checking permissions…`;
+ }
if (!hasTags) {
return t`This job doesn't have tags to run.`;
}
@@ -152,6 +166,7 @@ function RunButtonSection({ job, readOnly }: RunButtonSectionProps) {
id={job.id}
run={job.last_run}
isDisabled={!isSaved || !hasTags || readOnly}
+ isLoading={isCheckingPermissions}
onRun={handleRun}
/>
</Tooltip>
diff --git a/frontend/src/metabase/transforms/components/RunButton/RunButton.tsx b/frontend/src/metabase/transforms/components/RunButton/RunButton.tsx
index 4afb71ff0a9..b175bf1bee5 100644
--- a/frontend/src/metabase/transforms/components/RunButton/RunButton.tsx
+++ b/frontend/src/metabase/transforms/components/RunButton/RunButton.tsx
@@ -24,6 +24,7 @@ type RunButtonProps = {
id: TransformId | TransformJobId | undefined;
run: TransformRun | null | undefined;
isDisabled?: boolean;
+ isLoading?: boolean;
allowCancellation?: boolean;
size?: ButtonProps["size"];
onRun: () => void;
@@ -35,6 +36,7 @@ export const RunButton = forwardRef(function RunButton(
id,
run,
isDisabled: isExternallyDisabled = false,
+ isLoading = false,
allowCancellation = false,
size = "md",
onRun,
@@ -47,6 +49,7 @@ export const RunButton = forwardRef(function RunButton(
const { label, color, leftSection, isDisabled } = getRunButtonInfo({
run,
isRecent,
+ isLoading,
isDisabled: isExternallyDisabled || !!isMeterLocked,
});
@@ -95,6 +98,7 @@ export const RunButton = forwardRef(function RunButton(
type RunButtonOpts = {
run: TransformRun | null | undefined;
isRecent: boolean;
+ isLoading: boolean;
isDisabled: boolean;
};
@@ -108,6 +112,7 @@ type RunButtonInfo = {
function getRunButtonInfo({
run,
isRecent,
+ isLoading,
isDisabled,
}: RunButtonOpts): RunButtonInfo {
if (run?.status === "started") {
@@ -127,6 +132,14 @@ function getRunButtonInfo({
};
}
+ if (isLoading) {
+ return {
+ label: t`Run now`,
+ leftSection: <Loader size="sm" />,
+ isDisabled: true,
+ };
+ }
+
if (run == null || !isRecent || isDisabled) {
return {
label: t`Run now`,
diff --git a/frontend/src/metabase/transforms/pages/JobPage/JobPage.tsx b/frontend/src/metabase/transforms/pages/JobPage/JobPage.tsx
index dc930ba53e8..33638bf6f00 100644
--- a/frontend/src/metabase/transforms/pages/JobPage/JobPage.tsx
+++ b/frontend/src/metabase/transforms/pages/JobPage/JobPage.tsx
@@ -51,14 +51,11 @@ export function JobPage({ params }: JobPageProps) {
const { transformsDatabases, isLoadingDatabases, databasesError } =
useTransformPermissions();
- const {
- data: transforms,
- isLoading: isLoadingTransforms,
- error: transformsError,
- } = useListTransformJobTransformsQuery(jobId || skipToken);
+ const { data: transforms, isLoading: isLoadingTransforms } =
+ useListTransformJobTransformsQuery(jobId || skipToken);
const readOnly = useMemo(() => {
if (!transformsDatabases || !transforms) {
- return;
+ return true;
}
return !transforms.every((t) => canEditTransform(t, transformsDatabases));
}, [transforms, transformsDatabases]);
@@ -67,9 +64,8 @@ export function JobPage({ params }: JobPageProps) {
setIsPolling(isPollingNeeded(job));
}
- const isLoading = isLoadingJob || isLoadingDatabases || isLoadingTransforms;
- const error = jobError || databasesError || transformsError;
-
+ const isLoading = isLoadingJob || isLoadingDatabases;
+ const error = jobError || databasesError;
if (isLoading || error != null || job == null) {
return (
<Center h="100%">
@@ -78,15 +74,26 @@ export function JobPage({ params }: JobPageProps) {
);
}
- return <JobPageBody job={job} readOnly={readOnly} />;
+ return (
+ <JobPageBody
+ job={job}
+ readOnly={readOnly}
+ isCheckingPermissions={isLoadingTransforms}
+ />
+ );
}
type JobPageBodyProps = {
job: TransformJob;
readOnly?: boolean;
+ isCheckingPermissions?: boolean;
};
-function JobPageBody({ job, readOnly }: JobPageBodyProps) {
+function JobPageBody({
+ job,
+ readOnly,
+ isCheckingPermissions,
+}: JobPageBodyProps) {
const [updateJob] = useUpdateTransformJobMutation();
const { sendErrorToast, sendSuccessToast, sendUndoToast } =
useMetadataToasts();
@@ -151,6 +158,7 @@ function JobPageBody({ job, readOnly }: JobPageBodyProps) {
job={job}
menu={!readOnly && <JobMoreMenu job={job} />}
readOnly={readOnly}
+ isCheckingPermissions={isCheckingPermissions}
onNameChange={handleNameChange}
onScheduleChange={handleScheduleChange}
onTagListChange={handleTagListChange}
diff --git a/frontend/src/metabase/transforms/pages/JobPage/JobPage.unit.spec.tsx b/frontend/src/metabase/transforms/pages/JobPage/JobPage.unit.spec.tsx
new file mode 100644
index 00000000000..80f20e8deb3
--- /dev/null
+++ b/frontend/src/metabase/transforms/pages/JobPage/JobPage.unit.spec.tsx
@@ -0,0 +1,76 @@
+import fetchMock from "fetch-mock";
+import { Route } from "react-router";
+
+import { setupDatabaseListEndpoint } from "__support__/server-mocks";
+import {
+ setupGetTransformJobEndpoint,
+ setupListTransformTagsEndpoint,
+} from "__support__/server-mocks/transform";
+import { act, renderWithProviders, screen, within } from "__support__/ui";
+import * as Urls from "metabase/urls";
+import type { TransformJob } from "metabase-types/api";
+import {
+ createMockDatabase,
+ createMockTransformJob,
+} from "metabase-types/api/mocks";
+
+import { JobPage } from "./JobPage";
+
+const TRANSFORMS_DELAY = 1000;
+
+type SetupOpts = {
+ job?: TransformJob;
+ transformsDelay?: number;
+};
+
+const setup = ({
+ job = createMockTransformJob({ id: 1, name: "My Job" }),
+ transformsDelay = 0,
+}: SetupOpts = {}) => {
+ setupGetTransformJobEndpoint(job);
+ setupDatabaseListEndpoint([createMockDatabase()]);
+ setupListTransformTagsEndpoint([]);
+ fetchMock.get(`path:/api/transform-job/${job.id}/transforms`, [], {
+ delay: transformsDelay,
+ });
+
+ const path = Urls.transformJob(job.id);
+ renderWithProviders(
+ <Route path="/data-studio/transforms/jobs/:jobId" component={JobPage} />,
+ { withRouter: true, initialRoute: path },
+ );
+};
+
+describe("JobPage", () => {
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
+ it("renders the job details before the transform plan resolves", async () => {
+ jest.useFakeTimers({ advanceTimers: true });
+ setup({ transformsDelay: TRANSFORMS_DELAY });
+
+ // The job header and its details render without waiting for the slow
+ // transforms endpoint.
+ const header = await screen.findByTestId("jobs-header");
+ expect(within(header).getByDisplayValue("My Job")).toBeInTheDocument();
+ expect(screen.getByText("Transforms")).toBeInTheDocument();
+
+ // The transforms list hasn't loaded yet, and editing stays locked while
+ // permissions are still being checked.
+ expect(
+ screen.queryByText("There are no transforms for this job."),
+ ).not.toBeInTheDocument();
+ expect(screen.getByTestId("run-button")).toBeDisabled();
+
+ act(() => {
+ jest.advanceTimersByTime(TRANSFORMS_DELAY);
+ });
+
+ // Once the plan resolves, the transforms list renders and editing unlocks.
+ expect(
+ await screen.findByText("There are no transforms for this job."),
+ ).toBeInTheDocument();
+ expect(screen.getByTestId("run-button")).toBeEnabled();
+ });
+});