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

Show correct cases in Case Dialog on Entity Card #3245

Merged
merged 1 commit into from
Apr 7, 2023
Merged
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
71 changes: 25 additions & 46 deletions src/dispatch/static/dispatch/src/entity/EntityCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
rounded="xl"
class="d-flex align-center mx-4 mt-3 mb-3"
:elevation="hover ? 2 : 0"
@click="createCaseShow(getCaseTable())"
@click="openCaseTab"
>
<v-card-text class="d-flex align-center">
<v-progress-linear
Expand All @@ -79,11 +79,11 @@
</v-card>
</template>
</v-hover>
<v-dialog v-model="dialog" max-width="1080">
<v-dialog v-model="signalDialog" max-width="1080">
<template v-slot:activator="{ on }"></template>
<signal-instance-tab :inputSignalInstances="signalInstances" />
</v-dialog>
<v-dialog v-model="showCaseView" max-width="1080">
<v-dialog v-model="caseDialog" max-width="1080">
<template v-slot:activator="{ on }"></template>
<case-tab :inputCases="cases" />
</v-dialog>
Expand All @@ -98,6 +98,7 @@ import CaseApi from "@/case/api"
import CaseTab from "@/case/CaseTab.vue"
import EntityApi from "@/entity/api"
import SearchUtils from "@/search/utils"
import SignalInstanceApi from "@/signal/api"
import SignalInstanceTab from "@/signal/SignalInstanceTab.vue"

export default {
Expand All @@ -123,20 +124,19 @@ export default {
computed: {
...mapFields("entity", ["dialogs.showCaseView"]),
...mapFields("route", ["query"]),
badgeCount() {
return this.count >= 100 ? "x99+" : `x${this.count}`
},
},
data() {
return {
caseCount: null,
signalInstanceCount: null,
isLoading: true,
dialog: false,
signalDialog: false,
caseDialog: false,
signalInstances: [],
cases: [],
filters: {
entity: [],
start: null,
end: null,
},
}
},
async mounted() {
Expand All @@ -147,65 +147,44 @@ export default {
this.refreshData()
},
},
computed: {
badgeCount() {
return this.count >= 100 ? "x99+" : `x${this.count}`
},
},
methods: {
...mapActions("entity", ["createCaseShow"]),
async refreshData() {
try {
this.isLoading = true

const casePromise = EntityApi.getCases(this.entity.id, this.selectedDateTime).then(
(response) => response.data
)
const signalPromise = EntityApi.getSignalInstances(
this.entity.id,
this.selectedDateTime
).then((response) => response.data)

const [casesResponse, signalResponse] = await Promise.all([casePromise, signalPromise])
this.caseCount = casesResponse.cases.length
this.signalInstanceCount = signalResponse.instances.length

this.cases = casesResponse.cases
this.caseCount = this.cases.length

this.signalInstances = signalResponse.instances
this.signalInstanceCount = this.signalInstances.length

this.isLoading = false
} catch (error) {
console.error("Error in refreshData:", error)
}
},
async getSignalInstances(selectedDateTime) {
this.signalInstances = await EntityApi.getSignalInstances(
this.entity.id,
selectedDateTime
).then((response) => response.data.instances)
},
getCaseTable() {
this.filters.entities = [this.entity]
const startDate = this.getStartDate()
const endDate = new Date()
this.filters.start = [startDate]
this.filters.end = [endDate]

const expression = SearchUtils.createFilterExpression(this.filters)
if (!expression) return

const params = { filter: expression, itemsPerPage: 50 }

return CaseApi.getAll(params)
.then((response) => {
this.cases = response.data.items
return response.data.items
})
.catch((error) => {
console.error(error)
})
},
async openSignalInstanceTab() {
await this.getSignalInstances(this.selectedDateTime)
this.dialog = true
this.signalDialog = true
this.$nextTick(() => {
this.$refs.signalInstanceTab = this.signalInstances
})
},
async openCaseTab() {
this.caseDialog = true
this.$nextTick(() => {
this.$refs.caseTab = this.cases
})
},
getStartDate() {
return new Date(Date.now() - this.selectedDateTime * 86400000).toISOString()
},
Expand Down