-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into alerting/lazy-load-dataviews-searchsource
- Loading branch information
Showing
128 changed files
with
2,608 additions
and
1,044 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
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
128 changes: 1 addition & 127 deletions
128
..._viewer/public/components/doc_viewer_table/__snapshots__/table_cell_actions.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
src/plugins/unified_doc_viewer/public/components/doc_viewer_table/get_pin_control.test.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,63 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { DataViewField } from '@kbn/data-views-plugin/common'; | ||
import { TableRow } from './table_cell_actions'; | ||
import { getPinColumnControl } from './get_pin_control'; | ||
import { EuiDataGridCellValueElementProps } from '@elastic/eui/src/components/datagrid/data_grid_types'; | ||
|
||
describe('getPinControl', () => { | ||
const rows: TableRow[] = [ | ||
{ | ||
action: { | ||
onFilter: jest.fn(), | ||
flattenedField: 'flattenedField', | ||
onToggleColumn: jest.fn(), | ||
}, | ||
field: { | ||
pinned: true, | ||
onTogglePinned: jest.fn(), | ||
field: 'message', | ||
fieldMapping: new DataViewField({ | ||
type: 'keyword', | ||
name: 'message', | ||
searchable: true, | ||
aggregatable: true, | ||
}), | ||
fieldType: 'keyword', | ||
displayName: 'message', | ||
scripted: false, | ||
}, | ||
value: { | ||
ignored: undefined, | ||
formattedValue: 'test', | ||
}, | ||
}, | ||
]; | ||
|
||
it('should render correctly', () => { | ||
const control = getPinColumnControl({ rows }); | ||
const Cell = control.rowCellRender as React.FC<EuiDataGridCellValueElementProps>; | ||
render( | ||
<Cell | ||
rowIndex={0} | ||
columnId="test" | ||
setCellProps={jest.fn()} | ||
colIndex={0} | ||
isDetails={false} | ||
isExpanded={false} | ||
isExpandable={false} | ||
/> | ||
); | ||
|
||
screen.getByTestId('unifiedDocViewer_pinControlButton_message').click(); | ||
|
||
expect(rows[0].field.onTogglePinned).toHaveBeenCalledWith('message'); | ||
}); | ||
}); |
86 changes: 86 additions & 0 deletions
86
src/plugins/unified_doc_viewer/public/components/doc_viewer_table/get_pin_control.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,86 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { | ||
EuiButtonIcon, | ||
EuiDataGridControlColumn, | ||
EuiScreenReaderOnly, | ||
EuiToolTip, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { css } from '@emotion/react'; | ||
import type { TableRow } from './table_cell_actions'; | ||
|
||
interface PinControlCellProps { | ||
row: TableRow; | ||
} | ||
|
||
const PinControlCell: React.FC<PinControlCellProps> = React.memo(({ row }) => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
||
const fieldName = row.field.field; | ||
const isPinned = row.field.pinned; | ||
const label = isPinned | ||
? i18n.translate('unifiedDocViewer.docViews.table.unpinFieldLabel', { | ||
defaultMessage: 'Unpin field', | ||
}) | ||
: i18n.translate('unifiedDocViewer.docViews.table.pinFieldLabel', { | ||
defaultMessage: 'Pin field', | ||
}); | ||
|
||
return ( | ||
<div | ||
data-test-subj={`unifiedDocViewer_pinControl_${fieldName}`} | ||
className={!isPinned ? 'kbnDocViewer__fieldsGrid__pinAction' : undefined} | ||
css={css` | ||
margin-left: ${isPinned ? '-1px' : 0}; // to align filled/unfilled pin icons better | ||
width: ${euiTheme.size.l}; | ||
height: ${euiTheme.size.l}; | ||
overflow: hidden; | ||
`} | ||
> | ||
<EuiToolTip content={label} delay="long"> | ||
<EuiButtonIcon | ||
data-test-subj={`unifiedDocViewer_pinControlButton_${fieldName}`} | ||
iconSize="m" | ||
iconType={isPinned ? 'pinFilled' : 'pin'} | ||
color="text" | ||
aria-label={label} | ||
onClick={() => { | ||
row.field.onTogglePinned(fieldName); | ||
}} | ||
/> | ||
</EuiToolTip> | ||
</div> | ||
); | ||
}); | ||
|
||
export const getPinColumnControl = ({ rows }: { rows: TableRow[] }): EuiDataGridControlColumn => { | ||
return { | ||
id: 'pin_field', | ||
width: 32, | ||
headerCellRender: () => ( | ||
<EuiScreenReaderOnly> | ||
<span> | ||
{i18n.translate('unifiedDocViewer.fieldsTable.pinControlColumnHeader', { | ||
defaultMessage: 'Pin field column', | ||
})} | ||
</span> | ||
</EuiScreenReaderOnly> | ||
), | ||
rowCellRender: ({ rowIndex }) => { | ||
const row = rows[rowIndex]; | ||
if (!row) { | ||
return null; | ||
} | ||
return <PinControlCell key={`control-${row.field.field}`} row={row} />; | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.