fix(ui/ingest): Support invalid cron jobs (#10998)

This commit is contained in:
Andrew Sikowitz 2024-07-26 11:10:13 -07:00 committed by GitHub
parent 01b3461d99
commit 0274c70292
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 5 deletions

View File

@ -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,

View File

@ -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;
@ -53,6 +54,7 @@ export const DEFAULT_STATE: State = {
};
export const DEFAULT_CONTEXT = {
loaded: false,
urn: undefined,
user: undefined,
state: DEFAULT_STATE,

View File

@ -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';
@ -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]);

View File

@ -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>

View File

@ -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");