Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-09-06 01:36:43 +00:00
commit c6e00e0404
2 changed files with 69 additions and 31 deletions

View File

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

View File

@ -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;