Skip to content

feat: use custom app title #2584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 29 additions & 16 deletions src/containers/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,54 @@ import React from 'react';
import type {Store} from '@reduxjs/toolkit';
import type {History} from 'history';
import {Helmet} from 'react-helmet-async';
import {connect} from 'react-redux';

import {componentsRegistry} from '../../components/ComponentsProvider/componentsRegistry';
import type {RootState} from '../../store';
import {useTypedSelector} from '../../utils/hooks';
import ReduxTooltip from '../ReduxTooltip/ReduxTooltip';
import type {YDBEmbeddedUISettings} from '../UserSettings/settings';

import {useAppTitle} from './AppTitleContext';
import ContentWrapper, {Content} from './Content';
import {NavigationWrapper} from './NavigationWrapper';
import {Providers} from './Providers';

import './App.scss';

const defaultAppTitle = 'YDB Monitoring';

export interface AppProps {
store: Store;
history: History;
singleClusterMode: boolean;
userSettings?: YDBEmbeddedUISettings;
children?: React.ReactNode;
appTitle?: string;
}

function App({store, history, singleClusterMode, children, userSettings}: AppProps) {
function App({store, history, children, userSettings, appTitle = defaultAppTitle}: AppProps) {
const ChatPanel = componentsRegistry.get('ChatPanel');

return (
<Providers store={store} history={history}>
<Helmet defaultTitle="YDB Monitoring" titleTemplate="%s — YDB Monitoring" />
<Providers store={store} history={history} appTitle={appTitle}>
<AppContent userSettings={userSettings}>{children}</AppContent>
{ChatPanel && <ChatPanel />}
<ReduxTooltip />
</Providers>
);
}

function AppContent({
userSettings,
children,
}: {
userSettings?: YDBEmbeddedUISettings;
children?: React.ReactNode;
}) {
const {appTitle} = useAppTitle();
const singleClusterMode = useTypedSelector((state) => state.singleClusterMode);

return (
<React.Fragment>
<Helmet defaultTitle={appTitle} titleTemplate={`%s — ${appTitle}`} />
<ContentWrapper>
<NavigationWrapper
singleClusterMode={singleClusterMode}
Expand All @@ -39,16 +60,8 @@ function App({store, history, singleClusterMode, children, userSettings}: AppPro
<div id="fullscreen-root"></div>
</NavigationWrapper>
</ContentWrapper>
{ChatPanel && <ChatPanel />}
<ReduxTooltip />
</Providers>
</React.Fragment>
);
}

function mapStateToProps(state: RootState) {
return {
singleClusterMode: state.singleClusterMode,
};
}

export default connect(mapStateToProps)(App);
export default App;
24 changes: 24 additions & 0 deletions src/containers/App/AppTitleContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {createContext, useContext} from 'react';

interface AppTitleContextType {
appTitle: string;
}

const AppTitleContext = createContext<AppTitleContextType | undefined>(undefined);

interface AppTitleProviderProps {
appTitle: string;
children: React.ReactNode;
}

export function AppTitleProvider({appTitle, children}: AppTitleProviderProps) {
return <AppTitleContext.Provider value={{appTitle}}>{children}</AppTitleContext.Provider>;
}

export function useAppTitle(): AppTitleContextType {
const context = useContext(AppTitleContext);
if (context === undefined) {
throw new Error('useAppTitle must be used within an AppTitleProvider');
}
return context;
}
22 changes: 14 additions & 8 deletions src/containers/App/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,38 @@ import {THEME_KEY} from '../../utils/constants';
import {toaster} from '../../utils/createToast';
import {useSetting} from '../../utils/hooks';

import {AppTitleProvider} from './AppTitleContext';

interface ProvidersProps {
store: Store;
history: History;
componentsRegistry?: ComponentsRegistry;
children: React.ReactNode;
appTitle: string;
}

export function Providers({
store,
history,
componentsRegistry = defaultComponentsRegistry,
children,
appTitle,
}: ProvidersProps) {
return (
<HelmetProvider>
<Provider store={store}>
<Router history={history}>
<QueryParamProvider adapter={ReactRouter5Adapter}>
<Theme>
<ToasterProvider toaster={toaster}>
<ComponentsProvider registry={componentsRegistry}>
<NiceModal.Provider>{children}</NiceModal.Provider>
<ToasterComponent />
</ComponentsProvider>
</ToasterProvider>
</Theme>
<AppTitleProvider appTitle={appTitle}>
<Theme>
<ToasterProvider toaster={toaster}>
<ComponentsProvider registry={componentsRegistry}>
<NiceModal.Provider>{children}</NiceModal.Provider>
<ToasterComponent />
</ComponentsProvider>
</ToasterProvider>
</Theme>
</AppTitleProvider>
</QueryParamProvider>
</Router>
</Provider>
Expand Down
11 changes: 9 additions & 2 deletions src/containers/AppWithClusters/AppWithClusters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ export interface AppWithClustersProps {
history: History;
userSettings?: YDBEmbeddedUISettings;
children?: React.ReactNode;
appTitle?: string;
}

export function AppWithClusters({store, history, userSettings, children}: AppWithClustersProps) {
export function AppWithClusters({
store,
history,
userSettings,
appTitle,
children,
}: AppWithClustersProps) {
return (
<App store={store} history={history} userSettings={userSettings}>
<App store={store} history={history} userSettings={userSettings} appTitle={appTitle}>
<AppSlots.ClusterSlot>
{({component}) => {
return (
Expand Down
7 changes: 5 additions & 2 deletions src/containers/Cluster/Cluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
import {EFlag} from '../../types/api/enums';
import {cn} from '../../utils/cn';
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';
import {useAppTitle} from '../App/AppTitleContext';
import {Nodes} from '../Nodes/Nodes';
import {PaginatedStorage} from '../Storage/PaginatedStorage';
import {TabletsTable} from '../Tablets/TabletsTable';
Expand Down Expand Up @@ -127,11 +128,13 @@ export function Cluster({
[activeTabId, actualClusterTabs],
);

const {appTitle} = useAppTitle();

return (
<div className={b()} ref={container}>
<Helmet
defaultTitle={`${clusterTitle} — YDB Monitoring`}
titleTemplate={`%s — ${clusterTitle} — YDB Monitoring`}
defaultTitle={`${clusterTitle} — ${appTitle}`}
titleTemplate={`%s — ${clusterTitle} — ${appTitle}`}
>
{activeTab ? <title>{activeTab.title}</title> : null}
</Helmet>
Expand Down
7 changes: 3 additions & 4 deletions src/containers/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {nodeApi} from '../../store/reducers/node/node';
import type {PreparedNode} from '../../store/reducers/node/types';
import {cn} from '../../utils/cn';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useAppTitle} from '../App/AppTitleContext';
import {PaginatedStorage} from '../Storage/PaginatedStorage';
import {Tablets} from '../Tablets/Tablets';

Expand Down Expand Up @@ -121,12 +122,10 @@ interface NodePageHelmetProps {
}

function NodePageHelmet({node, activeTabTitle}: NodePageHelmetProps) {
const {appTitle} = useAppTitle();
const host = node?.Host ? node.Host : i18n('node');
return (
<Helmet
titleTemplate={`%s — ${host} — YDB Monitoring`}
defaultTitle={`${host} — YDB Monitoring`}
>
<Helmet titleTemplate={`%s — ${host} — ${appTitle}`} defaultTitle={`${host} — ${appTitle}`}>
<title>{activeTabTitle}</title>
</Helmet>
);
Expand Down
7 changes: 5 additions & 2 deletions src/containers/PDiskPage/PDiskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {cn} from '../../utils/cn';
import {getPDiskId, getSeverityColor} from '../../utils/disks/helpers';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {useAppTitle} from '../App/AppTitleContext';
import {PaginatedStorage} from '../Storage/PaginatedStorage';

import {DecommissionButton} from './DecommissionButton/DecommissionButton';
Expand Down Expand Up @@ -134,6 +135,8 @@ export function PDiskPage() {
}
};

const {appTitle} = useAppTitle();

const renderHelmet = () => {
const pDiskPagePart = pDiskId
? `${pDiskPageKeyset('pdisk')} ${pDiskId}`
Expand All @@ -143,8 +146,8 @@ export function PDiskPage() {

return (
<Helmet
titleTemplate={`%s - ${pDiskPagePart} — ${nodePagePart} — YDB Monitoring`}
defaultTitle={`${pDiskPagePart} — ${nodePagePart} — YDB Monitoring`}
titleTemplate={`%s - ${pDiskPagePart} — ${nodePagePart} — ${appTitle}`}
defaultTitle={`${pDiskPagePart} — ${nodePagePart} — ${appTitle}`}
/>
);
};
Expand Down
6 changes: 4 additions & 2 deletions src/containers/StorageGroupPage/StorageGroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {EFlag} from '../../types/api/enums';
import {valueIsDefined} from '../../utils';
import {cn} from '../../utils/cn';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useAppTitle} from '../App/AppTitleContext';
import {PaginatedStorage} from '../Storage/PaginatedStorage';

import {storageGroupPageKeyset} from './i18n';
Expand Down Expand Up @@ -53,6 +54,7 @@ export function StorageGroupPage() {
const storageGroupData = groupQuery.data?.groups?.[0];

const loading = groupQuery.isFetching && storageGroupData === undefined;
const {appTitle} = useAppTitle();

const renderHelmet = () => {
const pageTitle = groupId
Expand All @@ -61,8 +63,8 @@ export function StorageGroupPage() {

return (
<Helmet
titleTemplate={`%s - ${pageTitle} — YDB Monitoring`}
defaultTitle={`${pageTitle} — YDB Monitoring`}
titleTemplate={`%s - ${pageTitle} — ${appTitle}`}
defaultTitle={`${pageTitle} — ${appTitle}`}
/>
);
};
Expand Down
6 changes: 4 additions & 2 deletions src/containers/Tenant/Tenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {cn} from '../../utils/cn';
import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants';
import {useTypedDispatch, useTypedSelector} from '../../utils/hooks';
import {isAccessError} from '../../utils/response';
import {useAppTitle} from '../App/AppTitleContext';

import ObjectGeneral from './ObjectGeneral/ObjectGeneral';
import {ObjectSummary} from './ObjectSummary/ObjectSummary';
Expand Down Expand Up @@ -116,11 +117,12 @@ export function Tenant(props: TenantProps) {
}

const title = path || i18n('page.title');
const {appTitle} = useAppTitle();
return (
<div className={b()}>
<Helmet
defaultTitle={`${title} — YDB Monitoring`}
titleTemplate={`%s — ${title} — YDB Monitoring`}
defaultTitle={`${title} — ${appTitle}`}
titleTemplate={`%s — ${title} — ${appTitle}`}
/>
<LoaderWrapper loading={initialLoading}>
<PageError error={showBlockingError ? error : undefined}>
Expand Down
7 changes: 5 additions & 2 deletions src/containers/VDiskPage/VDiskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {cn} from '../../utils/cn';
import {getSeverityColor, getVDiskSlotBasedId} from '../../utils/disks/helpers';
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedToMakeChanges';
import {useAppTitle} from '../App/AppTitleContext';
import {PaginatedStorage} from '../Storage/PaginatedStorage';

import {VDiskTablets} from './VDiskTablets';
Expand Down Expand Up @@ -144,6 +145,8 @@ export function VDiskPage() {
);
};

const {appTitle} = useAppTitle();

const renderHelmet = () => {
const vDiskPagePart = vDiskSlotId
? `${vDiskPageKeyset('vdisk')} ${vDiskSlotId}`
Expand All @@ -157,8 +160,8 @@ export function VDiskPage() {

return (
<Helmet
titleTemplate={`%s - ${vDiskPagePart} - ${pDiskPagePart} — ${nodePagePart} — YDB Monitoring`}
defaultTitle={`${vDiskPagePart} - ${pDiskPagePart} — ${nodePagePart} — YDB Monitoring`}
titleTemplate={`%s - ${vDiskPagePart} - ${pDiskPagePart} — ${nodePagePart} — ${appTitle}`}
defaultTitle={`${vDiskPagePart} - ${pDiskPagePart} — ${nodePagePart} — ${appTitle}`}
/>
);
};
Expand Down
Loading