-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Data Explorer][Discover 2.0] Implement column actions (#4756)
* [Data Explorer][Discover 2.0] Emplement column actions Signed-off-by: ananzh <[email protected]> * Update discover_slice.tsx Signed-off-by: Ashwin P Chandran <[email protected]> --------- Signed-off-by: ananzh <[email protected]> Signed-off-by: Ashwin P Chandran <[email protected]> Co-authored-by: Ashwin P Chandran <[email protected]> Co-authored-by: Ashwin P Chandran <[email protected]>
- Loading branch information
1 parent
5c26614
commit 9a46a7c
Showing
6 changed files
with
156 additions
and
36 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
33 changes: 33 additions & 0 deletions
33
src/plugins/discover/public/application/utils/state_management/common.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,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { addColumn, removeColumn, reorderColumn, setColumns } from './common'; | ||
|
||
describe('commonUtils', () => { | ||
it('should handle addColumn', () => { | ||
expect(addColumn(['column1'], { column: 'column2' })).toEqual(['column1', 'column2']); | ||
expect(addColumn(['column1'], { column: 'column2', index: 0 })).toEqual(['column2', 'column1']); | ||
}); | ||
|
||
it('should handle removeColumn', () => { | ||
expect(removeColumn(['column1', 'column2'], 'column1')).toEqual(['column2']); | ||
}); | ||
|
||
it('should handle reorderColumn', () => { | ||
expect(reorderColumn(['column1', 'column2', 'column3'], 0, 2)).toEqual([ | ||
'column2', | ||
'column3', | ||
'column1', | ||
]); | ||
}); | ||
|
||
it('should handle setColumns', () => { | ||
expect(setColumns('timeField', ['timeField', 'column1', 'column2'])).toEqual([ | ||
'column1', | ||
'column2', | ||
]); | ||
expect(setColumns(undefined, ['column1', 'column2'])).toEqual(['column1', 'column2']); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/plugins/discover/public/application/utils/state_management/common.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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const addColumn = (columns: string[], action: { column: string; index?: number }) => { | ||
const { column, index } = action; | ||
const newColumns = [...(columns || [])]; | ||
if (index !== undefined) newColumns.splice(index, 0, column); | ||
else newColumns.push(column); | ||
return newColumns; | ||
}; | ||
|
||
export const removeColumn = (columns: string[], actionColumn: string) => { | ||
return (columns || []).filter((column) => column !== actionColumn); | ||
}; | ||
|
||
export const reorderColumn = (columns: string[], source: number, destination: number) => { | ||
const newColumns = [...(columns || [])]; | ||
const [removed] = newColumns.splice(source, 1); | ||
newColumns.splice(destination, 0, removed); | ||
return newColumns; | ||
}; | ||
|
||
export const setColumns = (timeField: string | undefined, columns: string[]) => { | ||
const newColumns = timeField && timeField === columns[0] ? columns.slice(1) : columns; | ||
return newColumns; | ||
}; |
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