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 globalHistoryAutomat.js
* @description Virtualized grid automat (`globalHistoryGridAutomat`) for
* infinite-scrolling global audit/change history via `react-virtual-aggridautomat`.
* @description Double-buffered chunk list automat (`globalHistoryAutomat`) for
* global system and change history logs 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 { globalHistory } from '../api';
import authAutomat from './authAutomat';
export const globalHistoryGridAutomat = createGridAutomat({
export const globalHistoryAutomat = createChunkListAutomat({
name: 'globalHistory',
blockSize: 50,
fetchRows: async ({ startRow, endRow, sortModel, filterModel }) => {
try {
const res = await globalHistory.list({
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 global history (backend route pending):', err);
return { rows: [], lastRow: 0 };
}
},
chunkSize: 50,
maxLruChunks: 50,
fetchPage: (params) => globalHistory.list(params),
});
// Reload on company switch or auth change
authAutomat.subscribe((auth) => {
if (auth.status === 'authed' && auth.user?.selectedCompanyId) {
globalHistoryGridAutomat.actions.reload();
}
});
// Alias for backwards compatibility
export const globalHistoryGridAutomat = globalHistoryAutomat;
export default globalHistoryGridAutomat;
export default globalHistoryAutomat;