From 3c18ecc796df706035e1e46fdbb7e86e0c8693e1 Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 28 Mar 2021 11:46:59 +0800 Subject: [PATCH] fix: display of action logs table data --- .../app/src/components/views/Field/index.tsx | 22 +++++++++++++++---- .../src/collections/action_changes.ts | 11 ++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/app/src/components/views/Field/index.tsx b/packages/app/src/components/views/Field/index.tsx index 95344daa1..8607f7cf1 100644 --- a/packages/app/src/components/views/Field/index.tsx +++ b/packages/app/src/components/views/Field/index.tsx @@ -256,7 +256,7 @@ export function LinkToField(props: any) { } export function LinkToFieldLink(props) { - const { data, isArr, itemIndex, ctx, parent, schema, schema: { title, labelField, viewName, name, target, collection_name } } = props; + const { data, isArr, itemIndex, ctx = {}, parent, schema, schema: { title, labelField, viewName, name, target, collection_name } } = props; // const [data, setData] = useState(props.data||{}); return ( @@ -266,7 +266,6 @@ export function LinkToFieldLink(props) { Drawer.open({ title: data[labelField], content: ({resolve, closeWithConfirm}) => { - // console.log({ctx, parent, data, props, schema}); const { index, mutate, dataSource, onChange } = ctx; return (
@@ -275,6 +274,9 @@ export function LinkToFieldLink(props) { closeWithConfirm && closeWithConfirm(true); }} noRequest={!!onChange} onFinish={(values) => { + if (typeof index === 'undefined') { + return; + } let items = [...dataSource]; const parentData = {...parent}; set(parentData, isArr ? [name, itemIndex] : [name], values); @@ -403,12 +405,23 @@ export function LogField(props) { } export function LogFieldValue(props) { - const { value, schema, data } = props; + const { value, data } = props; return ( -
{JSON.stringify(value)}
+ ) } +export function JsonField(props) { + const { value } = props; + if (typeof value === 'object') { + return ( +
+        {JSON.stringify(value, null, 2)}
+      
+ ); + } +} + export function ChinaRegion(props: any) { const { schema, value } = props; if (!value) { @@ -446,6 +459,7 @@ registerFieldComponents({ 'logs.field': LogField, 'logs.fieldValue': LogFieldValue, chinaRegion: ChinaRegion, + json: JsonField, }); export default function Field(props: any) { diff --git a/packages/plugin-action-logs/src/collections/action_changes.ts b/packages/plugin-action-logs/src/collections/action_changes.ts index 090c01690..2a3b34008 100644 --- a/packages/plugin-action-logs/src/collections/action_changes.ts +++ b/packages/plugin-action-logs/src/collections/action_changes.ts @@ -53,4 +53,15 @@ export default { title: '查看' } ], + views_v2: [ + { + type: 'table', + name: 'table', + fields: [ + 'field', + 'before', + 'after', + ], + } + ], } as TableOptions;