Skip to content

Commit 5bbb0b1

Browse files
kevglissjschroth
andauthored
Fixing case and incident form fill from url (#5323)
* Fixing case and incident form fill from url * Fix linting --------- Co-authored-by: Jason Schroth <[email protected]>
1 parent 4aa4217 commit 5bbb0b1

File tree

3 files changed

+76
-61
lines changed

3 files changed

+76
-61
lines changed

src/dispatch/static/dispatch/src/case/type/CaseTypeSelect.vue

+28-17
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
</template>
3838

3939
<script>
40-
import { cloneDeep } from "lodash"
41-
4240
import SearchUtils from "@/search/utils"
4341
import CaseTypeApi from "@/case/type/api"
4442
@@ -48,25 +46,19 @@ export default {
4846
props: {
4947
modelValue: {
5048
type: Object,
51-
default: function () {
52-
return {}
53-
},
49+
default: () => ({}),
5450
},
5551
project: {
56-
type: [Object],
52+
type: Object,
5753
default: null,
5854
},
5955
hint: {
6056
type: String,
61-
default: function () {
62-
return "Case Type to associate"
63-
},
57+
default: () => "Case Type to associate",
6458
},
6559
label: {
6660
type: String,
67-
default: function () {
68-
return "Case Type"
69-
},
61+
default: () => "Case Type",
7062
},
7163
},
7264
@@ -80,6 +72,7 @@ export default {
8072
numItems: 40,
8173
error: null,
8274
categories: [],
75+
selectedCaseType: null,
8376
is_type_in_project: () => {
8477
this.validateType()
8578
return this.error
@@ -90,9 +83,10 @@ export default {
9083
computed: {
9184
case_type: {
9285
get() {
93-
return cloneDeep(this.modelValue)
86+
return this.selectedCaseType || this.modelValue
9487
},
9588
set(value) {
89+
this.selectedCaseType = value
9690
this.$emit("update:modelValue", value)
9791
this.validateType()
9892
},
@@ -130,7 +124,7 @@ export default {
130124
},
131125
fetchData() {
132126
this.error = null
133-
this.loading = "error"
127+
this.loading = true
134128
135129
let filterOptions = {
136130
sortBy: ["name"],
@@ -182,6 +176,14 @@ export default {
182176
} else {
183177
this.more = false
184178
}
179+
180+
// Set the selected case type if it exists in the fetched items
181+
if (this.modelValue && this.modelValue.id) {
182+
const selectedItem = this.items.find((item) => item.id === this.modelValue.id)
183+
if (selectedItem) {
184+
this.selectedCaseType = selectedItem
185+
}
186+
}
185187
})
186188
},
187189
},
@@ -190,9 +192,18 @@ export default {
190192
search(val) {
191193
val && val !== this.select && this.fetchData()
192194
},
193-
value(val) {
194-
if (!val) return
195-
this.items.push(val)
195+
modelValue: {
196+
handler(newValue) {
197+
if (newValue && newValue.id) {
198+
const selectedItem = this.items.find((item) => item.id === newValue.id)
199+
if (selectedItem) {
200+
this.selectedCaseType = selectedItem
201+
}
202+
} else {
203+
this.selectedCaseType = null
204+
}
205+
},
206+
immediate: true,
196207
},
197208
case_type(newCaseType) {
198209
if (newCaseType) {

src/dispatch/static/dispatch/src/incident/priority/IncidentPrioritySelect.vue

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<v-select
3-
v-model="incident_priorities"
3+
v-model="selectedPriority"
44
:items="items"
55
item-title="name"
66
:item-props="(item) => ({ subtitle: item.description })"
@@ -14,8 +14,6 @@
1414
</template>
1515

1616
<script>
17-
import { cloneDeep } from "lodash"
18-
1917
import SearchUtils from "@/search/utils"
2018
import IncidentPriorityApi from "@/incident/priority/api"
2119
@@ -24,12 +22,10 @@ export default {
2422
props: {
2523
modelValue: {
2624
type: Object,
27-
default: function () {
28-
return {}
29-
},
25+
default: () => ({}),
3026
},
3127
project: {
32-
type: [Object],
28+
type: Object,
3329
default: null,
3430
},
3531
status: {
@@ -51,9 +47,17 @@ export default {
5147
},
5248
5349
computed: {
54-
incident_priorities: {
50+
selectedPriority: {
5551
get() {
56-
return cloneDeep(this.modelValue)
52+
if (!this.modelValue) return null
53+
if (this.modelValue.id) {
54+
return this.items.find((item) => item.id === this.modelValue.id) || null
55+
}
56+
// If we only have a name (e.g., from URL params), find by name
57+
if (this.modelValue.name) {
58+
return this.items.find((item) => item.name === this.modelValue.name) || null
59+
}
60+
return null
5761
},
5862
set(value) {
5963
this.$emit("update:modelValue", value)
@@ -64,7 +68,7 @@ export default {
6468
if (!this.project) return null
6569
const stablePriority = this.project.stable_priority
6670
if (!stablePriority) return null
67-
if (this.status == "Stable" && this.modelValue.name != stablePriority.name) {
71+
if (this.status == "Stable" && this.selectedPriority?.name != stablePriority.name) {
6872
return `Priority must be ${stablePriority.name} for Stable incidents`
6973
}
7074
return null
@@ -74,7 +78,7 @@ export default {
7478
methods: {
7579
validatePriority() {
7680
const project_id = this.project?.id || 0
77-
const in_project = this.incident_priorities?.project?.id == project_id
81+
const in_project = this.selectedPriority?.project?.id == project_id
7882
if (in_project) {
7983
this.error = true
8084
} else {
@@ -83,7 +87,7 @@ export default {
8387
},
8488
fetchData() {
8589
this.error = null
86-
this.loading = "error"
90+
this.loading = true
8791
8892
let filterOptions = {
8993
sortBy: ["view_order"],
@@ -121,16 +125,21 @@ export default {
121125
},
122126
},
123127
124-
created() {
125-
this.fetchData()
126-
this.$watch(
127-
(vm) => [vm.project, vm.status],
128-
() => {
128+
watch: {
129+
project: {
130+
handler() {
129131
this.fetchData()
130132
this.validatePriority()
131-
this.$emit("update:modelValue", this.incident_priorities)
132-
}
133-
)
133+
},
134+
deep: true,
135+
},
136+
status() {
137+
this.validatePriority()
138+
},
139+
},
140+
141+
created() {
142+
this.fetchData()
134143
},
135144
}
136145
</script>

src/dispatch/static/dispatch/src/incident/type/IncidentTypeSelect.vue

+19-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<v-select
3-
v-model="incident_type"
3+
v-model="selectedIncidentType"
44
:items="items"
55
:menu-props="{ maxHeight: '400' }"
66
item-title="name"
@@ -32,7 +32,6 @@
3232

3333
<script>
3434
import { cloneDeep } from "lodash"
35-
3635
import SearchUtils from "@/search/utils"
3736
import IncidentTypeApi from "@/incident/type/api"
3837
@@ -42,19 +41,15 @@ export default {
4241
props: {
4342
modelValue: {
4443
type: Object,
45-
default: function () {
46-
return {}
47-
},
44+
default: () => ({}),
4845
},
4946
project: {
50-
type: [Object],
47+
type: Object,
5148
default: null,
5249
},
5350
label: {
5451
type: String,
55-
default: function () {
56-
return "Type"
57-
},
52+
default: () => "Type",
5853
},
5954
},
6055
@@ -65,20 +60,28 @@ export default {
6560
more: false,
6661
numItems: 5,
6762
error: null,
63+
selectedIncidentType: null,
6864
is_type_in_project: () => {
6965
this.validateType()
7066
return this.error
7167
},
7268
}
7369
},
7470
75-
computed: {
76-
incident_type: {
77-
get() {
78-
return cloneDeep(this.modelValue)
71+
watch: {
72+
modelValue: {
73+
immediate: true,
74+
handler(newValue) {
75+
this.selectedIncidentType = cloneDeep(newValue)
7976
},
80-
set(value) {
81-
this.$emit("update:modelValue", value)
77+
},
78+
selectedIncidentType(newValue) {
79+
this.$emit("update:modelValue", newValue)
80+
this.validateType()
81+
},
82+
project: {
83+
handler() {
84+
this.fetchData()
8285
this.validateType()
8386
},
8487
},
@@ -91,7 +94,7 @@ export default {
9194
},
9295
validateType() {
9396
const project_id = this.project?.id || 0
94-
const in_project = this.incident_type?.project?.id == project_id
97+
const in_project = this.selectedIncidentType?.project?.id == project_id
9598
if (in_project) {
9699
this.error = true
97100
} else {
@@ -137,14 +140,6 @@ export default {
137140
138141
created() {
139142
this.fetchData()
140-
this.$watch(
141-
(vm) => [vm.project],
142-
() => {
143-
this.fetchData()
144-
this.validateType()
145-
this.$emit("update:modelValue", this.incident_type)
146-
}
147-
)
148143
},
149144
}
150145
</script>

0 commit comments

Comments
 (0)