-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Discover] One Discover context awareness #183797
Changes from all commits
a0785b9
386a18c
89e2a62
3cd00c5
b9519d4
ac6f2e5
de7c276
00669f7
b19bd7e
5e4318f
70d43dd
d3eee08
d2eee9c
a96bc15
b6984ce
0e5f2e1
ff90e2b
1de8849
807ee46
3829c28
f753702
8d7edd6
2939c99
d66c1d8
f887d88
f0d8bc1
3597c90
a8060f4
ebfcfae
fb050ca
ff97785
659c94a
0217bae
b80e57f
f16a506
c992dfe
b4477ef
5752651
3814f23
411d736
9ff0c83
ce85a6a
113f66f
6607524
0bfbe8a
f5fd842
3f1ba48
2b8f6bf
aa78635
0c1d023
8bab582
f2e6788
643e98d
965b97f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ import { onResizeGridColumn } from '../../../../utils/on_resize_grid_column'; | |
import { useContextualGridCustomisations } from '../../hooks/grid_customisations'; | ||
import { useIsEsqlMode } from '../../hooks/use_is_esql_mode'; | ||
import { useAdditionalFieldGroups } from '../../hooks/sidebar/use_additional_field_groups'; | ||
import { useProfileAccessor } from '../../../../context_awareness'; | ||
|
||
const containerStyles = css` | ||
position: relative; | ||
|
@@ -263,6 +264,12 @@ function DiscoverDocumentsComponent({ | |
useContextualGridCustomisations() || {}; | ||
const additionalFieldGroups = useAdditionalFieldGroups(); | ||
|
||
const getCellRenderersAccessor = useProfileAccessor('getCellRenderers'); | ||
const cellRenderers = useMemo(() => { | ||
const getCellRenderers = getCellRenderersAccessor(() => customCellRenderer ?? {}); | ||
return getCellRenderers(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be misunderstanding, but isn't it necessary to get the cell renderer for each row with the corresponding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unified Data Table cell renders are column based currently, so they don't work on individual records and can't be supported by If we decide we need it, I'd recommend we add support for them and do the necessary Unified Data Table refactoring in a followup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, I didn't know this was an intentional omission. Could this indicate that narrowing the composable profile interface by context type might be good? Because I would also have made that mistake when trying to implement a custom cell renderer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that would make sense and it's actually already supported, I just forgot to omit |
||
}, [customCellRenderer, getCellRenderersAccessor]); | ||
|
||
const documents = useObservable(stateContainer.dataState.data$.documents$); | ||
|
||
const callouts = useMemo( | ||
|
@@ -373,66 +380,64 @@ function DiscoverDocumentsComponent({ | |
</> | ||
)} | ||
{!isLegacy && ( | ||
<> | ||
<div className="unifiedDataTable"> | ||
<CellActionsProvider | ||
getTriggerCompatibleActions={uiActions.getTriggerCompatibleActions} | ||
> | ||
<DiscoverGridMemoized | ||
ariaLabelledBy="documentsAriaLabel" | ||
columns={currentColumns} | ||
columnsMeta={columnsMeta} | ||
expandedDoc={expandedDoc} | ||
dataView={dataView} | ||
loadingState={ | ||
isDataLoading | ||
? DataLoadingState.loading | ||
: isMoreDataLoading | ||
? DataLoadingState.loadingMore | ||
: DataLoadingState.loaded | ||
} | ||
rows={rows} | ||
sort={(sort as SortOrder[]) || []} | ||
searchDescription={savedSearch.description} | ||
searchTitle={savedSearch.title} | ||
setExpandedDoc={setExpandedDoc} | ||
showTimeCol={showTimeCol} | ||
settings={grid} | ||
onFilter={onAddFilter as DocViewFilterFn} | ||
onSetColumns={onSetColumns} | ||
onSort={onSort} | ||
onResize={onResizeDataGrid} | ||
useNewFieldsApi={useNewFieldsApi} | ||
configHeaderRowHeight={3} | ||
headerRowHeightState={headerRowHeight} | ||
onUpdateHeaderRowHeight={onUpdateHeaderRowHeight} | ||
rowHeightState={rowHeight} | ||
onUpdateRowHeight={onUpdateRowHeight} | ||
isSortEnabled={true} | ||
isPlainRecord={isEsqlMode} | ||
rowsPerPageState={rowsPerPage ?? getDefaultRowsPerPage(services.uiSettings)} | ||
onUpdateRowsPerPage={onUpdateRowsPerPage} | ||
maxAllowedSampleSize={getMaxAllowedSampleSize(services.uiSettings)} | ||
sampleSizeState={getAllowedSampleSize(sampleSizeState, services.uiSettings)} | ||
onUpdateSampleSize={!isEsqlMode ? onUpdateSampleSize : undefined} | ||
onFieldEdited={onFieldEdited} | ||
configRowHeight={uiSettings.get(ROW_HEIGHT_OPTION)} | ||
showMultiFields={uiSettings.get(SHOW_MULTIFIELDS)} | ||
maxDocFieldsDisplayed={uiSettings.get(MAX_DOC_FIELDS_DISPLAYED)} | ||
renderDocumentView={renderDocumentView} | ||
renderCustomToolbar={renderCustomToolbarWithElements} | ||
services={services} | ||
totalHits={totalHits} | ||
onFetchMoreRecords={onFetchMoreRecords} | ||
componentsTourSteps={TOUR_STEPS} | ||
externalCustomRenderers={customCellRenderer} | ||
customGridColumnsConfiguration={customGridColumnsConfiguration} | ||
customControlColumnsConfiguration={customControlColumnsConfiguration} | ||
additionalFieldGroups={additionalFieldGroups} | ||
/> | ||
</CellActionsProvider> | ||
</div> | ||
</> | ||
<div className="unifiedDataTable"> | ||
<CellActionsProvider | ||
getTriggerCompatibleActions={uiActions.getTriggerCompatibleActions} | ||
> | ||
<DiscoverGridMemoized | ||
ariaLabelledBy="documentsAriaLabel" | ||
columns={currentColumns} | ||
columnsMeta={columnsMeta} | ||
expandedDoc={expandedDoc} | ||
dataView={dataView} | ||
loadingState={ | ||
isDataLoading | ||
? DataLoadingState.loading | ||
: isMoreDataLoading | ||
? DataLoadingState.loadingMore | ||
: DataLoadingState.loaded | ||
} | ||
rows={rows} | ||
sort={(sort as SortOrder[]) || []} | ||
searchDescription={savedSearch.description} | ||
searchTitle={savedSearch.title} | ||
setExpandedDoc={setExpandedDoc} | ||
showTimeCol={showTimeCol} | ||
settings={grid} | ||
onFilter={onAddFilter as DocViewFilterFn} | ||
onSetColumns={onSetColumns} | ||
onSort={onSort} | ||
onResize={onResizeDataGrid} | ||
useNewFieldsApi={useNewFieldsApi} | ||
configHeaderRowHeight={3} | ||
headerRowHeightState={headerRowHeight} | ||
onUpdateHeaderRowHeight={onUpdateHeaderRowHeight} | ||
rowHeightState={rowHeight} | ||
onUpdateRowHeight={onUpdateRowHeight} | ||
isSortEnabled={true} | ||
isPlainRecord={isEsqlMode} | ||
rowsPerPageState={rowsPerPage ?? getDefaultRowsPerPage(services.uiSettings)} | ||
onUpdateRowsPerPage={onUpdateRowsPerPage} | ||
maxAllowedSampleSize={getMaxAllowedSampleSize(services.uiSettings)} | ||
sampleSizeState={getAllowedSampleSize(sampleSizeState, services.uiSettings)} | ||
onUpdateSampleSize={!isEsqlMode ? onUpdateSampleSize : undefined} | ||
onFieldEdited={onFieldEdited} | ||
configRowHeight={uiSettings.get(ROW_HEIGHT_OPTION)} | ||
showMultiFields={uiSettings.get(SHOW_MULTIFIELDS)} | ||
maxDocFieldsDisplayed={uiSettings.get(MAX_DOC_FIELDS_DISPLAYED)} | ||
renderDocumentView={renderDocumentView} | ||
renderCustomToolbar={renderCustomToolbarWithElements} | ||
services={services} | ||
totalHits={totalHits} | ||
onFetchMoreRecords={onFetchMoreRecords} | ||
componentsTourSteps={TOUR_STEPS} | ||
externalCustomRenderers={cellRenderers} | ||
customGridColumnsConfiguration={customGridColumnsConfiguration} | ||
customControlColumnsConfiguration={customControlColumnsConfiguration} | ||
additionalFieldGroups={additionalFieldGroups} | ||
/> | ||
</CellActionsProvider> | ||
</div> | ||
)} | ||
</EuiFlexItem> | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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 type { EsHitRecord } from '@kbn/discover-utils'; | ||
import type { ExecutionContract } from '@kbn/expressions-plugin/common'; | ||
import { RequestAdapter } from '@kbn/inspector-plugin/common'; | ||
import { of } from 'rxjs'; | ||
import { dataViewWithTimefieldMock } from '../../../__mocks__/data_view_with_timefield'; | ||
import { discoverServiceMock } from '../../../__mocks__/services'; | ||
import { fetchEsql } from './fetch_esql'; | ||
|
||
describe('fetchEsql', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('resolves with returned records', async () => { | ||
const hits = [ | ||
{ _id: '1', foo: 'bar' }, | ||
{ _id: '2', foo: 'baz' }, | ||
] as unknown as EsHitRecord[]; | ||
const records = hits.map((hit, i) => ({ | ||
id: String(i), | ||
raw: hit, | ||
flattened: hit, | ||
})); | ||
const expressionsExecuteSpy = jest.spyOn(discoverServiceMock.expressions, 'execute'); | ||
expressionsExecuteSpy.mockReturnValueOnce({ | ||
cancel: jest.fn(), | ||
getData: jest.fn(() => | ||
of({ | ||
result: { | ||
columns: ['_id', 'foo'], | ||
rows: hits, | ||
}, | ||
}) | ||
), | ||
} as unknown as ExecutionContract); | ||
const resolveDocumentProfileSpy = jest.spyOn( | ||
discoverServiceMock.profilesManager, | ||
'resolveDocumentProfile' | ||
); | ||
expect( | ||
await fetchEsql({ | ||
query: { esql: 'from *' }, | ||
dataView: dataViewWithTimefieldMock, | ||
inspectorAdapters: { requests: new RequestAdapter() }, | ||
data: discoverServiceMock.data, | ||
expressions: discoverServiceMock.expressions, | ||
profilesManager: discoverServiceMock.profilesManager, | ||
}) | ||
).toEqual({ | ||
records, | ||
esqlQueryColumns: ['_id', 'foo'], | ||
esqlHeaderWarning: undefined, | ||
}); | ||
expect(resolveDocumentProfileSpy).toHaveBeenCalledTimes(2); | ||
expect(resolveDocumentProfileSpy).toHaveBeenCalledWith({ record: records[0] }); | ||
expect(resolveDocumentProfileSpy).toHaveBeenCalledWith({ record: records[1] }); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: as
dataView
previously was the last optional argument, this function signature made sense. But if we add a parameter and invoke it without having a data view, we then need to force passing a second argument to pass then a third one, and it'll start looking something likeShall we refactor the function to get named parameters as we are adding the processRecord now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree with this, but
buildDataTableRecordList
is used outside of Discover and I'd like to avoid pinging other teams for review on this PR. I can make this change in a followup though to avoid blocking this one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a PR based on this one for the signature change here: #184976.