fix(page): improve document title handling and remove unused request (#6188)

* fix(page): improve document title handling and remove unused request

* fix(tests): remove unused remote schema request test for Page component
This commit is contained in:
Zeke Zhang 2025-02-10 20:42:12 +08:00 committed by GitHub
parent 765d14ec94
commit 9f7cc39a3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 39 deletions

View File

@ -21,7 +21,6 @@ import { useTranslation } from 'react-i18next';
import { NavigateFunction, Outlet, useOutletContext } from 'react-router-dom';
import { FormDialog } from '..';
import { antTableCell } from '../../../acl/style';
import { useRequest } from '../../../api-client';
import {
CurrentTabUidContext,
useCurrentSearchParams,
@ -392,25 +391,12 @@ const NocoBasePageHeader = React.memo(({ activeKey, className }: { activeKey: st
const hidePageTitle = fieldSchema['x-component-props']?.hidePageTitle;
useEffect(() => {
if (fieldSchema.title) {
const title = t(fieldSchema.title);
const title = t(fieldSchema.title) || t(currentRoute?.title);
if (title) {
setDocumentTitle(title);
setPageTitle(title);
}
}, [fieldSchema.title, pageTitle, setDocumentTitle, t]);
useRequest(
{
url: `/uiSchemas:getParentJsonSchema/${fieldSchema['x-uid']}`,
},
{
ready: !hidePageTitle && !fieldSchema.title,
onSuccess(data) {
setPageTitle(data.data.title);
setDocumentTitle(data.data.title);
},
},
);
}, [fieldSchema.title, pageTitle, setDocumentTitle, t, currentRoute?.title]);
return (
<>

View File

@ -46,28 +46,6 @@ describe('Page', () => {
expect(screen.queryByText('Test Title')).not.toBeInTheDocument();
});
test('should request remote schema when no title', async () => {
await renderAppOptions({
schema: {
type: 'void',
'x-uid': 'test',
'x-component': Page,
'x-decorator': DocumentTitleProvider,
},
apis: {
'/uiSchemas:getParentJsonSchema/test': {
data: {
title: 'remote title',
},
},
},
});
await waitFor(() => {
expect(screen.getByText('remote title')).toBeInTheDocument();
});
});
// TODO: This works normally in the actual page, but the test fails here
test.skip('add tab', async () => {
await renderAppOptions({