Skip to content

Commit a5c8bdf

Browse files
committed
👌 Integrated feedback
1 parent 2579d0e commit a5c8bdf

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/plugins/expressions/common/expression_functions/specs/map_column.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const mapColumn: ExpressionFunctionDefinition<
6161
aliases: ['exp', 'fn', 'function'],
6262
help: i18n.translate('expressions.functions.mapColumn.args.expressionHelpText', {
6363
defaultMessage:
64-
'A {CANVAS} expression that is passed to each row as a single row {DATATABLE}.',
64+
'An expression that is executed on every row, provided with a single-row {DATATABLE} context and returning the cell value.',
6565
values: {
6666
CANVAS: 'canvas',
6767
DATATABLE: '`datatable`',
@@ -73,7 +73,7 @@ export const mapColumn: ExpressionFunctionDefinition<
7373
types: ['string', 'null'],
7474
help: i18n.translate('expressions.functions.mapColumn.args.copyMetaFromHelpText', {
7575
defaultMessage:
76-
"If set, the meta object from the specified column id is copied over to the specified target column. Throws an exception if the column doesn't exist",
76+
"If set, the meta object from the specified column id is copied over to the specified target column. If the column doesn't exist it silently fails.",
7777
}),
7878
required: false,
7979
default: null,
@@ -104,7 +104,7 @@ export const mapColumn: ExpressionFunctionDefinition<
104104
meta: { type },
105105
};
106106
if (args.copyMetaFrom) {
107-
const metaSourceFrom = columns.find(({ name }) => name === args.copyMetaFrom);
107+
const metaSourceFrom = columns.find(({ id }) => id === args.copyMetaFrom);
108108
newColumn.meta = { ...newColumn.meta, ...(metaSourceFrom?.meta || {}) };
109109
}
110110

src/plugins/expressions/common/expression_functions/specs/tests/map_column.test.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,30 @@ describe('mapColumn', () => {
8484
});
8585

8686
it('should copy over the meta information from the specified column', () => {
87-
return runFn(testTable, { name: 'name', copyMetaFrom: 'time', expression: pricePlusTwo }).then(
88-
(result) => {
89-
const nameColumnIndex = result.columns.findIndex(({ name }) => name === 'name');
90-
expect(result.type).toBe('datatable');
91-
expect(result.columns[nameColumnIndex]).toEqual({
92-
id: 'name',
93-
name: 'name',
94-
meta: { type: 'date' },
95-
});
96-
}
97-
);
87+
return runFn(
88+
{
89+
...testTable,
90+
columns: [
91+
...testTable.columns,
92+
// add a new entry
93+
{
94+
id: 'myId',
95+
name: 'myName',
96+
meta: { type: 'date' },
97+
},
98+
],
99+
rows: testTable.rows.map((row) => ({ ...row, myId: Date.now() })),
100+
},
101+
{ name: 'name', copyMetaFrom: 'myId', expression: pricePlusTwo }
102+
).then((result) => {
103+
const nameColumnIndex = result.columns.findIndex(({ name }) => name === 'name');
104+
expect(result.type).toBe('datatable');
105+
expect(result.columns[nameColumnIndex]).toEqual({
106+
id: 'name',
107+
name: 'name',
108+
meta: { type: 'date' },
109+
});
110+
});
98111
});
99112

100113
it('should be resilient if the references column for meta information does not exists', () => {

0 commit comments

Comments
 (0)