u
This commit is contained in:
@@ -1,45 +1,26 @@
|
||||
/**
|
||||
* @file articleHistoryAutomat.js
|
||||
* @description Virtualized grid automat (`articleHistoryGridAutomat`) for
|
||||
* infinite-scrolling article history via `react-virtual-aggridautomat`.
|
||||
* @description Double-buffered chunk list automat (`articleHistoryAutomat`) for
|
||||
* article audit logs and history entries with multi-filter caching and LRU eviction.
|
||||
*
|
||||
* Upstream Triggers:
|
||||
* - `authAutomat`: Subscribes to auth state changes — calls `reload()` when
|
||||
* status reaches `'authed'` with a `selectedCompanyId`.
|
||||
* - AG Grid: Triggers `fetchRows()` on viewport scroll, sort, or filter changes.
|
||||
* - `authAutomat`: Subscribes to auth state changes — resets on `'anon'` or when
|
||||
* `selectedCompanyId` changes.
|
||||
* - Consumer UI: Calls `getItems()`, `requireChunk(start, end)`, `filter(search)`,
|
||||
* `addSeekMonth()`, `addSeekYear()`, `resetNegativeSeek()`.
|
||||
*/
|
||||
|
||||
import { createGridAutomat } from 'react-virtual-aggridautomat/createGridAutomat';
|
||||
import { createChunkListAutomat } from './createChunkListAutomat';
|
||||
import { article } from '../api';
|
||||
import authAutomat from './authAutomat';
|
||||
|
||||
export const articleHistoryGridAutomat = createGridAutomat({
|
||||
export const articleHistoryAutomat = createChunkListAutomat({
|
||||
name: 'articleHistory',
|
||||
blockSize: 50,
|
||||
fetchRows: async ({ startRow, endRow, sortModel, filterModel }) => {
|
||||
try {
|
||||
const res = await article.getHistory({
|
||||
startRow,
|
||||
endRow,
|
||||
sortModel,
|
||||
filterModel,
|
||||
});
|
||||
const rows = res?.rows ?? res?.history ?? res?.entries ?? (Array.isArray(res) ? res : []);
|
||||
const total = res?.total ?? res?.totalRows ?? res?.totalCount;
|
||||
const lastRow = total != null ? total : (rows.length < (endRow - startRow) ? startRow + rows.length : undefined);
|
||||
return { rows, lastRow };
|
||||
} catch (err) {
|
||||
console.warn('Failed to fetch article history (backend route pending):', err);
|
||||
return { rows: [], lastRow: 0 };
|
||||
}
|
||||
},
|
||||
chunkSize: 50,
|
||||
maxLruChunks: 50,
|
||||
fetchPage: (params) => article.getHistory(params),
|
||||
});
|
||||
|
||||
// Reload on company switch or auth change
|
||||
authAutomat.subscribe((auth) => {
|
||||
if (auth.status === 'authed' && auth.user?.selectedCompanyId) {
|
||||
articleHistoryGridAutomat.actions.reload();
|
||||
}
|
||||
});
|
||||
// Alias for backwards compatibility
|
||||
export const articleHistoryGridAutomat = articleHistoryAutomat;
|
||||
|
||||
export default articleHistoryGridAutomat;
|
||||
export default articleHistoryAutomat;
|
||||
|
||||
Reference in New Issue
Block a user