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

Diagnostics page #41

Merged
merged 2 commits into from
Jul 8, 2020
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
10 changes: 10 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ export default (store) => {
breadcrumb: 'Overview'
}
},
// diagnostics
{
path: '/diagnostics',
name: 'diagnostics',
component: () => import(/* webpackChunkName: "diagnostics" */ '@/views/Diagnostics'),
meta: {
title: 'Diagnostics',
breadcrumb: 'Diagnostics'
}
},
// remote CPs
{
path: '/remote-cp',
Expand Down
171 changes: 171 additions & 0 deletions src/views/Diagnostics.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<template>
<div class="local-cps">
<page-header noflex>
<h2 class="xxl">
{{ pageTitle }}
</h2>
</page-header>
<FrameSkeleton class="py-2 px-4">
<KCard
v-if="isReady"
border-variant="noBorder"
>
<template slot="body">
<prism
class="code-block"
language="json"
:code="codeOutput"
/>
</template>
<template slot="actions">
<KClipboardProvider
v-if="codeOutput"
v-slot="{ copyToClipboard }"
>
<KPop placement="bottom">
<KButton
appearance="primary"
@click="() => { copyToClipboard(codeOutput) }"
>
Copy config to clipboard
</KButton>
<div slot="content">
<p>Config copied to clipboard!</p>
</div>
</KPop>
</KClipboardProvider>
</template>
</KCard>

<!-- loading / error handling -->
<KEmptyState
v-if="isLoading || hasError"
cta-is-hidden
>
<template slot="title">
<div class="card-icon mb-3">
<KIcon
v-if="icon"
class="kong-icon--centered"
:color="iconColor"
:icon="icon"
size="42"
/>
</div>
<span v-if="isLoading">
Data Loading...
</span>
<span v-else-if="hasError">
An error has occurred while trying to load this data.
</span>
</template>
</KEmptyState>
</FrameSkeleton>
</div>
</template>

<script>
import { mapGetters } from 'vuex'
import Prism from 'vue-prismjs'
import 'prismjs/themes/prism.css'
import PageHeader from '@/components/Utils/PageHeader.vue'
import FrameSkeleton from '@/components/Skeletons/FrameSkeleton'

export default {
name: 'Diagnostics',
metaInfo: {
title: 'Diagnostics'
},
components: {
PageHeader,
FrameSkeleton,
Prism
},
data () {
return {
isLoading: true,
hasError: false
}
},
computed: {
...mapGetters({
config: 'getConfig'
}),
icon () {
if (this.isLoading) {
return 'spinner'
} else if (this.hasError) {
return 'warning'
}

return false
},
iconColor () {
if (this.hasError) {
return 'var(--yellow-base)'
}

return '#ccc'
},
isReady () {
return !this.hasError && !this.isLoading
},
pageTitle () {
const metaTitle = this.$route.meta.title

return metaTitle
},
codeOutput () {
const code = this.config

return JSON.stringify(code, null, 2)
},
configUrl () {
const url = localStorage.getItem('kumaApiUrl') || null
const apiUrl = url
? `${url}/config`
: null

return apiUrl
}
},
beforeMount () {
this.fetchData()
},
methods: {
fetchData () {
// if the config isn't present, run
if (!this.config) {
// fetch the config
this.$store.dispatch('getConfig')
.catch(error => {
this.hasError = true

console.log(error)
})
.finally(() => {
setTimeout(() => {
this.isLoading = false
}, process.env.VUE_APP_DATA_TIMEOUT)
})
} else {
setTimeout(() => {
this.isLoading = false
}, process.env.VUE_APP_DATA_TIMEOUT)
}
}
}
}
</script>

<style lang="scss" scoped>
.card-icon {
text-align: center;

img, svg {
display: block;
margin-left: auto;
margin-right: auto;
}
}
</style>