This commit is contained in:
seb
2026-10-04 19:12:55 +02:00
parent 9146ebaba1
commit 669954b496
7 changed files with 145 additions and 114 deletions

View File

@@ -246,20 +246,19 @@ export default class ArticleAttributesTab extends PureComponent {
const isExclusive = Boolean(targetAttr.exclusive);
const targetValId = Number(effectiveItemId);
const isAlreadyAssigned = assignedAttributes.some((a) => a.attributeValueId === targetValId);
const isMerkmalAlreadyAssigned = assignedAttributes.some((a) => a.attributeId === targetAttr.id);
if (isExclusive && isMerkmalAlreadyAssigned) {
enqueueSnackbar('Eindeutiges Merkmal ist bereits zugeordnet.', { variant: 'info' });
return;
}
if (isAlreadyAssigned) {
enqueueSnackbar('Bereits zugeordnet.', { variant: 'info' });
return;
}
const nextValues = isExclusive
? [
...assignedAttributes
.filter((a) => a.attributeId !== targetAttr.id)
.map((a) => a.attributeValueId),
targetValId,
]
: [...assignedAttributes.map((a) => a.attributeValueId), targetValId];
const nextValues = [...assignedAttributes.map((a) => a.attributeValueId), targetValId];
this.setState({ saving: true });
try {
@@ -282,6 +281,13 @@ export default class ArticleAttributesTab extends PureComponent {
if (!targetProp || !val) return;
const isExclusive = Boolean(targetProp.exclusive);
const isMerkmalAlreadyAssigned = assignedProperties.some((p) => p.propertyId === propId);
if (isExclusive && isMerkmalAlreadyAssigned) {
enqueueSnackbar('Eindeutiges Merkmal ist bereits zugeordnet.', { variant: 'info' });
return;
}
if (!isExclusive) {
const isAlreadyAssigned = assignedProperties.some(
(p) => p.propertyId === propId && p.value.trim().toLowerCase() === val.toLowerCase()
@@ -291,11 +297,8 @@ export default class ArticleAttributesTab extends PureComponent {
return;
}
}
const sourceProps = isExclusive
? assignedProperties.filter((p) => p.propertyId !== propId)
: assignedProperties;
const nextProps = [
...sourceProps.map((p) => ({ propertyId: p.propertyId, value: p.value, sort: p.sort })),
...assignedProperties.map((p) => ({ propertyId: p.propertyId, value: p.value, sort: p.sort })),
{ propertyId: propId, value: val },
];
@@ -470,6 +473,36 @@ export default class ArticleAttributesTab extends PureComponent {
assignedGroups.sort((a, b) => a.sort - b.sort || a.name.localeCompare(b.name));
const isExclusive = Boolean(selectedOption?.exclusive);
const isMerkmalAlreadyAssigned = isAttr
? assignedAttributes.some((a) => a.attributeId === selectedOption?.id)
: assignedProperties.some((p) => p.propertyId === selectedOption?.id);
const isValueAlreadyAssigned = isAttr
? assignedAttributes.some((a) => a.attributeValueId === Number(currentItemId))
: (Boolean(customValueText.trim()) && assignedProperties.some(
(p) => p.propertyId === selectedOption?.id && p.value.trim().toLowerCase() === customValueText.trim().toLowerCase()
));
const isUniqueAlreadyAdded = isExclusive && isMerkmalAlreadyAssigned;
const isAddDisabled =
saving ||
isVariantBlocked ||
!selectedMerkmalKey ||
(isAttr ? !currentItemId || availableItems.length === 0 : !customValueText.trim()) ||
isUniqueAlreadyAdded ||
isValueAlreadyAssigned;
let addTooltipTitle = 'Hinzufügen';
if (isUniqueAlreadyAdded) {
addTooltipTitle = 'Eindeutiges Merkmal ist bereits zugeordnet';
} else if (isValueAlreadyAssigned) {
addTooltipTitle = 'Bereits zugeordnet';
} else if (isVariantBlocked) {
addTooltipTitle = 'Varianten-Merkmal kann nicht zugeordnet werden';
}
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
{/* Unified Add Bar: [Merkmal ▼] [Wert ▼ / Input] [+] */}
@@ -531,16 +564,11 @@ export default class ArticleAttributesTab extends PureComponent {
/>
)}
<Tooltip title="Hinzufügen">
<Tooltip title={addTooltipTitle}>
<span>
<IconButton
color="primary"
disabled={
saving ||
isVariantBlocked ||
!selectedMerkmalKey ||
(isAttr ? !selectedItemId || availableItems.length === 0 : !customValueText.trim())
}
disabled={isAddDisabled}
onClick={() => void this.handleAddItem()}
sx={{
bgcolor: 'primary.main',