Merge branch 'next' into fix/package-version

This commit is contained in:
xilesun 2025-03-01 14:39:09 +08:00
commit c2e9875528
10 changed files with 610 additions and 73 deletions

View File

@ -373,6 +373,42 @@ export const dateTimeProps: { [key: string]: ISchema } = {
},
};
export const timeProps: { [key: string]: ISchema } = {
'uiSchema.x-component-props.format': {
type: 'string',
title: '{{t("Time format")}}',
'x-component': 'ExpiresRadio',
'x-decorator': 'FormItem',
'x-component-props': {
className: css`
color: red;
.ant-radio-wrapper {
display: flex;
margin: 5px 0px;
}
`,
defaultValue: 'h:mm a',
formats: ['hh:mm:ss a', 'HH:mm:ss'],
timeFormat: true,
},
default: 'HH:mm:ss',
enum: [
{
label: DateFormatCom({ format: 'hh:mm:ss a' }),
value: 'hh:mm:ss a',
},
{
label: DateFormatCom({ format: 'HH:mm:ss' }),
value: 'HH:mm:ss',
},
{
label: 'custom',
value: 'custom',
},
],
},
};
export const dataSource: ISchema = {
type: 'array',
title: '{{t("Options")}}',

View File

@ -8,7 +8,7 @@
*/
import { CollectionFieldInterface } from '../../data-source/collection-field-interface/CollectionFieldInterface';
import { defaultProps, operators } from './properties';
import { defaultProps, operators, timeProps } from './properties';
export class TimeFieldInterface extends CollectionFieldInterface {
name = 'time';
@ -28,23 +28,7 @@ export class TimeFieldInterface extends CollectionFieldInterface {
hasDefaultValue = true;
properties = {
...defaultProps,
'uiSchema.x-component-props.format': {
type: 'string',
title: '{{t("Time format")}}',
'x-component': 'Radio.Group',
'x-decorator': 'FormItem',
default: 'HH:mm:ss',
enum: [
{
label: '{{t("12 hour")}}',
value: 'hh:mm:ss a',
},
{
label: '{{t("24 hour")}}',
value: 'HH:mm:ss',
},
],
},
...timeProps,
};
filterable = {
operators: operators.time,

View File

@ -110,6 +110,7 @@ export abstract class CollectionFieldInterface {
'uiSchema.x-component-props.dateFormat',
'uiSchema.x-component-props.timeFormat',
'uiSchema.x-component-props.picker',
'uiSchema.x-component-props.format',
],
fulfill: {
state: {
@ -119,6 +120,7 @@ export abstract class CollectionFieldInterface {
dateFormat: '{{$deps[2]}}',
timeFormat: '{{$deps[3]}}',
picker: '{{$deps[4]}}',
format: '{{$deps[5]}}',
},
},
},

View File

@ -0,0 +1,66 @@
/**
* 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 { expect, expectSettingsMenu, test } from '@nocobase/test/e2e';
import dayjs from 'dayjs';
import { oneFormBlockWithTimeField, oneTableBlockWithTimeField } from './template';
test(' time format in form', async ({ page, mockPage }) => {
await mockPage(oneFormBlockWithTimeField).goto();
await expectSettingsMenu({
page,
showMenu: async () => {
await page.getByPlaceholder('Select time').hover();
await page.getByLabel('block-item-CollectionField').hover();
await page.getByLabel('designer-schema-settings-CollectionField-fieldSettings:FormItem-general').click();
},
supportedOptions: [
'Edit field title',
'Display title',
'Edit description',
'Edit tooltip',
'Required',
'Set default value',
'Pattern',
'Time format',
'Delete',
],
});
await page.getByText('Time format').click();
await page.getByRole('radio', { name: 'hh:mm:ss a' }).check();
await page.getByRole('button', { name: 'OK' }).click();
await page.getByPlaceholder('Select time').click();
await page.getByText('Now').click();
const value = await page.getByPlaceholder('Select time').inputValue();
const expectedTime = dayjs().format('hh:mm:ss a'); // 12-hour format
await expect(value).toBe(expectedTime);
});
test('Time format in table', async ({ page, mockPage, mockRecord }) => {
await mockPage(oneTableBlockWithTimeField).goto();
const time = dayjs().format('hh:mm:ss a');
await mockRecord('general', { time: time });
await expectSettingsMenu({
page,
showMenu: async () => {
await page.getByLabel('block-item-CardItem-general-table').click();
await page.getByRole('button', { name: 'time' }).hover();
await page
.getByRole('button', { name: 'designer-schema-settings-TableV2.Column-fieldSettings:TableColumn-general' })
.click();
},
supportedOptions: ['Custom column title', 'Column width', 'Sortable', 'Time format', 'Delete'],
});
await page.getByText('Time format').click();
await page.getByRole('radio', { name: 'hh:mm:ss a' }).check();
await page.getByRole('button', { name: 'OK' }).click();
await expect(page.getByRole('button', { name: time })).toBeVisible();
});

View File

@ -0,0 +1,360 @@
/**
* 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 { generalWithDatetime, PageConfig } from '@nocobase/test/e2e';
/**
* 1. Form \Table
* 5. time
*/
export const oneFormBlockWithTimeField: PageConfig = {
collections: generalWithDatetime,
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
'x-app-version': '1.6.0-beta.15',
properties: {
yjae0hw7w4m: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
'x-app-version': '1.6.0-beta.15',
properties: {
p2ud89cmdsj: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.6.0-beta.15',
properties: {
ic2lvywe453: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.6.0-beta.15',
properties: {
ejm452mcfqf: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: true,
},
'x-acl-action': 'general:create',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
'x-decorator-props': {
dataSource: 'main',
collection: 'general',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:createForm',
'x-component': 'CardItem',
'x-app-version': '1.6.0-beta.15',
properties: {
uizopeb0gdx: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useCreateFormBlockProps',
'x-app-version': '1.6.0-beta.15',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-app-version': '1.6.0-beta.15',
properties: {
m2x40wt0f0r: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.6.0-beta.15',
properties: {
'3kn5w9dj3h6': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.6.0-beta.15',
properties: {
time: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar': 'FormItemSchemaToolbar',
'x-settings': 'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field': 'general.time',
'x-component-props': {},
'x-app-version': '1.6.0-beta.15',
'x-uid': '76f5jb57ey9',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ur04ehrn1e6',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'v3894toxet8',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'j9rv21n3197',
'x-async': false,
'x-index': 1,
},
wm2nvr5d4j8: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'createForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
},
'x-app-version': '1.6.0-beta.15',
'x-uid': 'i2nzkcibwd4',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'cs3lcqbet7q',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'cc8fwk5axfs',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'hpmiaka8jlp',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'y4pqnipi0on',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '5j3ftwsuvk7',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'qif8bkjq7kv',
'x-async': true,
'x-index': 1,
},
};
/**
* 1. Form \Table
* 5. time
*/
export const oneTableBlockWithTimeField: PageConfig = {
collections: generalWithDatetime,
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
'x-app-version': '1.6.0-beta.15',
properties: {
yjae0hw7w4m: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
'x-app-version': '1.6.0-beta.15',
properties: {
sfktacc6qng: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '1.6.0-beta.15',
properties: {
aft3rjsnrr3: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '1.6.0-beta.15',
properties: {
n2tzols0da0: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'general:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'general',
dataSource: 'main',
action: 'list',
params: {
pageSize: 20,
},
rowKey: 'id',
showIndex: true,
dragSort: false,
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:table',
'x-component': 'CardItem',
'x-filter-targets': [],
'x-app-version': '1.6.0-beta.15',
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'table:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
style: {
marginBottom: 'var(--nb-spacing)',
},
},
'x-app-version': '1.6.0-beta.15',
'x-uid': '8zmjddrlpt7',
'x-async': false,
'x-index': 1,
},
'6et4p3qclc6': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'array',
'x-initializer': 'table:configureColumns',
'x-component': 'TableV2',
'x-use-component-props': 'useTableBlockProps',
'x-component-props': {
rowKey: 'id',
rowSelection: {
type: 'checkbox',
},
},
'x-app-version': '1.6.0-beta.15',
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Actions") }}',
'x-action-column': 'actions',
'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column',
'x-toolbar': 'TableColumnSchemaToolbar',
'x-initializer': 'table:configureItemActions',
'x-settings': 'fieldSettings:TableColumn',
'x-toolbar-props': {
initializer: 'table:configureItemActions',
},
'x-app-version': '1.6.0-beta.15',
properties: {
'8ujrihmuxwi': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '1.6.0-beta.15',
'x-uid': 'vpsnsemc5iz',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'to4z2kld8cb',
'x-async': false,
'x-index': 1,
},
host1qju9vo: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableV2.Column.Decorator',
'x-toolbar': 'TableColumnSchemaToolbar',
'x-settings': 'fieldSettings:TableColumn',
'x-component': 'TableV2.Column',
'x-app-version': '1.6.0-beta.15',
properties: {
time: {
_isJSONSchemaObject: true,
version: '2.0',
'x-collection-field': 'general.time',
'x-component': 'CollectionField',
'x-component-props': {},
'x-read-pretty': true,
'x-decorator': null,
'x-decorator-props': {
labelStyle: {
display: 'none',
},
},
'x-app-version': '1.6.0-beta.15',
'x-uid': '1t09d95p38h',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '38vdpp99z9s',
'x-async': false,
'x-index': 2,
},
},
'x-uid': '3ccldpb58hp',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'dtd0eeq2jwu',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'rnzuzapf9cz',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ikzfjf1vv39',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '5j3ftwsuvk7',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'qif8bkjq7kv',
'x-async': true,
'x-index': 1,
},
};

View File

@ -0,0 +1,31 @@
/**
* 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 { useFieldSchema } from '@formily/react';
import { SchemaSettings } from '../../../../application/schema-settings/SchemaSettings';
import { SchemaSettingsTimeFormat } from '../../../../schema-settings/SchemaSettingsTimeFormat';
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
export const timePickerComponentFieldSettings = new SchemaSettings({
name: 'fieldSettings:component:TimePicker',
items: [
{
name: 'timeDisplayFormat',
Component: SchemaSettingsTimeFormat as any,
useComponentProps() {
const schema = useFieldSchema();
const { fieldSchema: tableColumnSchema } = useColumnSchema();
const fieldSchema = tableColumnSchema || schema;
return {
fieldSchema,
};
},
},
],
});

View File

@ -78,7 +78,7 @@ import { subTablePopoverComponentFieldSettings } from '../modules/fields/compone
import { tagComponentFieldSettings } from '../modules/fields/component/Tag/tagComponentFieldSettings';
import { unixTimestampComponentFieldSettings } from '../modules/fields/component/UnixTimestamp/unixTimestampComponentFieldSettings';
import { dividerSettings } from '../modules/blocks/other-blocks/divider/dividerSettings';
import { timePickerComponentFieldSettings } from '../modules/fields/component/TimePicker/timePickerComponentFieldSettings';
export class SchemaSettingsPlugin extends Plugin {
async load() {
// block settings
@ -149,5 +149,6 @@ export class SchemaSettingsPlugin extends Plugin {
this.schemaSettingsManager.add(uploadAttachmentComponentFieldSettings);
this.schemaSettingsManager.add(previewComponentFieldSettings);
this.schemaSettingsManager.add(dividerSettings);
this.schemaSettingsManager.add(timePickerComponentFieldSettings);
}
}

View File

@ -0,0 +1,108 @@
/**
* 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 { css } from '@emotion/css';
import { ISchema, Schema, useField } from '@formily/react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { getPickerFormat } from '@nocobase/utils/client';
import { useCollectionManager_deprecated, useDesignable } from '..';
import { DateFormatCom, ExpiresRadio } from '../schema-component';
import { SchemaSettingsModalItem } from './SchemaSettings';
export const SchemaSettingsTimeFormat = function TimeFormatConfig(props: { fieldSchema: Schema }) {
const { fieldSchema } = props;
const field: any = useField();
const { dn } = useDesignable();
const { t } = useTranslation();
const { getCollectionJoinField } = useCollectionManager_deprecated();
const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']) || {};
const timeFormatDefaultValue =
fieldSchema?.['x-component-props']?.format ||
collectionField?.uiSchema?.['x-component-props']?.format ||
'HH:mm:ss';
return (
<SchemaSettingsModalItem
title={t('Time format')}
scope={{ getPickerFormat }}
schema={
{
type: 'object',
properties: {
format: {
type: 'string',
title: '{{t("Time format")}}',
'x-component': ExpiresRadio,
'x-decorator': 'FormItem',
'x-decorator-props': {
className: css`
margin-bottom: 0px;
`,
},
'x-component-props': {
className: css`
color: red;
.ant-radio-wrapper {
display: flex;
margin: 5px 0px;
}
`,
defaultValue: 'h:mm a',
formats: ['hh:mm:ss a', 'HH:mm:ss'],
timeFormat: true,
},
default: timeFormatDefaultValue,
enum: [
{
label: DateFormatCom({ format: 'hh:mm:ss a' }),
value: 'hh:mm:ss a',
},
{
label: DateFormatCom({ format: 'HH:mm:ss' }),
value: 'HH:mm:ss',
},
{
label: 'custom',
value: 'custom',
},
],
},
},
} as ISchema
}
onSubmit={(data) => {
const schema: any = {
['x-uid']: fieldSchema['x-uid'],
};
schema['x-component-props'] = field.componentProps || {};
fieldSchema['x-component-props'] = {
...(field.componentProps || {}),
...data,
};
schema['x-component-props'] = fieldSchema['x-component-props'];
field.componentProps = fieldSchema['x-component-props'];
//子表格/表格区块
const parts = (field.path.entire as string).split('.');
parts.pop();
const modifiedString = parts.join('.');
field.query(`${modifiedString}.*[0:].${fieldSchema.name}`).forEach((f) => {
if (f.props.name === fieldSchema.name) {
f.setComponentProps({ ...data });
}
});
dn.emit('patch', {
schema,
});
dn.refresh();
}}
/>
);
};

View File

@ -39,36 +39,10 @@ const getSchema = (schema: IField, record: any, compile) => {
if (!schema) {
return;
}
const properties = cloneDeep(schema.properties) as any;
const properties = schema.getConfigureFormProperties();
if (properties?.foreignKey) {
properties.foreignKey['x-component'] = ForeignKey;
}
if (schema.hasDefaultValue === true) {
properties['defaultValue'] = cloneDeep(schema?.default?.uiSchema);
properties.defaultValue.required = false;
properties['defaultValue']['title'] = compile('{{ t("Default value") }}');
properties['defaultValue']['x-decorator'] = 'FormItem';
properties['defaultValue']['x-reactions'] = {
dependencies: [
'uiSchema.x-component-props.gmt',
'uiSchema.x-component-props.showTime',
'uiSchema.x-component-props.dateFormat',
'uiSchema.x-component-props.timeFormat',
],
fulfill: {
state: {
componentProps: {
gmt: '{{$deps[0]}}',
showTime: '{{$deps[1]}}',
dateFormat: '{{$deps[2]}}',
timeFormat: '{{$deps[3]}}',
},
},
},
};
}
const initialValue: any = {
name: `f_${uid()}`,
...cloneDeep(schema.default),

View File

@ -49,36 +49,11 @@ const getSchema = ({
if (!schema) {
return;
}
const properties = cloneDeep(schema.properties) as any;
const properties = schema.getConfigureFormProperties();
if (properties?.name) {
properties.name['x-disabled'] = true;
}
if (schema.hasDefaultValue === true) {
properties['defaultValue'] = cloneDeep(schema.default.uiSchema) || {};
properties.defaultValue.required = false;
properties['defaultValue']['title'] = compile('{{ t("Default value") }}');
properties['defaultValue']['x-decorator'] = 'FormItem';
properties['defaultValue']['x-reactions'] = {
dependencies: [
'uiSchema.x-component-props.gmt',
'uiSchema.x-component-props.showTime',
'uiSchema.x-component-props.dateFormat',
'uiSchema.x-component-props.timeFormat',
],
fulfill: {
state: {
componentProps: {
gmt: '{{$deps[0]}}',
showTime: '{{$deps[1]}}',
dateFormat: '{{$deps[2]}}',
timeFormat: '{{$deps[3]}}',
},
},
},
};
properties['defaultValue']['x-disabled'] = true;
}
return {
type: 'object',
properties: {