Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix(dataset): Page blanks on large data load (apache#11979)
Browse files Browse the repository at this point in the history
* Implement pagination in <TableView> for Samples preview

* Increase page size

* Fix lint

* Render cells based on width

* Fix lint errors

* Additional tests and changes

* Search bar fix

* Additional fixes

* Suggested changes
  • Loading branch information
nikolagigic authored Dec 16, 2020
1 parent 2302adb commit 48fb8c0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
15 changes: 15 additions & 0 deletions superset-frontend/spec/javascripts/explore/utils_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
buildV1ChartDataPayload,
getExploreUrl,
getExploreLongUrl,
getDataTablePageSize,
shouldUseLegacyApi,
} from 'src/explore/exploreUtils';
import {
Expand Down Expand Up @@ -200,6 +201,20 @@ describe('exploreUtils', () => {
});
});

describe('getDataTablePageSize', () => {
it('divides samples data into pages dynamically', () => {
let pageSize;
pageSize = getDataTablePageSize(500);
expect(pageSize).toEqual(20);
pageSize = getDataTablePageSize(0);
expect(pageSize).toEqual(50);
pageSize = getDataTablePageSize(1);
expect(pageSize).toEqual(10000);
pageSize = getDataTablePageSize(1000000);
expect(pageSize).toEqual(5);
});
});

describe('buildV1ChartDataPayload', () => {
it('generate valid request payload despite no registered buildQuery', () => {
const v1RequestPayload = buildV1ChartDataPayload({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const useFilteredTableData = (
const formattedData = applyFormattingToTabularData(data);
return formattedData.filter((row: Record<string, any>) =>
Object.values(row).some(value =>
value.toString().toLowerCase().includes(filterText.toLowerCase()),
value?.toString().toLowerCase().includes(filterText.toLowerCase()),
),
);
}, [data, filterText]);
Expand Down
7 changes: 6 additions & 1 deletion superset-frontend/src/explore/components/DataTablesPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Loading from 'src/components/Loading';
import TableView, { EmptyWrapperType } from 'src/components/TableView';
import { getChartDataRequest } from 'src/chart/chartAction';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { getDataTablePageSize } from 'src/explore/exploreUtils';
import {
CopyToClipboardButton,
FilterInput,
Expand Down Expand Up @@ -181,6 +182,9 @@ export const DataTablesPane = ({
};

const renderDataTable = (type: string) => {
// restrict cell count to 10000 or min 5 rows to avoid crashing browser
const columnsLength = columns[type].length;
const pageSize = getDataTablePageSize(columnsLength);
if (isLoading[type]) {
return <Loading />;
}
Expand All @@ -195,7 +199,8 @@ export const DataTablesPane = ({
<TableView
columns={columns[type]}
data={filteredData[type]}
withPagination={false}
withPagination
pageSize={pageSize}
noDataText={t('No data')}
emptyWrapperType={EmptyWrapperType.Small}
className="table-condensed"
Expand Down
8 changes: 8 additions & 0 deletions superset-frontend/src/explore/exploreUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ export function postForm(url, payload, target = '_blank') {
document.body.removeChild(hiddenForm);
}

export function getDataTablePageSize(columnsLength) {
let pageSize;
if (columnsLength) {
pageSize = Math.ceil(Math.max(5, 10000 / columnsLength));
}
return pageSize || 50;
}

export const exportChart = ({
formData,
resultFormat = 'json',
Expand Down

0 comments on commit 48fb8c0

Please sign in to comment.