-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ui for application errors (#143)
Closes #127
- Loading branch information
Showing
7 changed files
with
234 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<template> | ||
<q-page padding> | ||
<q-table title="Application Errors" :columns="errorColumns" :rows="errorStore.errors" :loading="errorStore.loading" v-model:pagination="errorStore.pagination" @request="errorStore.load"> | ||
|
||
<template v-slot:top-right> | ||
<q-select outlined emit-value map-options v-model="errorStore.status" :options="filterOptions" label="Filter By" dense style="min-width: 150px" @update:model-value="errorStore.load()"/> | ||
<q-btn icon="fa-solid fa-wand-sparkles" label="Resolve All" @click="errorStore.resolveAll()" class="on-right"/> | ||
</template> | ||
|
||
<template v-slot:body-cell-firstOccurred="props"> | ||
<q-td :props="props"> | ||
<span> | ||
{{ fromNow(props.row.createdAt) }} | ||
<q-tooltip class="bg-grey-5 text-black"> | ||
{{ formatDate(props.row.createdAt) }} | ||
</q-tooltip> | ||
</span> | ||
</q-td> | ||
</template> | ||
|
||
<template v-slot:body-cell-lastOccurred="props"> | ||
<q-td :props="props"> | ||
<span> | ||
{{ fromNow(props.row.updatedAt) }} | ||
<q-tooltip class="bg-grey-5 text-black"> | ||
{{ formatDate(props.row.updatedAt) }} | ||
</q-tooltip> | ||
</span> | ||
</q-td> | ||
</template> | ||
|
||
<template v-slot:body-cell-actions="props"> | ||
<q-td :props="props"> | ||
<q-btn size="sm" icon="fa-solid fa-wand-sparkles" @click="errorStore.resolve(props.row.id)"> | ||
<q-tooltip>Resolve error</q-tooltip> | ||
</q-btn> | ||
</q-td> | ||
</template> | ||
|
||
</q-table> | ||
</q-page> | ||
</template> | ||
|
||
<script setup> | ||
import { onMounted } from 'vue' | ||
import { formatDate, fromNow } from '../utils/time' | ||
import { useErrorStore } from 'stores/errorStore' | ||
// Stores | ||
const errorStore = useErrorStore() | ||
// Reactive data | ||
// Constant data | ||
const filterOptions = ['UNRESOLVED', 'RESOLVED'] | ||
const errorColumns = [ | ||
{ | ||
name: 'description', | ||
label: 'Description', | ||
field: 'description', | ||
align: 'left' | ||
}, | ||
{ | ||
name: 'numberOfOccurrences', | ||
label: 'Number of Occurrences', | ||
field: 'numTimesOccurred', | ||
align: 'left' | ||
}, | ||
{ | ||
name: 'firstOccurred', | ||
label: 'First Occurred', | ||
align: 'left' | ||
}, | ||
{ | ||
name: 'lastOccurred', | ||
label: 'Last Occurred', | ||
align: 'left' | ||
}, | ||
{ | ||
name: 'actions', | ||
label: 'Actions', | ||
align: 'left' | ||
} | ||
] | ||
// Methods | ||
onMounted(() => { | ||
errorStore.load() | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { defineStore } from 'pinia' | ||
import { api } from 'src/boot/axios' | ||
import { ref } from 'vue' | ||
|
||
export const useErrorStore = defineStore('error', () => { | ||
const errors = ref([]) | ||
const loading = ref(false) | ||
const pagination = ref({ | ||
page: 1, | ||
rowsPerPage: 25, | ||
rowsNumber: 0 | ||
}) | ||
const status = ref('UNRESOLVED') | ||
|
||
async function load (props) { | ||
loading.value = true | ||
|
||
if (props !== undefined) { | ||
pagination.value.page = props.pagination.page | ||
pagination.value.rowsPerPage = props.pagination.rowsPerPage | ||
} | ||
|
||
const params = { | ||
pageNumber: pagination.value.page, | ||
pageSize: pagination.value.rowsPerPage, | ||
status: status.value | ||
} | ||
|
||
const response = await api.get('/kiwi/application-errors', { params }) | ||
errors.value = response.data.items | ||
pagination.value.rowsNumber = response.data.totalCount | ||
loading.value = false | ||
} | ||
|
||
function resolve (id) { | ||
return api.put(`/kiwi/application-errors/resolve/${id}`) | ||
.then(() => load()) | ||
} | ||
|
||
function resolveAll () { | ||
return api.put('/kiwi/application-errors/resolve') | ||
.then(() => load()) | ||
} | ||
|
||
return { errors, loading, pagination, load, resolve, resolveAll, status } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { installQuasar } from '@quasar/quasar-app-extension-testing-unit-vitest' | ||
import { shallowMount } from '@vue/test-utils' | ||
import { describe, expect, it } from 'vitest' | ||
import ErrorsPage from 'pages/ErrorsPage.vue' | ||
import { createTestingPinia } from '@pinia/testing' | ||
|
||
installQuasar() | ||
|
||
describe('ErrorsPage', () => { | ||
it('should mount the errors page without errors', () => { | ||
const wrapper = shallowMount(ErrorsPage, { | ||
global: { | ||
plugins: [createTestingPinia()] | ||
} | ||
}) | ||
|
||
expect(wrapper).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { setActivePinia, createPinia } from 'pinia' | ||
import { useErrorStore } from 'src/stores/errorStore' | ||
import { beforeEach, vi, describe, it, expect } from 'vitest' | ||
import { api } from 'src/boot/axios' | ||
|
||
beforeEach(() => { | ||
setActivePinia(createPinia()) | ||
|
||
vi.mock('src/boot/axios', () => { | ||
const api = { | ||
get: vi.fn().mockImplementation(() => Promise.resolve({ data: { name: 'dev' } })), | ||
put: vi.fn().mockImplementation(() => Promise.resolve(true)) | ||
} | ||
|
||
return { api } | ||
}) | ||
}) | ||
|
||
describe('load', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()) | ||
}) | ||
|
||
it('should use defaults', () => { | ||
const errorStore = useErrorStore() | ||
|
||
errorStore.load() | ||
|
||
expect(api.get).toHaveBeenCalled() | ||
expect(api.get).toHaveBeenCalledWith('/kiwi/application-errors', { params: { pageNumber: 1, pageSize: 25, status: 'UNRESOLVED' } }) | ||
}) | ||
|
||
it('should use provided props', () => { | ||
const errorStore = useErrorStore() | ||
|
||
errorStore.load({ pagination: { page: 5, rowsPerPage: 50 } }) | ||
|
||
expect(api.get).toHaveBeenCalled() | ||
expect(api.get).toHaveBeenCalledWith('/kiwi/application-errors', { params: { pageNumber: 5, pageSize: 50, status: 'UNRESOLVED' } }) | ||
}) | ||
}) | ||
|
||
describe('resolve', () => { | ||
it('should call resolve for given id', () => { | ||
const errorStore = useErrorStore() | ||
|
||
errorStore.resolve(1) | ||
|
||
expect(api.put).toHaveBeenCalledWith('/kiwi/application-errors/resolve/1') | ||
}) | ||
}) | ||
|
||
describe('resolveAll', () => { | ||
it('should call resolveAll', () => { | ||
const errorStore = useErrorStore() | ||
|
||
errorStore.resolveAll() | ||
|
||
expect(api.put).toHaveBeenCalledWith('/kiwi/application-errors/resolve') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters