2022-03-14 12:45:27 +00:00
|
|
|
import { mapGetters } from 'vuex';
|
|
|
|
import { formatTime } from '@chatwoot/utils';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
accountSummary: 'getAccountSummary',
|
2022-03-28 07:38:23 +00:00
|
|
|
accountReport: 'getAccountReports',
|
2022-03-14 12:45:27 +00:00
|
|
|
}),
|
|
|
|
calculateTrend() {
|
|
|
|
return metric_key => {
|
|
|
|
if (!this.accountSummary.previous[metric_key]) return 0;
|
|
|
|
return Math.round(
|
|
|
|
((this.accountSummary[metric_key] -
|
|
|
|
this.accountSummary.previous[metric_key]) /
|
|
|
|
this.accountSummary.previous[metric_key]) *
|
|
|
|
100
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
displayMetric() {
|
|
|
|
return metric_key => {
|
2022-03-28 07:38:23 +00:00
|
|
|
if (this.isAverageMetricType(metric_key)) {
|
2022-03-14 12:45:27 +00:00
|
|
|
return formatTime(this.accountSummary[metric_key]);
|
|
|
|
}
|
|
|
|
return this.accountSummary[metric_key];
|
|
|
|
};
|
|
|
|
},
|
2022-03-28 07:38:23 +00:00
|
|
|
displayInfoText() {
|
|
|
|
return metric_key => {
|
|
|
|
if (this.metrics[this.currentSelection].KEY !== metric_key) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if (this.isAverageMetricType(metric_key)) {
|
|
|
|
const total = this.accountReport.data
|
|
|
|
.map(item => item.count)
|
|
|
|
.reduce((prev, curr) => prev + curr, 0);
|
|
|
|
return `${this.metrics[this.currentSelection].INFO_TEXT} ${total}`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
},
|
|
|
|
isAverageMetricType() {
|
|
|
|
return metric_key => {
|
|
|
|
return ['avg_first_response_time', 'avg_resolution_time'].includes(
|
|
|
|
metric_key
|
|
|
|
);
|
|
|
|
};
|
|
|
|
},
|
2022-03-14 12:45:27 +00:00
|
|
|
},
|
|
|
|
};
|