From 94aa8df382ddc670f15134269cffc7a736e0100a Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Fri, 23 Aug 2024 15:47:11 +0800 Subject: [PATCH] fix(data-vi): allow to map integer enum value (#5115) --- .../src/client/__tests__/utils.test.ts | 44 +++++++++++++++++++ .../src/client/utils.ts | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/plugins/@nocobase/plugin-data-visualization/src/client/__tests__/utils.test.ts diff --git a/packages/plugins/@nocobase/plugin-data-visualization/src/client/__tests__/utils.test.ts b/packages/plugins/@nocobase/plugin-data-visualization/src/client/__tests__/utils.test.ts new file mode 100644 index 0000000000..b862bedd63 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-data-visualization/src/client/__tests__/utils.test.ts @@ -0,0 +1,44 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { processData } from '../utils'; + +describe('utils', () => { + it('processFields', () => { + expect( + processData( + [ + { + name: 'tag', + type: 'bigInt', + interface: 'select', + uiSchema: { + type: 'string', + enum: [ + { + value: '1', + label: 'Yes', + }, + { + value: '2', + label: 'No', + }, + ], + }, + label: 'Tag', + value: 'tag', + key: 'tag', + }, + ], + [{ tag: 1 }], + {}, + ), + ).toEqual([{ tag: 'Yes' }]); + }); +}); diff --git a/packages/plugins/@nocobase/plugin-data-visualization/src/client/utils.ts b/packages/plugins/@nocobase/plugin-data-visualization/src/client/utils.ts index e1a098c983..a823640fa5 100644 --- a/packages/plugins/@nocobase/plugin-data-visualization/src/client/utils.ts +++ b/packages/plugins/@nocobase/plugin-data-visualization/src/client/utils.ts @@ -93,7 +93,7 @@ export const processData = (selectedFields: FieldOption[], data: any[], scope: a if (Array.isArray(value)) { return value.map((v) => parseEnum(field, v)); } - const option = options.find((option) => option.value === value); + const option = options.find((option) => option.value === (value?.toString?.() || value)); return Schema.compile(option?.label || value, scope); }; return data.map((record) => {