feat: added tracker for views (#675)

This commit is contained in:
Dakshesh Jain 2023-04-03 15:04:48 +05:30 committed by GitHub
parent 0cf498651c
commit 353197f583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import type {
IPageBlock,
IProject,
IState,
IView,
IWorkspace,
} from "types";
@ -37,6 +38,8 @@ type ModuleEventType = "MODULE_CREATE" | "MODULE_UPDATE" | "MODULE_DELETE";
type PagesEventType = "PAGE_CREATE" | "PAGE_UPDATE" | "PAGE_DELETE";
type ViewEventType = "VIEW_CREATE" | "VIEW_UPDATE" | "VIEW_DELETE";
type PageBlocksEventType =
| "PAGE_BLOCK_CREATE"
| "PAGE_BLOCK_UPDATE"
@ -365,6 +368,30 @@ class TrackEventServices extends APIService {
},
});
}
async trackViewEvent(data: IView, eventName: ViewEventType): Promise<any> {
let payload: any;
if (eventName === "VIEW_DELETE") payload = data;
else
payload = {
labels: Boolean(data.query_data.labels),
assignees: Boolean(data.query_data.assignees),
priority: Boolean(data.query_data.priority),
state: Boolean(data.query_data.state),
created_by: Boolean(data.query_data.created_by),
};
return this.request({
url: "/api/track-event",
method: "POST",
data: {
eventName,
extra: {
...payload,
},
},
});
}
}
const trackEventServices = new TrackEventServices();

View File

@ -1,10 +1,15 @@
// services
import APIService from "services/api.service";
import trackEventServices from "services/track-event.service";
// types
import { IView } from "types/views";
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
const trackEvent =
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
class ViewServices extends APIService {
constructor() {
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
@ -12,7 +17,10 @@ class ViewServices extends APIService {
async createView(workspaceSlug: string, projectId: string, data: IView): Promise<any> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/`, data)
.then((response) => response?.data)
.then((response) => {
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_CREATE");
return response?.data;
})
.catch((error) => {
throw error?.response?.data;
});
@ -25,7 +33,10 @@ class ViewServices extends APIService {
data: IView
): Promise<any> {
return this.put(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`, data)
.then((response) => response?.data)
.then((response) => {
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_UPDATE");
return response?.data;
})
.catch((error) => {
throw error?.response?.data;
});
@ -41,7 +52,10 @@ class ViewServices extends APIService {
`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`,
data
)
.then((response) => response?.data)
.then((response) => {
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_UPDATE");
return response?.data;
})
.catch((error) => {
throw error?.response?.data;
});
@ -49,7 +63,10 @@ class ViewServices extends APIService {
async deleteView(workspaceSlug: string, projectId: string, viewId: string): Promise<any> {
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/`)
.then((response) => response?.data)
.then((response) => {
if (trackEvent) trackEventServices.trackViewEvent(response?.data, "VIEW_DELETE");
return response?.data;
})
.catch((error) => {
throw error?.response?.data;
});
@ -111,7 +128,6 @@ class ViewServices extends APIService {
throw error?.response?.data;
});
}
}
export default new ViewServices();