From 272b64b81b714f24c91dface29478bde6aceddff Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 18 Dec 2020 15:36:38 +0800 Subject: [PATCH] feat: add relation field component for table and detail --- packages/app/src/components/views/Field/index.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/app/src/components/views/Field/index.tsx b/packages/app/src/components/views/Field/index.tsx index f5fa620c9..96b719a69 100644 --- a/packages/app/src/components/views/Field/index.tsx +++ b/packages/app/src/components/views/Field/index.tsx @@ -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(); @@ -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 => ( + {get(item, labelField)} + )); +} + 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) {