Skip to content

Commit 9c5b75f

Browse files
authored
Merge pull request #83 from DJManuel/main
Add Rule Identifier to RuleSlot
2 parents cc0daeb + 89b9dc2 commit 9c5b75f

File tree

6 files changed

+11
-0
lines changed

6 files changed

+11
-0
lines changed

docs/styling.md

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ The `rule` slot allows for customizing markup around each rule component.
9090

9191
The slot receives an object with the shape of the [RuleSlotProps
9292
object](https://github.com/rtucek/vue-query-builder/blob/master/types/index.d.ts#L47).
93+
An exact rule can be identified based on the `ruleCtrl.ruleIdentifier` for dynamic content.
9394

9495
You'll have to use Vue's [Dynamic
9596
Component](https://vuejs.org/v2/guide/components.html#Dynamic-Components) feature for displaying the

src/QueryBuilderRule.vue

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class QueryBuilderRule extends Vue {
4343
return {
4444
ruleComponent: this.component,
4545
ruleData: this.query.value,
46+
ruleIdentifier: this.query.identifier,
4647
updateRuleData: (ruleData: any) => this.ruleUpdate(ruleData),
4748
};
4849
}

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface GroupCtrlSlotProps {
4747
export interface RuleSlotProps {
4848
ruleComponent: Component | string,
4949
ruleData: any,
50+
ruleIdentifier: string,
5051
updateRuleData: (newData: any) => void,
5152
}
5253

tests/components/Component.vue

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export default class Input extends Vue {
66
@Prop({
77
default: null,
88
}) readonly value!: any;
9+
10+
@Prop({
11+
default: null,
12+
}) readonly identifier!: string;
913
}
1014
</script>
1115

tests/unit/slots.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ describe('Testing slot related features', () => {
182182
<component
183183
:is="props.ruleComponent"
184184
:value="props.ruleData"
185+
:identifier="props.ruleIdentifier"
185186
@input="props.updateRuleData"
186187
class="slot-rule"
187188
/>
@@ -197,6 +198,8 @@ describe('Testing slot related features', () => {
197198
// Verify rule slot is properly rendered
198199
expect(ruleComponent.is(Component)).toBeTruthy();
199200
expect(ruleComponent.vm.$props.value).toBe('A');
201+
expect(rule.vm.$props.query.identifier).toBe('txt');
202+
expect(ruleComponent.vm.$props.identifier).toBe('txt');
200203
ruleComponent.vm.$emit('input', 'a');
201204
expect((rule.emitted('query-update') as any)[0][0]).toStrictEqual({ identifier: 'txt', value: 'a' });
202205

types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export interface GroupCtrlSlotProps {
4747
export interface RuleSlotProps {
4848
ruleComponent: Component | string,
4949
ruleData: any,
50+
ruleIdentifier: string,
5051
updateRuleData: (newData: any) => void,
5152
}

0 commit comments

Comments
 (0)