Description
Hi, first of all thank you for such a great library!
I am facing an issue where I have multiple rules using the same component.
I noticed this behavior when trying to get data into the (custom) component of a (custom / scoped) RuleSlot. Within this component, I have a drop-down that eventually will fetch data from a DB / API. In the end there will be ~30 rules that have a dropdown selection, and in my opinion it is not worth creating 30 custom (pretty much duplicate) dropdown components. Therefor I am trying to use a single component in multiple rules, with different data fetched in the dropdown.
One of the main issue is the identification of the exact rule based on the data that is being forwarded into the RuleSlot:
src/QueryBuilderRule.vue#L81 and src/QueryBuilderRule.vue#L42
Only with this information currently provided, the exact rule can only be found out by matching the ruleComponent
(and ruleData
, dependend if initialValue
is different):
ruleName() {
return this.rules
.find(r => r.component === this.ruleCtrl.ruleComponent)
.name;
},
however, as I have multiple rules that have the same component, this won't work (it only give back the first element in the rules array it finds).
To fix this behavior, the identifier
from the rules would be needed inside the RuleSlot.
Basically in the get ruleSlotProps
(src/QueryBuilderRule.vue#L42) adding one item to the object being forwarded to the RuleSlot:
get ruleSlotProps(): RuleSlotProps {
return {
ruleComponent: this.component,
ruleData: this.query.value,
ruleIdentifier: this.query.identifier
updateRuleData: (ruleData: any) => this.ruleUpdate(ruleData),
};
}
When this ruleIdentifier
is available in the RuleSlot the ruleName (and exact rule) can be found:
.find(r => r.identifier=== this.ruleCtrl.ruleIdentifier)
Thank you!