mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 09:57:33 -02:30
display current page name in document title
This commit is contained in:
@@ -27,7 +27,7 @@ import { isAuthenticated } from 'util/auth';
|
|||||||
import { getLanguageWithoutRegionCode } from 'util/language';
|
import { getLanguageWithoutRegionCode } from 'util/language';
|
||||||
import Metrics from 'screens/Metrics';
|
import Metrics from 'screens/Metrics';
|
||||||
import SubscriptionEdit from 'screens/Setting/Subscription/SubscriptionEdit';
|
import SubscriptionEdit from 'screens/Setting/Subscription/SubscriptionEdit';
|
||||||
import { RootAPI } from 'api';
|
import useTitle from 'hooks/useTitle';
|
||||||
import { dynamicActivate, locales } from './i18nLoader';
|
import { dynamicActivate, locales } from './i18nLoader';
|
||||||
import getRouteConfig from './routeConfig';
|
import getRouteConfig from './routeConfig';
|
||||||
import { SESSION_REDIRECT_URL } from './constants';
|
import { SESSION_REDIRECT_URL } from './constants';
|
||||||
@@ -150,16 +150,7 @@ function App() {
|
|||||||
dynamicActivate(language);
|
dynamicActivate(language);
|
||||||
}, [language]);
|
}, [language]);
|
||||||
|
|
||||||
useEffect(() => {
|
useTitle();
|
||||||
async function fetchBrandName() {
|
|
||||||
const {
|
|
||||||
data: { BRAND_NAME },
|
|
||||||
} = await RootAPI.readAssetVariables();
|
|
||||||
|
|
||||||
document.title = BRAND_NAME;
|
|
||||||
}
|
|
||||||
fetchBrandName();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const redirectURL = window.sessionStorage.getItem(SESSION_REDIRECT_URL);
|
const redirectURL = window.sessionStorage.getItem(SESSION_REDIRECT_URL);
|
||||||
if (redirectURL) {
|
if (redirectURL) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import useTitle from 'hooks/useTitle';
|
||||||
|
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import {
|
import {
|
||||||
@@ -12,7 +13,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
import { HistoryIcon } from '@patternfly/react-icons';
|
import { HistoryIcon } from '@patternfly/react-icons';
|
||||||
import { Link, Route, useRouteMatch } from 'react-router-dom';
|
import { Link, Route, useRouteMatch, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
const ScreenHeader = ({ breadcrumbConfig, streamType }) => {
|
const ScreenHeader = ({ breadcrumbConfig, streamType }) => {
|
||||||
const { light } = PageSectionVariants;
|
const { light } = PageSectionVariants;
|
||||||
@@ -20,6 +21,16 @@ const ScreenHeader = ({ breadcrumbConfig, streamType }) => {
|
|||||||
path: Object.keys(breadcrumbConfig)[0],
|
path: Object.keys(breadcrumbConfig)[0],
|
||||||
strict: true,
|
strict: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const location = useLocation();
|
||||||
|
const parts = location.pathname.split('/');
|
||||||
|
if (parts.length > 2) {
|
||||||
|
parts.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathTitle = breadcrumbConfig[parts.join('/')];
|
||||||
|
useTitle(pathTitle);
|
||||||
|
|
||||||
const isOnlyOneCrumb = oneCrumbMatch && oneCrumbMatch.isExact;
|
const isOnlyOneCrumb = oneCrumbMatch && oneCrumbMatch.isExact;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
19
awx/ui/src/hooks/useTitle.js
Normal file
19
awx/ui/src/hooks/useTitle.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import useBrandName from './useBrandName';
|
||||||
|
|
||||||
|
export default function useTitle(title) {
|
||||||
|
const brandName = useBrandName();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const prevTitle = document.title;
|
||||||
|
if (title) {
|
||||||
|
document.title = `${brandName} | ${title}`;
|
||||||
|
} else {
|
||||||
|
document.title = brandName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.title = prevTitle;
|
||||||
|
};
|
||||||
|
}, [title, brandName]);
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import PaginatedTable, {
|
|||||||
getSearchableKeys,
|
getSearchableKeys,
|
||||||
} from 'components/PaginatedTable';
|
} from 'components/PaginatedTable';
|
||||||
import useRequest from 'hooks/useRequest';
|
import useRequest from 'hooks/useRequest';
|
||||||
|
import useTitle from 'hooks/useTitle';
|
||||||
import { getQSConfig, parseQueryString, updateQueryString } from 'util/qs';
|
import { getQSConfig, parseQueryString, updateQueryString } from 'util/qs';
|
||||||
import { ActivityStreamAPI } from 'api';
|
import { ActivityStreamAPI } from 'api';
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ function ActivityStream() {
|
|||||||
const [isTypeDropdownOpen, setIsTypeDropdownOpen] = useState(false);
|
const [isTypeDropdownOpen, setIsTypeDropdownOpen] = useState(false);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
useTitle(t`Activity Stream`);
|
||||||
const urlParams = new URLSearchParams(location.search);
|
const urlParams = new URLSearchParams(location.search);
|
||||||
|
|
||||||
const activityStreamType = urlParams.get('type') || 'all';
|
const activityStreamType = urlParams.get('type') || 'all';
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ jest.mock('axios', () => ({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
jest.mock('hooks/useTitle');
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (networkRequestUrl) {
|
if (networkRequestUrl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user