-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds dimensionName to datatable column meta information (#106514)
- Loading branch information
Showing
13 changed files
with
198 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/plugins/vis_type_pie/public/__snapshots__/pie_fn.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/plugins/visualizations/common/expression_functions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './range'; | ||
export * from './vis_dimension'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/plugins/visualizations/common/prepare_log_table.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { prepareLogTable } from './prepare_log_table'; | ||
|
||
describe('prepareLogTable', () => { | ||
test('returns first matching dimension name', () => { | ||
const datatable = { | ||
columns: [ | ||
{ | ||
meta: {}, | ||
}, | ||
{ | ||
meta: {}, | ||
}, | ||
{ | ||
meta: {}, | ||
}, | ||
], | ||
}; | ||
const logTable = prepareLogTable(datatable as any, [ | ||
[[{ accessor: 0 } as any], 'dimension1'], | ||
[[{ accessor: 2 } as any], 'dimension3'], | ||
[[{ accessor: 1 } as any], 'dimension2'], | ||
]); | ||
expect(logTable).toMatchInlineSnapshot( | ||
{ | ||
columns: [ | ||
{ | ||
meta: { | ||
dimensionName: 'dimension1', | ||
}, | ||
}, | ||
{ | ||
meta: { | ||
dimensionName: 'dimension2', | ||
}, | ||
}, | ||
{ | ||
meta: { | ||
dimensionName: 'dimension3', | ||
}, | ||
}, | ||
], | ||
}, | ||
` | ||
Object { | ||
"columns": Array [ | ||
Object { | ||
"meta": Object { | ||
"dimensionName": "dimension1", | ||
}, | ||
}, | ||
Object { | ||
"meta": Object { | ||
"dimensionName": "dimension2", | ||
}, | ||
}, | ||
Object { | ||
"meta": Object { | ||
"dimensionName": "dimension3", | ||
}, | ||
}, | ||
], | ||
} | ||
` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ExpressionValueVisDimension } from './expression_functions/vis_dimension'; | ||
import { Datatable } from '../../expressions/common/expression_types/specs'; | ||
|
||
export type Dimension = [ExpressionValueVisDimension[] | undefined, string]; | ||
|
||
const getDimensionName = (columnIndex: number, dimensions: Dimension[]) => { | ||
for (const dimension of dimensions) { | ||
if (dimension[0]?.find((d) => d.accessor === columnIndex)) { | ||
return dimension[1]; | ||
} | ||
} | ||
}; | ||
|
||
export const prepareLogTable = (datatable: Datatable, dimensions: Dimension[]) => { | ||
return { | ||
...datatable, | ||
columns: datatable.columns.map((column, columnIndex) => { | ||
return { | ||
...column, | ||
meta: { | ||
...column.meta, | ||
dimensionName: getDimensionName(columnIndex, dimensions), | ||
}, | ||
}; | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters