Skip to content

Commit c56ed0e

Browse files
Address review: cursor in TableState, no useCallback/useEffect
1 parent 21b85cb commit c56ed0e

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

airflow-core/src/airflow/ui/src/components/DataTable/searchParams.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ export const stateToSearchParams = (state: TableState, defaultTableState?: Table
4444
queryParams.set(OFFSET_PARAM, `${state.pagination.pageIndex}`);
4545
}
4646

47-
// Clear cursor when table state changes (sort, page size, etc.).
48-
queryParams.delete(CURSOR_PARAM);
47+
if (state.cursor !== undefined && state.cursor !== "") {
48+
queryParams.set(CURSOR_PARAM, state.cursor);
49+
} else {
50+
queryParams.delete(CURSOR_PARAM);
51+
}
4952

5053
if (state.sorting.length) {
5154
state.sorting.forEach(({ desc, id }) => {
@@ -76,6 +79,13 @@ export const searchParamsToState = (searchParams: URLSearchParams, defaultState:
7679
},
7780
};
7881
}
82+
83+
const cursorValue = searchParams.get(CURSOR_PARAM);
84+
85+
if (cursorValue !== null) {
86+
urlState = { ...urlState, cursor: cursorValue };
87+
}
88+
7989
const sorts = searchParams.getAll(SORT_PARAM);
8090
const sorting: SortingState = sorts.map((sort) => ({
8191
desc: sort.startsWith("-"),

airflow-core/src/airflow/ui/src/components/DataTable/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { JSX, ReactNode } from "react";
2222

2323
export type TableState = {
2424
columnVisibility?: VisibilityState;
25+
cursor?: string;
2526
pagination: PaginationState;
2627
sorting: SortingState;
2728
};

airflow-core/src/airflow/ui/src/pages/TaskInstances/TaskInstances.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type TaskInstanceRow = { row: { original: TaskInstanceResponse } };
5454
const getRowKey = (ti: TaskInstanceResponse) => `${ti.dag_id}:${ti.dag_run_id}:${ti.task_id}:${ti.map_index}`;
5555

5656
const {
57-
CURSOR: CURSOR_PARAM,
5857
DAG_ID_PATTERN: DAG_ID_PATTERN_PARAM,
5958
DAG_VERSION: DAG_VERSION_PARAM,
6059
DURATION_GTE: DURATION_GTE_PARAM,
@@ -261,25 +260,7 @@ const taskInstanceColumns = ({
261260
export const TaskInstances = () => {
262261
const { t: translate } = useTranslation();
263262
const { dagId, groupId, runId, taskId } = useParams();
264-
const [searchParams, setSearchParams] = useSearchParams();
265-
266-
const cursor = searchParams.get(CURSOR_PARAM) ?? "";
267-
const setCursor = (value: string) => {
268-
setSearchParams(
269-
(prev) => {
270-
const next = new URLSearchParams(prev);
271-
272-
if (value) {
273-
next.set(CURSOR_PARAM, value);
274-
} else {
275-
next.delete(CURSOR_PARAM);
276-
}
277-
278-
return next;
279-
},
280-
{ replace: true },
281-
);
282-
};
263+
const [searchParams] = useSearchParams();
283264

284265
const { setTableURLState, tableURLState } = useTableURLState({
285266
columnVisibility: {
@@ -291,7 +272,7 @@ export const TaskInstances = () => {
291272
queue: false,
292273
},
293274
});
294-
const { pagination, sorting } = tableURLState;
275+
const { cursor, pagination, sorting } = tableURLState;
295276
const [sort] = sorting;
296277
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-id"];
297278

@@ -317,7 +298,7 @@ export const TaskInstances = () => {
317298

318299
const { data, error, isLoading } = useTaskInstanceServiceGetTaskInstances(
319300
{
320-
cursor,
301+
cursor: cursor ?? "",
321302
dagId: dagId ?? "~",
322303
dagIdPattern: filteredDagIdPattern ?? undefined,
323304
dagRunId: runId ?? "~",
@@ -358,12 +339,12 @@ export const TaskInstances = () => {
358339
hasPrevious: previousCursor !== undefined && previousCursor !== null,
359340
onNext: () => {
360341
if (nextCursor !== undefined && nextCursor !== null) {
361-
setCursor(nextCursor);
342+
setTableURLState({ cursor: nextCursor, pagination, sorting });
362343
}
363344
},
364345
onPrevious: () => {
365346
if (previousCursor !== undefined && previousCursor !== null) {
366-
setCursor(previousCursor);
347+
setTableURLState({ cursor: previousCursor, pagination, sorting });
367348
}
368349
},
369350
};

airflow-core/src/airflow/ui/src/utils/useFiltersHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const useFiltersHandler = (searchParamKeys: Array<FilterableSearchParamsK
145145

146146
const handleFiltersChange = (filters: Record<string, FilterValue>) => {
147147
setTableURLState({
148+
cursor: undefined,
148149
pagination: { ...pagination, pageIndex: 0 },
149150
sorting,
150151
});

0 commit comments

Comments
 (0)