|
4 | 4 | <v-btn @click="checkMetricsDataQuality">Check Metric data quality</v-btn>
|
5 | 5 | <v-spacer/>
|
6 | 6 | <v-btn @click="copyToClipboard('metricsJsonText')">Copy Metrics to Clipboard</v-btn>
|
| 7 | + <v-btn color="primary" @click="downloadMetricsCSV">Download CSV (Summary)</v-btn> |
| 8 | + <v-btn color="secondary" @click="downloadFullMetricsCSV">Download CSV (Full)</v-btn> |
7 | 9 | </div>
|
8 | 10 | <transition name="fade">
|
9 | 11 | <div v-if="showQualityMessage || showCopyMessage || showSeatMessage" :class="{'copy-message': true, 'error': isError}">{{ message }}</div>
|
|
31 | 33 | </template>
|
32 | 34 |
|
33 | 35 | <script lang="ts">
|
34 |
| -import { defineComponent } from 'vue'; |
| 36 | +import { defineComponent, toRaw } from 'vue'; |
35 | 37 | import { MetricsValidator } from '@/model/MetricsValidator';
|
| 38 | +import { convertMetricsToCSV, convertCopilotMetricsToCSV, downloadCSV } from '@/utils/csvExport'; |
36 | 39 | import type { CopilotMetrics } from '@/model/Copilot_Metrics';
|
37 | 40 | import type { Metrics } from '@/model/Metrics';
|
38 | 41 |
|
@@ -94,7 +97,9 @@ export default defineComponent({
|
94 | 97 | },
|
95 | 98 |
|
96 | 99 | checkMetricsDataQuality() {
|
97 |
| - const validator = new MetricsValidator(this.originalMetrics); |
| 100 | + // Convert reactive proxy to raw object using Vue's toRaw |
| 101 | + const rawOriginalMetrics = toRaw(this.originalMetrics) as CopilotMetrics[]; |
| 102 | + const validator = new MetricsValidator(rawOriginalMetrics); |
98 | 103 |
|
99 | 104 | // console.log(validator);
|
100 | 105 | // create a new MetricsValidator object
|
@@ -123,6 +128,60 @@ export default defineComponent({
|
123 | 128 | setTimeout(() => {
|
124 | 129 | this.showQualityMessage = false;
|
125 | 130 | }, 6000);
|
| 131 | + }, |
| 132 | +
|
| 133 | + downloadMetricsCSV() { |
| 134 | + try { |
| 135 | + // Convert reactive proxy to raw object using Vue's toRaw |
| 136 | + const rawMetrics = toRaw(this.metrics) as Metrics[]; |
| 137 | + const csvContent = convertMetricsToCSV(rawMetrics); |
| 138 | + if (csvContent) { |
| 139 | + const currentDate = new Date().toISOString().split('T')[0]; |
| 140 | + const filename = `copilot-metrics-summary-${currentDate}.csv`; |
| 141 | + downloadCSV(csvContent, filename); |
| 142 | + this.message = 'Summary CSV file downloaded successfully!'; |
| 143 | + this.isError = false; |
| 144 | + } else { |
| 145 | + this.message = 'No metrics data available to export.'; |
| 146 | + this.isError = true; |
| 147 | + } |
| 148 | + } catch (error) { |
| 149 | + this.message = 'Error generating CSV file.'; |
| 150 | + this.isError = true; |
| 151 | + console.error('Error generating CSV:', error); |
| 152 | + } |
| 153 | +
|
| 154 | + this.showCopyMessage = true; |
| 155 | + setTimeout(() => { |
| 156 | + this.showCopyMessage = false; |
| 157 | + }, 3000); |
| 158 | + }, |
| 159 | +
|
| 160 | + downloadFullMetricsCSV() { |
| 161 | + try { |
| 162 | + // Convert reactive proxy to raw object using Vue's toRaw |
| 163 | + const rawMetrics = toRaw(this.originalMetrics) as CopilotMetrics[]; |
| 164 | + const csvContent = convertCopilotMetricsToCSV(rawMetrics); |
| 165 | + if (csvContent) { |
| 166 | + const currentDate = new Date().toISOString().split('T')[0]; |
| 167 | + const filename = `copilot-metrics-full-${currentDate}.csv`; |
| 168 | + downloadCSV(csvContent, filename); |
| 169 | + this.message = 'Full CSV file downloaded successfully!'; |
| 170 | + this.isError = false; |
| 171 | + } else { |
| 172 | + this.message = 'No metrics data available to export.'; |
| 173 | + this.isError = true; |
| 174 | + } |
| 175 | + } catch (error) { |
| 176 | + this.message = 'Error generating CSV file.'; |
| 177 | + this.isError = true; |
| 178 | + console.error('Error generating CSV:', error); |
| 179 | + } |
| 180 | +
|
| 181 | + this.showCopyMessage = true; |
| 182 | + setTimeout(() => { |
| 183 | + this.showCopyMessage = false; |
| 184 | + }, 3000); |
126 | 185 | }
|
127 | 186 | }
|
128 | 187 | });
|
|
0 commit comments