Skip to content

Commit

Permalink
fix(workflowengine): require a VueConstructor object as operation plugin
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
blizzz committed Feb 12, 2025
1 parent f2b25a4 commit 46bdf15
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
21 changes: 20 additions & 1 deletion apps/workflowengine/src/components/Rule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
<div class="flow-icon icon-confirm" />
<div class="action">
<Operation :operation="operation" :colored="false">
<div v-if="operation.component"
ref="operationComponent" >

Check failure on line 33 in apps/workflowengine/src/components/Rule.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected no space before '>', but found
</div>
<component :is="operation.options"
v-if="operation.options"
v-else-if="operation.options"
v-model="rule.operation"
@input="updateOperation" />
</Operation>
Expand Down Expand Up @@ -98,9 +101,13 @@ export default {
error: null,
dirty: this.rule.id < 0,
originalRule: null,
component: null,
}
},
computed: {
/**
* @returns {OperatorPlugin}
*/
operation() {
return this.$store.getters.getOperationForRule(this.rule)
},
Expand All @@ -126,10 +133,22 @@ export default {
},
mounted() {
this.originalRule = JSON.parse(JSON.stringify(this.rule))

if (this.operation?.component) {
this.component = new this.operation.component()

Check failure on line 138 in apps/workflowengine/src/components/Rule.vue

View workflow job for this annotation

GitHub Actions / NPM lint

A constructor name should not start with a lowercase letter
this.component.$mount(this.$refs.operationComponent)
this.component.$on('input', this.updateOperation)
this.component.$props.value = this.rule.operation
} else if (this.operation?.options) {
// keeping this in an else for apps that try to be backwards compatible and may ship both
// to be removed in 03/2028
console.warn('Developer warning: `OperatorPlugin.options` is deprecated. Use `OperatorPlugin.components` instead.')
}
},
methods: {
async updateOperation(operation) {
this.$set(this.rule, 'operation', operation)
this.component.$props.value = operation
await this.updateRule()
},
validate(/* state */) {
Expand Down
3 changes: 3 additions & 0 deletions apps/workflowengine/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ const store = new Store({
return rule1.id - rule2.id || rule2.class - rule1.class
})
},
/**
* @return {OperatorPlugin}
*/
getOperationForRule(state) {
return (rule) => state.operations[rule.class]
},
Expand Down
11 changes: 9 additions & 2 deletions apps/workflowengine/src/workflowengine.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ import ShippedChecks from './components/Checks/index.js'
* @property {string} id - The PHP class name of the check
* @property {string} operation - Default value for the operation field
* @property {string} color - Custom color code to be applied for the operator selector
* @property {Vue} component - A vue component to handle the rendering of options
* @property {object} [options] - Deprecated: **Use `component` instead**
*
* A vue component to handle the rendering of options.
* The component should handle the v-model directive properly,
* so it needs a value property to receive data and emit an input
* event once the data has changed
* event once the data has changed.
*
* Will be removed in 03/2028.
* @property {VueConstructor} [component] - A vue constructor as returned by `Vue.extend()`.
* It has to emit the `$input` event when a value was changed.
* The `value` property will be set initially with the rule operation value.
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/workflowengine-workflowengine.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/workflowengine-workflowengine.js.map

Large diffs are not rendered by default.

0 comments on commit 46bdf15

Please sign in to comment.