diff --git a/airflow/www/static/js/grid/index.d.ts b/airflow/www/static/js/grid/index.d.ts index 55aefc95ec2fe7..174b4e5e510a4b 100644 --- a/airflow/www/static/js/grid/index.d.ts +++ b/airflow/www/static/js/grid/index.d.ts @@ -17,8 +17,7 @@ * under the License. */ -/* eslint-disable no-var */ - +// define global variables that come from FAB declare global { const autoRefreshInterval: number | undefined; const stateColors: { diff --git a/airflow/www/static/js/grid/renderTaskRows.test.tsx b/airflow/www/static/js/grid/renderTaskRows.test.tsx index 7b1596512a8a48..4f5fabc9209a9a 100644 --- a/airflow/www/static/js/grid/renderTaskRows.test.tsx +++ b/airflow/www/static/js/grid/renderTaskRows.test.tsx @@ -24,10 +24,11 @@ import { render } from '@testing-library/react'; import renderTaskRows from './renderTaskRows'; import { TableWrapper } from './utils/testUtils'; +import type { Task } from './types'; describe('Test renderTaskRows', () => { test('Renders name and task instance', () => { - const task = { + const task: Task = { id: null, label: null, children: [ @@ -37,16 +38,11 @@ describe('Test renderTaskRows', () => { label: 'group_1', instances: [ { - dagId: 'dagId', - duration: 0, endDate: '2021-10-26T15:42:03.391939+00:00', - executionDate: '2021-10-25T15:41:09.726436+00:00', - operator: 'DummyOperator', runId: 'run1', startDate: '2021-10-26T15:42:03.391917+00:00', state: 'success', taskId: 'group_1', - tryNumber: 1, }, ], children: [ @@ -56,16 +52,11 @@ describe('Test renderTaskRows', () => { extraLinks: [], instances: [ { - dagId: 'dagId', - duration: 0, endDate: '2021-10-26T15:42:03.391939+00:00', - executionDate: '2021-10-25T15:41:09.726436+00:00', - operator: 'DummyOperator', runId: 'run1', startDate: '2021-10-26T15:42:03.391917+00:00', state: 'success', taskId: 'group_1.task_1', - tryNumber: 1, }, ], }, @@ -110,7 +101,7 @@ describe('Test renderTaskRows', () => { }); test('Still renders correctly if task instance is null', () => { - const task = { + const task: Task = { id: null, label: null, children: [ @@ -118,18 +109,18 @@ describe('Test renderTaskRows', () => { extraLinks: [], id: 'group_1', label: 'group_1', - instances: [null], + instances: [], children: [ { id: 'group_1.task_1', label: 'group_1.task_1', extraLinks: [], - instances: [null], + instances: [], }, ], }, ], - instances: [null], + instances: [], }; const { queryByTestId, getByText } = render( diff --git a/airflow/www/static/js/grid/renderTaskRows.tsx b/airflow/www/static/js/grid/renderTaskRows.tsx index 2e59eb648b1f11..532d153fb2fcf2 100644 --- a/airflow/www/static/js/grid/renderTaskRows.tsx +++ b/airflow/www/static/js/grid/renderTaskRows.tsx @@ -31,15 +31,16 @@ import StatusBox, { boxSize, boxSizePx } from './components/StatusBox'; import TaskName from './components/TaskName'; import useSelection, { SelectionProps } from './utils/useSelection'; +import type { Task, DagRun } from './types'; const boxPadding = 3; const boxPaddingPx = `${boxPadding}px`; const columnWidth = boxSize + 2 * boxPadding; interface RowProps { - task: any + task: Task; + dagRunIds: DagRun['runId'][]; level?: number; - dagRunIds: string[]; openParentCount?: number; openGroupIds?: string[]; onToggleGroups?: (groupIds: string[]) => void; @@ -48,18 +49,22 @@ interface RowProps { const renderTaskRows: React.FC = ({ task, level = 0, ...rest -}) => task.children && task.children.map((t: any) => ( - // eslint-disable-next-line @typescript-eslint/no-use-before-define - -)); +}) => ( + <> + {(task?.children || []).map((t) => ( + // eslint-disable-next-line @typescript-eslint/no-use-before-define + + ))} + +); interface TaskInstancesProps { - task: any; + task: Task; dagRunIds: string[]; selectedRunId?: string | null; onSelect: (selection: SelectionProps) => void; @@ -72,7 +77,7 @@ const TaskInstances: React.FC = ({ {dagRunIds.map((runId: string) => { // Check if an instance exists for the run, or return an empty box - const instance = task.instances.find((ti: any) => ti && ti.runId === runId); + const instance = task.instances.find((ti) => ti && ti.runId === runId); const isSelected = selectedRunId === runId; return ( = (props) => { // assure the function is the same across renders const memoizedToggle = useCallback( () => { - if (isGroup) { + if (isGroup && task.label) { let newGroupIds = []; if (!isOpen) { newGroupIds = [...openGroupIds, task.label];