fix: form validation rules data lost when collapsing panel (#6949)

* fix: form validation rules data lost when collapsing panel

* fix: test

* fix: date picker not refreshed after toggling from 'is between' back to 'is'

* fix: bug
This commit is contained in:
Katherine 2025-05-29 16:52:54 +08:00 committed by GitHub
parent d0dbc2428c
commit d25e69a66e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 12 deletions

View File

@ -679,7 +679,7 @@ export function getOperators() {
}
function parseFullDate(dateStr) {
return new Date(dateStr);
return new Date(`${dateStr}T00:00:00`);
}
function parseMonth(dateStr) {

View File

@ -64,37 +64,67 @@ export const datetime = [
label: "{{ t('is') }}",
value: '$dateOn',
selected: true,
schema: { 'x-component': 'DateFilterDynamicComponent' },
schema: {
'x-component': 'DateFilterDynamicComponent',
'x-component-props': {
isRange: false,
},
},
onlyFilterAction: true, //schema 仅在Filter.Action生效筛选表单中不生效
},
{
label: "{{ t('is not') }}",
value: '$dateNotOn',
schema: { 'x-component': 'DateFilterDynamicComponent' },
schema: {
'x-component': 'DateFilterDynamicComponent',
'x-component-props': {
isRange: false,
},
},
onlyFilterAction: true,
},
{
label: "{{ t('is before') }}",
value: '$dateBefore',
schema: { 'x-component': 'DateFilterDynamicComponent' },
schema: {
'x-component': 'DateFilterDynamicComponent',
'x-component-props': {
isRange: false,
},
},
onlyFilterAction: true,
},
{
label: "{{ t('is after') }}",
value: '$dateAfter',
schema: { 'x-component': 'DateFilterDynamicComponent' },
schema: {
'x-component': 'DateFilterDynamicComponent',
'x-component-props': {
isRange: false,
},
},
onlyFilterAction: true,
},
{
label: "{{ t('is on or after') }}",
value: '$dateNotBefore',
schema: { 'x-component': 'DateFilterDynamicComponent' },
schema: {
'x-component': 'DateFilterDynamicComponent',
'x-component-props': {
isRange: false,
},
},
onlyFilterAction: true,
},
{
label: "{{ t('is on or before') }}",
value: '$dateNotAfter',
schema: { 'x-component': 'DateFilterDynamicComponent' },
schema: {
'x-component': 'DateFilterDynamicComponent',
'x-component-props': {
isRange: false,
},
},
onlyFilterAction: true,
},
{

View File

@ -6,7 +6,7 @@
* 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 { ArrayCollapse, FormLayout } from '@formily/antd-v5';
import { FormLayout } from '@formily/antd-v5';
import { Field } from '@formily/core';
import { ISchema, useField, useFieldSchema } from '@formily/react';
import _ from 'lodash';
@ -29,7 +29,7 @@ import { useIsAllowToSetDefaultValue } from '../../../../schema-settings/hooks/u
import { getTempFieldState } from '../../../../schema-settings/LinkageRules/bindLinkageRulesToFiled';
import { ActionType } from '../../../../schema-settings/LinkageRules/type';
import { SchemaSettingsDefaultValue } from '../../../../schema-settings/SchemaSettingsDefaultValue';
import { ArrayCollapse } from '../../../../schema-settings/LinkageRules/components/LinkageHeader';
export const fieldSettingsFormItem = new SchemaSettings({
name: 'fieldSettings:FormItem',
items: [
@ -344,12 +344,17 @@ export const fieldSettingsFormItem = new SchemaSettings({
type: 'object',
'x-component': 'ArrayCollapse.CollapsePanel',
'x-component-props': {
header: '{{ t("Validation rule") }}',
header: t('Validation rule'),
},
properties: {
index: {
type: 'void',
'x-component': 'ArrayCollapse.Index',
'x-component-props': {
style: {
lineHeight: '28px',
},
},
},
layout: {
type: 'void',

View File

@ -28,7 +28,7 @@ describe('Filter', () => {
// 弹窗中显示的内容
expect(within(tooltip).getByText(/name/i)).toBeInTheDocument();
expect(within(tooltip).getByText(/ne/i)).toBeInTheDocument();
expect(within(tooltip).getByTitle(/ne/i)).toBeInTheDocument();
expect(within(tooltip).getByText(/tags \/ title/i)).toBeInTheDocument();
expect(within(tooltip).getByText(/eq/i)).toBeInTheDocument();
expect(within(tooltip).getByText(/^Add condition$/i)).toBeInTheDocument();

View File

@ -131,7 +131,6 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
</Card>
);
};
const renderItems = () => {
return (
<Collapse
@ -168,6 +167,8 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
<Badge size="small" className="errors-badge" count={errors.length}>
{header}
</Badge>
) : props.header ? (
props.header
) : (
<LinkageRulesTitle item={item.initialValue || item} index={index} />
)}