Skip to content

Commit

Permalink
[ML] Transforms/DFA: Render EuiDataGrad for more than 0 rows. (elasti…
Browse files Browse the repository at this point in the history
…c#156403)

Fixes the React dev mode warning "Warning: Can't perform a React state
update on an unmounted component." by only rendering `EuiDataGrid` if
there's more than 0 rows.
  • Loading branch information
walterra authored May 3, 2023
1 parent 36c31f5 commit 3f52ff6
Showing 1 changed file with 69 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,74 +346,76 @@ export const DataGrid: FC<Props> = memo(
<EuiSpacer size="m" />
</div>
)}
<EuiMutationObserver
observerOptions={{ subtree: true, attributes: true, childList: true }}
onMutation={onMutation}
>
{(mutationRef) => (
<div css={cssOverride} ref={mutationRef}>
<EuiDataGrid
aria-label={isWithHeader(props) ? props.title : ''}
columns={columnsWithCharts.map((c) => {
c.initialWidth = 165;
return c;
})}
columnVisibility={{ visibleColumns, setVisibleColumns }}
trailingControlColumns={trailingControlColumns}
gridStyle={euiDataGridStyle}
rowCount={rowCount}
renderCellValue={renderCellValue}
renderCellPopover={renderCellPopover}
sorting={{ columns: sortingColumns, onSort }}
toolbarVisibility={{
...euiDataGridToolbarSettings,
...(chartsButtonVisible
? {
additionalControls: (
<EuiToolTip
content={i18n.translate(
'xpack.ml.dataGrid.histogramButtonToolTipContent',
{
defaultMessage:
'Queries run to fetch histogram chart data will use a sample size per shard of {samplerShardSize} documents.',
values: {
samplerShardSize: DEFAULT_SAMPLER_SHARD_SIZE,
},
}
)}
>
<EuiButtonEmpty
aria-pressed={chartsVisible === true}
className={`euiDataGrid__controlBtn${
chartsVisible === true ? ' euiDataGrid__controlBtn--active' : ''
}`}
data-test-subj={`${dataTestSubj}HistogramButton`}
size="xs"
iconType="visBarVertical"
color="text"
onClick={toggleChartVisibility}
disabled={chartsVisible === undefined}
{rowCount > 0 && (
<EuiMutationObserver
observerOptions={{ subtree: true, attributes: true, childList: true }}
onMutation={onMutation}
>
{(mutationRef) => (
<div css={cssOverride} ref={mutationRef}>
<EuiDataGrid
aria-label={isWithHeader(props) ? props.title : ''}
columns={columnsWithCharts.map((c) => {
c.initialWidth = 165;
return c;
})}
columnVisibility={{ visibleColumns, setVisibleColumns }}
trailingControlColumns={trailingControlColumns}
gridStyle={euiDataGridStyle}
rowCount={rowCount}
renderCellValue={renderCellValue}
renderCellPopover={renderCellPopover}
sorting={{ columns: sortingColumns, onSort }}
toolbarVisibility={{
...euiDataGridToolbarSettings,
...(chartsButtonVisible
? {
additionalControls: (
<EuiToolTip
content={i18n.translate(
'xpack.ml.dataGrid.histogramButtonToolTipContent',
{
defaultMessage:
'Queries run to fetch histogram chart data will use a sample size per shard of {samplerShardSize} documents.',
values: {
samplerShardSize: DEFAULT_SAMPLER_SHARD_SIZE,
},
}
)}
>
<FormattedMessage
id="xpack.ml.dataGrid.histogramButtonText"
defaultMessage="Histogram charts"
/>
</EuiButtonEmpty>
</EuiToolTip>
),
}
: {}),
}}
pagination={{
...pagination,
pageSizeOptions: [5, 10, 25],
onChangeItemsPerPage,
onChangePage,
}}
/>
</div>
)}
</EuiMutationObserver>
<EuiButtonEmpty
aria-pressed={chartsVisible === true}
className={`euiDataGrid__controlBtn${
chartsVisible === true ? ' euiDataGrid__controlBtn--active' : ''
}`}
data-test-subj={`${dataTestSubj}HistogramButton`}
size="xs"
iconType="visBarVertical"
color="text"
onClick={toggleChartVisibility}
disabled={chartsVisible === undefined}
>
<FormattedMessage
id="xpack.ml.dataGrid.histogramButtonText"
defaultMessage="Histogram charts"
/>
</EuiButtonEmpty>
</EuiToolTip>
),
}
: {}),
}}
pagination={{
...pagination,
pageSizeOptions: [5, 10, 25],
onChangeItemsPerPage,
onChangePage,
}}
/>
</div>
)}
</EuiMutationObserver>
)}
</div>
);
},
Expand Down

0 comments on commit 3f52ff6

Please sign in to comment.