Skip to content

Commit e299112

Browse files
committed
enable populating the reference KeySearch from query params
1 parent a010d91 commit e299112

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

admin_ui/src/components/KeySearch.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
v-show="showModal"
2121
:isFilter="isFilter"
2222
:tableName="tableName"
23+
:initialReferenceID="hiddenSelectedValue"
2324
@close="showModal = false"
2425
@update="handleUpdate($event)"
2526
/>
@@ -84,9 +85,15 @@ export default defineComponent({
8485
this.hiddenSelectedValue = newValue
8586
}
8687
},
87-
async mounted() {
88-
this.selectedValue = this.readable
89-
this.hiddenSelectedValue = this.rowID
88+
mounted() {
89+
if (this.isFilter) {
90+
const queryValue = this.$route.query[this.fieldName]
91+
if (queryValue) {
92+
// only need FK query value (e.g director=1),
93+
// modal will emit readable automatically
94+
this.hiddenSelectedValue = queryValue
95+
}
96+
}
9097
}
9198
})
9299
</script>

admin_ui/src/components/KeySearchModal.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export default defineComponent({
6363
isNullable: {
6464
type: Boolean as PropType<boolean>,
6565
default: true
66+
},
67+
initialReferenceID: {
68+
type: undefined as unknown as PropType<RowID | undefined>
6669
}
6770
},
6871
data() {
@@ -118,13 +121,29 @@ export default defineComponent({
118121
},
119122
selectResult(id: RowID | null, readable: string) {
120123
this.$emit("update", { id, readable })
124+
},
125+
async emitInitialReferenceID() {
126+
if (!this.initialReferenceID) return
127+
128+
// Look for readable value in fetched IDs
129+
const match = this.ids.find(
130+
([id]) => id === this.initialReferenceID
131+
)
132+
133+
if (match) {
134+
this.$emit("update", {
135+
id: match[0],
136+
readable: match[1]
137+
})
138+
}
121139
}
122140
},
123141
watch: {
124142
async tableName(value: string) {
125143
this.offset = 0
126144
if (value) {
127145
this.ids = await this.fetchData()
146+
await this.emitInitialReferenceID()
128147
}
129148
},
130149
async searchTerm() {
@@ -144,6 +163,7 @@ export default defineComponent({
144163
async mounted() {
145164
if (this.tableName) {
146165
this.ids = await this.fetchData()
166+
await this.emitInitialReferenceID()
147167
}
148168
}
149169
})

0 commit comments

Comments
 (0)