mirror of
https://github.com/grafana/grafana.git
synced 2025-09-26 11:14:07 +08:00
feat: Possibility to change document title on pages using the Page component
This commit is contained in:
@ -7,7 +7,7 @@ import PageContents from './PageContents';
|
|||||||
import { CustomScrollbar } from '@grafana/ui';
|
import { CustomScrollbar } from '@grafana/ui';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string;
|
title?: string;
|
||||||
children: JSX.Element[] | JSX.Element;
|
children: JSX.Element[] | JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,12 +23,24 @@ class Page extends Component<Props> {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.body.classList.add(this.bodyClass);
|
this.body.classList.add(this.bodyClass);
|
||||||
this.copyFooter();
|
this.copyFooter();
|
||||||
|
this.updateTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps: Props) {
|
||||||
|
if (prevProps.title !== this.props.title) {
|
||||||
|
this.updateTitle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.body.classList.remove(this.bodyClass);
|
this.body.classList.remove(this.bodyClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateTitle = () => {
|
||||||
|
const { title } = this.props;
|
||||||
|
document.title = title ? title + ' - Grafana' : 'Grafana';
|
||||||
|
}
|
||||||
|
|
||||||
copyFooter = () => {
|
copyFooter = () => {
|
||||||
const c = this.scrollbarElementRef.current;
|
const c = this.scrollbarElementRef.current;
|
||||||
c.append(this.footer);
|
c.append(this.footer);
|
||||||
|
Reference in New Issue
Block a user