Merge branch 'main' into next
Some checks are pending
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run

This commit is contained in:
GitHub Actions Bot 2024-07-26 16:12:28 +00:00
commit bd5af6b68f
3 changed files with 55 additions and 8 deletions

View File

@ -31,16 +31,16 @@ export const ReadPretty = observer(
(props: SelectReadPrettyProps) => {
const fieldNames = { ...defaultFieldNames, ...props.fieldNames };
const field = useField<any>();
const collectionField = useCollectionField();
const dataSource = field.dataSource || props.options || collectionField?.uiSchema.enum || [];
const currentOptions = getCurrentOptions(field.value, dataSource, fieldNames);
if (!isValid(props.value)) {
if (!isValid(props.value) && !currentOptions.length) {
return <div />;
}
if (isArrayField(field) && field?.value?.length === 0) {
return <div />;
}
const collectionField = useCollectionField();
const dataSource = field.dataSource || props.options || collectionField?.uiSchema.enum || [];
const currentOptions = getCurrentOptions(field.value, dataSource, fieldNames);
return (
<div>

View File

@ -0,0 +1,49 @@
import React from 'react';
import { mockApp } from '@nocobase/client/demo-utils';
import { SchemaComponent, Plugin, ISchema } from '@nocobase/client';
const options = [
{
label: '福建',
value: 'FuJian',
children: [
{ label: '{{t("福州")}}', value: 'FZ' },
{ label: '莆田', value: 'PT' },
],
},
{ label: '江苏', value: 'XZ' },
{ label: '浙江', value: 'ZX' },
{ lable: '未选择', value: null },
];
const schema: ISchema = {
type: 'void',
name: 'root',
'x-decorator': 'FormV2',
'x-component': 'ShowFormData',
properties: {
test: {
type: 'string',
title: 'Test',
enum: options,
'x-decorator': 'FormItem',
'x-component': 'Select',
default: null,
},
},
};
const Demo = () => {
return <SchemaComponent schema={schema} />;
};
class DemoPlugin extends Plugin {
async load() {
this.app.router.add('root', { path: '/', Component: Demo });
}
}
const app = mockApp({
plugins: [DemoPlugin],
});
export default app.getRootComponent();

View File

@ -43,11 +43,9 @@ function flatData(data: any[], fieldNames: FieldNames): any[] {
return newArr;
}
export function getCurrentOptions(values: string | string[], dataSource: any[], fieldNames: FieldNames): Option[] {
export function getCurrentOptions(values: any | any[], dataSource: any[], fieldNames: FieldNames): Option[] {
const result = flatData(dataSource, fieldNames);
const arrValues = castArray(values)
.filter((item) => item != null)
.map((val) => (isPlainObject(val) ? val[fieldNames.value] : val)) as string[];
const arrValues = castArray(values).map((val) => (isPlainObject(val) ? val[fieldNames.value] : val)) as any[];
function findOptions(options: any[]): Option[] {
if (!options) return [];