Skip to content

Commit 1398a3b

Browse files
Subham-KRLXYour friendly bot
authored andcommitted
[v3-2-test] UI: Show DAG name in browser tab title (apache#67169)
(cherry picked from commit ea7481d) Co-authored-by: Subham <subhamsangwan26@gmail.com>
1 parent 72ee444 commit 1398a3b

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

airflow-core/src/airflow/ui/src/layouts/BaseLayout.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { useConfig } from "src/queries/useConfig";
2929
import { Nav } from "./Nav";
3030

3131
export const BaseLayout = ({ children }: PropsWithChildren) => {
32-
const instanceName = useConfig("instance_name");
3332
const { i18n } = useTranslation();
3433
const { data: pluginData } = usePluginServiceGetPlugins();
3534
const theme = useConfig("theme") as unknown as { icon?: string; icon_dark_mode?: string } | undefined;
@@ -39,10 +38,6 @@ export const BaseLayout = ({ children }: PropsWithChildren) => {
3938
.flatMap((plugin) => plugin.react_apps)
4039
.filter((reactApp: ReactAppResponse) => reactApp.destination === "base") ?? [];
4140

42-
if (typeof instanceName === "string") {
43-
document.title = instanceName;
44-
}
45-
4641
useEffect(() => {
4742
const html = document.documentElement;
4843

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { usePluginTabs } from "src/hooks/usePluginTabs";
3232
import { useRequiredActionTabs } from "src/hooks/useRequiredActionTabs";
3333
import { DetailsLayout } from "src/layouts/Details/DetailsLayout";
3434
import { useRefreshOnNewDagRuns } from "src/queries/useRefreshOnNewDagRuns";
35-
import { isStatePending, useAutoRefresh } from "src/utils";
35+
import { isStatePending, useAutoRefresh, useDocumentTitle } from "src/utils";
3636

3737
import { DagNotFound } from "./DagNotFound";
3838
import { Header } from "./Header";
@@ -86,6 +86,8 @@ export const Dag = () => {
8686
},
8787
);
8888

89+
useDocumentTitle(dag?.dag_display_name ?? dagId);
90+
8991
// Ensures continuous refresh to detect new runs when there's no
9092
// pending state and new runs are initiated from other page
9193
useRefreshOnNewDagRuns(dagId, hasPendingRuns, dag?.is_paused);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export { getDuration, renderDuration } from "./datetimeUtils";
2222
export { createErrorToaster, getErrorStatus } from "./errorHandling";
2323
export { getMetaKey } from "./getMetaKey";
2424
export { useContainerWidth } from "./useContainerWidth";
25+
export { useDocumentTitle } from "./useDocumentTitle";
2526
export { useFiltersHandler, type FilterableSearchParamsKeys } from "./useFiltersHandler";
2627
export * from "./query";
2728
export { STATE_PRIORITY, sortStateEntries } from "./stateUtils";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*!
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { useEffect } from "react";
20+
21+
import { useConfig } from "src/queries/useConfig";
22+
23+
export const useDocumentTitle = (pageTitle?: string | null) => {
24+
const instanceConfig = useConfig("instance_name");
25+
const instanceName = typeof instanceConfig === "string" ? instanceConfig : "Airflow";
26+
27+
useEffect(() => {
28+
const previousTitle = document.title;
29+
30+
if (typeof pageTitle === "string" && pageTitle.length > 0) {
31+
document.title = `${pageTitle} - ${instanceName}`;
32+
}
33+
34+
return () => {
35+
document.title = previousTitle;
36+
};
37+
}, [pageTitle, instanceName]);
38+
};

0 commit comments

Comments
 (0)