Files
plane/web/core/services/analytics.service.ts
JayashTripathy 14d2d69120 [WEB-4230] refactor: Analytics code refacor, Removal of nivo charts dependencies and translations (#7131)
* chore: added code split for the analytics store

* chore: done some refactor

* refactor: update entity keys in analytics and translations

* chore: updated the translations

* refactor: simplify AnalyticsStoreV2 class by removing unnecessary constructor

* feat: add AnalyticsStoreV2 class and interface for enhanced analytics functionality

* feat: enhance WorkItemsModal and analytics store with isEpic functionality

* feat: integrate isEpic state into TotalInsights and WorkItemsModal components

* refactor: remove isEpic state from WorkItemsModalMainContent component

* refactor: removed old  analytics components and related services

* refactor: new analytics

* refactor: removed all nivo chart dependencies

* chore: resolved coderabbit comments

* fix: update processUrl to handle custom-work-items in peek view

* feat: implement CSV export functionality in InsightTable component

* feat: enhance analytics service with filter parameters and improve data handling in InsightTable

* feat: add new translation keys for various statuses across multiple languages

* [WEB-4246] fix: enhance analytics components to include 'isEpic' parameter for improved data fetching

* chore: update yarn.lock to remove deprecated @nivo packages and clean up unused dependencies
2025-06-06 01:53:38 +05:30

100 lines
2.7 KiB
TypeScript

import { API_BASE_URL } from "@plane/constants";
import { IAnalyticsResponse, TAnalyticsTabsBase, TAnalyticsGraphsBase, TAnalyticsFilterParams } from "@plane/types";
import { APIService } from "./api.service";
export class AnalyticsService extends APIService {
constructor() {
super(API_BASE_URL);
}
async getAdvanceAnalytics<T extends IAnalyticsResponse>(
workspaceSlug: string,
tab: TAnalyticsTabsBase,
params?: TAnalyticsFilterParams,
isPeekView?: boolean
): Promise<T> {
return this.get(this.processUrl<TAnalyticsTabsBase>("advance-analytics", workspaceSlug, tab, params, isPeekView), {
params: {
tab,
...params,
},
})
.then((res) => res?.data)
.catch((err) => {
throw err?.response?.data;
});
}
async getAdvanceAnalyticsStats<T>(
workspaceSlug: string,
tab: Exclude<TAnalyticsTabsBase, "overview">,
params?: TAnalyticsFilterParams,
isPeekView?: boolean
): Promise<T> {
const processedUrl = this.processUrl<Exclude<TAnalyticsTabsBase, "overview">>(
"advance-analytics-stats",
workspaceSlug,
tab,
params,
isPeekView
);
return this.get(processedUrl, {
params: {
type: tab,
...params,
},
})
.then((res) => res?.data)
.catch((err) => {
throw err?.response?.data;
});
}
async getAdvanceAnalyticsCharts<T>(
workspaceSlug: string,
tab: TAnalyticsGraphsBase,
params?: TAnalyticsFilterParams,
isPeekView?: boolean
): Promise<T> {
const processedUrl = this.processUrl<TAnalyticsGraphsBase>(
"advance-analytics-charts",
workspaceSlug,
tab,
params,
isPeekView
);
return this.get(processedUrl, {
params: {
type: tab,
...params,
},
})
.then((res) => res?.data)
.catch((err) => {
throw err?.response?.data;
});
}
processUrl<T extends string>(
endpoint: string,
workspaceSlug: string,
tab: TAnalyticsGraphsBase | TAnalyticsTabsBase,
params?: TAnalyticsFilterParams,
isPeekView?: boolean
) {
let processedUrl = `/api/workspaces/${workspaceSlug}`;
if (isPeekView && (tab === "work-items" || tab === "custom-work-items")) {
const projectIds = params?.project_ids;
if (typeof projectIds !== "string" || !projectIds.trim()) {
throw new Error("project_ids parameter is required for peek view of work items");
}
const projectId = projectIds.split(",")[0];
if (!projectId) {
throw new Error("Invalid project_ids format - no project ID found");
}
processedUrl += `/projects/${projectId}`;
}
return `${processedUrl}/${endpoint}`;
}
}