Skip to content

Commit

Permalink
fix(ui/ingest): Support invalid cron jobs (datahub-project#10998)
Browse files Browse the repository at this point in the history
  • Loading branch information
asikowitz authored Jul 26, 2024
1 parent 01b3461 commit 0274c70
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions datahub-web-react/src/app/context/UserContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const UserContextProvider = ({ children }: { children: React.ReactNode }) => {
return (
<UserContext.Provider
value={{
loaded: !!meData,
urn: meData?.me?.corpUser?.urn,
user: meData?.me?.corpUser as CorpUser,
platformPrivileges: meData?.me?.platformPrivileges as PlatformPrivileges,
Expand Down
2 changes: 2 additions & 0 deletions datahub-web-react/src/app/context/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type State = {
* Context about the currently-authenticated user.
*/
export type UserContextType = {
loaded: boolean;
urn?: string | null;
user?: CorpUser | null;
platformPrivileges?: PlatformPrivileges | null;
Expand All @@ -53,6 +54,7 @@ export const DEFAULT_STATE: State = {
};

export const DEFAULT_CONTEXT = {
loaded: false,
urn: undefined,
user: undefined,
state: DEFAULT_STATE,
Expand Down
14 changes: 10 additions & 4 deletions datahub-web-react/src/app/ingest/ManageIngestionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tabs, Typography } from 'antd';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { IngestionSourceList } from './source/IngestionSourceList';
import { useAppConfig } from '../useAppConfig';
Expand Down Expand Up @@ -51,12 +51,18 @@ export const ManageIngestionPage = () => {
* 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<TabType>(defaultTab);
const [selectedTab, setSelectedTab] = useState<TabType>(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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Tooltip title={tooltip || 'Not scheduled'}>
<Typography.Text code>{schedule || 'None'}</Typography.Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 0274c70

Please sign in to comment.