This is an automated email from the ASF dual-hosted git repository.
choo121600 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new 6bc429c0a56 [v3-4-test] UI: Keep Dag list filters when returning
through the Dags link (#76953) (#77187)
6bc429c0a56 is described below
commit 6bc429c0a560040414f12e6ad8ac38db90cacc83
Author: Yeonguk Choo <[email protected]>
AuthorDate: Tue Nov 17 19:59:07 2026 +0900
[v3-4-test] UI: Keep Dag list filters when returning through the Dags link
(#76953) (#77187)
The Dag list keeps its filters only in the URL, and the Dags button in
the nav and the Dags tab above the list both pointed at a bare /dags.
Opening a Dag, or switching to Dag Runs, and coming back through either
link reset the list to its default view, so users had to rebuild the
filters each time. Browser Back worked; the links didn't.
The list's last query is held in memory above the routes rather than in
localStorage, so each browser tab keeps its own view, a new tab still
opens the plain list, and nothing writes the URL on landing to race the
paused default or a pinned preset. Paging and sort are left behind: they
describe where you were in the list, and sort already falls back to its
stored per-page default.
(cherry picked from commit 3d8302a9ead0501450a55a40115032c3384ddcc3)
Co-authored-by: Brent Bovenzi <[email protected]>
---
.../dagsListSearch/Context.ts} | 24 +-------
.../dagsListSearch/DagsListSearchProvider.test.tsx | 72 ++++++++++++++++++++++
.../dagsListSearch/DagsListSearchProvider.tsx | 56 +++++++++++++++++
.../dagsListSearch/index.ts} | 25 +-------
.../src/airflow/ui/src/layouts/BaseLayout.tsx | 43 +++++++------
.../src/airflow/ui/src/layouts/DagsLayout.test.tsx | 45 ++++++++++++++
.../src/airflow/ui/src/layouts/DagsLayout.tsx | 5 +-
.../airflow/ui/src/layouts/Nav/DagsButton.test.tsx | 12 ++++
.../src/airflow/ui/src/layouts/Nav/DagsButton.tsx | 3 +
.../src/airflow/ui/src/layouts/Nav/NavButton.tsx | 14 ++++-
10 files changed, 232 insertions(+), 67 deletions(-)
diff --git a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
b/airflow-core/src/airflow/ui/src/context/dagsListSearch/Context.ts
similarity index 57%
copy from airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
copy to airflow-core/src/airflow/ui/src/context/dagsListSearch/Context.ts
index f1d66e1250f..199774b09f7 100644
--- a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
+++ b/airflow-core/src/airflow/ui/src/context/dagsListSearch/Context.ts
@@ -16,26 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-import type { PropsWithChildren } from "react";
+import { createContext, useContext } from "react";
-import { Box } from "@chakra-ui/react";
-import { useTranslation } from "react-i18next";
+export const DagsListSearchContext = createContext("");
-import { NavTabs } from "./Details/NavTabs";
-
-export const DagsLayout = ({ children }: PropsWithChildren) => {
- const { t: translate } = useTranslation();
-
- const tabs = [
- { label: translate("nav.dags"), value: "/dags" },
- { label: translate("dagRun_other"), value: "/dag_runs" },
- { label: translate("taskInstance_other"), value: "/task_instances" },
- ];
-
- return (
- <Box>
- <NavTabs tabs={tabs} />
- {children}
- </Box>
- );
-};
+export const useDagsListSearch = () => useContext(DagsListSearchContext);
diff --git
a/airflow-core/src/airflow/ui/src/context/dagsListSearch/DagsListSearchProvider.test.tsx
b/airflow-core/src/airflow/ui/src/context/dagsListSearch/DagsListSearchProvider.test.tsx
new file mode 100644
index 00000000000..7d1a8e9cfd9
--- /dev/null
+++
b/airflow-core/src/airflow/ui/src/context/dagsListSearch/DagsListSearchProvider.test.tsx
@@ -0,0 +1,72 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import "@testing-library/jest-dom/vitest";
+import { fireEvent, render, screen } from "@testing-library/react";
+import { MemoryRouter, useNavigate } from "react-router-dom";
+import { describe, expect, it } from "vitest";
+
+import { useDagsListSearch } from "./Context";
+import { DagsListSearchProvider } from "./DagsListSearchProvider";
+
+const RememberedSearch = () => <output>{useDagsListSearch()}</output>;
+
+const GoTo = ({ path }: { readonly path: string }) => {
+ const navigate = useNavigate();
+
+ return <button onClick={() => void navigate(path)} type="button">{`go
${path}`}</button>;
+};
+
+const renderAt = (startPath: string, destinations: Array<string>) =>
+ render(
+ <MemoryRouter initialEntries={[startPath]}>
+ <DagsListSearchProvider>
+ <RememberedSearch />
+ {destinations.map((path) => (
+ <GoTo key={path} path={path} />
+ ))}
+ </DagsListSearchProvider>
+ </MemoryRouter>,
+ );
+
+const goTo = (path: string) => fireEvent.click(screen.getByRole("button", {
name: `go ${path}` }));
+
+describe("DagsListSearchProvider", () => {
+ it("keeps the list's filters and search after leaving it, without paging or
sort", () => {
+
renderAt("/dags?tags=example&name_pattern=bash&offset=50&limit=25&sort=-dag_id",
["/dags/example_dag"]);
+
+ goTo("/dags/example_dag");
+
+
expect(screen.getByRole("status")).toHaveTextContent("tags=example&name_pattern=bash");
+ });
+
+ it("forgets the query once the list is cleared", () => {
+ renderAt("/dags?tags=example", ["/dags", "/dags/example_dag"]);
+
+ goTo("/dags");
+ goTo("/dags/example_dag");
+
+ expect(screen.getByRole("status")).toBeEmptyDOMElement();
+ });
+
+ it("starts empty when the first page is not the list", () => {
+ renderAt("/dags/example_dag?tags=example", []);
+
+ expect(screen.getByRole("status")).toBeEmptyDOMElement();
+ });
+});
diff --git
a/airflow-core/src/airflow/ui/src/context/dagsListSearch/DagsListSearchProvider.tsx
b/airflow-core/src/airflow/ui/src/context/dagsListSearch/DagsListSearchProvider.tsx
new file mode 100644
index 00000000000..8131aae6fb9
--- /dev/null
+++
b/airflow-core/src/airflow/ui/src/context/dagsListSearch/DagsListSearchProvider.tsx
@@ -0,0 +1,56 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { type PropsWithChildren, useState } from "react";
+
+import { useLocation, useMatch } from "react-router-dom";
+
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+import { DagsListSearchContext } from "./Context";
+
+const LIST_POSITION_KEYS = [
+ SearchParamsKeys.CURSOR,
+ SearchParamsKeys.LIMIT,
+ SearchParamsKeys.OFFSET,
+ SearchParamsKeys.SORT,
+];
+
+const removeListPosition = (search: string) => {
+ const params = new URLSearchParams(search);
+
+ LIST_POSITION_KEYS.forEach((key) => params.delete(key));
+
+ return params.toString();
+};
+
+// Remembers the Dag list's last query so links back to the list can reopen
the same view. It lives
+// in memory above the routes, so each browser tab keeps its own and a new tab
starts from the
+// plain list.
+export const DagsListSearchProvider = ({ children }: PropsWithChildren) => {
+ const { search } = useLocation();
+ const isOnDagsList = useMatch("/dags") !== null;
+ const [listSearch, setListSearch] = useState("");
+ const currentListSearch = isOnDagsList ? removeListPosition(search) :
listSearch;
+
+ if (currentListSearch !== listSearch) {
+ setListSearch(currentListSearch);
+ }
+
+ return <DagsListSearchContext.Provider
value={listSearch}>{children}</DagsListSearchContext.Provider>;
+};
diff --git a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
b/airflow-core/src/airflow/ui/src/context/dagsListSearch/index.ts
similarity index 57%
copy from airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
copy to airflow-core/src/airflow/ui/src/context/dagsListSearch/index.ts
index f1d66e1250f..d201ec72ac7 100644
--- a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
+++ b/airflow-core/src/airflow/ui/src/context/dagsListSearch/index.ts
@@ -16,26 +16,5 @@
* specific language governing permissions and limitations
* under the License.
*/
-import type { PropsWithChildren } from "react";
-
-import { Box } from "@chakra-ui/react";
-import { useTranslation } from "react-i18next";
-
-import { NavTabs } from "./Details/NavTabs";
-
-export const DagsLayout = ({ children }: PropsWithChildren) => {
- const { t: translate } = useTranslation();
-
- const tabs = [
- { label: translate("nav.dags"), value: "/dags" },
- { label: translate("dagRun_other"), value: "/dag_runs" },
- { label: translate("taskInstance_other"), value: "/task_instances" },
- ];
-
- return (
- <Box>
- <NavTabs tabs={tabs} />
- {children}
- </Box>
- );
-};
+export * from "./Context";
+export * from "./DagsListSearchProvider";
diff --git a/airflow-core/src/airflow/ui/src/layouts/BaseLayout.tsx
b/airflow-core/src/airflow/ui/src/layouts/BaseLayout.tsx
index 351081a8733..dd45d5306c4 100644
--- a/airflow-core/src/airflow/ui/src/layouts/BaseLayout.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/BaseLayout.tsx
@@ -29,6 +29,7 @@ import { ReactPlugin } from "src/pages/ReactPlugin";
import { KeyboardShortcutsModal } from "src/components/KeyboardShortcuts";
+import { DagsListSearchProvider } from "src/context/dagsListSearch";
import { useConfig } from "src/queries/useConfig";
import { DocumentTitleProvider } from "src/utils";
@@ -108,27 +109,29 @@ export const BaseLayout = ({ children }:
PropsWithChildren) => {
return (
<LocaleProvider locale={i18n.language || "en"}>
<DocumentTitleProvider>
- <Box display="flex" flexDirection="column" h="100vh">
- <KeyboardShortcutsModal />
- <Nav />
- <Box
- _ltr={{ ml: 16 }}
- _rtl={{ mr: 16 }}
- data-testid="main-content"
- display="flex"
- flex={1}
- flexDirection="column"
- minH={0}
- overflowY="auto"
- p={3}
- pb={0}
- >
- {baseReactPlugins.map((plugin) => (
- <ReactPlugin key={plugin.name} reactApp={plugin} />
- ))}
- {children ?? <Outlet />}
+ <DagsListSearchProvider>
+ <Box display="flex" flexDirection="column" h="100vh">
+ <KeyboardShortcutsModal />
+ <Nav />
+ <Box
+ _ltr={{ ml: 16 }}
+ _rtl={{ mr: 16 }}
+ data-testid="main-content"
+ display="flex"
+ flex={1}
+ flexDirection="column"
+ minH={0}
+ overflowY="auto"
+ p={3}
+ pb={0}
+ >
+ {baseReactPlugins.map((plugin) => (
+ <ReactPlugin key={plugin.name} reactApp={plugin} />
+ ))}
+ {children ?? <Outlet />}
+ </Box>
</Box>
- </Box>
+ </DagsListSearchProvider>
</DocumentTitleProvider>
</LocaleProvider>
);
diff --git a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.test.tsx
b/airflow-core/src/airflow/ui/src/layouts/DagsLayout.test.tsx
new file mode 100644
index 00000000000..cf1c40a6f3d
--- /dev/null
+++ b/airflow-core/src/airflow/ui/src/layouts/DagsLayout.test.tsx
@@ -0,0 +1,45 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import "@testing-library/jest-dom/vitest";
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+
+import { DagsListSearchContext } from "src/context/dagsListSearch";
+import { Wrapper } from "src/utils/Wrapper";
+
+import { DagsLayout } from "./DagsLayout";
+
+vi.mock("src/utils", async () => {
+ const actual = await vi.importActual("src/utils");
+
+ return { ...actual, useContainerWidth: () => 1000 };
+});
+
+describe("DagsLayout", () => {
+ it("links the Dags tab to the remembered list query", () => {
+ render(
+ <DagsListSearchContext.Provider value="tags=example">
+ <DagsLayout />
+ </DagsListSearchContext.Provider>,
+ { wrapper: Wrapper },
+ );
+
+ expect(screen.getByRole("link", { name: "nav.dags"
})).toHaveAttribute("href", "/dags?tags=example");
+ });
+});
diff --git a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
b/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
index f1d66e1250f..f75bb16bcd0 100644
--- a/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/DagsLayout.tsx
@@ -21,13 +21,16 @@ import type { PropsWithChildren } from "react";
import { Box } from "@chakra-ui/react";
import { useTranslation } from "react-i18next";
+import { useDagsListSearch } from "src/context/dagsListSearch";
+
import { NavTabs } from "./Details/NavTabs";
export const DagsLayout = ({ children }: PropsWithChildren) => {
const { t: translate } = useTranslation();
+ const dagsListSearch = useDagsListSearch();
const tabs = [
- { label: translate("nav.dags"), value: "/dags" },
+ { label: translate("nav.dags"), search: dagsListSearch, value: "/dags" },
{ label: translate("dagRun_other"), value: "/dag_runs" },
{ label: translate("taskInstance_other"), value: "/task_instances" },
];
diff --git a/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.test.tsx
b/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.test.tsx
index 42af91ba6d4..5f988b7fd8e 100644
--- a/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.test.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.test.tsx
@@ -23,6 +23,7 @@ import { fireEvent, render, screen } from
"@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it } from "vitest";
+import { DagsListSearchContext } from "src/context/dagsListSearch";
import { BaseWrapper, Wrapper } from "src/utils/Wrapper";
import { DagsButton } from "./DagsButton";
@@ -46,6 +47,17 @@ describe("DagsButton", () => {
expect(getLink()).toHaveAttribute("href", "/dags");
});
+ it("links to the Dags page with the remembered list query", () => {
+ render(
+ <DagsListSearchContext.Provider value="tags=example">
+ <DagsButton authorizedMenuItems={["Dags"]} />
+ </DagsListSearchContext.Provider>,
+ { wrapper: Wrapper },
+ );
+
+ expect(getLink()).toHaveAttribute("href", "/dags?tags=example");
+ });
+
it.each(["/dags", "/dags/example_dag/runs"])("is highlighted on %s", (path)
=> {
render(<DagsButton authorizedMenuItems={["Dags"]} />, { wrapper:
wrapperAt(path) });
diff --git a/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.tsx
b/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.tsx
index 4c6fbf8db84..3c25f4f7655 100644
--- a/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/Nav/DagsButton.tsx
@@ -21,11 +21,13 @@ import { useTranslation } from "react-i18next";
import type { MenuItem } from "openapi/requests/types.gen";
import { DagIcon } from "src/assets/DagIcon";
+import { useDagsListSearch } from "src/context/dagsListSearch";
import { NavButton } from "./NavButton";
export const DagsButton = ({ authorizedMenuItems }: { readonly
authorizedMenuItems: Array<MenuItem> }) => {
const { t: translate } = useTranslation();
+ const dagsListSearch = useDagsListSearch();
const isAuthorized = authorizedMenuItems.includes("Dags");
// Without a destination NavButton renders a real <button>, which can be
disabled. A disabled
@@ -35,6 +37,7 @@ export const DagsButton = ({ authorizedMenuItems }: {
readonly authorizedMenuIte
data-testid="nav-dags-link"
disabled={!isAuthorized}
icon={DagIcon}
+ search={dagsListSearch}
title={translate("nav.dags")}
to={isAuthorized ? "/dags" : undefined}
/>
diff --git a/airflow-core/src/airflow/ui/src/layouts/Nav/NavButton.tsx
b/airflow-core/src/airflow/ui/src/layouts/Nav/NavButton.tsx
index 5b1f7d6c2e0..24bce25f292 100644
--- a/airflow-core/src/airflow/ui/src/layouts/Nav/NavButton.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/Nav/NavButton.tsx
@@ -35,13 +35,23 @@ type NavButtonProps = {
readonly icon: ForwardRefExoticComponent<IconProps &
RefAttributes<SVGSVGElement>> | IconType;
readonly isExternal?: boolean;
readonly pluginIcon?: ReactNode;
+ // Only applies to a single internal `to`.
+ readonly search?: string;
readonly title: string;
// A single destination renders the button as a link; an array only affects
isActive matching
// (used for buttons like menu triggers that should highlight for any of
several routes).
readonly to?: Array<string> | string;
} & ButtonProps;
-export const NavButton = ({ icon, isExternal = false, pluginIcon, title, to,
...rest }: NavButtonProps) => {
+export const NavButton = ({
+ icon,
+ isExternal = false,
+ pluginIcon,
+ search,
+ title,
+ to,
+ ...rest
+}: NavButtonProps) => {
const { pathname } = useLocation();
const activePaths = to === undefined ? [] : Array.isArray(to) ? to : [to];
@@ -113,7 +123,7 @@ export const NavButton = ({ icon, isExternal = false,
pluginIcon, title, to, ...
return (
<Button as={Link} asChild {...commonButtonProps}>
- <RouterLink to={to}>
+ <RouterLink to={{ pathname: to, search }}>
{pluginIcon ?? <Icon as={icon} boxSize={5} />}
<Box {...commonLabelProps}>{title}</Box>
</RouterLink>