This commit is contained in:
seb
2026-10-28 00:08:45 +01:00
parent fab291f68e
commit 96d0ae6742
88 changed files with 3871 additions and 5334 deletions

View File

@@ -10,8 +10,7 @@ import Tooltip from '@mui/material/Tooltip';
import AddIcon from '@mui/icons-material/Add';
import { notifyError } from '../../../utils/notify';
import { enqueueSnackbar } from 'notistack';
import attributeAutomat, { selectAttributes } from '../../../automats/attributeAutomat';
import propertyAutomat, { selectProperties } from '../../../automats/propertyAutomat';
import companyAutomat, { selectAttributes, selectProperties } from '../../../automats/companyAutomat';
import artikelAutomat, { getArticle } from '../../../automats/artikelAutomat';
import { article as articleApi } from '../../../api';
@@ -81,26 +80,27 @@ export default class ArticleAttributesTab extends PureComponent {
componentDidMount() {
this._cancelled = false;
this.unsubAttr = attributeAutomat.subscribe((state) => {
this.unsubCompany = companyAutomat.subscribe((state) => {
if (this._cancelled) return;
this.setState((prev) => {
let nextKey = prev.selectedMerkmalKey;
let nextItemId = prev.selectedItemId;
const selectableAttrs = state.attributes;
const globalProps = state.properties;
const isCurrentKeyValid =
nextKey &&
(selectableAttrs.some((a) => `attr-${a.id}` === nextKey) ||
prev.globalProperties.some((p) => `prop-${p.id}` === nextKey));
globalProps.some((p) => `prop-${p.id}` === nextKey));
if (!isCurrentKeyValid) {
const first = selectableAttrs[0];
if (first) {
nextKey = `attr-${first.id}`;
nextItemId = first.values?.[0]?.id ?? '';
} else if (prev.globalProperties[0]) {
nextKey = `prop-${prev.globalProperties[0].id}`;
} else if (globalProps[0]) {
nextKey = `prop-${globalProps[0].id}`;
nextItemId = '';
} else {
nextKey = '';
@@ -108,38 +108,24 @@ export default class ArticleAttributesTab extends PureComponent {
}
}
return {
globalAttributes: state.attributes,
globalAttributes: selectableAttrs,
globalProperties: globalProps,
selectedMerkmalKey: nextKey,
selectedItemId: nextItemId,
};
});
});
this.unsubProp = propertyAutomat.subscribe((state) => {
if (this._cancelled) return;
this.setState((prev) => {
const selectableAttrs = prev.globalAttributes;
let nextKey = prev.selectedMerkmalKey;
if (!nextKey && !selectableAttrs.length && state.properties[0]) {
nextKey = `prop-${state.properties[0].id}`;
}
return {
globalProperties: state.properties,
selectedMerkmalKey: nextKey,
};
});
});
}, ['attributes', 'properties']);
this.unsubArtikel = artikelAutomat.subscribe(() => {
if (this._cancelled) return;
this.forceUpdate();
});
if (attributeAutomat.state.status === 'idle') {
void attributeAutomat.actions.load();
if (companyAutomat.state.attributesStatus === 'idle') {
void companyAutomat.actions.loadAttributes();
}
if (propertyAutomat.state.status === 'idle') {
void propertyAutomat.actions.load();
if (companyAutomat.state.propertiesStatus === 'idle') {
void companyAutomat.actions.loadProperties();
}
void this.loadArticleData(this.props.sku);
@@ -153,8 +139,7 @@ export default class ArticleAttributesTab extends PureComponent {
componentWillUnmount() {
this._cancelled = true;
this.unsubAttr?.();
this.unsubProp?.();
this.unsubCompany?.();
this.unsubArtikel?.();
}

View File

@@ -16,7 +16,7 @@ import sseAutomat from '../../../automats/sseAutomat';
import shipmentAutomat from '../../../automats/shipmentAutomat';
import orderAutomat from '../../../automats/orderAutomat';
import entityAutomat from '../../../automats/entityAutomat';
import brandAutomat from '../../../automats/brandAutomat';
import companyAutomat from '../../../automats/companyAutomat';
import { shipment as shipmentApi, order as orderApi } from '../../../api';
import { ShipmentDetailDialog } from '../../manifest';
import SkeleHashImage from '../../settings/SkeleHashImage';
@@ -709,8 +709,8 @@ class ArticleHistoryTab extends PureComponent {
if (entityAutomat.state.status === 'idle') {
void entityAutomat.actions.load().catch(() => {});
}
if (brandAutomat.state.status === 'idle') {
void brandAutomat.actions.load().catch(() => {});
if (companyAutomat.state.brandsStatus === 'idle') {
void companyAutomat.actions.loadBrands().catch(() => {});
}
}
@@ -868,7 +868,7 @@ class ArticleHistoryTab extends PureComponent {
handleOpenBrand(brandName) {
if (!brandName) return;
const match = (brandAutomat.state.brands || []).find(
const match = (companyAutomat.state.brands || []).find(
(b) => b && (b.name?.toLowerCase() === brandName.toLowerCase() || String(b.id) === String(brandName)),
);
const brandParam = match?.id != null ? String(match.id) : brandName;

View File

@@ -9,7 +9,7 @@ import GoogleIcon from '@mui/icons-material/Google';
import { enqueueSnackbar } from 'notistack';
import { article as articleApi } from '../../../api';
import { artikelAutomat, getArticle } from '../../../automats';
import artikelAutomat, { getArticle } from '../../../automats/artikelAutomat';
import { notifyError } from '../../../utils/notify';
import {
articleEans,

View File

@@ -23,7 +23,6 @@ import { enqueueSnackbar } from 'notistack';
import { article as articleApi } from '../../../api';
import { notifyError } from '../../../utils/notify';
import { formatPrice } from '../../../utils/price';
import supplierAutomat from '../../../automats/supplierAutomat';
import { articleSupplierAutomat } from '../../../automats/articleDetailAutomat';
import sseAutomat from '../../../automats/sseAutomat';
import companyAutomat from '../../../automats/companyAutomat';
@@ -93,7 +92,7 @@ export default class ArticleSupplierTab extends PureComponent {
// 2. Fetch available company suppliers
try {
const companySuppliers = await supplierAutomat.actions.load();
const companySuppliers = await companyAutomat.actions.loadSuppliers();
this.setState({ companySuppliers: companySuppliers ?? [] });
} catch (err) {
notifyError(err);