forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
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] Enable sort and cell actions for table (o…
…pensearch-project#4787) * [Data Explorer][Discover 2.0] Enable sort and cell actions for table Signed-off-by: ananzh <[email protected]> * update test snapshot Signed-off-by: ananzh <[email protected]> --------- Signed-off-by: ananzh <[email protected]> (cherry picked from commit 8766395)
- Loading branch information
Showing
8 changed files
with
221 additions
and
122 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
76 changes: 76 additions & 0 deletions
76
...plugins/discover/public/application/components/data_grid/data_grid_table_cell_actions.tsx
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,76 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiDataGridColumnCellActionProps } from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
import { IndexPatternField } from '../../../../../data/common'; | ||
import { useDataGridContext } from './data_grid_table_context'; | ||
|
||
export function getCellActions(field: IndexPatternField) { | ||
const cellActions = field.filterable | ||
? [ | ||
({ rowIndex, columnId, Component }: EuiDataGridColumnCellActionProps) => { | ||
const { indexPattern, rows, onFilter } = useDataGridContext(); | ||
|
||
const filterForValueText = i18n.translate('discover.filterForValue', { | ||
defaultMessage: 'Filter for value', | ||
}); | ||
const filterForValueLabel = i18n.translate('discover.filterForValueLabel', { | ||
defaultMessage: 'Filter for value: {value}', | ||
values: { value: columnId }, | ||
}); | ||
|
||
return ( | ||
<Component | ||
onClick={() => { | ||
const row = rows[rowIndex]; | ||
const flattened = indexPattern.flattenHit(row); | ||
|
||
if (flattened) { | ||
onFilter(columnId, flattened[columnId], '+'); | ||
} | ||
}} | ||
iconType="plusInCircle" | ||
aria-label={filterForValueLabel} | ||
data-test-subj="filterForValue" | ||
> | ||
{filterForValueText} | ||
</Component> | ||
); | ||
}, | ||
({ rowIndex, columnId, Component }: EuiDataGridColumnCellActionProps) => { | ||
const { indexPattern, rows, onFilter } = useDataGridContext(); | ||
|
||
const filterOutValueText = i18n.translate('discover.filterOutValue', { | ||
defaultMessage: 'Filter out value', | ||
}); | ||
const filterOutValueLabel = i18n.translate('discover.filterOutValueLabel', { | ||
defaultMessage: 'Filter out value: {value}', | ||
values: { value: columnId }, | ||
}); | ||
|
||
return ( | ||
<Component | ||
onClick={() => { | ||
const row = rows[rowIndex]; | ||
const flattened = indexPattern.flattenHit(row); | ||
|
||
if (flattened) { | ||
onFilter(columnId, flattened[columnId], '-'); | ||
} | ||
}} | ||
iconType="minusInCircle" | ||
aria-label={filterOutValueLabel} | ||
data-test-subj="filterOutValue" | ||
> | ||
{filterOutValueText} | ||
</Component> | ||
); | ||
}, | ||
] | ||
: undefined; | ||
return cellActions; | ||
} |
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
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
Oops, something went wrong.