Skip to content

Commit

Permalink
fix sorting change causing blank table by removing table render timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Oct 31, 2019
1 parent 55e827e commit 649baf0
Showing 1 changed file with 1 addition and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,12 @@ interface Props {
export const ResultsTable: FC<Props> = React.memo(({ jobConfig, jobStatus }) => {
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(25);
const [clearTable, setClearTable] = useState(false);
const [selectedFields, setSelectedFields] = useState([] as EsFieldName[]);
const [isColumnsPopoverVisible, setColumnsPopoverVisible] = useState(false);
const [searchQuery, setSearchQuery] = useState<SavedSearchQuery>(defaultSearchQuery);
const [searchError, setSearchError] = useState<any>(undefined);
const [searchString, setSearchString] = useState<string | undefined>(undefined);

// EuiInMemoryTable has an issue with dynamic sortable columns
// and will trigger a full page Kibana error in such a case.
// The following is a workaround until this is solved upstream:
// - If the sortable/columns config changes,
// the table will be unmounted/not rendered.
// This is what setClearTable(true) in toggleColumn() does.
// - After that on next render it gets re-enabled. To make sure React
// doesn't consolidate the state updates, setTimeout is used.
if (clearTable) {
setTimeout(() => setClearTable(false), 0);
}

function toggleColumnsPopover() {
setColumnsPopoverVisible(!isColumnsPopoverVisible);
}
Expand All @@ -94,7 +81,6 @@ export const ResultsTable: FC<Props> = React.memo(({ jobConfig, jobStatus }) =>

function toggleColumn(column: EsFieldName) {
if (tableItems.length > 0 && jobConfig !== undefined) {
setClearTable(true);
// spread to a new array otherwise the component wouldn't re-render
setSelectedFields([...toggleSelectedField(selectedFields, column)]);
}
Expand Down Expand Up @@ -269,7 +255,6 @@ export const ResultsTable: FC<Props> = React.memo(({ jobConfig, jobStatus }) =>
setPageSize(size);

if (sort.field !== sortField || sort.direction !== sortDirection) {
setClearTable(true);
loadExploreData({ ...sort, searchQuery });
}
};
Expand Down Expand Up @@ -445,7 +430,7 @@ export const ResultsTable: FC<Props> = React.memo(({ jobConfig, jobStatus }) =>
{status !== INDEX_STATUS.LOADING && (
<EuiProgress size="xs" color="accent" max={1} value={0} />
)}
{clearTable === false && (columns.length > 0 || searchQuery !== defaultSearchQuery) && (
{(columns.length > 0 || searchQuery !== defaultSearchQuery) && (
<Fragment>
<EuiSpacer />
<MlInMemoryTableBasic
Expand Down

0 comments on commit 649baf0

Please sign in to comment.