Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(workflowengine): minimally adapt check operator FileMimeType to u…
…se web component

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Apr 3, 2025
commit e97b4702daf4db4cb49a247546e571c8f2b76e90
4 changes: 2 additions & 2 deletions apps/workflowengine/src/components/Check.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export default {
this.currentOperator = this.operators.find((operator) => operator.operator === this.check.operator)

if (this.currentElement) {
console.error(this.$refs)
this.$refs.checkComponent.value = this.currentOption
// If we do not set it, the check`s value would remain empty. Unsure why Vue behaves this way.
this.$refs.checkComponent.modelValue = undefined
} else if (this.currentOption?.component) {
// keeping this in an else for apps that try to be backwards compatible and may ship both
// to be removed in 03/2028
Expand Down
35 changes: 29 additions & 6 deletions apps/workflowengine/src/components/Checks/FileMimeType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
-->
<template>
<div>
<NcSelect :value="currentValue"
<NcSelect
:model-value="newValue"
:placeholder="t('workflowengine', 'Select a file type')"
label="label"
:options="options"
Expand All @@ -30,8 +31,8 @@
</template>
</NcSelect>
<input v-if="!isPredefined"
:model-value="newValue"
type="text"
:value="currentValue.id"
:placeholder="t('workflowengine', 'e.g. httpd/unix-directory')"
@input="updateCustom">
</div>
Expand All @@ -50,8 +51,10 @@ export default {
NcSelect,
},
mixins: [
valueMixin,
],

emits: ['update:model-value'],

data() {
return {
predefinedTypes: [
Expand All @@ -76,8 +79,18 @@ export default {
id: 'application/pdf',
},
],
newValue: [],
}
},
props: {
modelValue: {
type: String,
default: '',
},
},
beforeMount() {
this.updateInternalValue()
},
computed: {
options() {
return [...this.predefinedTypes, this.customValue]
Expand Down Expand Up @@ -108,6 +121,12 @@ export default {
}
},
},
watch: {
modelValue() {
console.error("DEBUG: watch modelValue fileSystemTag")
this.updateInternalValue()
},
},
methods: {
validateRegex(string) {
const regexRegex = /^\/(.*)\/([gui]{0,3})$/
Expand All @@ -117,12 +136,16 @@ export default {
setValue(value) {
if (value !== null) {
this.newValue = value.id
this.$emit('input', this.newValue)
this.$emit('update:model-value', this.newValue)
}
},
updateCustom(event) {
this.newValue = event.target.value
this.$emit('input', this.newValue)
this.newValue = event.target.value || event.detail[0]
this.$emit('update:model-value', this.newValue)
},
updateInternalValue() {
console.error("DEBUG: updateInternalValue filemimetype " + this.modelValue)
this.newValue = this.modelValue
},
},
}
Expand Down
22 changes: 3 additions & 19 deletions apps/workflowengine/src/components/Checks/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { stringValidator, validateIPv4, validateIPv6 } from '../../helpers/validators.js'
import { registerCustomElement } from '../../helpers/window.js'
import FileMimeType from './FileMimeType.vue'
import FileSystemTag from './FileSystemTag.vue'

Expand Down Expand Up @@ -34,7 +35,7 @@ const FileChecks = [
class: 'OCA\\WorkflowEngine\\Check\\FileMimeType',
name: t('workflowengine', 'File MIME type'),
operators: stringOrRegexOperators,
component: FileMimeType,
element: registerCustomElement(FileMimeType, 'oca-workflowengine-checks-file_mime_type'),
},

{
Expand Down Expand Up @@ -80,25 +81,8 @@ const FileChecks = [
{ operator: 'is', name: t('workflowengine', 'is tagged with') },
{ operator: '!is', name: t('workflowengine', 'is not tagged with') },
],
webComponent: registerWebComponent(FileSystemTag, 'oca-workflowengine-file_system_tag'),
element: registerCustomElement(FileSystemTag, 'oca-workflowengine-file_system_tag'),
},
]

/**
*
* @param VueComponent
* @param webComponentId
*/
function registerWebComponent(VueComponent, webComponentId) {
const WrappedComponent = wrap(Vue, VueComponent)
window.customElements.define(webComponentId, WrappedComponent)

// In Vue 2, wrap doesn't support disabling shadow :(
// Disable with a hack
Object.defineProperty(WrappedComponent.prototype, 'attachShadow', { value() { return this } })
Object.defineProperty(WrappedComponent.prototype, 'shadowRoot', { get() { return this } })

return webComponentId
}

export default FileChecks
30 changes: 30 additions & 0 deletions apps/workflowengine/src/helpers/window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import wrap from '@vue/web-component-wrapper'
import Vue from 'vue'

/**
*
* @param VueComponent {Object} The Vue component to turn into a Web Components custom element.
* @param customElementId {string} The element name, it must be unique. Recommended pattern oca-$appid-(checks|operations)-$use_case, example: oca-my_app-checks-request_user_agent
*/
function registerCustomElement(VueComponent, customElementId) {
const WrappedComponent = wrap(Vue, VueComponent)
if (window.customElements.get(customElementId)) {
console.error('Custom element with ID ' + customElementId + ' is already defined!')
throw new Error('Custom element with ID ' + customElementId + ' is already defined!')
}
window.customElements.define(customElementId, WrappedComponent)

// In Vue 2, wrap doesn't support disabling shadow :(
// Disable with a hack
Object.defineProperty(WrappedComponent.prototype, 'attachShadow', { value() { return this } })
Object.defineProperty(WrappedComponent.prototype, 'shadowRoot', { get() { return this } })

return customElementId
}

export { registerCustomElement }