Skip to content

Commit

Permalink
Fixing case and incident form fill from url
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss committed Oct 10, 2024
1 parent 2d5a5b4 commit 63def27
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 60 deletions.
44 changes: 28 additions & 16 deletions src/dispatch/static/dispatch/src/case/type/CaseTypeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

<script>
import { cloneDeep } from "lodash"

Check failure on line 40 in src/dispatch/static/dispatch/src/case/type/CaseTypeSelect.vue

View workflow job for this annotation

GitHub Actions / build

'cloneDeep' is defined but never used
import SearchUtils from "@/search/utils"
import CaseTypeApi from "@/case/type/api"
Expand All @@ -48,25 +47,19 @@ export default {
props: {
modelValue: {
type: Object,
default: function () {
return {}
},
default: () => ({}),
},
project: {
type: [Object],
type: Object,
default: null,
},
hint: {
type: String,
default: function () {
return "Case Type to associate"
},
default: () => "Case Type to associate",
},
label: {
type: String,
default: function () {
return "Case Type"
},
default: () => "Case Type",
},
},
Expand All @@ -80,6 +73,7 @@ export default {
numItems: 40,
error: null,
categories: [],
selectedCaseType: null,
is_type_in_project: () => {
this.validateType()
return this.error
Expand All @@ -90,9 +84,10 @@ export default {
computed: {
case_type: {
get() {
return cloneDeep(this.modelValue)
return this.selectedCaseType || this.modelValue
},
set(value) {
this.selectedCaseType = value
this.$emit("update:modelValue", value)
this.validateType()
},
Expand Down Expand Up @@ -130,7 +125,7 @@ export default {
},
fetchData() {
this.error = null
this.loading = "error"
this.loading = true
let filterOptions = {
sortBy: ["name"],
Expand Down Expand Up @@ -182,6 +177,14 @@ export default {
} else {
this.more = false
}
// Set the selected case type if it exists in the fetched items
if (this.modelValue && this.modelValue.id) {
const selectedItem = this.items.find((item) => item.id === this.modelValue.id)
if (selectedItem) {
this.selectedCaseType = selectedItem
}
}
})
},
},
Expand All @@ -190,9 +193,18 @@ export default {
search(val) {
val && val !== this.select && this.fetchData()
},
value(val) {
if (!val) return
this.items.push(val)
modelValue: {
handler(newValue) {
if (newValue && newValue.id) {
const selectedItem = this.items.find((item) => item.id === newValue.id)
if (selectedItem) {
this.selectedCaseType = selectedItem
}
} else {
this.selectedCaseType = null
}
},
immediate: true,
},
case_type(newCaseType) {
if (newCaseType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-select
v-model="incident_priorities"
v-model="selectedPriority"
:items="items"
item-title="name"
:item-props="(item) => ({ subtitle: item.description })"
Expand All @@ -14,8 +14,6 @@
</template>

<script>
import { cloneDeep } from "lodash"
import SearchUtils from "@/search/utils"
import IncidentPriorityApi from "@/incident/priority/api"
Expand All @@ -24,12 +22,10 @@ export default {
props: {
modelValue: {
type: Object,
default: function () {
return {}
},
default: () => ({}),
},
project: {
type: [Object],
type: Object,
default: null,
},
status: {
Expand All @@ -51,9 +47,17 @@ export default {
},
computed: {
incident_priorities: {
selectedPriority: {
get() {
return cloneDeep(this.modelValue)
if (!this.modelValue) return null
if (this.modelValue.id) {
return this.items.find((item) => item.id === this.modelValue.id) || null
}
// If we only have a name (e.g., from URL params), find by name
if (this.modelValue.name) {
return this.items.find((item) => item.name === this.modelValue.name) || null
}
return null
},
set(value) {
this.$emit("update:modelValue", value)
Expand All @@ -64,7 +68,7 @@ export default {
if (!this.project) return null
const stablePriority = this.project.stable_priority
if (!stablePriority) return null
if (this.status == "Stable" && this.modelValue.name != stablePriority.name) {
if (this.status == "Stable" && this.selectedPriority?.name != stablePriority.name) {
return `Priority must be ${stablePriority.name} for Stable incidents`
}
return null
Expand All @@ -74,7 +78,7 @@ export default {
methods: {
validatePriority() {
const project_id = this.project?.id || 0
const in_project = this.incident_priorities?.project?.id == project_id
const in_project = this.selectedPriority?.project?.id == project_id
if (in_project) {
this.error = true
} else {
Expand All @@ -83,7 +87,7 @@ export default {
},
fetchData() {
this.error = null
this.loading = "error"
this.loading = true
let filterOptions = {
sortBy: ["view_order"],
Expand Down Expand Up @@ -121,16 +125,21 @@ export default {
},
},
created() {
this.fetchData()
this.$watch(
(vm) => [vm.project, vm.status],
() => {
watch: {
project: {
handler() {
this.fetchData()
this.validatePriority()
this.$emit("update:modelValue", this.incident_priorities)
}
)
},
deep: true,
},
status() {
this.validatePriority()
},
},
created() {
this.fetchData()
},
}
</script>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-select
v-model="incident_type"
v-model="selectedIncidentType"
:items="items"
:menu-props="{ maxHeight: '400' }"
item-title="name"
Expand Down Expand Up @@ -32,7 +32,6 @@

<script>
import { cloneDeep } from "lodash"
import SearchUtils from "@/search/utils"
import IncidentTypeApi from "@/incident/type/api"
Expand All @@ -42,19 +41,15 @@ export default {
props: {
modelValue: {
type: Object,
default: function () {
return {}
},
default: () => ({}),
},
project: {
type: [Object],
type: Object,
default: null,
},
label: {
type: String,
default: function () {
return "Type"
},
default: () => "Type",
},
},
Expand All @@ -65,20 +60,28 @@ export default {
more: false,
numItems: 5,
error: null,
selectedIncidentType: null,
is_type_in_project: () => {
this.validateType()
return this.error
},
}
},
computed: {
incident_type: {
get() {
return cloneDeep(this.modelValue)
watch: {
modelValue: {
immediate: true,
handler(newValue) {
this.selectedIncidentType = cloneDeep(newValue)
},
set(value) {
this.$emit("update:modelValue", value)
},
selectedIncidentType(newValue) {
this.$emit("update:modelValue", newValue)
this.validateType()
},
project: {
handler() {
this.fetchData()
this.validateType()
},
},
Expand All @@ -91,7 +94,7 @@ export default {
},
validateType() {
const project_id = this.project?.id || 0
const in_project = this.incident_type?.project?.id == project_id
const in_project = this.selectedIncidentType?.project?.id == project_id
if (in_project) {
this.error = true
} else {
Expand Down Expand Up @@ -137,14 +140,6 @@ export default {
created() {
this.fetchData()
this.$watch(
(vm) => [vm.project],
() => {
this.fetchData()
this.validateType()
this.$emit("update:modelValue", this.incident_type)
}
)
},
}
</script>

0 comments on commit 63def27

Please sign in to comment.