Skip to content

Commit 84716f0

Browse files
committed
Refactor ApiResponse.vue component to improve JSON display and add copy to clipboard functionality
1 parent b21bfa7 commit 84716f0

File tree

2 files changed

+82
-28
lines changed

2 files changed

+82
-28
lines changed

src/components/ApiResponse.vue

Lines changed: 82 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,86 @@
11
<template>
2-
<v-container>
3-
<!-- Displaying the JSON object -->
4-
<v-card max-height="600px" class="overflow-y-auto">
5-
<pre>{{ JSON.stringify(metrics, null, 2) }}</pre>
6-
</v-card>
7-
</v-container>
2+
<v-container>
3+
<!-- Displaying the JSON object -->
4+
<v-card max-height="600px" class="overflow-y-auto">
5+
<pre ref="jsonText">{{ JSON.stringify(metrics, null, 2) }}</pre>
6+
</v-card>
7+
<br>
8+
<div class="copy-container">
9+
<v-btn @click="copyToClipboard">Copy to Clipboard</v-btn>
10+
<transition name="fade">
11+
<div v-if="showCopyMessage" :class="{'copy-message': true, 'error': isError}">{{ message }}</div>
12+
</transition>
13+
</div>
14+
</v-container>
815
</template>
9-
10-
<script lang="ts">
11-
import { defineComponent } from 'vue';
12-
13-
export default defineComponent({
14-
name: 'ApiResponse',
15-
props: {
16-
metrics: {
17-
type: Object,
18-
required: true
19-
}
20-
},
2116

22-
});
23-
</script>
24-
25-
<style scoped>
26-
.tiles-container {
27-
display: flex;
28-
justify-content: flex-start;
29-
flex-wrap: wrap;
17+
<script lang="ts">
18+
import { defineComponent } from 'vue';
19+
20+
export default defineComponent({
21+
name: 'ApiResponse',
22+
props: {
23+
metrics: {
24+
type: Object,
25+
required: true
26+
}
27+
},
28+
data() {
29+
return {
30+
showCopyMessage: false,
31+
isError: false,
32+
message : ''
33+
34+
};
35+
},
36+
methods: {
37+
copyToClipboard() {
38+
const jsonText = this.$refs.jsonText as HTMLElement;
39+
navigator.clipboard.writeText(jsonText.innerText)
40+
.then(() => {
41+
this.message = 'Copied to clipboard!';
42+
this.isError = false;
43+
})
44+
.catch(err => {
45+
this.message = 'Could not copy text!';
46+
this.isError = true;
47+
console.error('Could not copy text: ', err);
48+
});
49+
50+
this.showCopyMessage = true;
51+
setTimeout(() => {
52+
this.showCopyMessage = false;
53+
}, 3000);
54+
}
3055
}
31-
</style>
56+
57+
});
58+
</script>
59+
60+
<style scoped>
61+
.tiles-container {
62+
display: flex;
63+
justify-content: flex-start;
64+
flex-wrap: wrap;
65+
}
66+
.copy-container {
67+
display: flex;
68+
align-items: center;
69+
}
70+
.copy-message {
71+
margin-left: 10px;
72+
font-family: Roboto, sans-serif;
73+
}
74+
.copy-message.error {
75+
color: red;
76+
}
77+
.copy-message:not(.error) {
78+
color: darkgreen;
79+
}
80+
.fade-enter-active, .fade-leave-active {
81+
transition: opacity 0.5s;
82+
}
83+
.fade-enter, .fade-leave-to {
84+
opacity: 0;
85+
}
86+
</style>

src/components/MainComponent.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export default defineComponent({
6565
},
6666
itemName() {
6767
if (process.env.VUE_APP_SCOPE === 'enterprise' || process.env.VUE_APP_SCOPE === 'organization') {
68-
console.log(process.env.VUE_APP_SCOPE);
6968
return process.env.VUE_APP_SCOPE;
7069
} else {
7170
console.log("invalid");

0 commit comments

Comments
 (0)