Commit f34caaa0 authored by Matija Obreza's avatar Matija Obreza

Fix: Amphibian preview for small datasets clears existing column

parent 0d308f31
......@@ -66,6 +66,7 @@ class PreviewPage extends React.Component<IPreviewPageProps, any> {
preview: null,
error: null,
currentSheet: 0,
hasMoreData: true,
sheetRows: null,
columns: [],
};
......@@ -95,7 +96,7 @@ class PreviewPage extends React.Component<IPreviewPageProps, any> {
if (preview.state !== 'READY' && preview.state !== 'ERROR') {
setTimeout(() => this.getPreview(uuid), 2000);
}
this.setState({ preview, error: null, currentSheet: 0, sheetRows: null });
this.setState({ preview, error: null, currentSheet: 0, sheetRows: null, hasMoreData: true });
return preview;
}).then((preview) => {
if (preview.sheets) {
......@@ -114,8 +115,17 @@ class PreviewPage extends React.Component<IPreviewPageProps, any> {
return getPreviewData(uuid, sheet, startRow, 100)
// load
.then((data) => {
const clean = new Set<string>();
if (! data || data.length === 0) {
this.setState({ hasMoreData: false });
return data;
}
let columns = [];
const clean = new Set<string>();
if (this.state.columns) {
// existing columns
this.state.columns.forEach((column) => clean.add(column));
}
// new columns
data.map((r) => Object.keys(r).map((k) => clean.add(k)));
for (const key of clean) {
columns.push(key);
......@@ -128,7 +138,8 @@ class PreviewPage extends React.Component<IPreviewPageProps, any> {
}
}
const prevData = this.state.sheetRows ? this.state.sheetRows : [];
this.setState({ error: null, columns, sheetRows: [ ...prevData, ...data ], currentSheet: sheet });
// console.log(`Old ${prevData.length} New ${data.length} columns=`, columns);
this.setState({ error: null, columns, sheetRows: [ ...prevData, ...data ], currentSheet: sheet, hasMoreData: data.length === 100 });
return data;
})
// err
......@@ -136,7 +147,7 @@ class PreviewPage extends React.Component<IPreviewPageProps, any> {
}
private loadMoreIfPossible = () => {
if (! this.state.preview || ! this.state.preview.referenceUuid || ! this.state.sheetRows) {
if (! this.state.preview || ! this.state.preview.referenceUuid || ! this.state.sheetRows || ! this.state.hasMoreData) {
return;
}
console.log('Loading more!');
......@@ -194,9 +205,11 @@ class PreviewPage extends React.Component<IPreviewPageProps, any> {
</Grid>
) }
</Grid>
<VisibilitySensor offset={ { bottom: -100 } } onChange={ this.loadMoreIfPossible }>
{ () => <div>&nbsp;</div> }
</VisibilitySensor>
{ this.state.sheetRows && this.state.hasMoreData &&
<VisibilitySensor offset={ { bottom: -100 } } onChange={ this.loadMoreIfPossible }>
{ () => <div>&nbsp;</div> }
</VisibilitySensor>
}
</PageLayout>
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment