Skip to content

Commit

Permalink
Adding validation for incident type
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 committed Oct 23, 2024
1 parent ddb0de0 commit 14375e4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default {
}
}
filterOptions = SearchUtils.createParametersFromTableOptions({ ...filterOptions })
filterOptions = SearchUtils.createParametersFromTableOptions({ ...filterOptions }, "CaseType")
CaseTypeApi.getAll(filterOptions)
.then((response) => {
Expand Down Expand Up @@ -170,6 +170,7 @@ export default {
watch: {
project() {
this.validateType()
this.fetchData()
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export default {
watch: {
project() {
this.validatePriority()
this.fetchData()
},
status() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:label="label"
return-object
:loading="loading"
:rules="[validationRule]"
:rules="[is_type_in_project]"
>
<template #item="{ props, item }">
<v-list-item v-bind="props" :title="null">
Expand Down Expand Up @@ -61,34 +61,51 @@ export default {
numItems: 5,
total: 0,
lastProjectId: null,
error: null,
is_type_in_project: () => {
this.validateType()
return this.error
},
}
},
computed: {
selectedIncidentType: {
get() {
return this.modelValue || null
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)
this.validateType()
},
},
isTypeValid() {
const project_id = this.project?.id || 0
return this.selectedIncidentType?.project?.id == project_id
},
validationRule() {
return this.isTypeValid || "Only types in selected project are allowed"
},
},
watch: {
project() {
this.validateType()
this.fetchData()
},
},
methods: {
validateType() {
const project_id = this.project?.id || 0
const in_project = this.selectedIncidentType?.project?.id == project_id
if (in_project) {
this.error = true
} else {
this.error = "Only types in selected project are allowed"
}
},
clearSelection() {
this.selectedIncidentType = null
},
Expand All @@ -112,7 +129,10 @@ export default {
}
}
filterOptions = SearchUtils.createParametersFromTableOptions(filterOptions)
filterOptions = SearchUtils.createParametersFromTableOptions(
{ ...filterOptions },
"IncidentType"
)
IncidentTypeApi.getAll(filterOptions)
.then((response) => {
Expand Down

0 comments on commit 14375e4

Please sign in to comment.