Skip to content

Commit c2a34e6

Browse files
Small adjustments and cleaning
1 parent db2e117 commit c2a34e6

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searc
2222

2323
import type { TableState } from "./types";
2424

25-
const { LIMIT: LIMIT_PARAM, OFFSET: OFFSET_PARAM, SORT: SORT_PARAM }: SearchParamsKeysType = SearchParamsKeys;
25+
const {
26+
CURSOR: CURSOR_PARAM,
27+
LIMIT: LIMIT_PARAM,
28+
OFFSET: OFFSET_PARAM,
29+
SORT: SORT_PARAM,
30+
}: SearchParamsKeysType = SearchParamsKeys;
2631

2732
export const stateToSearchParams = (state: TableState, defaultTableState?: TableState): URLSearchParams => {
2833
const queryParams = new URLSearchParams(globalThis.location.search);
@@ -39,6 +44,9 @@ export const stateToSearchParams = (state: TableState, defaultTableState?: Table
3944
queryParams.set(OFFSET_PARAM, `${state.pagination.pageIndex}`);
4045
}
4146

47+
// Clear cursor when table state changes (sort, page size, etc.).
48+
queryParams.delete(CURSOR_PARAM);
49+
4250
if (state.sorting.length) {
4351
state.sorting.forEach(({ desc, id }) => {
4452
if (defaultTableState?.sorting.find((sort) => sort.id === id && sort.desc === desc)) {

airflow-core/src/airflow/ui/src/constants/searchParams.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export enum SearchParamsKeys {
2727
CREATED_AT_GTE = "created_at_gte",
2828
CREATED_AT_LTE = "created_at_lte",
2929
CREATED_AT_RANGE = "created_at_range",
30+
CURSOR = "cursor",
3031
DAG_DISPLAY_NAME_PATTERN = "dag_display_name_pattern",
3132
DAG_ID = "dag_id",
3233
DAG_ID_PATTERN = "dag_id_pattern",

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import { Flex, Link } from "@chakra-ui/react";
2222
import type { ColumnDef } from "@tanstack/react-table";
2323
import type { TFunction } from "i18next";
24-
import { useState } from "react";
2524
import { useTranslation } from "react-i18next";
2625
import { Link as RouterLink, useParams, useSearchParams } from "react-router-dom";
2726

@@ -55,6 +54,7 @@ type TaskInstanceRow = { row: { original: TaskInstanceResponse } };
5554
const getRowKey = (ti: TaskInstanceResponse) => `${ti.dag_id}:${ti.dag_run_id}:${ti.task_id}:${ti.map_index}`;
5655

5756
const {
57+
CURSOR: CURSOR_PARAM,
5858
DAG_ID_PATTERN: DAG_ID_PATTERN_PARAM,
5959
DAG_VERSION: DAG_VERSION_PARAM,
6060
DURATION_GTE: DURATION_GTE_PARAM,
@@ -261,7 +261,26 @@ const taskInstanceColumns = ({
261261
export const TaskInstances = () => {
262262
const { t: translate } = useTranslation();
263263
const { dagId, groupId, runId, taskId } = useParams();
264-
const [searchParams] = useSearchParams();
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+
};
283+
265284
const { setTableURLState, tableURLState } = useTableURLState({
266285
columnVisibility: {
267286
dag_version: false,
@@ -276,17 +295,6 @@ export const TaskInstances = () => {
276295
const [sort] = sorting;
277296
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-id"];
278297

279-
// Reset cursor when filters or sort change. URL search params capture both,
280-
// so comparing their serialized form detects any change without useEffect.
281-
const [cursor, setCursor] = useState<string>("");
282-
const searchKey = searchParams.toString();
283-
const [prevSearchKey, setPrevSearchKey] = useState(searchKey);
284-
285-
if (searchKey !== prevSearchKey) {
286-
setCursor("");
287-
setPrevSearchKey(searchKey);
288-
}
289-
290298
const filteredState = searchParams.getAll(STATE_PARAM);
291299
const filteredDagVersion = searchParams.get(DAG_VERSION_PARAM);
292300
const durationGte = searchParams.get(DURATION_GTE_PARAM);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export const useFiltersHandler = (searchParamKeys: Array<FilterableSearchParamsK
167167
});
168168

169169
newParams.delete(SearchParamsKeys.OFFSET);
170+
newParams.delete(SearchParamsKeys.CURSOR);
170171

171172
return newParams;
172173
});

0 commit comments

Comments
 (0)