-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a993917
commit 7ffa41e
Showing
7 changed files
with
73 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
component/src/utils/outerTableComponents/pagination/async/paginationAsyncStartData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {PageButtonContainerElement} from '../../../../elements/pagination/pageButtons/pageButtonContainerElement'; | ||
import {UpdateCellsForRows} from '../../../insertRemoveStructure/update/updateCellsForRows'; | ||
import {AsyncStartData, PaginationInternal} from '../../../../types/paginationInternal'; | ||
import {InsertNewRow} from '../../../insertRemoveStructure/insert/insertNewRow'; | ||
import {InitialDataProcessing} from '../../../data/initialDataProcessing'; | ||
import {CELL_UPDATE_TYPE} from '../../../../enums/onUpdateCellType'; | ||
import {PaginationAsyncUtils} from './paginationAsyncUtils'; | ||
import {Pagination} from '../../../../types/pagination'; | ||
import {EMPTY_STRING} from '../../../../consts/text'; | ||
import {ActiveTable} from '../../../../activeTable'; | ||
|
||
export class PaginationAsyncStartData { | ||
private static fillTotalDataRows(at: ActiveTable, asyncStartData: AsyncStartData) { | ||
const {totalDataRows, data: asyncData, failed} = asyncStartData; | ||
if (at.data.length < totalDataRows || failed) { | ||
const maxRowLength = Math.max(at.data[0]?.length || 0, InitialDataProcessing.getMaxRowLength(asyncData)); | ||
const headerDelta = Number(!at.dataStartsAtHeader); | ||
const newData = new Array(totalDataRows - at.data.length + headerDelta).fill( | ||
new Array(maxRowLength).fill(EMPTY_STRING) | ||
); | ||
const startIndex = at.data.length; | ||
at.data.splice(at.data.length, 0, ...newData); | ||
newData.forEach((row, index) => { | ||
const rowEl = InsertNewRow.insertNewRow(at, startIndex + index, false, row); | ||
setTimeout(() => { | ||
UpdateCellsForRows.updateRowCells(at, rowEl, startIndex + index, CELL_UPDATE_TYPE.UPDATE, false); | ||
}); | ||
}); | ||
PageButtonContainerElement.repopulateButtons(at); | ||
} | ||
} | ||
|
||
public static populate(at: ActiveTable, startData: AsyncStartData) { | ||
const {data, totalDataRows, failed} = startData; | ||
if (data.length > 0 && totalDataRows > 0 && (at.data.length > 0 || InitialDataProcessing.getMaxRowLength(data) > 0)) { | ||
PaginationAsyncStartData.fillTotalDataRows(at, startData); | ||
if (!failed) PaginationAsyncUtils.insertData(at, data, 1); | ||
} | ||
} | ||
|
||
public static async get(at: ActiveTable, pagination: Pagination, paginationInternal: PaginationInternal) { | ||
const {_async, rowsPerPage: rowsPerPageC} = pagination; | ||
if (!_async) return; | ||
const {rowsPerPage: rowsPerPageI} = paginationInternal; | ||
const rowsPerPage = typeof rowsPerPageC === 'number' ? rowsPerPageC : rowsPerPageI; | ||
try { | ||
// not handling partial failures because users would be looking at partial data without knowing about it | ||
const [totalDataRows, data] = await Promise.all([_async.getTotalRows(), _async.getPageData(1, rowsPerPage)]); | ||
return {totalDataRows, data}; | ||
} catch (e) { | ||
setTimeout(() => PaginationAsyncUtils.displayError(e, at)); | ||
return {totalDataRows: 0, data: [['', '']], failed: true}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters