Fix rows loading indefinitely when no rows are returned.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Madeorsk 2024-07-27 14:05:42 +02:00
parent 2513e711b1
commit 2753b6eb9f
Signed by: Madeorsk
SSH key fingerprint: SHA256:J9G0ofIOLKf7kyS2IfrMqtMaPdfsk1W02+oGueZzDDU

View file

@ -85,6 +85,12 @@ class AsyncManager<CK extends ColumnKey>
protected promisedRowsCells: Partial<Record<CK, Promised<CellDefinition>>>[] = [];
/**
* Tells if rows are loaded or not.
* @protected
*/
protected rowsLoaded: boolean = false;
/**
* Rows data.
* @protected
@ -109,6 +115,7 @@ class AsyncManager<CK extends ColumnKey>
*/
handle(data: SmartableData<CK>): void
{
this.rowsLoaded = false;
this.promisedData.refresh(data);
}
@ -125,6 +132,7 @@ class AsyncManager<CK extends ColumnKey>
// Initialize rows data and cells definitions.
this.rowsData = [];
this.cellsDefinitions = [];
this.rowsLoaded = true;
for (const [rowId, rowDefinition] of rowsDefinitions.entries())
{ // Get row data of each row.
@ -218,20 +226,21 @@ class AsyncManager<CK extends ColumnKey>
{
if (!(
// Checking that there is at least one changed value.
this.rowsData.length > 0 && this.cellsDefinitions.some((rowCells) => (
this.rowsData.length > 0 || this.cellsDefinitions.some((rowCells) => (
Object.keys(rowCells).length > 0
))
|| ((this.rowsLoaded && !this.currentDataState.rows) || (!this.rowsLoaded && this.currentDataState.rows))
)) // Nothing has changed.
return;
// Initialize new data.
const newData = {
rows: [
rows: !this.rowsLoaded ? undefined : [
...(this.currentDataState?.rows ?? [])
],
};
for (const [rowId, newRow] of this.rowsData.entries())
for (const [rowId, newRow] of this.rowsData?.entries())
{ // Update value of each new row.
newData.rows[rowId] = {
element: newRow.element,
@ -240,7 +249,7 @@ class AsyncManager<CK extends ColumnKey>
};
}
for (const [rowId, rowCells] of this.cellsDefinitions.entries())
for (const [rowId, rowCells] of this.cellsDefinitions?.entries())
{ // Update cells of each changed row.
newData.rows[rowId] = {
...newData.rows[rowId],