From 0274c7029209d1d075450c0977e82dfb58767c63 Mon Sep 17 00:00:00 2001 From: Andrew Sikowitz Date: Fri, 26 Jul 2024 11:10:13 -0700 Subject: [PATCH] fix(ui/ingest): Support invalid cron jobs (#10998) --- .../src/app/context/UserContextProvider.tsx | 1 + datahub-web-react/src/app/context/userContext.tsx | 2 ++ .../src/app/ingest/ManageIngestionPage.tsx | 14 ++++++++++---- .../ingest/source/IngestionSourceTableColumns.tsx | 8 +++++++- .../cypress/e2e/mutations/managing_secrets.js | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/datahub-web-react/src/app/context/UserContextProvider.tsx b/datahub-web-react/src/app/context/UserContextProvider.tsx index 3bcff15cc2..66593d346f 100644 --- a/datahub-web-react/src/app/context/UserContextProvider.tsx +++ b/datahub-web-react/src/app/context/UserContextProvider.tsx @@ -127,6 +127,7 @@ const UserContextProvider = ({ children }: { children: React.ReactNode }) => { return ( { * Determines which view should be visible: ingestion sources or secrets. */ const me = useUserContext(); - const { config } = useAppConfig(); + const { config, loaded } = useAppConfig(); const isIngestionEnabled = config?.managedIngestionConfig.enabled; const showIngestionTab = isIngestionEnabled && me && me.platformPrivileges?.manageIngestion; const showSecretsTab = isIngestionEnabled && me && me.platformPrivileges?.manageSecrets; - const defaultTab = showIngestionTab ? TabType.Sources : TabType.Secrets; - const [selectedTab, setSelectedTab] = useState(defaultTab); + const [selectedTab, setSelectedTab] = useState(TabType.Sources); + + // defaultTab might not be calculated correctly on mount, if `config` or `me` haven't been loaded yet + useEffect(() => { + if (loaded && me.loaded && !showIngestionTab && selectedTab === TabType.Sources) { + setSelectedTab(TabType.Secrets); + } + }, [loaded, me.loaded, showIngestionTab, selectedTab]); const onClickTab = (newTab: string) => { setSelectedTab(TabType[newTab]); diff --git a/datahub-web-react/src/app/ingest/source/IngestionSourceTableColumns.tsx b/datahub-web-react/src/app/ingest/source/IngestionSourceTableColumns.tsx index 155e75f189..4b7fb47222 100644 --- a/datahub-web-react/src/app/ingest/source/IngestionSourceTableColumns.tsx +++ b/datahub-web-react/src/app/ingest/source/IngestionSourceTableColumns.tsx @@ -106,7 +106,13 @@ export function LastExecutionColumn(time: any) { } export function ScheduleColumn(schedule: any, record: any) { - const tooltip = schedule && `Runs ${cronstrue.toString(schedule).toLowerCase()} (${record.timezone})`; + let tooltip: string; + try { + tooltip = schedule && `Runs ${cronstrue.toString(schedule).toLowerCase()} (${record.timezone})`; + } catch (e) { + tooltip = 'Invalid cron schedule'; + console.debug('Error parsing cron schedule', e); + } return ( {schedule || 'None'} diff --git a/smoke-test/tests/cypress/cypress/e2e/mutations/managing_secrets.js b/smoke-test/tests/cypress/cypress/e2e/mutations/managing_secrets.js index 6953fe0494..dd331fbcbd 100644 --- a/smoke-test/tests/cypress/cypress/e2e/mutations/managing_secrets.js +++ b/smoke-test/tests/cypress/cypress/e2e/mutations/managing_secrets.js @@ -11,6 +11,7 @@ describe("managing secrets for ingestion creation", () => { // Navigate to the manage ingestion page → secrets cy.loginWithCredentials(); cy.goToIngestionPage(); + cy.clickOptionWithText("Secrets"); // Create a new secret cy.clickOptionWithTestId("create-secret-button");