Skip to content

Commit

Permalink
[Discover] fix single doc view
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaanj committed Jun 28, 2021
1 parent 1a65a04 commit 37b5b41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -128,7 +132,7 @@ export const DocViewerTable = ({
<EuiInMemoryTable
className="kbnDocViewer__table"
items={items}
columns={DOC_VIEW_COLUMNS}
columns={tableColumns}
rowProps={onSetRowProps}
pagination={false}
responsive={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,38 @@ import { FieldRecord } from './table';
import { TableActions } from './table_cell_actions';
import { TableFieldValue } from './table_cell_value';

export const DOC_VIEW_COLUMNS: Array<EuiBasicTableColumn<FieldRecord>> = [
{
field: 'action',
className: 'kbnDocViewer__tableActionsCell',
width: '108px',
name: (
<EuiText size="xs">
<strong>
<FormattedMessage
id="discover.fieldChooser.discoverField.actions"
defaultMessage="Actions"
/>
</strong>
</EuiText>
),
render: (
{ flattenedField, isActive, onFilter, onToggleColumn }: FieldRecord['action'],
{ field: { fieldName, fieldMapping } }: FieldRecord
) => {
return (
onFilter && (
<TableActions
isActive={isActive}
fieldName={fieldName}
fieldMapping={fieldMapping}
flattenedField={flattenedField}
onFilter={onFilter}
onToggleColumn={onToggleColumn}
/>
)
);
},
export const ACTIONS_COLUMN: EuiBasicTableColumn<FieldRecord> = {
field: 'action',
className: 'kbnDocViewer__tableActionsCell',
width: '108px',
name: (
<EuiText size="xs">
<strong>
<FormattedMessage
id="discover.fieldChooser.discoverField.actions"
defaultMessage="Actions"
/>
</strong>
</EuiText>
),
render: (
{ flattenedField, isActive, onFilter, onToggleColumn }: FieldRecord['action'],
{ field: { fieldName, fieldMapping } }: FieldRecord
) => {
return (
<TableActions
isActive={isActive}
fieldName={fieldName}
fieldMapping={fieldMapping}
flattenedField={flattenedField}
onFilter={onFilter!}
onToggleColumn={onToggleColumn}
/>
);
},
};

export const MAIN_COLUMNS: Array<EuiBasicTableColumn<FieldRecord>> = [
{
field: 'field',
className: 'kbnDocViewer__tableFieldNameCell',
Expand Down

0 comments on commit 37b5b41

Please sign in to comment.