mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:18:03 +00:00
refactor(client): allow select to show null option as tag in read pretty mode if configured (#4950)
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (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
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (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
* refactor(client): allow select to show null option if conifgured * test(client): add default value in demo * fix(client): remove useless logic
This commit is contained in:
parent
96e538ab54
commit
5b1bd1e5fa
@ -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>
|
||||
|
@ -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();
|
@ -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 [];
|
||||
|
Loading…
Reference in New Issue
Block a user