Skip to content

Commit

Permalink
add alert item highlight feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Linko91 committed Aug 23, 2024
1 parent 2c75476 commit 064f3b8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
20 changes: 17 additions & 3 deletions frontend/src/components/incidentManagement/alerts/AlertItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
class="alert-item"
:class="['status-' + alert?.status, { compact, embedded, 'cursor-pointer': compact }]"
:class="['status-' + alert?.status, { compact, embedded, 'cursor-pointer': compact, highlight }]"
@click="compact ? openDetails() : undefined"
>
<n-spin :show="loading">
Expand Down Expand Up @@ -229,7 +229,7 @@
</template>

<script setup lang="ts">
import { computed, onBeforeMount, ref, toRefs } from "vue"
import { computed, onBeforeMount, onMounted, ref, toRefs } from "vue"
import { NModal, NPopover, NButton, NSpin, NTooltip, NCard, useMessage, useDialog } from "naive-ui"
import { useSettingsStore } from "@/stores/settings"
import { useGoto } from "@/composables/useGoto"
Expand All @@ -253,10 +253,13 @@ const props = defineProps<{
alertId?: number
compact?: boolean
embedded?: boolean
detailsOnMounted?: boolean
highlight?: boolean
}>()
const { alertData, alertId, compact, embedded } = toRefs(props)
const { alertData, alertId, compact, embedded, detailsOnMounted, highlight } = toRefs(props)

const emit = defineEmits<{
(e: "opened"): void
(e: "deleted"): void
(e: "updated", value: Alert): void
}>()
Expand Down Expand Up @@ -327,6 +330,7 @@ function emitDelete() {
}

function openDetails() {
emit("opened")
showDetails.value = true
}

Expand All @@ -343,6 +347,12 @@ onBeforeMount(() => {
alert.value = _clone(alertData.value)
}
})

onMounted(() => {
if (detailsOnMounted.value) {
openDetails()
}
})
</script>

<style lang="scss" scoped>
Expand Down Expand Up @@ -387,6 +397,10 @@ onBeforeMount(() => {
box-shadow: 0px 0px 0px 1px var(--primary-color);
}

&.highlight {
box-shadow: 0px 0px 0px 1px var(--primary-color);
}

&:not(.compact) {
.header-box {
.id {
Expand Down
32 changes: 31 additions & 1 deletion frontend/src/components/incidentManagement/alerts/AlertsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@
v-for="alert of alertsList"
:key="alert.id"
:alertData="alert"
:highlight="highlight === alert.id.toString()"
:detailsOnMounted="highlight === alert.id.toString() && !highlightedItemOpened"
class="item-appear item-appear-bottom item-appear-005"
@opened="highlightedItemOpened = true"
@deleted="getData()"
@updated="updateAlert($event)"
/>
Expand All @@ -149,7 +152,7 @@
</template>

<script setup lang="ts">
import { ref, onBeforeMount, computed, watch, provide } from "vue"
import { ref, onBeforeMount, computed, watch, provide, toRefs, nextTick } from "vue"
import {
useMessage,
NSpin,
Expand Down Expand Up @@ -177,6 +180,9 @@ export interface AlertsListFilter {
value: string | AlertStatus
}
const props = defineProps<{ highlight: string | null | undefined }>()
const { highlight } = toRefs(props)
const FilterIcon = "carbon:filter-edit"
const InfoIcon = "carbon:information"
Expand Down Expand Up @@ -223,6 +229,9 @@ const statusOptions: { label: string; value: AlertStatus }[] = [
const usersOptions = computed(() => availableUsers.value.map(o => ({ label: o, value: o })))
const highlightedItemFound = ref(!highlight.value)
const highlightedItemOpened = ref(!highlight.value)
watch(showFilters, val => {
if (!val) {
filters.value = _cloneDeep(lastFilters.value)
Expand All @@ -248,6 +257,27 @@ watch(pageSize, () => {
}
})
watch(
alertsList,
() => {
if (
alertsList.value.length &&
!alertsList.value.find(o => o.id.toString() === highlight.value) &&
currentPage.value < total.value &&
!highlightedItemFound.value
) {
nextTick(() => {
currentPage.value++
})
}
if (alertsList.value.find(o => o.id.toString() === highlight.value)) {
highlightedItemFound.value = true
}
},
{ immediate: true }
)
provide("assignable-users", availableUsers)
provide("linkable-cases", linkableCases)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/incidentManagement/cases/CaseItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,12 @@ import { useSettingsStore } from "@/stores/settings"
const props = defineProps<{
caseData?: Case
caseId?: number
detailsOnMounted?: boolean
compact?: boolean
embedded?: boolean
detailsOnMounted?: boolean
highlight?: boolean
}>()
const { caseData, caseId, detailsOnMounted, compact, embedded, highlight } = toRefs(props)
const { caseData, caseId, compact, embedded, detailsOnMounted, highlight } = toRefs(props)
const emit = defineEmits<{
(e: "opened"): void
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/components/incidentManagement/cases/CasesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</template>

<script setup lang="ts">
import { ref, onBeforeMount, computed, watch, toRefs, provide } from "vue"
import { ref, onBeforeMount, computed, watch, toRefs, provide, nextTick } from "vue"
import {
useMessage,
NSpin,
Expand Down Expand Up @@ -196,11 +196,11 @@ const showFilters = ref(false)
const casesList = ref<Case[]>([])
const availableUsers = ref<string[]>([])
const pageSize = ref(5)
const pageSize = ref(25)
const currentPage = ref(1)
const simpleMode = ref(false)
const showSizePicker = ref(true)
const pageSizes = [5, 10, 25, 50, 100]
const pageSizes = [10, 25, 50, 100]
const header = ref()
const pageSlot = ref(8)
Expand Down Expand Up @@ -280,11 +280,14 @@ watch(
const totalPages = Math.ceil(casesList.value.length / pageSize.value)
if (
itemsPaginated.value.length &&
!itemsPaginated.value.find(o => o.id.toString() === highlight.value) &&
currentPage.value < totalPages &&
!highlightedItemFound.value
) {
currentPage.value++
nextTick(() => {
currentPage.value++
})
}
if (itemsPaginated.value.find(o => o.id.toString() === highlight.value)) {
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/views/incidentManagement/Alerts.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<template>
<div class="page">
<AlertsList />
<AlertsList :highlight />
</div>
</template>

<script setup lang="ts">
import AlertsList from "@/components/incidentManagement/alerts/AlertsList.vue"
import { onBeforeMount, ref } from "vue"
import { useRoute } from "vue-router"
const route = useRoute()
const highlight = ref<string | undefined>(undefined)
onBeforeMount(() => {
if (route.query?.alert_id) {
highlight.value = route.query.alert_id.toString() || undefined
}
})
</script>

0 comments on commit 064f3b8

Please sign in to comment.