Skip to content

Commit e8e91c8

Browse files
committed
fix selects, both operator and match selects and value selects
1 parent 0ceb2a9 commit e8e91c8

File tree

3 files changed

+50
-21
lines changed

3 files changed

+50
-21
lines changed

admin_ui/src/components/InputField.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222

2323
<template v-if="choices && type != 'array'">
2424
<OperatorField :columnName="columnName" v-if="isFilter" />
25+
<!-- prevent null value as default -->
2526
<ChoiceSelect
2627
:choices="choices"
2728
:fieldName="columnName"
2829
:isFilter="isFilter"
2930
:isNullable="isNullable"
30-
:value="value"
31+
:value="localValue || 'all'"
3132
/>
3233
</template>
3334

admin_ui/src/components/MatchField.vue

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
<template>
2-
<select :name="columnName + '__match'">
3-
<option
4-
:key="match"
5-
:selected="match == 'contains'"
6-
:value="match"
7-
v-for="match in matches"
8-
>
2+
<select :name="columnName + '__match'" v-model="selectedMatch">
3+
<option :key="match" :value="match" v-for="match in matches">
94
{{ match }}
105
</option>
116
</select>
127
</template>
138

14-
<script setup lang="ts">
15-
import type { PropType } from "vue"
9+
<script lang="ts">
10+
import { defineComponent, type PropType } from "vue"
1611
17-
defineProps({
18-
columnName: {
19-
type: String as PropType<string>,
20-
required: true
12+
export default defineComponent({
13+
props: {
14+
columnName: {
15+
type: String as PropType<string>,
16+
required: true
17+
}
18+
},
19+
data() {
20+
return {
21+
selectedMatch: "contains", // default
22+
matches: ["contains", "exact", "starts", "ends"]
23+
}
24+
},
25+
mounted() {
26+
// read query params from url
27+
const queryValue = this.$route.query[
28+
this.columnName + "__match"
29+
] as string
30+
31+
// use match if present in query params, otherwise keep default
32+
if (queryValue && this.matches.includes(queryValue)) {
33+
this.selectedMatch = queryValue
34+
}
2135
}
2236
})
23-
24-
const matches: string[] = ["contains", "exact", "starts", "ends"]
2537
</script>
2638

2739
<style>

admin_ui/src/components/OperatorField.vue

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<template>
2-
<select :name="columnName + '__operator'">
2+
<select :name="columnName + '__operator'" v-model="selectedOperator">
33
<option
4-
:key="operator.label"
5-
:selected="operator.value == 'e'"
6-
:value="operator.value"
74
v-for="operator in operators"
5+
:key="operator.value"
6+
:value="operator.value"
87
>
98
{{ operator.label }}
109
</option>
@@ -23,6 +22,7 @@ export default defineComponent({
2322
},
2423
data() {
2524
return {
25+
selectedOperator: "e", // default
2626
operators: [
2727
{
2828
label: "Equals",
@@ -50,8 +50,24 @@ export default defineComponent({
5050
}
5151
]
5252
}
53+
},
54+
mounted() {
55+
// read query params from url
56+
const queryValue = this.$route.query[
57+
this.columnName + "__operator"
58+
] as string
59+
60+
// use operator if present in query params otherwise keep default
61+
if (
62+
queryValue &&
63+
this.operators.some(
64+
(operator: any) => operator.value === queryValue
65+
)
66+
) {
67+
this.selectedOperator = queryValue
68+
}
5369
}
5470
})
5571
</script>
5672

57-
<style></style>
73+
<style></style>

0 commit comments

Comments
 (0)