Skip to content

Commit

Permalink
remove any, add comment for global vars
Browse files Browse the repository at this point in the history
  • Loading branch information
bbovenzi committed Jun 17, 2022
1 parent 68a4f3d commit dbcbb7f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
3 changes: 1 addition & 2 deletions airflow/www/static/js/grid/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
21 changes: 6 additions & 15 deletions airflow/www/static/js/grid/renderTaskRows.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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: [
Expand All @@ -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,
},
],
},
Expand Down Expand Up @@ -110,26 +101,26 @@ describe('Test renderTaskRows', () => {
});

test('Still renders correctly if task instance is null', () => {
const task = {
const task: Task = {
id: null,
label: null,
children: [
{
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(
Expand Down
33 changes: 19 additions & 14 deletions airflow/www/static/js/grid/renderTaskRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,18 +49,22 @@ interface RowProps {

const renderTaskRows: React.FC<RowProps> = ({
task, level = 0, ...rest
}) => task.children && task.children.map((t: any) => (
// eslint-disable-next-line @typescript-eslint/no-use-before-define
<Row
{...rest}
key={t.id}
task={t}
level={level}
/>
));
}) => (
<>
{(task?.children || []).map((t) => (
// eslint-disable-next-line @typescript-eslint/no-use-before-define
<Row
{...rest}
key={t.id}
task={t}
level={level}
/>
))}
</>
);

interface TaskInstancesProps {
task: any;
task: Task;
dagRunIds: string[];
selectedRunId?: string | null;
onSelect: (selection: SelectionProps) => void;
Expand All @@ -72,7 +77,7 @@ const TaskInstances: React.FC<TaskInstancesProps> = ({
<Flex justifyContent="flex-end">
{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 (
<Box
Expand Down Expand Up @@ -122,7 +127,7 @@ const Row: React.FC<RowProps> = (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];
Expand Down

0 comments on commit dbcbb7f

Please sign in to comment.