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

View File

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