Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to filter cases by participant and assignee #4707

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/dispatch/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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"
Expand Down Expand Up @@ -360,6 +360,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),
Expand All @@ -375,6 +376,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 = []
Expand Down
38 changes: 38 additions & 0 deletions src/dispatch/static/dispatch/src/case/TableFilterDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/dispatch/static/dispatch/src/case/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const getDefaultSelectedState = () => {
incidents: [],
loading: false,
name: null,
participant: null,
project: null,
related: [],
reporter: null,
Expand Down Expand Up @@ -91,6 +92,7 @@ const state = {
start: null,
end: null,
},
participant: null,
},
q: "",
page: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/static/dispatch/src/router/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/search/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading