Skip to content

Commit ea77b8a

Browse files
committed
Make API call from MainComponent and pass metrics to child components plus cleanup
1 parent 31c6140 commit ea77b8a

File tree

4 files changed

+253
-320
lines changed

4 files changed

+253
-320
lines changed

.github/workflows/azure-static-web-apps-red-forest-047f4de10.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/components/ApiResponse.vue

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,28 @@
11
<template>
2-
<!-- API Error Message -->
3-
<div v-if="apiError" class="error-message" v-html="apiError"></div>
4-
<div v-if="!apiError">
5-
6-
<v-container>
2+
<v-container>
73
<!-- Displaying the JSON object -->
8-
<v-card max-height="600px" class="overflow-y-auto">
9-
<pre>{{ JSON.stringify(metrics, null, 2) }}</pre>
10-
</v-card>
11-
</v-container>
12-
</div>
4+
<v-card max-height="600px" class="overflow-y-auto">
5+
<pre>{{ JSON.stringify(metrics, null, 2) }}</pre>
6+
</v-card>
7+
</v-container>
138
</template>
149

1510
<script lang="ts">
16-
import { defineComponent, ref } from 'vue';
17-
import { getGitHubCopilotMetricsApi } from '../api/GitHubApi';
18-
import { Metrics } from '../model/MetricsData';
11+
import { defineComponent } from 'vue';
1912
2013
export default defineComponent({
2114
name: 'ApiResponse',
22-
setup() {
23-
const metrics = ref<Metrics[]>([]);
24-
25-
// API Error Message
26-
const apiError = ref<string | null>(null);
27-
28-
getGitHubCopilotMetricsApi().then(data => {
29-
metrics.value = data;
30-
31-
}).catch(error => {
32-
console.log(error);
33-
// Check the status code of the error response
34-
if (error.response && error.response.status) {
35-
switch (error.response.status) {
36-
case 401:
37-
apiError.value = '401 Unauthorized access - check if your token in the .env file is correct.';
38-
break;
39-
case 404:
40-
apiError.value = `404 Not Found - is the organization '${process.env.VUE_APP_GITHUB_ORG}' correct?`;
41-
break;
42-
default:
43-
apiError.value = error.message;
44-
break;
15+
props: {
16+
metrics: {
17+
type: Object,
18+
required: true
4519
}
46-
} else {
47-
// Update apiError with the error message
48-
apiError.value = error.message;
49-
}
50-
// Add a new line to the apiError message
51-
apiError.value += ' <br> If .env file is modified, restart the changes to take effect.';
52-
53-
});
54-
55-
return { metrics, apiError };
5620
},
57-
5821
5922
});
6023
</script>
6124

6225
<style scoped>
63-
.error-message {
64-
color: red;
65-
}
66-
67-
.center-table {
68-
margin-left: auto;
69-
margin-right: auto;
70-
}
71-
7226
.tiles-container {
7327
display: flex;
7428
justify-content: flex-start;

src/components/MainComponent.vue

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@
1717
</v-tabs>
1818
</template>
1919
</v-toolbar>
20-
<v-window v-model="tab">
20+
21+
<!-- API Error Message -->
22+
<div v-if="apiError" class="error-message" v-html="apiError"></div>
23+
<div v-if="!apiError">
24+
<v-window v-if="metricsReady" v-model="tab">
2125
<v-window-item v-for="item in items" :key="item" :value="item">
2226
<v-card flat>
23-
<MetricsViewer v-if="item === 'organization'" />
27+
<MetricsViewer v-if="item === 'organization'" :metrics="metrics" />
2428
<LanguagesBreakdown v-if="item === 'languages'" />
2529
<CopilotChatViewer v-if="item === 'copilot chat'" />
26-
<ApiResponse v-if="item === 'api response'" />
30+
<ApiResponse v-if="item === 'api response'" :metrics="metrics" />
2731
</v-card>
2832
</v-window-item>
2933
</v-window>
34+
</div>
35+
3036
</v-card>
3137
</template>
3238

@@ -35,7 +41,10 @@ import { defineComponent } from 'vue'
3541
import MetricsViewer from './MetricsViewer.vue'
3642
import LanguagesBreakdown from './LanguagesBreakdown.vue'
3743
import CopilotChatViewer from './CopilotChatViewer.vue'
38-
import ApiResponse from './ApiResponse.vue'
44+
import ApiResponse from './ApiResponse.vue'
45+
import { ref } from 'vue';
46+
import { getGitHubCopilotMetricsApi } from '../api/GitHubApi';
47+
import { Metrics } from '../model/MetricsData';
3948
4049
4150
export default defineComponent({
@@ -54,8 +63,53 @@ export default defineComponent({
5463
data () {
5564
return {
5665
items: ['organization', 'languages', 'copilot chat', 'api response'],
57-
tab: null,
66+
tab: null
5867
}
5968
},
69+
setup() {
70+
const metricsReady = ref(false);
71+
const metrics = ref<Metrics[]>([]);
72+
73+
// API Error Message
74+
const apiError = ref<string | undefined>(undefined);
75+
76+
getGitHubCopilotMetricsApi().then(data => {
77+
metrics.value = data;
78+
79+
// Set metricsReady to true after the call completes.
80+
metricsReady.value = true;
81+
82+
}).catch(error => {
83+
console.log(error);
84+
// Check the status code of the error response
85+
if (error.response && error.response.status) {
86+
switch (error.response.status) {
87+
case 401:
88+
apiError.value = '401 Unauthorized access - check if your token in the .env file is correct.';
89+
break;
90+
case 404:
91+
apiError.value = `404 Not Found - is the organization '${process.env.VUE_APP_GITHUB_ORG}' correct?`;
92+
break;
93+
default:
94+
apiError.value = error.message;
95+
break;
96+
}
97+
} else {
98+
// Update apiError with the error message
99+
apiError.value = error.message;
100+
}
101+
// Add a new line to the apiError message
102+
apiError.value += ' <br> If .env file is modified, restart the changes to take effect.';
103+
104+
});
105+
106+
return { metricsReady, metrics, apiError };
107+
}
60108
})
61109
</script>
110+
111+
<style scoped>
112+
.error-message {
113+
color: red;
114+
}
115+
</style>

0 commit comments

Comments
 (0)