mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
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:
parent
765d14ec94
commit
9f7cc39a3d
@ -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 (
|
||||
<>
|
||||
|
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user