Skip to content

Commit

Permalink
👌 Integrated feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Feb 23, 2021
1 parent 2579d0e commit a5c8bdf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const mapColumn: ExpressionFunctionDefinition<
aliases: ['exp', 'fn', 'function'],
help: i18n.translate('expressions.functions.mapColumn.args.expressionHelpText', {
defaultMessage:
'A {CANVAS} expression that is passed to each row as a single row {DATATABLE}.',
'An expression that is executed on every row, provided with a single-row {DATATABLE} context and returning the cell value.',
values: {
CANVAS: 'canvas',
DATATABLE: '`datatable`',
Expand All @@ -73,7 +73,7 @@ export const mapColumn: ExpressionFunctionDefinition<
types: ['string', 'null'],
help: i18n.translate('expressions.functions.mapColumn.args.copyMetaFromHelpText', {
defaultMessage:
"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",
"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.",
}),
required: false,
default: null,
Expand Down Expand Up @@ -104,7 +104,7 @@ export const mapColumn: ExpressionFunctionDefinition<
meta: { type },
};
if (args.copyMetaFrom) {
const metaSourceFrom = columns.find(({ name }) => name === args.copyMetaFrom);
const metaSourceFrom = columns.find(({ id }) => id === args.copyMetaFrom);
newColumn.meta = { ...newColumn.meta, ...(metaSourceFrom?.meta || {}) };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,30 @@ describe('mapColumn', () => {
});

it('should copy over the meta information from the specified column', () => {
return runFn(testTable, { name: 'name', copyMetaFrom: 'time', expression: pricePlusTwo }).then(
(result) => {
const nameColumnIndex = result.columns.findIndex(({ name }) => name === 'name');
expect(result.type).toBe('datatable');
expect(result.columns[nameColumnIndex]).toEqual({
id: 'name',
name: 'name',
meta: { type: 'date' },
});
}
);
return runFn(
{
...testTable,
columns: [
...testTable.columns,
// add a new entry
{
id: 'myId',
name: 'myName',
meta: { type: 'date' },
},
],
rows: testTable.rows.map((row) => ({ ...row, myId: Date.now() })),
},
{ name: 'name', copyMetaFrom: 'myId', expression: pricePlusTwo }
).then((result) => {
const nameColumnIndex = result.columns.findIndex(({ name }) => name === 'name');
expect(result.type).toBe('datatable');
expect(result.columns[nameColumnIndex]).toEqual({
id: 'name',
name: 'name',
meta: { type: 'date' },
});
});
});

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

0 comments on commit a5c8bdf

Please sign in to comment.