feat(wizard): support OR logic for requirements (at least one dependency satisfies requirements)
All checks were successful
Staging Build / build (push) Successful in 3m32s
All checks were successful
Staging Build / build (push) Successful in 3m32s
This commit is contained in:
@@ -55,7 +55,7 @@ function toggleModuleInList(
|
||||
const beforeLength = next.length
|
||||
next = next.filter(mId => {
|
||||
const m = modules.find(mod => mod.id === mId)
|
||||
return !m?.requirements || m.requirements.every(reqId => next.includes(reqId))
|
||||
return !m?.requirements || m.requirements.length === 0 || m.requirements.some(reqId => next.includes(reqId))
|
||||
})
|
||||
changed = next.length !== beforeLength
|
||||
}
|
||||
@@ -69,7 +69,7 @@ function toggleModuleInList(
|
||||
|
||||
function isModuleDisabled(module: ProductModule, selectedModules: string[]): boolean {
|
||||
const requirementsMet = !module.requirements?.length ||
|
||||
module.requirements.every(reqId => selectedModules.includes(reqId))
|
||||
module.requirements.some(reqId => selectedModules.includes(reqId))
|
||||
const isExcluded = module.exclusions?.some(exId => selectedModules.includes(exId))
|
||||
return !requirementsMet || !!isExcluded
|
||||
}
|
||||
@@ -237,12 +237,12 @@ export function OrderWizard({
|
||||
|
||||
// Requirements check
|
||||
if (prod.requirements && prod.requirements.length > 0) {
|
||||
const missing = prod.requirements.filter(reqId => !selectedProductIds.includes(reqId))
|
||||
if (missing.length > 0) {
|
||||
const names = missing
|
||||
const hasMetRequirement = prod.requirements.some(reqId => selectedProductIds.includes(reqId))
|
||||
if (!hasMetRequirement) {
|
||||
const names = prod.requirements
|
||||
.map(reqId => products.find(p => p.id === reqId)?.name || reqId)
|
||||
.join(', ')
|
||||
errors.push(`"${prod.name}" benötigt das Produkt: ${names}`)
|
||||
.join(' oder ')
|
||||
errors.push(`"${prod.name}" benötigt mindestens eines dieser Produkte: ${names}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -898,8 +898,8 @@ export function OrderWizard({
|
||||
)}
|
||||
{disabled && (
|
||||
<p className="text-[10px] text-destructive mt-1">
|
||||
{module.requirements?.some(
|
||||
reqId => !sel?.moduleIds.includes(reqId)
|
||||
{module.requirements?.length && !module.requirements.some(
|
||||
reqId => sel?.moduleIds.includes(reqId)
|
||||
)
|
||||
? 'Benötigt weitere Module'
|
||||
: 'Nicht kombinierbar mit aktueller Auswahl'}
|
||||
|
||||
Reference in New Issue
Block a user