This commit is contained in:
seb
2026-10-03 07:32:29 +02:00
parent bc4a1e0468
commit c79ece307c
19 changed files with 622 additions and 69 deletions

View File

@@ -0,0 +1,34 @@
import { createGridAutomat } from 'react-virtual-aggridautomat';
import { article } from '../api';
import authAutomat from './authAutomat';
export const articleHistoryGridAutomat = createGridAutomat({
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 };
}
},
});
// Reload on company switch or auth change
authAutomat.subscribe((auth) => {
if (auth.status === 'authed' && auth.user?.selectedCompanyId) {
articleHistoryGridAutomat.actions.reload();
}
});
export default articleHistoryGridAutomat;

View File

@@ -0,0 +1,34 @@
import { createGridAutomat } from 'react-virtual-aggridautomat';
import { globalHistory } from '../api';
import authAutomat from './authAutomat';
export const globalHistoryGridAutomat = createGridAutomat({
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 };
}
},
});
// Reload on company switch or auth change
authAutomat.subscribe((auth) => {
if (auth.status === 'authed' && auth.user?.selectedCompanyId) {
globalHistoryGridAutomat.actions.reload();
}
});
export default globalHistoryGridAutomat;

View File

@@ -70,3 +70,6 @@ export {
invalidateAllCategoryViews,
} from './categoryAutomat';
export { default as articleHistoryGridAutomat } from './articleHistoryAutomat';
export { default as globalHistoryGridAutomat } from './globalHistoryAutomat';