From 1a534a3c191b465fe1a81145e04b68bd84de3db5 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Thu, 11 May 2023 17:38:46 +0530 Subject: [PATCH] feat: plane analytics (#1029) * chore: global bar graph component * chore: global pie graph component * chore: global line graph component * chore: removed unnecessary file * chore: refactored global chart components to accept all props * chore: function to convert response to chart data * chore: global calendar graph component added * chore: global scatter plot graph component * feat: analytics boilerplate created * chore: null value for segment and project * chore: clean up file * chore: change project query param key * chore: export, refresh buttons, analytics table * fix: analytics fetch key error * chore: show only integer values in the y-axis * chore: custom x-axis tick values and bar colors * refactor: divide analytics page into granular components * chore: convert analytics page to modal, save analytics modal * fix: build error * fix: modal overflow issues, analytics loading screen * chore: custom tooltip, refactor: graphs folder structure * refactor: folder structure, chore: x-axis tick values for larger data * chore: code cleanup * chore: remove unnecessary files * fix: refresh analytics button on error * feat: scope and demand analytics * refactor: scope and demand and custom analytics folder structure * fix: dynamic import type * chore: minor updates * feat: project, cycle and module level analytics * style: project analytics modal * fix: merge conflicts --- .../create-update-analytics-modal.tsx | 158 ++++++++++++ .../custom-analytics/custom-analytics.tsx | 148 +++++++++++ .../custom-analytics/graph/custom-tooltip.tsx | 34 +++ .../custom-analytics/graph/index.tsx | 102 ++++++++ .../analytics/custom-analytics/index.ts | 5 + .../analytics/custom-analytics/sidebar.tsx | 232 ++++++++++++++++++ .../analytics/custom-analytics/table.tsx | 116 +++++++++ apps/app/components/analytics/index.ts | 4 + .../components/analytics/project-modal.tsx | 93 +++++++ .../analytics/scope-and-demand/demand.tsx | 63 +++++ .../analytics/scope-and-demand/index.ts | 3 + .../scope-and-demand/scope-and-demand.tsx | 67 +++++ .../analytics/scope-and-demand/scope.tsx | 98 ++++++++ .../components/analytics/workspace-modal.tsx | 70 ++++++ .../core/calendar-view/calendar-header.tsx | 10 +- .../components/core/calendar-view/index.ts | 2 +- apps/app/components/core/feeds.tsx | 2 +- .../app/components/cycles/transfer-issues.tsx | 2 +- apps/app/components/integration/jira/root.tsx | 2 +- apps/app/components/ui/custom-menu.tsx | 2 +- apps/app/components/ui/graphs/bar-graph.tsx | 13 +- .../components/ui/graphs/calendar-graph.tsx | 4 +- apps/app/components/ui/graphs/line-graph.tsx | 4 +- apps/app/components/ui/graphs/pie-graph.tsx | 4 +- .../ui/graphs/scatter-plot-graph.tsx | 4 +- .../components/ui/product-updates-modal.tsx | 6 +- .../components/workspace/sidebar-dropdown.tsx | 2 +- .../app/components/workspace/sidebar-menu.tsx | 149 +++++++---- apps/app/constants/analytics.ts | 146 +++++++++++ apps/app/constants/calendar.ts | 28 +-- apps/app/constants/fetch-keys.ts | 12 +- apps/app/constants/graph.ts | 8 +- apps/app/helpers/array.helper.ts | 5 + apps/app/layouts/app-layout/app-sidebar.tsx | 14 +- apps/app/layouts/app-layout/index.tsx | 166 ------------- .../project-authorization-wrapper.tsx | 19 +- .../workspace-authorization-wrapper.tsx | 24 +- apps/app/pages/[workspaceSlug]/index.tsx | 5 +- .../projects/[projectId]/cycles/[cycleId].tsx | 19 +- .../projects/[projectId]/issues/index.tsx | 15 +- .../[projectId]/modules/[moduleId].tsx | 12 +- .../projects/[projectId]/modules/index.tsx | 2 +- apps/app/services/analytics.service.ts | 59 +++++ apps/app/types/analytics.d.ts | 83 +++++++ apps/app/types/index.d.ts | 1 + 45 files changed, 1730 insertions(+), 287 deletions(-) create mode 100644 apps/app/components/analytics/custom-analytics/create-update-analytics-modal.tsx create mode 100644 apps/app/components/analytics/custom-analytics/custom-analytics.tsx create mode 100644 apps/app/components/analytics/custom-analytics/graph/custom-tooltip.tsx create mode 100644 apps/app/components/analytics/custom-analytics/graph/index.tsx create mode 100644 apps/app/components/analytics/custom-analytics/index.ts create mode 100644 apps/app/components/analytics/custom-analytics/sidebar.tsx create mode 100644 apps/app/components/analytics/custom-analytics/table.tsx create mode 100644 apps/app/components/analytics/index.ts create mode 100644 apps/app/components/analytics/project-modal.tsx create mode 100644 apps/app/components/analytics/scope-and-demand/demand.tsx create mode 100644 apps/app/components/analytics/scope-and-demand/index.ts create mode 100644 apps/app/components/analytics/scope-and-demand/scope-and-demand.tsx create mode 100644 apps/app/components/analytics/scope-and-demand/scope.tsx create mode 100644 apps/app/components/analytics/workspace-modal.tsx create mode 100644 apps/app/constants/analytics.ts delete mode 100644 apps/app/layouts/app-layout/index.tsx create mode 100644 apps/app/services/analytics.service.ts create mode 100644 apps/app/types/analytics.d.ts diff --git a/apps/app/components/analytics/custom-analytics/create-update-analytics-modal.tsx b/apps/app/components/analytics/custom-analytics/create-update-analytics-modal.tsx new file mode 100644 index 000000000..625a2a4c7 --- /dev/null +++ b/apps/app/components/analytics/custom-analytics/create-update-analytics-modal.tsx @@ -0,0 +1,158 @@ +import React from "react"; + +import { useRouter } from "next/router"; + +// react-hook-form +import { useForm } from "react-hook-form"; +// headless ui +import { Dialog, Transition } from "@headlessui/react"; +// services +import analyticsService from "services/analytics.service"; +// hooks +import useToast from "hooks/use-toast"; +// ui +import { Input, PrimaryButton, SecondaryButton, TextArea } from "components/ui"; +// types +import { IAnalyticsParams, ISaveAnalyticsFormData } from "types"; + +// types +type Props = { + isOpen: boolean; + handleClose: () => void; + params?: IAnalyticsParams; +}; + +type FormValues = { + name: string; + description: string; +}; + +const defaultValues: FormValues = { + name: "", + description: "", +}; + +export const CreateUpdateAnalyticsModal: React.FC = ({ isOpen, handleClose, params }) => { + const router = useRouter(); + const { workspaceSlug } = router.query; + + const { setToastAlert } = useToast(); + + const { + register, + formState: { errors, isSubmitting }, + handleSubmit, + reset, + } = useForm({ + defaultValues, + }); + + const onClose = () => { + handleClose(); + reset(defaultValues); + }; + + const onSubmit = async (formData: FormValues) => { + if (!workspaceSlug) return; + + const payload: ISaveAnalyticsFormData = { + name: formData.name, + description: formData.description, + query_dict: { + x_axis: "priority", + y_axis: "issue_count", + ...params, + project: params?.project ? [params.project] : [], + }, + }; + + await analyticsService + .saveAnalytics(workspaceSlug.toString(), payload) + .then(() => { + setToastAlert({ + type: "success", + title: "Success!", + message: "Analytics saved successfully.", + }); + onClose(); + }) + .catch(() => + setToastAlert({ + type: "error", + title: "Error!", + message: "Analytics could not be saved. Please try again.", + }) + ); + }; + + return ( + + + +
+ + +
+
+ + +
+
+ + Save Analytics + +
+ +