Transformations: Ignore value displayName for columns for matrix grouping (#106647)

* Ignore value displayName for columns for matrix grouping

* Fix spelling
This commit is contained in:
Kristina
2025-06-20 16:33:29 -05:00
committed by GitHub
parent f27098a976
commit 0e35c8bdb4
2 changed files with 50 additions and 1 deletions
@@ -226,6 +226,52 @@ describe('Grouping to Matrix', () => {
});
});
it('properly handles the value display name (by ignoring it)', async () => {
const cfg: DataTransformerConfig<GroupingToMatrixTransformerOptions> = {
id: DataTransformerID.groupingToMatrix,
options: {
columnField: 'Column',
rowField: 'Row',
valueField: 'CustomName',
},
};
const seriesA = toDataFrame({
name: 'A',
fields: [
{ name: 'Column', type: FieldType.string, values: ['C1', 'C1', 'C2'] },
{ name: 'Row', type: FieldType.string, values: ['R1', 'R2', 'R1'] },
{ name: 'Temp', type: FieldType.number, values: [1, 4, 5], config: { displayName: 'CustomName' } },
],
});
await expect(transformDataFrame([cfg], [seriesA])).toEmitValuesWith((received) => {
const processed = received[0];
const expected: Field[] = [
{
name: 'Row\\Column',
type: FieldType.string,
values: ['R1', 'R2'],
config: {},
},
{
name: 'C1',
type: FieldType.number,
values: [1, 4],
config: {},
},
{
name: 'C2',
type: FieldType.number,
values: [5, ''],
config: {},
},
];
expect(processed[0].fields).toEqual(expected);
});
});
it('generates Matrix with multiple fields and value type', async () => {
const cfg: DataTransformerConfig<GroupingToMatrixTransformerOptions> = {
id: DataTransformerID.groupingToMatrix,
@@ -60,7 +60,7 @@ export const groupingToMatrixTransformer: DataTransformerInfo<GroupingToMatrixTr
numFields += frame.fields.length;
}
return `Grouping to matrix requiers at least 3 fields to work. Currently there are ${numFields} fields.`;
return `Grouping to matrix requires at least 3 fields to work. Currently there are ${numFields} fields.`;
},
operator: (options: GroupingToMatrixTransformerOptions, ctx: DataTransformContext) => (source) =>
source.pipe(
@@ -126,6 +126,9 @@ export const groupingToMatrixTransformer: DataTransformerInfo<GroupingToMatrixTr
valueField.config = { ...valueField.config, displayNameFromDS: undefined };
}
// the names of these columns need to be the selected column values, and not be overridden with the display name
delete valueField.config.displayName;
fields.push({
name: columnName?.toString() ?? null,
values: values,