chore: views events updated

This commit is contained in:
LAKHAN BAHETI 2024-05-02 18:16:19 +05:30
parent 9f9b31245d
commit 2f67ca7a5f
2 changed files with 22 additions and 4 deletions

View File

@ -8,12 +8,13 @@ import { ContextMenu, CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from
// components // components
import { CreateUpdateProjectViewModal, DeleteProjectViewModal } from "@/components/views"; import { CreateUpdateProjectViewModal, DeleteProjectViewModal } from "@/components/views";
// constants // constants
import { E_VIEWS } from "@/constants/event-tracker";
import { EUserProjectRoles } from "@/constants/project"; import { EUserProjectRoles } from "@/constants/project";
// helpers // helpers
import { cn } from "@/helpers/common.helper"; import { cn } from "@/helpers/common.helper";
import { copyUrlToClipboard } from "@/helpers/string.helper"; import { copyUrlToClipboard } from "@/helpers/string.helper";
// hooks // hooks
import { useUser } from "@/hooks/store"; import { useEventTracker, useUser } from "@/hooks/store";
type Props = { type Props = {
parentRef: React.RefObject<HTMLElement>; parentRef: React.RefObject<HTMLElement>;
@ -31,6 +32,7 @@ export const ViewQuickActions: React.FC<Props> = observer((props) => {
const { const {
membership: { currentProjectRole }, membership: { currentProjectRole },
} = useUser(); } = useUser();
const { setTrackElement } = useEventTracker();
// auth // auth
const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER;
@ -48,7 +50,10 @@ export const ViewQuickActions: React.FC<Props> = observer((props) => {
const MENU_ITEMS: TContextMenuItem[] = [ const MENU_ITEMS: TContextMenuItem[] = [
{ {
key: "edit", key: "edit",
action: () => setCreateUpdateViewModal(true), action: () => {
setTrackElement(E_VIEWS);
setCreateUpdateViewModal(true);
},
title: "Edit", title: "Edit",
icon: Pencil, icon: Pencil,
shouldRender: isEditingAllowed, shouldRender: isEditingAllowed,
@ -67,7 +72,10 @@ export const ViewQuickActions: React.FC<Props> = observer((props) => {
}, },
{ {
key: "delete", key: "delete",
action: () => setDeleteViewModal(true), action: () => {
setTrackElement(E_VIEWS);
setDeleteViewModal(true);
},
title: "Delete", title: "Delete",
icon: Trash2, icon: Trash2,
shouldRender: isEditingAllowed, shouldRender: isEditingAllowed,

View File

@ -7,11 +7,12 @@ import { IProjectView } from "@plane/types";
import { FavoriteStar } from "@/components/core"; import { FavoriteStar } from "@/components/core";
import { DeleteProjectViewModal, CreateUpdateProjectViewModal, ViewQuickActions } from "@/components/views"; import { DeleteProjectViewModal, CreateUpdateProjectViewModal, ViewQuickActions } from "@/components/views";
// constants // constants
import { E_VIEWS, VIEW_FAVORITED, VIEW_UNFAVORITED } from "@/constants/event-tracker";
import { EUserProjectRoles } from "@/constants/project"; import { EUserProjectRoles } from "@/constants/project";
// helpers // helpers
import { calculateTotalFilters } from "@/helpers/filter.helper"; import { calculateTotalFilters } from "@/helpers/filter.helper";
// hooks // hooks
import { useProjectView, useUser } from "@/hooks/store"; import { useEventTracker, useProjectView, useUser } from "@/hooks/store";
type Props = { type Props = {
parentRef: React.RefObject<HTMLElement>; parentRef: React.RefObject<HTMLElement>;
@ -31,6 +32,7 @@ export const ViewListItemAction: FC<Props> = observer((props) => {
membership: { currentProjectRole }, membership: { currentProjectRole },
} = useUser(); } = useUser();
const { addViewToFavorites, removeViewFromFavorites } = useProjectView(); const { addViewToFavorites, removeViewFromFavorites } = useProjectView();
const { captureEvent } = useEventTracker();
// derived values // derived values
const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER;
@ -42,12 +44,20 @@ export const ViewListItemAction: FC<Props> = observer((props) => {
if (!workspaceSlug || !projectId) return; if (!workspaceSlug || !projectId) return;
addViewToFavorites(workspaceSlug.toString(), projectId.toString(), view.id); addViewToFavorites(workspaceSlug.toString(), projectId.toString(), view.id);
captureEvent(VIEW_FAVORITED, {
view_id: view.id,
element: E_VIEWS,
});
}; };
const handleRemoveFromFavorites = () => { const handleRemoveFromFavorites = () => {
if (!workspaceSlug || !projectId) return; if (!workspaceSlug || !projectId) return;
removeViewFromFavorites(workspaceSlug.toString(), projectId.toString(), view.id); removeViewFromFavorites(workspaceSlug.toString(), projectId.toString(), view.id);
captureEvent(VIEW_UNFAVORITED, {
view_id: view.id,
element: E_VIEWS,
});
}; };
return ( return (