This improves the Captain overview by loading reporting metrics and FAQ stats from separate endpoints. Range changes now refresh only the metrics, while reopen-rate calculation reuses the resolved conversation count to avoid redundant database queries. ## What changed - Split Captain overview metrics and FAQ stats into separate APIs. - Fetch FAQ stats independently from range-based metrics. - Reuse resolved conversation totals when calculating reopen rate. - Skip the reopen query when there are no resolved conversations.
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
/* global axios */
|
|
import ApiClient from '../ApiClient';
|
|
|
|
// Viewer's UTC offset in hours, matching the reports API convention so the
|
|
// backend can anchor calendar ranges to the viewer's day.
|
|
const getTimezoneOffset = () => -new Date().getTimezoneOffset() / 60;
|
|
|
|
class CaptainAssistant extends ApiClient {
|
|
constructor() {
|
|
super('captain/assistants', { accountScoped: true });
|
|
}
|
|
|
|
get({ page = 1, searchKey } = {}) {
|
|
return axios.get(this.url, {
|
|
params: {
|
|
page,
|
|
searchKey,
|
|
},
|
|
});
|
|
}
|
|
|
|
playground({ assistantId, messageContent, messageHistory }) {
|
|
return axios.post(`${this.url}/${assistantId}/playground`, {
|
|
message_content: messageContent,
|
|
message_history: messageHistory,
|
|
});
|
|
}
|
|
|
|
getMetrics({ assistantId, range, signal }) {
|
|
const requestConfig = {
|
|
params: { range, timezone_offset: getTimezoneOffset() },
|
|
};
|
|
if (signal) requestConfig.signal = signal;
|
|
|
|
return axios.get(`${this.url}/${assistantId}/metrics`, requestConfig);
|
|
}
|
|
|
|
getFaqStats({ assistantId, signal }) {
|
|
const requestConfig = {};
|
|
if (signal) requestConfig.signal = signal;
|
|
|
|
return axios.get(`${this.url}/${assistantId}/faq_stats`, requestConfig);
|
|
}
|
|
|
|
getSummary({ assistantId, range, stats }) {
|
|
return axios.get(`${this.url}/${assistantId}/summary`, {
|
|
params: { range, timezone_offset: getTimezoneOffset(), stats },
|
|
});
|
|
}
|
|
|
|
getDrilldown({ assistantId, metric, range, page, signal }) {
|
|
const requestConfig = {
|
|
params: {
|
|
metric,
|
|
range,
|
|
timezone_offset: getTimezoneOffset(),
|
|
page,
|
|
},
|
|
};
|
|
if (signal) requestConfig.signal = signal;
|
|
|
|
return axios.get(`${this.url}/${assistantId}/drilldown`, requestConfig);
|
|
}
|
|
}
|
|
|
|
export default new CaptainAssistant();
|