Skip to content

Commit 46bdf15

Browse files
committed
fix(workflowengine): require a VueConstructor object as operation plugin
solves an incompatibility issue when the providing app registers their code from an incompatible nextcloud-vue version. Also changes and clarifies WorkflowEngine API. This is necessary to stay compatible with the original way, but also promotes usage of the originally declared but never used "component" attribute on registration. Signed-off-by: Arthur Schiwon <[email protected]>
1 parent f2b25a4 commit 46bdf15

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

apps/workflowengine/src/components/Rule.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
<div class="flow-icon icon-confirm" />
3030
<div class="action">
3131
<Operation :operation="operation" :colored="false">
32+
<div v-if="operation.component"
33+
ref="operationComponent" >
34+
</div>
3235
<component :is="operation.options"
33-
v-if="operation.options"
36+
v-else-if="operation.options"
3437
v-model="rule.operation"
3538
@input="updateOperation" />
3639
</Operation>
@@ -98,9 +101,13 @@ export default {
98101
error: null,
99102
dirty: this.rule.id < 0,
100103
originalRule: null,
104+
component: null,
101105
}
102106
},
103107
computed: {
108+
/**
109+
* @returns {OperatorPlugin}
110+
*/
104111
operation() {
105112
return this.$store.getters.getOperationForRule(this.rule)
106113
},
@@ -126,10 +133,22 @@ export default {
126133
},
127134
mounted() {
128135
this.originalRule = JSON.parse(JSON.stringify(this.rule))
136+
137+
if (this.operation?.component) {
138+
this.component = new this.operation.component()
139+
this.component.$mount(this.$refs.operationComponent)
140+
this.component.$on('input', this.updateOperation)
141+
this.component.$props.value = this.rule.operation
142+
} else if (this.operation?.options) {
143+
// keeping this in an else for apps that try to be backwards compatible and may ship both
144+
// to be removed in 03/2028
145+
console.warn('Developer warning: `OperatorPlugin.options` is deprecated. Use `OperatorPlugin.components` instead.')
146+
}
129147
},
130148
methods: {
131149
async updateOperation(operation) {
132150
this.$set(this.rule, 'operation', operation)
151+
this.component.$props.value = operation
133152
await this.updateRule()
134153
},
135154
validate(/* state */) {

apps/workflowengine/src/store.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ const store = new Store({
127127
return rule1.id - rule2.id || rule2.class - rule1.class
128128
})
129129
},
130+
/**
131+
* @return {OperatorPlugin}
132+
*/
130133
getOperationForRule(state) {
131134
return (rule) => state.operations[rule.class]
132135
},

apps/workflowengine/src/workflowengine.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@ import ShippedChecks from './components/Checks/index.js'
3030
* @property {string} id - The PHP class name of the check
3131
* @property {string} operation - Default value for the operation field
3232
* @property {string} color - Custom color code to be applied for the operator selector
33-
* @property {Vue} component - A vue component to handle the rendering of options
33+
* @property {object} [options] - Deprecated: **Use `component` instead**
34+
*
35+
* A vue component to handle the rendering of options.
3436
* The component should handle the v-model directive properly,
3537
* so it needs a value property to receive data and emit an input
36-
* event once the data has changed
38+
* event once the data has changed.
39+
*
40+
* Will be removed in 03/2028.
41+
* @property {VueConstructor} [component] - A vue constructor as returned by `Vue.extend()`.
42+
* It has to emit the `$input` event when a value was changed.
43+
* The `value` property will be set initially with the rule operation value.
3744
*/
3845

3946
/**

dist/workflowengine-workflowengine.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/workflowengine-workflowengine.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)