- Conversation Target: {{ conversation_target }}
-
@@ -52,27 +49,24 @@ export default {
type: Object,
default: null,
},
- hint: {
+ label: {
type: String,
- default: () => "Case Type to associate",
+ default: () => "Type",
},
- label: {
+ hint: {
type: String,
- default: () => "Case Type",
+ default: () => "Case Type to associate",
},
},
data() {
return {
- conversation_target: null,
loading: false,
items: [],
- search: null,
more: false,
numItems: 40,
error: null,
- categories: [],
- selectedCaseType: null,
+ lastProjectId: null,
is_type_in_project: () => {
this.validateType()
return this.error
@@ -81,41 +75,35 @@ export default {
},
computed: {
- case_type: {
+ selectedCaseType: {
get() {
- return this.selectedCaseType || this.modelValue
+ if (!this.modelValue) return null
+ if (this.modelValue.id) {
+ return this.items.find((item) => item.id === this.modelValue.id) || null
+ }
+ if (this.modelValue.name) {
+ return this.items.find((item) => item.name === this.modelValue.name) || null
+ }
+ return null
},
set(value) {
- this.selectedCaseType = value
this.$emit("update:modelValue", value)
this.validateType()
},
},
show_error() {
- let items_names = this.items.map((item) => item.name)
- let selected_item = this.case_type?.name || ""
- if (items_names.includes(selected_item) || selected_item == "") {
- return null
- }
- return "Not a valid case type"
+ return null // Implement any specific error logic here if needed
},
},
methods: {
loadMore() {
- this.numItems = this.numItems + 5
+ this.numItems += 40
this.fetchData()
},
validateType() {
- let in_project
- if (this.project?.name) {
- let project_name = this.project?.name || ""
- in_project = this.case_type?.project?.name == project_name
- } else {
- let project_id = this.project?.id || 0
- in_project = this.case_type?.project?.id == project_id
- }
-
+ const project_id = this.project?.id || 0
+ const in_project = this.selectedCaseType?.project?.id == project_id
if (in_project) {
this.error = true
} else {
@@ -144,86 +132,58 @@ export default {
filterOptions = SearchUtils.createParametersFromTableOptions({ ...filterOptions })
- CaseTypeApi.getAll(filterOptions).then((response) => {
- // re-sort items by oncall service
- this.items = []
- this.categories = []
- let new_items = {}
- response.data.items.forEach((item) => {
- let category = "Team: " + (item.oncall_service?.name || "None")
- new_items[category] = new_items[category] || []
- new_items[category].push(item)
+ CaseTypeApi.getAll(filterOptions)
+ .then((response) => {
+ this.items = []
+ let new_items = {}
+ response.data.items.forEach((item) => {
+ let category = "Team: " + (item.oncall_service?.name || "None")
+ new_items[category] = new_items[category] || []
+ new_items[category].push(item)
+ })
+ let keys = Object.keys(new_items)
+ keys.sort((a, b) => {
+ if (a === "Team: None") return 1
+ if (b === "Team: None") return -1
+ return a.localeCompare(b)
+ })
+ keys.forEach((category) => {
+ this.items.push({ category: category })
+ for (let item of new_items[category]) {
+ this.items.push(item)
+ }
+ })
+ this.more = response.data.total > this.items.length
})
- let keys = Object.keys(new_items)
- // ensure Team: None is always at the end
- keys.sort((a, b) => {
- if (a === "Team: None") return 1
- if (b === "Team: None") return -1
- return a.localeCompare(b)
+ .catch((error) => {
+ console.error("Error fetching case types:", error)
+ this.error = "Failed to load case types"
})
- keys.forEach((category) => {
- this.items.push({ category: category })
- for (let item of new_items[category]) {
- this.items.push(item)
- }
+ .finally(() => {
+ this.loading = false
})
-
- this.total = response.data.total
- this.loading = false
-
- if (this.items.length < this.total) {
- this.more = true
- } 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
- }
- }
- })
+ },
+ resetSelection() {
+ this.$emit("update:modelValue", null)
},
},
watch: {
- search(val) {
- val && val !== this.select && this.fetchData()
- },
- 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
+ project: {
+ handler(newProject) {
+ if (newProject?.id !== this.lastProjectId) {
+ this.lastProjectId = newProject?.id
+ this.resetSelection()
+ this.fetchData()
}
+ this.validateType()
},
- immediate: true,
- },
- case_type(newCaseType) {
- if (newCaseType) {
- this.conversation_target = newCaseType.conversation_target
- } else {
- this.conversation_target = null
- }
+ deep: true,
},
},
created() {
this.fetchData()
- this.$watch(
- (vm) => [vm.project],
- () => {
- this.fetchData()
- this.validateType()
- this.$emit("update:modelValue", this.case_type)
- }
- )
},
}
diff --git a/src/dispatch/static/dispatch/src/incident/priority/IncidentPrioritySelect.vue b/src/dispatch/static/dispatch/src/incident/priority/IncidentPrioritySelect.vue
index d9de9659d804..08ab2d6e0270 100644
--- a/src/dispatch/static/dispatch/src/incident/priority/IncidentPrioritySelect.vue
+++ b/src/dispatch/static/dispatch/src/incident/priority/IncidentPrioritySelect.vue
@@ -39,6 +39,7 @@ export default {
loading: false,
items: [],
error: null,
+ lastProjectId: null,
is_priority_in_project: () => {
this.validatePriority()
return this.error
@@ -123,12 +124,19 @@ export default {
this.loading = false
})
},
+ resetSelection() {
+ this.$emit("update:modelValue", null)
+ },
},
watch: {
project: {
- handler() {
- this.fetchData()
+ handler(newProject) {
+ if (newProject?.id !== this.lastProjectId) {
+ this.lastProjectId = newProject?.id
+ this.resetSelection()
+ this.fetchData()
+ }
this.validatePriority()
},
deep: true,
diff --git a/src/dispatch/static/dispatch/src/incident/type/IncidentTypeSelect.vue b/src/dispatch/static/dispatch/src/incident/type/IncidentTypeSelect.vue
index 4f936fd174a5..e7e8c62c3d51 100644
--- a/src/dispatch/static/dispatch/src/incident/type/IncidentTypeSelect.vue
+++ b/src/dispatch/static/dispatch/src/incident/type/IncidentTypeSelect.vue
@@ -7,7 +7,7 @@
:label="label"
return-object
:loading="loading"
- :rules="[is_type_in_project]"
+ :rules="[validationRule]"
>