mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 21:28:34 +08:00
refactor: reset form values after create action (#2905)
* refactor: reset form after create action * fix: association select support reset * fix: map field support form reset * fix: formula field support form reset * fix: josn field support form reset * fix: attachement field support form reset * fix: map field support form reset * fix: map field support form reset * fix: map field support form reset * fix: console
This commit is contained in:
parent
24c10a6f00
commit
e35e4af5e7
@ -112,7 +112,7 @@ export const useCreateActionProps = () => {
|
||||
const variables = useVariables();
|
||||
const localVariables = useLocalVariables({ currentForm: form });
|
||||
const { getActiveFieldsName } = useFormActiveFields() || {};
|
||||
|
||||
const { t } = useTranslation();
|
||||
const action = actionField.componentProps.saveMode || 'create';
|
||||
const filterKeys = actionField.componentProps.filterKeys?.checked || [];
|
||||
return {
|
||||
@ -187,6 +187,8 @@ export const useCreateActionProps = () => {
|
||||
__parent?.service?.refresh?.();
|
||||
setVisible?.(false);
|
||||
if (!onSuccess?.successMessage) {
|
||||
message.success(t('Saved successfully'));
|
||||
await form.reset();
|
||||
return;
|
||||
}
|
||||
if (onSuccess?.manualClose) {
|
||||
@ -205,6 +207,7 @@ export const useCreateActionProps = () => {
|
||||
});
|
||||
} else {
|
||||
message.success(compile(onSuccess?.successMessage));
|
||||
await form.reset();
|
||||
if (onSuccess?.redirecting && onSuccess?.redirectTo) {
|
||||
if (isURL(onSuccess.redirectTo)) {
|
||||
window.location.href = onSuccess.redirectTo;
|
||||
|
@ -58,6 +58,11 @@ const InternalAssociationSelect = observer((props: AssociationSelectProps) => {
|
||||
const api = useAPIClient();
|
||||
const resource = api.resource(collectionField.target);
|
||||
const linkageFields = filterAnalyses(field.componentProps?.service?.params?.filter);
|
||||
useEffect(() => {
|
||||
const initValue = isVariable(field.value) ? undefined : field.value;
|
||||
const value = Array.isArray(initValue) ? initValue.filter(Boolean) : initValue;
|
||||
setInnerValue(value);
|
||||
}, [field.value]);
|
||||
useEffect(() => {
|
||||
const id = uid();
|
||||
form.addEffects(id, () => {
|
||||
@ -111,7 +116,6 @@ const InternalAssociationSelect = observer((props: AssociationSelectProps) => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div key={fieldSchema.name}>
|
||||
<Space.Compact style={{ display: 'flex', lineHeight: '32px' }}>
|
||||
@ -124,7 +128,6 @@ const InternalAssociationSelect = observer((props: AssociationSelectProps) => {
|
||||
service={service}
|
||||
onChange={(value) => {
|
||||
const val = value?.length !== 0 ? value : null;
|
||||
setInnerValue(val);
|
||||
props.onChange?.(val);
|
||||
}}
|
||||
CustomDropdownRender={addMode === 'quickAdd' && QuickAddContent}
|
||||
|
@ -96,6 +96,8 @@ const InternalFileManager = (props) => {
|
||||
};
|
||||
});
|
||||
setOptions(opts);
|
||||
} else {
|
||||
setOptions([]);
|
||||
}
|
||||
}, [value, fieldNames?.label]);
|
||||
|
||||
|
@ -15,6 +15,8 @@ export const Json = React.forwardRef<typeof Input.TextArea, JSONTextAreaProps>(
|
||||
try {
|
||||
if (value != null) {
|
||||
setText(JSON.stringify(value, null, space));
|
||||
} else {
|
||||
setText(undefined);
|
||||
}
|
||||
} catch (ex) {
|
||||
//
|
||||
|
@ -33,7 +33,6 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
const { t } = useTranslation();
|
||||
const uploadProps = useUploadProps({ ...props });
|
||||
const { wrapSSR, hashId, componentCls: prefixCls } = useStyles();
|
||||
|
||||
const internalFileList = useRef([]);
|
||||
|
||||
function closeIFrameModal() {
|
||||
@ -169,6 +168,7 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
onChange?.(toValue(list));
|
||||
}
|
||||
setFileList(list.map(toItem));
|
||||
setSync(true);
|
||||
} else {
|
||||
if (info.file.status === 'done') {
|
||||
// TODO(BUG): object 的联动有问题,不响应,折中的办法先置空再赋值
|
||||
@ -176,6 +176,7 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
onChange?.(info.file?.response?.data);
|
||||
}
|
||||
setFileList([toItem(info.file)]);
|
||||
setSync(true);
|
||||
}
|
||||
}}
|
||||
showUploadList={false}
|
||||
@ -229,6 +230,7 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
onCancel={closeIFrameModal}
|
||||
footer={[
|
||||
<Button
|
||||
key="download"
|
||||
style={{
|
||||
textTransform: 'capitalize',
|
||||
}}
|
||||
@ -241,7 +243,7 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
>
|
||||
{t('download')}
|
||||
</Button>,
|
||||
<Button onClick={closeIFrameModal} style={{ textTransform: 'capitalize' }}>
|
||||
<Button key="close" onClick={closeIFrameModal} style={{ textTransform: 'capitalize' }}>
|
||||
{t('close')}
|
||||
</Button>,
|
||||
]}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { onFormInputChange } from '@formily/core';
|
||||
import { onFormValuesChange } from '@formily/core';
|
||||
import { useField, useFieldSchema, useFormEffects } from '@formily/react';
|
||||
import { toJS } from '@formily/reactive';
|
||||
import type { CollectionOptions } from '@nocobase/client';
|
||||
@ -82,7 +82,7 @@ export function Result(props) {
|
||||
}, [value]);
|
||||
|
||||
useFormEffects(() => {
|
||||
onFormInputChange((form) => {
|
||||
onFormValuesChange((form) => {
|
||||
if (
|
||||
(fieldSchema.name as string).indexOf('.') >= 0 ||
|
||||
!formBlockContext?.form ||
|
||||
@ -100,7 +100,7 @@ export function Result(props) {
|
||||
v = null;
|
||||
}
|
||||
if (v == null && editingValue == null) {
|
||||
return;
|
||||
setEditingValue(v);
|
||||
}
|
||||
setEditingValue(v);
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import AMapLoader from '@amap/amap-jsapi-loader';
|
||||
import '@amap/amap-jsapi-types';
|
||||
import { SyncOutlined } from '@ant-design/icons';
|
||||
import { useFieldSchema } from '@formily/react';
|
||||
import { useField, useFieldSchema } from '@formily/react';
|
||||
import { css, useCollection } from '@nocobase/client';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import { Alert, App, Button, Spin } from 'antd';
|
||||
@ -293,6 +293,14 @@ export const AMapComponent = React.forwardRef<AMapForwardedRefProps, AMapCompone
|
||||
|
||||
// 当值变更时,toggle mouseTool
|
||||
useEffect(() => {
|
||||
if (!value && (mouseTool.current || editor.current)) {
|
||||
toRemoveOverlay();
|
||||
if (editor.current) {
|
||||
editor.current.setTarget();
|
||||
editor.current.close();
|
||||
}
|
||||
onChange?.(null);
|
||||
}
|
||||
if (!mouseTool.current || !editor.current) return;
|
||||
const target = editor.current.getTarget();
|
||||
if (target) {
|
||||
|
@ -268,6 +268,11 @@ export const GoogleMapsComponent = React.forwardRef<GoogleMapForwardedRefProps,
|
||||
|
||||
// edit mode
|
||||
useEffect(() => {
|
||||
if (!value && map.current) {
|
||||
toRemoveOverlay();
|
||||
drawingManagerRef?.current?.setDrawingMode?.(drawingMode.current);
|
||||
onChange?.(null);
|
||||
}
|
||||
if (!map.current) return;
|
||||
if (!value || (!readonly && overlayRef.current)) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user