This commit is contained in:
seb
2026-10-16 13:51:18 +02:00
parent d851c6e1e9
commit 764d6f850a
12 changed files with 2211 additions and 328 deletions

View File

@@ -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;