Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2931,8 +2931,6 @@ paths:
type: array
items:
type: string
default:
- dag_id
title: Order By
- name: is_favorite
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const DataTable = <TData,>({
columns,
data,
enableHiding: true,
enableMultiSort: true,
getCoreRowModel: getCoreRowModel(),
getExpandedRowModel: getExpandedRowModel(),
getPaginationRowModel: getPaginationRowModel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ export const stateToSearchParams = (state: TableState, defaultTableState?: Table
}

if (state.sorting.length) {
queryParams.delete(SORT_PARAM);
state.sorting.forEach(({ desc, id }) => {
if (defaultTableState?.sorting.find((sort) => sort.id === id && sort.desc === desc)) {
queryParams.delete(SORT_PARAM, `${desc ? "-" : ""}${id}`);
} else {
queryParams.set(SORT_PARAM, `${desc ? "-" : ""}${id}`);
}
queryParams.append(SORT_PARAM, `${desc ? "-" : ""}${id}`);
});
} else {
queryParams.delete(SORT_PARAM);
Expand Down
5 changes: 3 additions & 2 deletions airflow-core/src/airflow/ui/src/pages/Asset/AssetLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ProgressBar } from "src/components/ui";
import { AssetGraph } from "./AssetGraph";
import { CreateAssetEvent } from "./CreateAssetEvent";
import { Header } from "./Header";
import { getOrderBy } from "src/utils";

export const AssetLayout = () => {
const { i18n, t: translate } = useTranslation(["assets", "common"]);
Expand All @@ -40,8 +41,8 @@ export const AssetLayout = () => {

const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-timestamp"];

const orderBy = getOrderBy("-timestamp");

const { data: asset, isLoading } = useAssetServiceGetAsset(
{ assetId: assetId === undefined ? 0 : parseInt(assetId, 10) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SearchBar } from "src/components/SearchBar";
import Time from "src/components/Time";
import { SearchParamsKeys } from "src/constants/searchParams";
import { CreateAssetEvent } from "src/pages/Asset/CreateAssetEvent";
import { getOrderBy } from "src/utils";

import { DependencyPopover } from "./DependencyPopover";

Expand Down Expand Up @@ -104,8 +105,8 @@ export const AssetsList = () => {

const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : undefined;

const orderBy = getOrderBy();

const { data, error, isLoading } = useAssetServiceGetAssets({
limit: pagination.pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ActionBar } from "src/components/ui/ActionBar";
import { Checkbox } from "src/components/ui/Checkbox";
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
import { useConnectionTypeMeta } from "src/queries/useConnectionTypeMeta";
import { getOrderBy } from "src/utils";

import AddConnectionButton from "./AddConnectionButton";
import DeleteConnectionButton from "./DeleteConnectionButton";
Expand Down Expand Up @@ -134,8 +135,8 @@ export const Connections = () => {

useConnectionTypeMeta(); // Pre-fetch connection type metadata
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["connection_id"];
const orderBy = getOrderBy("-connection_id");

const { data, error, isFetching, isLoading } = useConnectionServiceGetConnections({
connectionIdPattern: connectionIdPattern ?? undefined,
limit: pagination.pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const Overview = () => {
});
const { data: gridRuns, isLoading: isLoadingRuns } = useGridRuns({ limit });
const { data: assetEventsData, isLoading: isLoadingAssetEvents } = useAssetServiceGetAssetEvents({
limit,
limit: 6,
Copy link
Member

@pierrejeambrun pierrejeambrun Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we hardcoding "6" here?

orderBy: [assetSortBy],
sourceDagId: dagId,
timestampGte: startDate,
Expand Down
5 changes: 2 additions & 3 deletions airflow-core/src/airflow/ui/src/pages/DagRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { Select } from "src/components/ui";
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
import { dagRunTypeOptions, dagRunStateOptions as stateOptions } from "src/constants/stateOptions";
import DeleteRunButton from "src/pages/DeleteRunButton";
import { renderDuration, useAutoRefresh, isStatePending } from "src/utils";
import { renderDuration, useAutoRefresh, isStatePending, getOrderBy } from "src/utils";

type DagRunRow = { row: { original: DAGRunResponse } };
const {
Expand Down Expand Up @@ -174,8 +174,7 @@ export const DagRuns = () => {

const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-run_after"];
const orderBy = getOrderBy("-run_after");

const { pageIndex, pageSize } = pagination;
const filteredState = searchParams.get(STATE_PARAM);
Expand Down
6 changes: 3 additions & 3 deletions airflow-core/src/airflow/ui/src/pages/DagsList/DagsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { SearchParamsKeys } from "src/constants/searchParams";
import { DagsLayout } from "src/layouts/DagsLayout";
import { useConfig } from "src/queries/useConfig";
import { useDags } from "src/queries/useDags";
import { getOrderBy } from "src/utils";

import { DAGImportErrors } from "../Dashboard/Stats/DAGImportErrors";
import { DagCard } from "./DagCard";
Expand Down Expand Up @@ -208,8 +209,7 @@ export const DagsList = () => {
searchParams.get(NAME_PATTERN) ?? savedSearchPattern,
);

const [sort] = sorting;
const orderBy = sort ? `${sort.desc ? "-" : ""}${sort.id}` : "dag_display_name";
const orderBy = getOrderBy("-last_run_start_date");

const columns = useMemo(() => createColumns(translate), [translate]);

Expand Down Expand Up @@ -252,7 +252,7 @@ export const DagsList = () => {
lastDagRunState,
limit: pagination.pageSize,
offset: pagination.pageIndex * pagination.pageSize,
orderBy: [orderBy],
orderBy: orderBy,
owners,
paused,
tags: selectedTags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { createDagSortOptions } from "src/constants/sortParams";

type Props = {
readonly handleSortChange: ({ value }: SelectValueChangeDetails<Array<string>>) => void;
readonly orderBy?: string;
readonly orderBy?: Array<string>;
};

export const SortSelect = ({ handleSortChange, orderBy }: Props) => {
Expand All @@ -36,7 +36,7 @@ export const SortSelect = ({ handleSortChange, orderBy }: Props) => {
collection={dagSortOptions}
data-testid="sort-by-select"
onValueChange={handleSortChange}
value={orderBy === undefined ? undefined : [orderBy]}
value={orderBy === undefined ? undefined : orderBy}
width="310px"
>
<Select.Trigger>
Expand Down
4 changes: 2 additions & 2 deletions airflow-core/src/airflow/ui/src/pages/Events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useTableURLState } from "src/components/DataTable/useTableUrlState";
import { ErrorAlert } from "src/components/ErrorAlert";
import RenderedJsonField from "src/components/RenderedJsonField";
import Time from "src/components/Time";
import { getOrderBy } from "src/utils";

type EventsColumn = {
dagId?: string;
Expand Down Expand Up @@ -146,10 +147,9 @@ export const Events = () => {
const { dagId, runId, taskId } = useParams();
const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const { onClose, onOpen, open } = useDisclosure();

const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-when"];
const orderBy = getOrderBy("-when");

const { data, error, isFetching, isLoading } = useEventLogServiceGetEventLogs(
{
Expand Down
4 changes: 2 additions & 2 deletions airflow-core/src/airflow/ui/src/pages/Pools/Pools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SearchBar } from "src/components/SearchBar";
import { Select } from "src/components/ui";
import type { SearchParamsKeysType } from "src/constants/searchParams";
import { SearchParamsKeys } from "src/constants/searchParams";
import { getOrderBy } from "src/utils";

import AddPoolButton from "./AddPoolButton";
import PoolBarCard from "./PoolBarCard";
Expand All @@ -58,8 +59,7 @@ export const Pools = () => {

const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["name"];
const orderBy = getOrderBy("name");

const { data, error, isLoading } = usePoolServiceGetPools({
limit: pagination.pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { StateBadge } from "src/components/StateBadge";
import Time from "src/components/Time";
import { TruncatedText } from "src/components/TruncatedText";
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
import { getDuration, useAutoRefresh, isStatePending } from "src/utils";
import { getDuration, useAutoRefresh, isStatePending, getOrderBy } from "src/utils";
import { getTaskInstanceLink } from "src/utils/links";

import DeleteTaskInstanceButton from "./DeleteTaskInstanceButton";
Expand Down Expand Up @@ -191,8 +191,7 @@ export const TaskInstances = () => {
const [searchParams] = useSearchParams();
const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-start_date", "-run_after"];
const orderBy = getOrderBy("-start_date");

const filteredState = searchParams.getAll(STATE_PARAM);
const startDate = searchParams.get(START_DATE_PARAM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { Button, Tooltip } from "src/components/ui";
import { ActionBar } from "src/components/ui/ActionBar";
import { Checkbox } from "src/components/ui/Checkbox";
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
import { getOrderBy } from "src/utils";
import { TrimText } from "src/utils/TrimText";
import { downloadJson } from "src/utils/downloadJson";

Expand Down Expand Up @@ -123,8 +124,7 @@ export const Variables = () => {
);
const [selectedVariables, setSelectedVariables] = useState<Record<string, string | undefined>>({});
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id === "value" ? "_val" : sort.id}`] : ["-key"];
const orderBy = getOrderBy("-key").map((el) => el.replace("value", "_val"));

const { data, error, isFetching, isLoading } = useVariableServiceGetVariables({
limit: pagination.pageSize,
Expand Down
6 changes: 6 additions & 0 deletions airflow-core/src/airflow/ui/src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { useDagServiceGetDagDetails } from "openapi/queries";
import type { TaskInstanceState } from "openapi/requests/types.gen";
import { useConfig } from "src/queries/useConfig";

export const getOrderBy = (defaultOrder?: string): Array<string> => {
const sortParam = new URLSearchParams(globalThis.location.search).getAll("sort");

return sortParam.length === 0 && defaultOrder !== undefined ? [defaultOrder] : sortParam;
};

export const isStatePending = (state?: TaskInstanceState | null) =>
state === "deferred" ||
state === "scheduled" ||
Expand Down
Loading