fix(mobile): fix 'Edit link' setting (#5068)

This commit is contained in:
Zeke Zhang
2024-08-16 12:02:11 +08:00
committed by GitHub
parent 41d7af5457
commit 4aaab331ae
4 changed files with 65 additions and 18 deletions
@@ -7,15 +7,15 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { ISchema } from '@formily/react';
import _ from 'lodash';
import { ISchema, useFieldSchema } from '@formily/react';
import { TFunction, useTranslation } from 'react-i18next';
import { SchemaSettingsItemType } from '../types';
import { getNewSchema, useHookDefault, useSchemaByType } from './util';
import { useColumnSchema } from '../../../schema-component';
import { useCompile } from '../../../schema-component/hooks/useCompile';
import { useDesignable } from '../../../schema-component/hooks/useDesignable';
import { useColumnSchema } from '../../../schema-component';
import { SchemaSettingsItemType } from '../types';
import { getNewSchema, useHookDefault, useSchemaByType } from './util';
export interface CreateModalSchemaSettingsItemProps {
name: string;
@@ -19,11 +19,7 @@ import { ButtonEditor, RemoveButton } from '../../../schema-component/antd/actio
import { SchemaSettingsLinkageRules, SchemaSettingsModalItem } from '../../../schema-settings';
import { useURLAndHTMLSchema } from './useURLAndHTMLSchema';
interface SchemaSettingsActionLinkItemProps {
afterSubmit?: () => void;
}
export const SchemaSettingsActionLinkItem: FC<SchemaSettingsActionLinkItemProps> = ({ afterSubmit }) => {
export const SchemaSettingsActionLinkItem: FC = () => {
const field = useField();
const fieldSchema = useFieldSchema();
const { dn } = useDesignable();
@@ -70,7 +66,6 @@ export const SchemaSettingsActionLinkItem: FC<SchemaSettingsActionLinkItemProps>
},
});
dn.refresh();
afterSubmit?.();
}}
initialValues={initialValues}
/>
@@ -0,0 +1,57 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { ArrayItems } from '@formily/antd-v5';
import { useFieldSchema } from '@formily/react';
import { SchemaSettingsModalItem, useURLAndHTMLSchema } from '@nocobase/client';
import React, { FC } from 'react';
import { useTranslation } from 'react-i18next';
import { useMobileRoutes } from '../../../../mobile-providers/context/MobileRoutes';
export const SchemaSettingsActionLinkItem: FC = () => {
const fieldSchema = useFieldSchema();
const { t } = useTranslation();
const { urlSchema, paramsSchema, openInNewWindowSchema } = useURLAndHTMLSchema();
const { resource, refresh } = useMobileRoutes();
const componentProps = fieldSchema['x-component-props'] || {};
const initialValues = {
url: componentProps.url,
params: componentProps.params || [{}],
openInNewWindow: componentProps.openInNewWindow,
};
return (
<SchemaSettingsModalItem
title={t('Edit link')}
components={{ ArrayItems }}
schema={{
type: 'object',
title: t('Edit link'),
properties: {
url: {
...urlSchema,
required: true,
},
params: paramsSchema,
openInNewWindow: openInNewWindowSchema,
},
}}
onSubmit={async ({ url, params, openInNewWindow }) => {
const schema = fieldSchema.toJSON();
const id = Number(schema.name);
await resource.update({
filterByTk: id,
values: { options: { ...schema['x-component-props'], url, params, openInNewWindow } },
});
refresh();
}}
initialValues={initialValues}
/>
);
};
@@ -7,8 +7,9 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { SchemaSettings, SchemaSettingsActionLinkItem } from '@nocobase/client';
import { editTabItemSettingsItem, removeTabItemSettingsItem, useUpdateTabBarItem } from '../../MobileTabBar.Item';
import { SchemaSettings } from '@nocobase/client';
import { editTabItemSettingsItem, removeTabItemSettingsItem } from '../../MobileTabBar.Item';
import { SchemaSettingsActionLinkItem } from './SchemaSettingsActionLinkItem';
export const mobileTabBarLinkSettings = new SchemaSettings({
name: 'mobile:tab-bar:link',
@@ -17,12 +18,6 @@ export const mobileTabBarLinkSettings = new SchemaSettings({
{
name: 'editLink',
Component: SchemaSettingsActionLinkItem,
useComponentProps() {
const afterSubmit = useUpdateTabBarItem();
return {
afterSubmit,
};
},
},
{
name: 'divider',