fix(record-picker): title field

This commit is contained in:
chenos 2023-04-01 21:37:12 +08:00
parent 2f8e7a8087
commit bcc417a79f
4 changed files with 17 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import { ISchema, useField, useFieldSchema } from '@formily/react';
import _ from 'lodash';
import React from 'react';
import { useTranslation } from 'react-i18next';
import {
@ -9,7 +10,6 @@ import {
} from '../../../collection-manager';
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
import { useCompile, useDesignable } from '../../hooks';
import _ from 'lodash';
export const AssociationFilterItemDesigner = (props) => {
const fieldSchema = useFieldSchema();
@ -30,9 +30,10 @@ export const AssociationFilterItemDesigner = (props) => {
const targetFields = collectionField?.target ? getCollectionFields(collectionField?.target) : [];
const options = targetFields
.filter(
(field) => field?.interface && ['id', 'input', 'phone', 'email', 'integer', 'number'].includes(field?.interface),
)
// .filter(
// (field) => field?.interface && ['id', 'input', 'phone', 'email', 'integer', 'number'].includes(field?.interface),
// )
.filter((field) => !field?.target && field.type !== 'boolean')
.map((field) => ({
value: field?.name,
label: compile(field?.uiSchema?.title) || field?.name,

View File

@ -6,6 +6,7 @@ import cls from 'classnames';
import React, { ChangeEvent, MouseEvent, useMemo, useState } from 'react';
import { SortableItem } from '../../common';
import { useCompile, useDesigner, useProps } from '../../hooks';
import { getLabelFormatValue, useLabelUiSchema } from '../record-picker';
import { AssociationFilter } from './AssociationFilter';
const { Panel } = Collapse;
@ -78,6 +79,7 @@ export const AssociationFilterItem = (props) => {
};
const title = fieldSchema.title ?? collectionField.uiSchema?.title;
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.title || 'label');
return (
<SortableItem
@ -221,7 +223,9 @@ export const AssociationFilterItem = (props) => {
treeData={list}
onSelect={onSelect}
fieldNames={fieldNames}
titleRender={(node) => compile(node[labelKey])}
titleRender={(node) => {
return getLabelFormatValue(labelUiSchema, compile(node[labelKey]));
}}
selectedKeys={selectedKeys}
blockNode
/>

View File

@ -1,4 +1,3 @@
import { css } from '@emotion/css';
import { observer, RecursionField, useFieldSchema } from '@formily/react';
import { toArr } from '@formily/shared';
import { Typography } from 'antd';
@ -46,7 +45,7 @@ export const ReadPrettyRecordPicker: React.FC = observer((props: any) => {
const renderRecords = () =>
toArr(props.value).map((record, index, arr) => {
const val = toValue(compile(record?.[fieldNames?.label || 'label']), 'N/A');
const text = getLabelFormatValue(labelUiSchema, val);
const text = getLabelFormatValue(labelUiSchema, val, true);
return (
<Fragment key={`${record.id}_${index}`}>
<span>

View File

@ -1,7 +1,9 @@
import { ISchema } from '@formily/react';
import { isArr } from '@formily/shared';
import { getDefaultFormat, str2moment } from '@nocobase/utils/client';
import { Tag } from 'antd';
import moment from 'moment';
import React from 'react';
import { CollectionFieldOptions, useCollectionManager } from '../../../collection-manager';
export const useLabelUiSchema = (collectionField: CollectionFieldOptions, label: string): ISchema => {
@ -20,9 +22,12 @@ export const getDatePickerLabels = (props): string => {
return isArr(labels) ? labels.join('~') : labels;
};
export const getLabelFormatValue = (labelUiSchema: ISchema, value: any): string => {
export const getLabelFormatValue = (labelUiSchema: ISchema, value: any, isTag = false): any => {
if (Array.isArray(labelUiSchema?.enum) && value) {
const opt: any = labelUiSchema.enum.find((option: any) => option.value === value);
if (isTag) {
return React.createElement(Tag, { color: opt?.color, children: opt?.label });
}
return opt?.label;
}
switch (labelUiSchema?.['x-component']) {