Fix logic bugs

This commit is contained in:
Julien Nahum 2024-01-17 14:26:31 +01:00
parent 8655f8d92e
commit dc3608f085
5 changed files with 49 additions and 40 deletions

View File

@ -83,6 +83,10 @@ class FormLogicConditionChecker
private function checkListContains ($condition, $fieldValue): bool { private function checkListContains ($condition, $fieldValue): bool {
if (is_null($fieldValue)) return false; if (is_null($fieldValue)) return false;
if (!is_array($fieldValue)) {
return $this->checkEquals($condition, $fieldValue);
}
if (is_array($condition['value'])) { if (is_array($condition['value'])) {
return count(array_intersect($condition['value'], $fieldValue)) === count($condition['value']); return count(array_intersect($condition['value'], $fieldValue)) === count($condition['value']);
} else { } else {

View File

@ -1,6 +1,6 @@
<template> <template>
<div v-if="isMounted" class="flex flex-wrap"> <div v-if="content" class="flex flex-wrap">
<div class="w-full font-semibold text-gray-700 dark:text-gray-300 mb-2"> <div class="w-full font-semibold text-gray-700 dark:text-gray-300 mb-2">
{{ property.name }} {{ property.name }}
</div> </div>
@ -9,7 +9,7 @@
@update:model-value="operatorChanged()" @update:model-value="operatorChanged()"
/> />
<template v-if="hasInput"> <template v-if="needsInput">
<component v-bind="inputComponentData" :is="inputComponentData.component" v-model="content.value" class="w-full" <component v-bind="inputComponentData" :is="inputComponentData.component" v-model="content.value" class="w-full"
:name="'value_'+property.id" placeholder="Filter Value" :name="'value_'+property.id" placeholder="Filter Value"
@update:model-value="emitInput()" @update:model-value="emitInput()"
@ -24,14 +24,13 @@ import OpenFilters from '../../../../../data/open_filters.json'
export default { export default {
components: { }, components: { },
props: { props: {
value: { required: true } modelValue: { required: true }
}, },
data () { data () {
return { return {
content: { ...this.value }, content: { ...this.modelValue },
available_filters: OpenFilters, available_filters: OpenFilters,
isMounted: false,
hasInput: false, hasInput: false,
inputComponent: { inputComponent: {
text: 'TextInput', text: 'TextInput',
@ -84,22 +83,45 @@ export default {
name: this.optionFilterNames(key, this.property.type) name: this.optionFilterNames(key, this.property.type)
} }
}) })
},
needsInput () {
const operator = this.selectedOperator()
if (!operator) {
return false
} }
const operatorFormat = operator.format
if (!operatorFormat) return true
if (operator.expected_type === 'boolean' && operatorFormat.type === 'enum' && operatorFormat.values.length === 1) {
return false
} else if (operator.expected_type === 'object' && operatorFormat.type === 'empty' && operatorFormat.values === '{}') {
return false
}
return true
},
}, },
mounted () { watch: {
if (!this.content.operator) { modelValue() {
this.content.operator = this.operators[0].value if (this.modelValue) {
this.operatorChanged() console.log(this.modelValue)
} else { this.content = {
this.hasInput = this.needsInput() operator: this.operators[0].value,
} ...this.modelValue,
property_meta: {
this.content.property_meta = {
id: this.property.id, id: this.property.id,
type: this.property.type type: this.property.type
} }
this.isMounted = true }
}
},
'content.operator': function (val) {
if (val) {
console.log(val,'operatorChanged')
this.operatorChanged()
}
}
}, },
methods: { methods: {
@ -122,7 +144,6 @@ export default {
const operator = this.selectedOperator() const operator = this.selectedOperator()
const operatorFormat = operator.format const operatorFormat = operator.format
this.hasInput = this.needsInput()
if (operator.expected_type === 'boolean' && operatorFormat.type === 'enum' && operatorFormat.values.length === 1) { if (operator.expected_type === 'boolean' && operatorFormat.type === 'enum' && operatorFormat.values.length === 1) {
this.content.value = operator.format.values[0] this.content.value = operator.format.values[0]
@ -133,22 +154,6 @@ export default {
} }
this.emitInput() this.emitInput()
}, },
needsInput () {
const operator = this.selectedOperator()
if (!operator) {
return false
}
const operatorFormat = operator.format
if (!operatorFormat) return true
if (operator.expected_type === 'boolean' && operatorFormat.type === 'enum' && operatorFormat.values.length === 1) {
return false
} else if (operator.expected_type === 'object' && operatorFormat.type === 'empty' && operatorFormat.values === '{}') {
return false
}
return true
},
selectedOperator () { selectedOperator () {
if (!this.content.operator) { if (!this.content.operator) {
return null return null

View File

@ -5,7 +5,7 @@
</div> </div>
<dropdown v-else class="inline"> <dropdown v-else class="inline">
<template #trigger="{toggle}"> <template #trigger="{toggle}">
<v-button color="white" class="mr-2" @click="toggle"> <v-button color="white" @click="toggle">
<svg class="w-4 h-4 inline -mt-1" viewBox="0 0 16 4" fill="none" <svg class="w-4 h-4 inline -mt-1" viewBox="0 0 16 4" fill="none"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
> >

View File

@ -20,7 +20,7 @@
{{ form.title }} {{ form.title }}
</h2> </h2>
<div class="flex"> <div class="flex">
<extra-menu :form="form"/> <extra-menu class="mr-2" :form="form"/>
<v-button v-track.view_form_click="{form_id:form.id, form_slug:form.slug}" target="_blank" <v-button v-track.view_form_click="{form_id:form.id, form_slug:form.slug}" target="_blank"
:href="form.share_url" color="white" :href="form.share_url" color="white"

View File

@ -21,12 +21,12 @@
</div> </div>
</div> </div>
<div class="flex bg-white"> <div class="flex bg-white">
<div class="w-full md:w-4/5 lg:w-3/5 md:mx-auto md:max-w-4xl px-4"> <div class="w-full md:w-4/5 lg:w-3/5 md:mx-auto md:max-w-4xl">
<div class="mt-8 pb-0"> <div class="mt-8 pb-0">
<text-input v-if="forms.length > 0" class="mb-6" v-model="search" name="search" label="Search a form" <text-input v-if="forms.length > 0" class="mb-6 px-4" v-model="search" name="search" label="Search a form"
placeholder="Name of form to search" placeholder="Name of form to search"
/> />
<div v-if="allTags.length > 0" class="mb-4"> <div v-if="allTags.length > 0" class="mb-4 px-6">
<div v-for="tag in allTags" :key="tag" <div v-for="tag in allTags" :key="tag"
:class="[ :class="[
'inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ring-1 ring-inset cursor-pointer mr-2', 'inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ring-1 ring-inset cursor-pointer mr-2',