fix(data-vi): allow to map integer enum value (#5115)

This commit is contained in:
YANG QIA 2024-08-23 15:47:11 +08:00 committed by GitHub
parent 6b03c725cf
commit 94aa8df382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 1 deletions

View File

@ -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' }]);
});
});

View File

@ -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) => {