feat: add relation field component for table and detail

This commit is contained in:
chenos 2020-12-18 15:36:38 +08:00
parent d755558009
commit 272b64b81b

View File

@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react';
import moment from 'moment';
import { Tag } from 'antd';
import Icon from '@/components/icons';
import get from 'lodash/get';
const InterfaceTypes = new Map<string, any>();
@ -111,6 +112,18 @@ export function DataSourceField(props: any) {
)
}
export function RealtionField(props: any) {
const { schema: { labelField }, value } = props;
if (!value) {
return;
}
console.log(labelField, value);
const items = Array.isArray(value) ? value : [value];
return items.map(item => (
<span>{get(item, labelField)}</span>
));
}
registerFieldComponents({
string: StringField,
textarea: TextareaField,
@ -125,6 +138,8 @@ registerFieldComponents({
createdAt: DateTimeField,
updatedAt: DateTimeField,
icon: IconField,
createdBy: RealtionField,
updatedBy: RealtionField,
});
export default function Field(props: any) {