-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Lens] Rename columns #38278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
flash1293
merged 39 commits into
elastic:feature/lens
from
flash1293:lens/rename-columns
Jun 12, 2019
Merged
[Lens] Rename columns #38278
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f46855e
[lens] Dimension panel lets users select operations and fields indivi…
wylieconlon 7ae8d66
Basic xy chart suggestions
chrisdavies 6e4d523
Re-apply XY config panel after force merge
chrisdavies a57f406
Merge upstream
chrisdavies dcde41d
Merge remote-tracking branch 'origin/feature/lens' into lens/aggregat…
wylieconlon 0a9facd
Tweaks per Wylie's feedback
chrisdavies 291883c
Merge branch 'feature/lens' of github.com:elastic/kibana into lens/xy…
chrisdavies be86ff3
Add xy chart internationalization
chrisdavies 4a3ea3f
Merge remote-tracking branch 'origin/master' into lens/aggregations
wylieconlon 30f69e3
Split files and add tests
wylieconlon 82e2865
Merge remote-tracking branch 'origin/feature/lens' into lens/aggregat…
wylieconlon 18efd00
Update xy chart i18n implementation
chrisdavies fe4238a
Fix dimension labeling and add clear button
wylieconlon 1fe793b
Fix i18n id
chrisdavies 7a04220
Merge upstream
chrisdavies 91691fb
pass datasource api into visualization init
flash1293 dbd98fc
fix type errors
flash1293 4d09416
Support more aggregations, aggregation nesting, rollups, and clearing
wylieconlon 6f81ded
Merge remote-tracking branch 'origin/feature/lens' into lens/aggregat…
wylieconlon 3bf54d4
Fix esaggs expression
wylieconlon 60408c5
Merge branch 'feature/lens' into lens/datasource-in-vis
flash1293 1a0ac97
fix test
flash1293 4bbb927
Merge branch 'lens/datasource-in-vis' into lens/aggregations
flash1293 cf82581
add function to remap columns to their real names
flash1293 07188d1
add tests for rename_columns function
flash1293 9983e86
Merge branch 'feature/lens' into lens/datasource-in-vis
flash1293 81df38a
Merge branch 'feature/lens' into lens/rename-columns
flash1293 241187b
Merge remote-tracking branch 'origin/feature/lens' into lens/aggregat…
wylieconlon 8c50598
Increase top-level test coverage of dimension panel
wylieconlon 64a8951
switch initialize parameters
flash1293 08a7a80
Merge branch 'feature/lens' into lens/datasource-in-vis
flash1293 d4f4ea5
fix test
flash1293 a33283c
Merge branch 'lens/datasource-in-vis' into lens/rename-columns
flash1293 e02f87c
Fix tests
flash1293 680ddeb
Merge branch 'lens/aggregations' into lens/rename-columns
flash1293 934e4cc
Merge branch 'feature/lens' into lens/rename-columns
flash1293 dbef025
Merge branch 'feature/lens' into lens/rename-columns
flash1293 5f1b4c3
Merge branch 'feature/lens' into lens/rename-columns
flash1293 70dda55
improve code style and add i18n for expression function
flash1293 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
103 changes: 103 additions & 0 deletions
103
x-pack/plugins/lens/public/indexpattern_plugin/rename_columns.test.ts
This file contains hidden or 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,103 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { renameColumns } from './rename_columns'; | ||
| import { KibanaDatatable } from 'src/legacy/core_plugins/interpreter/types'; | ||
|
|
||
| describe('rename_columns', () => { | ||
| it('should rename columns of a given datatable', () => { | ||
| const input: KibanaDatatable = { | ||
| type: 'kibana_datatable', | ||
| columns: [{ id: 'a', name: 'A' }, { id: 'b', name: 'B' }], | ||
| rows: [{ a: 1, b: 2 }, { a: 3, b: 4 }, { a: 5, b: 6 }, { a: 7, b: 8 }], | ||
| }; | ||
|
|
||
| const idMap = { | ||
| a: 'b', | ||
| b: 'c', | ||
| }; | ||
|
|
||
| expect(renameColumns.fn(input, { idMap: JSON.stringify(idMap) }, {})).toMatchInlineSnapshot(` | ||
| Object { | ||
| "columns": Array [ | ||
| Object { | ||
| "id": "b", | ||
| "name": "A", | ||
| }, | ||
| Object { | ||
| "id": "c", | ||
| "name": "B", | ||
| }, | ||
| ], | ||
| "rows": Array [ | ||
| Object { | ||
| "b": 1, | ||
| "c": 2, | ||
| }, | ||
| Object { | ||
| "b": 3, | ||
| "c": 4, | ||
| }, | ||
| Object { | ||
| "b": 5, | ||
| "c": 6, | ||
| }, | ||
| Object { | ||
| "b": 7, | ||
| "c": 8, | ||
| }, | ||
| ], | ||
| "type": "kibana_datatable", | ||
| } | ||
| `); | ||
| }); | ||
|
|
||
| it('should keep columns which are not mapped', () => { | ||
| const input: KibanaDatatable = { | ||
| type: 'kibana_datatable', | ||
| columns: [{ id: 'a', name: 'A' }, { id: 'b', name: 'B' }], | ||
| rows: [{ a: 1, b: 2 }, { a: 3, b: 4 }, { a: 5, b: 6 }, { a: 7, b: 8 }], | ||
| }; | ||
|
|
||
| const idMap = { | ||
| b: 'c', | ||
| }; | ||
|
|
||
| expect(renameColumns.fn(input, { idMap: JSON.stringify(idMap) }, {})).toMatchInlineSnapshot(` | ||
| Object { | ||
| "columns": Array [ | ||
| Object { | ||
| "id": "a", | ||
| "name": "A", | ||
| }, | ||
| Object { | ||
| "id": "c", | ||
| "name": "B", | ||
| }, | ||
| ], | ||
| "rows": Array [ | ||
| Object { | ||
| "a": 1, | ||
| "c": 2, | ||
| }, | ||
| Object { | ||
| "a": 3, | ||
| "c": 4, | ||
| }, | ||
| Object { | ||
| "a": 5, | ||
| "c": 6, | ||
| }, | ||
| Object { | ||
| "a": 7, | ||
| "c": 8, | ||
| }, | ||
| ], | ||
| "type": "kibana_datatable", | ||
| } | ||
| `); | ||
| }); | ||
| }); |
64 changes: 64 additions & 0 deletions
64
x-pack/plugins/lens/public/indexpattern_plugin/rename_columns.ts
This file contains hidden or 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,64 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { i18n } from '@kbn/i18n'; | ||
| import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/types'; | ||
| import { KibanaDatatable } from '../types'; | ||
|
|
||
| interface RemapArgs { | ||
| idMap: string; | ||
| } | ||
|
|
||
| export const renameColumns: ExpressionFunction< | ||
| 'lens_rename_columns', | ||
| KibanaDatatable, | ||
| RemapArgs, | ||
| KibanaDatatable | ||
| > = { | ||
| name: 'lens_rename_columns', | ||
| type: 'kibana_datatable', | ||
| help: i18n.translate('lens.functions.renameColumns.help', { | ||
| defaultMessage: 'A helper to rename the columns of a datatable', | ||
| }), | ||
| args: { | ||
| idMap: { | ||
| types: ['string'], | ||
| help: i18n.translate('lens.functions.renameColumns.idMap.help', { | ||
| defaultMessage: | ||
| 'A JSON encoded object in which keys are the old column ids and values are the corresponding new ones. All other columns ids are kept.', | ||
| }), | ||
| }, | ||
| }, | ||
| context: { | ||
| types: ['kibana_datatable'], | ||
| }, | ||
| fn(data: KibanaDatatable, { idMap: encodedIdMap }: RemapArgs) { | ||
| const idMap = JSON.parse(encodedIdMap) as Record<string, string>; | ||
| return { | ||
| type: 'kibana_datatable', | ||
| rows: data.rows.map(row => { | ||
| const mappedRow: Record<string, unknown> = {}; | ||
| Object.entries(idMap).forEach(([fromId, toId]) => { | ||
| mappedRow[toId] = row[fromId]; | ||
| }); | ||
|
|
||
| Object.entries(row).forEach(([id, value]) => { | ||
| if (id in idMap) { | ||
| mappedRow[idMap[id]] = value; | ||
| } else { | ||
| mappedRow[id] = value; | ||
| } | ||
| }); | ||
|
|
||
| return mappedRow; | ||
| }), | ||
| columns: data.columns.map(column => ({ | ||
| ...column, | ||
| id: idMap[column.id] ? idMap[column.id] : column.id, | ||
| })), | ||
| }; | ||
| }, | ||
| }; | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.