From 37b5b41c7043941da2fe25a4442fe00ec9a73c25 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Mon, 28 Jun 2021 19:30:08 +0300 Subject: [PATCH] [Discover] fix single doc view --- .../application/components/table/table.tsx | 8 ++- .../components/table/table_columns.tsx | 63 +++++++++---------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/plugins/discover/public/application/components/table/table.tsx b/src/plugins/discover/public/application/components/table/table.tsx index 6844ba19d7bcd1..065b146105a651 100644 --- a/src/plugins/discover/public/application/components/table/table.tsx +++ b/src/plugins/discover/public/application/components/table/table.tsx @@ -17,7 +17,7 @@ import { ElasticSearchHit, DocViewRenderProps, } from '../../doc_views/doc_views_types'; -import { DOC_VIEW_COLUMNS } from './table_columns'; +import { ACTIONS_COLUMN, MAIN_COLUMNS } from './table_columns'; export interface DocViewerTableProps { columns?: string[]; @@ -62,6 +62,10 @@ export const DocViewerTable = ({ const formattedHit = useMemo(() => indexPattern?.formatHit(hit, 'html'), [hit, indexPattern]); + const tableColumns = useMemo(() => { + return filter ? [ACTIONS_COLUMN, ...MAIN_COLUMNS] : MAIN_COLUMNS; + }, [filter]); + const onToggleColumn = useCallback( (field: string) => { if (!onRemoveColumn || !onAddColumn || !columns) { @@ -128,7 +132,7 @@ export const DocViewerTable = ({ > = [ - { - field: 'action', - className: 'kbnDocViewer__tableActionsCell', - width: '108px', - name: ( - - - - - - ), - render: ( - { flattenedField, isActive, onFilter, onToggleColumn }: FieldRecord['action'], - { field: { fieldName, fieldMapping } }: FieldRecord - ) => { - return ( - onFilter && ( - - ) - ); - }, +export const ACTIONS_COLUMN: EuiBasicTableColumn = { + field: 'action', + className: 'kbnDocViewer__tableActionsCell', + width: '108px', + name: ( + + + + + + ), + render: ( + { flattenedField, isActive, onFilter, onToggleColumn }: FieldRecord['action'], + { field: { fieldName, fieldMapping } }: FieldRecord + ) => { + return ( + + ); }, +}; + +export const MAIN_COLUMNS: Array> = [ { field: 'field', className: 'kbnDocViewer__tableFieldNameCell',