Skip to content

Commit

Permalink
perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra authored and Michail Yasonik committed Feb 25, 2020
1 parent 9eb57e6 commit 156a558
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,19 @@ import { wrapInI18nContext } from '../../../kibana_services';
import { DiscoverGrid } from './discover_grid';

export function createDiscoverGridDirective(reactDirective: any) {
return reactDirective(wrapInI18nContext(DiscoverGrid));
return reactDirective(wrapInI18nContext(DiscoverGrid), [
['columns', { watchDepth: 'collection' }],
['rows', { watchDepth: 'collection' }],
['indexPattern', { watchDepth: 'reference' }],
['sort', { watchDepth: 'value' }],
['sampleSize', { watchDepth: 'reference' }],
['searchDescription', { watchDepth: 'reference' }],
['searchTitle', { watchDepth: 'reference' }],
['useShortDots', { watchDepth: 'value' }],
['onFilter', { watchDepth: 'reference', wrapApply: false }],
['onRemoveColumn', { watchDepth: 'reference', wrapApply: false }],
['onAddColumn', { watchDepth: 'reference', wrapApply: false }],
['getContextAppHref', { watchDepth: 'reference', wrapApply: false }],
['onSort', { watchDepth: 'reference', wrapApply: false }],
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function CellPopover({
);
}

export function DiscoverGrid({
export const DiscoverGrid = React.memo(function DiscoverGridInner({
rows,
columns,
sort,
Expand All @@ -139,17 +139,9 @@ export function DiscoverGrid({
}: Props) {
const actionColumnId = 'uniqueString'; // TODO should be guaranteed unique...
const lowestPageSize = 50;
const timeNode = useMemo(
() => (
<span>
{i18n.translate('kbn.discover.timeLabel', {
defaultMessage: 'Time',
})}
</span>
),
[]
);
const timeString = useRenderToText(timeNode, 'Time');
const timeString = i18n.translate('kbn.discover.timeLabel', {
defaultMessage: 'Time',
});
const [flyoutRow, setFlyoutRow] = useState<ElasticSearchHit | undefined>(undefined);

const dataGridColumns = columns.map(
Expand Down Expand Up @@ -218,9 +210,14 @@ export function DiscoverGrid({
* Visibility and order
*/
const [visibleColumns, setVisibleColumns] = useState(dataGridColumns.map(obj => obj.id));
const mounted = React.useRef(false);
useEffect(() => {
// every time a column is added, make it visible
setVisibleColumns(dataGridColumns.map(obj => obj.id));
if (!mounted.current) {
mounted.current = true;
} else {
setVisibleColumns(dataGridColumns.map(obj => obj.id));
}
}, [dataGridColumns.length]); // eslint-disable-line react-hooks/exhaustive-deps

/**
Expand Down Expand Up @@ -444,4 +441,4 @@ export function DiscoverGrid({
)}
</>
);
}
});
11 changes: 11 additions & 0 deletions src/legacy/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,5 +1163,16 @@ export function getUiSettingDefaults() {
category: ['accessibility'],
requiresPageReload: true,
},
'doc_table:legacyTable': {
name: i18n.translate('kbn.advancedSettings.docTableVersionName', {
defaultMessage: 'Use legacy table',
}),
value: false,
description: i18n.translate('kbn.advancedSettings.docTableVersionDescription', {
defaultMessage:
'Prefer the legacy version of the documents table in Discover while available',
}),
category: ['discover'],
},
};
}

0 comments on commit 156a558

Please sign in to comment.