This commit is contained in:
seb
2026-10-09 20:17:12 +02:00
parent 14ae017b64
commit 1bbeeaeff4

View File

@@ -10,7 +10,6 @@ import { backendErrorFrom } from '../../utils/backendError';
import { notifyError } from '../../utils/notify'; import { notifyError } from '../../utils/notify';
import { setLastArticleSku } from '../../automats'; import { setLastArticleSku } from '../../automats';
import brandAutomat from '../../automats/brandAutomat'; import brandAutomat from '../../automats/brandAutomat';
import ResultsPagination from '../../components/article/ResultsPagination';
import { enqueueSnackbar } from 'notistack'; import { enqueueSnackbar } from 'notistack';
import { import {
BrandImageSearchDialog, BrandImageSearchDialog,
@@ -37,15 +36,11 @@ class ArtikelMarkenPage extends PureComponent {
status: brandAutomat.state.status === 'succeeded' ? 'ready' : 'loading', status: brandAutomat.state.status === 'succeeded' ? 'ready' : 'loading',
error: brandAutomat.state.error ? backendErrorFrom({ message: brandAutomat.state.error }) : null, error: brandAutomat.state.error ? backendErrorFrom({ message: brandAutomat.state.error }) : null,
brands: brandAutomat.state.brands || [], brands: brandAutomat.state.brands || [],
pageSize: 10,
currentPage: 1,
newName: '', newName: '',
busyKey: null, busyKey: null,
searchBrand: null, searchBrand: null,
}; };
this._cancelled = false; this._cancelled = false;
this.fillSpaceRef = createRef();
this.paginationRef = createRef();
this.createRowRef = createRef(); this.createRowRef = createRef();
this.handleCreate = this.handleCreate.bind(this); this.handleCreate = this.handleCreate.bind(this);
this.handleRetry = this.handleRetry.bind(this); this.handleRetry = this.handleRetry.bind(this);
@@ -53,8 +48,6 @@ class ArtikelMarkenPage extends PureComponent {
this.handleRename = this.handleRename.bind(this); this.handleRename = this.handleRename.bind(this);
this.handleDelete = this.handleDelete.bind(this); this.handleDelete = this.handleDelete.bind(this);
this.handleSearchLogo = this.handleSearchLogo.bind(this); this.handleSearchLogo = this.handleSearchLogo.bind(this);
this.handleMeasurement = this.handleMeasurement.bind(this);
this.handlePageChange = this.handlePageChange.bind(this);
} }
componentDidMount() { componentDidMount() {
@@ -81,16 +74,7 @@ class ArtikelMarkenPage extends PureComponent {
} }
applyBrands(brands) { applyBrands(brands) {
this.setState((state) => { this.setState({ status: 'ready', error: null, brands });
const total = brands.length;
const pageCount = Math.max(1, Math.ceil(total / Math.max(1, state.pageSize)));
return {
status: 'ready',
error: null,
brands,
currentPage: Math.min(state.currentPage, pageCount),
};
});
} }
async loadBrands() { async loadBrands() {
@@ -107,20 +91,6 @@ class ArtikelMarkenPage extends PureComponent {
} }
} }
// FillSpace measures how many rows fit; page size is purely local —
// no fetch, the automat already holds the full list.
handleMeasurement(count) {
if (!count || count <= 0 || count === this.state.pageSize) return;
this.setState((state) => {
const pageCount = Math.max(1, Math.ceil(state.brands.length / count));
return { pageSize: count, currentPage: Math.min(state.currentPage, pageCount) };
});
}
handlePageChange(_event, page) {
this.setState({ currentPage: Math.max(1, Number(page) || 1) });
}
handleRetry() { handleRetry() {
void this.loadBrands(); void this.loadBrands();
} }
@@ -181,14 +151,8 @@ class ArtikelMarkenPage extends PureComponent {
} }
render() { render() {
const { status, error, brands, pageSize, currentPage, newName, busyKey } = this.state; const { status, error, brands, newName, busyKey } = this.state;
const busy = busyKey != null; const busy = busyKey != null;
const total = brands.length;
const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
const safePage = Math.min(Math.max(1, currentPage), pageCount);
const offset = (safePage - 1) * pageSize;
const pageBrands = brands.slice(offset, offset + pageSize);
const showPagination = total > pageSize;
if (status === 'loading') { if (status === 'loading') {
return ( return (
@@ -205,27 +169,15 @@ class ArtikelMarkenPage extends PureComponent {
return ( return (
<PanelTileGrid> <PanelTileGrid>
<PanelTile wide={2} minHeight={0} color={PURPLE_PANEL} sx={{ pb: 0 }}> <PanelTile wide={2} minHeight={0} color={PURPLE_PANEL} sx={{ pb: 0 }}>
<Box ref={this.paginationRef} sx={{ mb: 1 }}>
<ResultsPagination
invisible={!showPagination}
offset={showPagination ? offset : 0}
totalCount={showPagination ? total : pageSize + 1}
pageSize={pageSize}
pageCount={showPagination ? pageCount : 1}
currentPage={showPagination ? safePage : 1}
onPageChange={this.handlePageChange}
/>
</Box>
<FillSpace <FillSpace
ref={this.fillSpaceRef} aboveRef={[]}
aboveRef={this.paginationRef}
belowRef={this.createRowRef} belowRef={this.createRowRef}
reserveBottom={32} reserveBottom={32}
onMeasurement={this.handleMeasurement} minPageSize={10}
measureElement={<BrandRowMeasureSample />} measureElement={<BrandRowMeasureSample />}
minHeight={0} minHeight={0}
sx={{ overflowX: 'hidden', overflowY: 'auto', width: '100%' }} items={brands}
> renderPage={(pageBrands) => (
<ArtikelMarkenTable <ArtikelMarkenTable
brands={pageBrands} brands={pageBrands}
busyKey={busyKey} busyKey={busyKey}
@@ -234,7 +186,8 @@ class ArtikelMarkenPage extends PureComponent {
onDelete={this.handleDelete} onDelete={this.handleDelete}
sx={{ width: '100%' }} sx={{ width: '100%' }}
/> />
</FillSpace> )}
/>
<Box ref={this.createRowRef} sx={{ display: 'flex', alignItems: 'center', gap: 1, mt: 2, pb: 2 }}> <Box ref={this.createRowRef} sx={{ display: 'flex', alignItems: 'center', gap: 1, mt: 2, pb: 2 }}>
<SingleLineTextEdit <SingleLineTextEdit