mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +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 { NavigateFunction, Outlet, useOutletContext } from 'react-router-dom';
|
||||||
import { FormDialog } from '..';
|
import { FormDialog } from '..';
|
||||||
import { antTableCell } from '../../../acl/style';
|
import { antTableCell } from '../../../acl/style';
|
||||||
import { useRequest } from '../../../api-client';
|
|
||||||
import {
|
import {
|
||||||
CurrentTabUidContext,
|
CurrentTabUidContext,
|
||||||
useCurrentSearchParams,
|
useCurrentSearchParams,
|
||||||
@ -392,25 +391,12 @@ const NocoBasePageHeader = React.memo(({ activeKey, className }: { activeKey: st
|
|||||||
const hidePageTitle = fieldSchema['x-component-props']?.hidePageTitle;
|
const hidePageTitle = fieldSchema['x-component-props']?.hidePageTitle;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fieldSchema.title) {
|
const title = t(fieldSchema.title) || t(currentRoute?.title);
|
||||||
const title = t(fieldSchema.title);
|
if (title) {
|
||||||
setDocumentTitle(title);
|
setDocumentTitle(title);
|
||||||
setPageTitle(title);
|
setPageTitle(title);
|
||||||
}
|
}
|
||||||
}, [fieldSchema.title, pageTitle, setDocumentTitle, t]);
|
}, [fieldSchema.title, pageTitle, setDocumentTitle, t, currentRoute?.title]);
|
||||||
|
|
||||||
useRequest(
|
|
||||||
{
|
|
||||||
url: `/uiSchemas:getParentJsonSchema/${fieldSchema['x-uid']}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ready: !hidePageTitle && !fieldSchema.title,
|
|
||||||
onSuccess(data) {
|
|
||||||
setPageTitle(data.data.title);
|
|
||||||
setDocumentTitle(data.data.title);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -46,28 +46,6 @@ describe('Page', () => {
|
|||||||
expect(screen.queryByText('Test Title')).not.toBeInTheDocument();
|
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
|
// TODO: This works normally in the actual page, but the test fails here
|
||||||
test.skip('add tab', async () => {
|
test.skip('add tab', async () => {
|
||||||
await renderAppOptions({
|
await renderAppOptions({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user