From 156a558e987d9943d817c11e69c8910780139d6f Mon Sep 17 00:00:00 2001 From: Marta Bondyra Date: Mon, 24 Feb 2020 22:15:18 -0500 Subject: [PATCH] perf improvements --- .../create_discover_grid_directive.tsx | 16 +++++++++++- .../discover_grid/discover_grid.tsx | 25 ++++++++----------- .../kibana/ui_setting_defaults.js | 11 ++++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/create_discover_grid_directive.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/create_discover_grid_directive.tsx index c861ed9ec18fc..cd004a22c02aa 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/create_discover_grid_directive.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/create_discover_grid_directive.tsx @@ -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 }], + ]); } diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/discover_grid.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/discover_grid.tsx index 900d9274b2982..c6fbc6b0cf206 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/discover_grid.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/discover_grid/discover_grid.tsx @@ -121,7 +121,7 @@ function CellPopover({ ); } -export function DiscoverGrid({ +export const DiscoverGrid = React.memo(function DiscoverGridInner({ rows, columns, sort, @@ -139,17 +139,9 @@ export function DiscoverGrid({ }: Props) { const actionColumnId = 'uniqueString'; // TODO should be guaranteed unique... const lowestPageSize = 50; - const timeNode = useMemo( - () => ( - - {i18n.translate('kbn.discover.timeLabel', { - defaultMessage: 'Time', - })} - - ), - [] - ); - const timeString = useRenderToText(timeNode, 'Time'); + const timeString = i18n.translate('kbn.discover.timeLabel', { + defaultMessage: 'Time', + }); const [flyoutRow, setFlyoutRow] = useState(undefined); const dataGridColumns = columns.map( @@ -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 /** @@ -444,4 +441,4 @@ export function DiscoverGrid({ )} ); -} +}); diff --git a/src/legacy/core_plugins/kibana/ui_setting_defaults.js b/src/legacy/core_plugins/kibana/ui_setting_defaults.js index c0628b72c2ce7..6cd1730fa31d7 100644 --- a/src/legacy/core_plugins/kibana/ui_setting_defaults.js +++ b/src/legacy/core_plugins/kibana/ui_setting_defaults.js @@ -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'], + }, }; }