Skip to content

Commit

Permalink
Adding ability to filter cases by participant and assignee (#4707)
Browse files Browse the repository at this point in the history
whitdog47 authored and metroid-samus committed May 16, 2024
1 parent 1551a4e commit d172dfa
Showing 5 changed files with 48 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/dispatch/database/service.py
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ def __init__(self, filter_spec):
def get_named_models(self):
if "model" in self.filter_spec:
model = self.filter_spec["model"]
if model in ["Participant", "Commander"]:
if model in ["Participant", "Commander", "Assignee"]:
return {"IndividualContact"}
if model == "TagAll":
return {"Tag"}
@@ -122,7 +122,7 @@ def get_named_models(self):

def format_for_sqlalchemy(self, query, default_model):
filter_spec = self.filter_spec
if filter_spec.get("model") in ["Participant", "Commander"]:
if filter_spec.get("model") in ["Participant", "Commander", "Assignee"]:
filter_spec["model"] = "IndividualContact"
elif filter_spec.get("model") == "TagAll":
filter_spec["model"] = "Tag"
@@ -359,6 +359,7 @@ def apply_filter_specific_joins(model: Base, filter_spec: dict, query: orm.query
(DispatchUser, "Organization"): (DispatchUser.organizations, True),
(Case, "Tag"): (Case.tags, True),
(Case, "TagType"): (Case.tags, True),
(Case, "IndividualContact"): (Case.participants, True),
(Incident, "Tag"): (Incident.tags, True),
(Incident, "TagType"): (Incident.tags, True),
(Incident, "IndividualContact"): (Incident.participants, True),
@@ -374,6 +375,8 @@ def apply_filter_specific_joins(model: Base, filter_spec: dict, query: orm.query
# Replace mapping if looking for commander
if "Commander" in str(filter_spec):
model_map.update({(Incident, "IndividualContact"): (Incident.commander, True)})
if "Assignee" in str(filter_spec):
model_map.update({(Case, "IndividualContact"): (Case.assignee, True)})

filter_models = get_named_models(filters)
joined_models = []
38 changes: 38 additions & 0 deletions src/dispatch/static/dispatch/src/case/TableFilterDialog.vue
Original file line number Diff line number Diff line change
@@ -42,6 +42,26 @@
:project="local_project"
/>
</v-list-item>
<v-list-item>
<v-card class="mx-auto">
<v-card-title>Case Participant</v-card-title>
<v-card-subtitle>Show only cases with this participant</v-card-subtitle>
<participant-select
class="ml-10 mr-5"
v-model="local_participant"
label="Participant"
hint="Show only cases with this participant"
:project="local_project"
clearable
/>
<v-checkbox
class="ml-10 mr-5"
v-model="local_participant_is_assignee"
label="And this participant is the Assignee"
:disabled="local_participant == null"
/>
</v-card>
</v-list-item>
</v-list>
<v-card-actions>
<v-spacer />
@@ -85,6 +105,8 @@ const local_reported_at = ref({})
const local_status = ref([])
const local_tag = ref([])
const local_tag_type = ref([])
const local_participant = ref(null)
const local_participant_is_assignee = ref(false)
const case_priority = computed(
() => store.state.case_management.table.options.filters.case_priority
@@ -107,10 +129,24 @@ const numFilters = computed(() => {
status.value?.length || 0,
tag.value?.length || 0,
tag_type.value?.length || 0,
local_participant.value == null ? 0 : 1,
])
})
const applyFilters = () => {
let filtered_participant = null
let filtered_assignee = null
if (Array.isArray(local_participant.value)) {
local_participant.value = local_participant.value[0]
}
if (local_participant_is_assignee.value) {
filtered_assignee = local_participant.value
filtered_participant = null
} else {
filtered_assignee = null
filtered_participant = local_participant.value
}
const filters = {
case_priority: local_case_priority.value,
case_severity: local_case_severity.value,
@@ -121,6 +157,8 @@ const applyFilters = () => {
status: local_status.value,
tag: local_tag.value,
tag_type: local_tag_type.value,
participant: filtered_participant,
assignee: filtered_assignee,
}
// Commit the mutation to update the filters in the Vuex store
2 changes: 2 additions & 0 deletions src/dispatch/static/dispatch/src/case/store.js
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ const getDefaultSelectedState = () => {
incidents: [],
loading: false,
name: null,
participant: null,
project: null,
related: [],
reporter: null,
@@ -91,6 +92,7 @@ const state = {
start: null,
end: null,
},
participant: null,
},
q: "",
page: 1,
4 changes: 2 additions & 2 deletions src/dispatch/static/dispatch/src/router/utils.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ export default {
return
}
each(value, function (item) {
if (["commander", "participant"].includes(key)) {
if (["commander", "participant", "assignee"].includes(key)) {
if (has(flatFilters, key)) {
if (typeof item === "string" || item instanceof String) {
flatFilters[key].push(item)
@@ -85,7 +85,7 @@ export default {
}
return
}
if (["commander", "participant"].includes(key)) {
if (["commander", "participant", "assignee"].includes(key)) {
if (typeof value === "string" || value instanceof String) {
if (has(filters, key)) {
filters[key].push({ email: value })
2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/search/utils.js
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@ export default {
if (!value) {
return
}
if (["commander", "participant"].includes(key) && has(value, "email")) {
if (["commander", "participant", "assignee"].includes(key) && has(value, "email")) {
subFilter.push({
model: toPascalCase(key),
field: "email",

0 comments on commit d172dfa

Please sign in to comment.