mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-06 14:09:25 +08:00
Merge branch 'main' into next
This commit is contained in:
commit
c6e00e0404
@ -10,7 +10,8 @@
|
||||
import { processData } from '../utils';
|
||||
|
||||
describe('utils', () => {
|
||||
it('processFields', () => {
|
||||
describe('process data', () => {
|
||||
it('should process select field', () => {
|
||||
expect(
|
||||
processData(
|
||||
[
|
||||
@ -41,4 +42,40 @@ describe('utils', () => {
|
||||
),
|
||||
).toEqual([{ tag: 'Yes' }]);
|
||||
});
|
||||
it('should not process when aggregating', () => {
|
||||
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',
|
||||
query: {
|
||||
field: 'tag',
|
||||
aggregation: 'count',
|
||||
},
|
||||
},
|
||||
],
|
||||
[{ tag: 1 }],
|
||||
{},
|
||||
),
|
||||
).toEqual([{ tag: 1 }]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -94,6 +94,7 @@ export const getSelectedFields = (fields: FieldOption[], query: QueryProps) => {
|
||||
key: selectedField.alias || fieldProps?.key,
|
||||
label: selectedField.alias || fieldProps?.label,
|
||||
value: selectedField.alias || fieldProps?.value,
|
||||
query: selectedField,
|
||||
};
|
||||
});
|
||||
};
|
||||
@ -105,7 +106,7 @@ export const getSelectedFields = (fields: FieldOption[], query: QueryProps) => {
|
||||
return selectedFields;
|
||||
};
|
||||
|
||||
export const processData = (selectedFields: FieldOption[], data: any[], scope: any) => {
|
||||
export const processData = (selectedFields: (FieldOption & { query?: any })[], data: any[], scope: any) => {
|
||||
const parseEnum = (field: FieldOption, value: any) => {
|
||||
const options = field.uiSchema?.enum as { value: string; label: string }[];
|
||||
if (!options || !Array.isArray(options)) {
|
||||
@ -120,7 +121,7 @@ export const processData = (selectedFields: FieldOption[], data: any[], scope: a
|
||||
return data.map((record) => {
|
||||
const processed = {};
|
||||
Object.entries(record).forEach(([key, value]) => {
|
||||
const field = selectedFields.find((field) => field.value === key);
|
||||
const field = selectedFields.find((field) => field.value === key && !field?.query?.aggregation);
|
||||
if (!field) {
|
||||
processed[key] = value;
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user