From 967f9c92322965dbae6083fe634d7fd104207521 Mon Sep 17 00:00:00 2001 From: LAKHAN BAHETI Date: Tue, 12 Mar 2024 09:40:54 +0530 Subject: [PATCH] fix: filter event logic --- .../core/modals/gpt-assistant-popover.tsx | 6 +-- .../widgets/issue-panels/issues-list.tsx | 2 +- web/components/headers/cycle-issues.tsx | 15 ++++--- web/components/headers/global-issues.tsx | 10 ++--- web/components/headers/module-issues.tsx | 11 ++--- web/components/headers/project-issues.tsx | 11 ++--- .../headers/project-view-issues.tsx | 11 ++--- .../inbox/modals/create-issue-modal.tsx | 2 +- .../roots/project-view-root.tsx | 6 +-- .../roots/all-issue-layout-root.tsx | 7 ++-- .../roots/archived-issue-layout-root.tsx | 8 ++-- .../issue-layouts/roots/cycle-layout-root.tsx | 10 ++--- .../roots/draft-issue-layout-root.tsx | 8 ++-- .../roots/module-layout-root.tsx | 10 ++--- .../roots/project-view-layout-root.tsx | 10 ++--- web/components/issues/issue-modal/form.tsx | 2 +- .../projects/[projectId]/pages/[pageId].tsx | 42 +++++++++---------- 17 files changed, 79 insertions(+), 92 deletions(-) diff --git a/web/components/core/modals/gpt-assistant-popover.tsx b/web/components/core/modals/gpt-assistant-popover.tsx index 7157d0537..97a75474d 100644 --- a/web/components/core/modals/gpt-assistant-popover.tsx +++ b/web/components/core/modals/gpt-assistant-popover.tsx @@ -16,9 +16,9 @@ type Props = { isOpen: boolean; projectId: string; handleClose: () => void; - onResponse: (question: string, response: any) => void; - onGenerateResponse?: (question: string, response: any) => void; - onReGenerateResponse?: (question: string, response: any) => void; + onResponse: (query: string, response: any) => void; + onGenerateResponse?: (query: string, response: any) => void; + onReGenerateResponse?: (query: string, response: any) => void; onError?: (error: any) => void; placement?: Placement; prompt?: string; diff --git a/web/components/dashboard/widgets/issue-panels/issues-list.tsx b/web/components/dashboard/widgets/issue-panels/issues-list.tsx index 8f1204bd7..4c8d8d589 100644 --- a/web/components/dashboard/widgets/issue-panels/issues-list.tsx +++ b/web/components/dashboard/widgets/issue-panels/issues-list.tsx @@ -44,7 +44,7 @@ export const WidgetIssuesList: React.FC = (props) => { element_id: tab, mode: "peek", filters: { - due_date: issue.target_date, + target_date: issue.target_date, }, }); }; diff --git a/web/components/headers/cycle-issues.tsx b/web/components/headers/cycle-issues.tsx index 7e4a27999..5cc763127 100644 --- a/web/components/headers/cycle-issues.tsx +++ b/web/components/headers/cycle-issues.tsx @@ -122,22 +122,19 @@ export const CycleIssuesHeader: React.FC = observer(() => { (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !projectId) return; const newValues = issueFilters?.filters?.[key] ?? []; - let isFilterRemoved = false; + if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); - else isFilterRemoved = true; }); } else { - if (issueFilters?.filters?.[key]?.includes(value)) { - newValues.splice(newValues.indexOf(value), 1); - isFilterRemoved = true; - } else newValues.push(value); + if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); + else newValues.push(value); } updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }, cycleId).then(() => captureIssuesFilterEvent({ - eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, + eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED, payload: { routePath: router.asPath, filters: issueFilters, @@ -254,7 +251,9 @@ export const CycleIssuesHeader: React.FC = observer(() => { className="ml-1.5 flex-shrink-0" placement="bottom-start" > - {currentProjectCycleIds?.map((cycleId) => )} + {currentProjectCycleIds?.map((cycleId) => ( + + ))} } /> diff --git a/web/components/headers/global-issues.tsx b/web/components/headers/global-issues.tsx index 3c70b4dc6..3208242ef 100644 --- a/web/components/headers/global-issues.tsx +++ b/web/components/headers/global-issues.tsx @@ -62,18 +62,14 @@ export const GlobalIssuesHeader: React.FC = observer((props) => { (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !globalViewId) return; const newValues = issueFilters?.filters?.[key] ?? []; - let isFilterRemoved = false; if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); - else isFilterRemoved = true; }); } else { - if (issueFilters?.filters?.[key]?.includes(value)) { - isFilterRemoved = true; - newValues.splice(newValues.indexOf(value), 1); - } else newValues.push(value); + if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); + else newValues.push(value); } updateFilters( @@ -84,7 +80,7 @@ export const GlobalIssuesHeader: React.FC = observer((props) => { globalViewId.toString() ).then(() => { captureIssuesFilterEvent({ - eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, + eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED, payload: { routePath: router.asPath, filters: issueFilters, diff --git a/web/components/headers/module-issues.tsx b/web/components/headers/module-issues.tsx index 71f0d9de8..1b851b04e 100644 --- a/web/components/headers/module-issues.tsx +++ b/web/components/headers/module-issues.tsx @@ -123,22 +123,19 @@ export const ModuleIssuesHeader: React.FC = observer(() => { (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!projectId) return; const newValues = issueFilters?.filters?.[key] ?? []; - let isFilterRemoved = false; + if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); - else isFilterRemoved = true; }); } else { - if (issueFilters?.filters?.[key]?.includes(value)) { - isFilterRemoved = true; - newValues.splice(newValues.indexOf(value), 1); - } else newValues.push(value); + if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); + else newValues.push(value); } updateFilters(projectId.toString(), EIssueFilterType.FILTERS, { [key]: newValues }).then(() => { captureIssuesFilterEvent({ - eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, + eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED, payload: { routePath: router.asPath, filters: issueFilters, diff --git a/web/components/headers/project-issues.tsx b/web/components/headers/project-issues.tsx index f42dcf089..68609f9c0 100644 --- a/web/components/headers/project-issues.tsx +++ b/web/components/headers/project-issues.tsx @@ -70,22 +70,19 @@ export const ProjectIssuesHeader: React.FC = observer(() => { (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !projectId) return; const newValues = issueFilters?.filters?.[key] ?? []; - let isFilterRemoved = false; + if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); - else isFilterRemoved = true; }); } else { - if (issueFilters?.filters?.[key]?.includes(value)) { - newValues.splice(newValues.indexOf(value), 1); - isFilterRemoved = true; - } else newValues.push(value); + if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); + else newValues.push(value); } updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }).then(() => captureIssuesFilterEvent({ - eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, + eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED, payload: { routePath: router.asPath, filters: issueFilters, diff --git a/web/components/headers/project-view-issues.tsx b/web/components/headers/project-view-issues.tsx index 8a747c651..62e3b37ad 100644 --- a/web/components/headers/project-view-issues.tsx +++ b/web/components/headers/project-view-issues.tsx @@ -90,17 +90,14 @@ export const ProjectViewIssuesHeader: React.FC = observer(() => { (key: keyof IIssueFilterOptions, value: string | string[]) => { if (!workspaceSlug || !projectId || !viewId) return; const newValues = issueFilters?.filters?.[key] ?? []; - let isFilterRemoved = false; + if (Array.isArray(value)) { value.forEach((val) => { if (!newValues.includes(val)) newValues.push(val); - else isFilterRemoved = true; }); } else { - if (issueFilters?.filters?.[key]?.includes(value)) { - isFilterRemoved = true; - newValues.splice(newValues.indexOf(value), 1); - } else newValues.push(value); + if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1); + else newValues.push(value); } updateFilters( @@ -111,7 +108,7 @@ export const ProjectViewIssuesHeader: React.FC = observer(() => { viewId.toString() ).then(() => { captureIssuesFilterEvent({ - eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, + eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED, payload: { routePath: router.asPath, filters: issueFilters, diff --git a/web/components/inbox/modals/create-issue-modal.tsx b/web/components/inbox/modals/create-issue-modal.tsx index 2ba4fd323..9c72bb4a8 100644 --- a/web/components/inbox/modals/create-issue-modal.tsx +++ b/web/components/inbox/modals/create-issue-modal.tsx @@ -249,7 +249,7 @@ export const CreateInboxIssueModal: React.FC = observer((props) => { // this is done so that the title do not reset after gpt popover closed reset(getValues()); }} - onResponse={(response) => { + onResponse={(_,response) => { handleAiAssistance(response); }} button={ diff --git a/web/components/issues/issue-layouts/filters/applied-filters/roots/project-view-root.tsx b/web/components/issues/issue-layouts/filters/applied-filters/roots/project-view-root.tsx index 9863fec15..0ef17573a 100644 --- a/web/components/issues/issue-layouts/filters/applied-filters/roots/project-view-root.tsx +++ b/web/components/issues/issue-layouts/filters/applied-filters/roots/project-view-root.tsx @@ -92,14 +92,14 @@ export const ProjectViewAppliedFiltersRoot: React.FC = observer(() => { filters: { ...(appliedFilters ?? {}), }, - }).then((res) => { + }).then((res) => captureEvent(VIEW_UPDATED, { view_id: res.id, filters: res.filters, element: "View Navbar", state: "SUCCESS", - }); - }); + }) + ); }; return ( diff --git a/web/components/issues/issue-layouts/roots/all-issue-layout-root.tsx b/web/components/issues/issue-layouts/roots/all-issue-layout-root.tsx index 6f7c8f586..d3f7abd4d 100644 --- a/web/components/issues/issue-layouts/roots/all-issue-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/all-issue-layout-root.tsx @@ -92,11 +92,12 @@ export const AllIssueLayoutRoot: React.FC = observer(() => { if (workspaceSlug && globalViewId) { await fetchAllGlobalViews(workspaceSlug.toString()); await fetchFilters(workspaceSlug.toString(), globalViewId.toString()); - captureIssuesListOpenedEvent({ - routePath: router.asPath, - }); await fetchIssues(workspaceSlug.toString(), globalViewId.toString(), issueIds ? "mutation" : "init-loader"); routerFilterParams(); + captureIssuesListOpenedEvent({ + filters: globalViewId ? filters?.[globalViewId.toString()] : undefined, + routePath: router.asPath, + }); } }, { revalidateIfStale: false, revalidateOnFocus: false } diff --git a/web/components/issues/issue-layouts/roots/archived-issue-layout-root.tsx b/web/components/issues/issue-layouts/roots/archived-issue-layout-root.tsx index e00da4636..7b936664a 100644 --- a/web/components/issues/issue-layouts/roots/archived-issue-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/archived-issue-layout-root.tsx @@ -28,15 +28,15 @@ export const ArchivedIssueLayoutRoot: React.FC = observer(() => { async () => { if (workspaceSlug && projectId) { await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString()); - captureIssuesListOpenedEvent({ - routePath: router.asPath, - filters: issuesFilter?.issueFilters?.filters, - }); await issues?.fetchIssues( workspaceSlug.toString(), projectId.toString(), issues?.groupedIssueIds ? "mutation" : "init-loader" ); + captureIssuesListOpenedEvent({ + routePath: router.asPath, + filters: issuesFilter?.issueFilters?.filters, + }); } }, { revalidateIfStale: false, revalidateOnFocus: false } diff --git a/web/components/issues/issue-layouts/roots/cycle-layout-root.tsx b/web/components/issues/issue-layouts/roots/cycle-layout-root.tsx index ecedcf3c4..ec884bc32 100644 --- a/web/components/issues/issue-layouts/roots/cycle-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/cycle-layout-root.tsx @@ -41,16 +41,16 @@ export const CycleLayoutRoot: React.FC = observer(() => { async () => { if (workspaceSlug && projectId && cycleId) { await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), cycleId.toString()); - captureIssuesListOpenedEvent({ - routePath: router.asPath, - filters: issuesFilter?.issueFilters?.filters, - }); await issues?.fetchIssues( workspaceSlug.toString(), projectId.toString(), issues?.groupedIssueIds ? "mutation" : "init-loader", cycleId.toString() ); + captureIssuesListOpenedEvent({ + routePath: router.asPath, + filters: issuesFilter?.issueFilters?.filters, + }); } }, { revalidateIfStale: false, revalidateOnFocus: false } @@ -131,7 +131,7 @@ export const CycleLayoutRoot: React.FC = observer(() => { ) : null} {/* peek overview */} - + )} diff --git a/web/components/issues/issue-layouts/roots/draft-issue-layout-root.tsx b/web/components/issues/issue-layouts/roots/draft-issue-layout-root.tsx index 835e496ed..8666b8609 100644 --- a/web/components/issues/issue-layouts/roots/draft-issue-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/draft-issue-layout-root.tsx @@ -28,15 +28,15 @@ export const DraftIssueLayoutRoot: React.FC = observer(() => { async () => { if (workspaceSlug && projectId) { await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString()); - captureIssuesListOpenedEvent({ - routePath: router.asPath, - filters: issuesFilter?.issueFilters?.filters, - }); await issues?.fetchIssues( workspaceSlug.toString(), projectId.toString(), issues?.groupedIssueIds ? "mutation" : "init-loader" ); + captureIssuesListOpenedEvent({ + routePath: router.asPath, + filters: issuesFilter?.issueFilters?.filters, + }); } }, { revalidateIfStale: false, revalidateOnFocus: false } diff --git a/web/components/issues/issue-layouts/roots/module-layout-root.tsx b/web/components/issues/issue-layouts/roots/module-layout-root.tsx index 182cb3737..2f758d6ea 100644 --- a/web/components/issues/issue-layouts/roots/module-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/module-layout-root.tsx @@ -37,16 +37,16 @@ export const ModuleLayoutRoot: React.FC = observer(() => { async () => { if (workspaceSlug && projectId && moduleId) { await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), moduleId.toString()); - captureIssuesListOpenedEvent({ - routePath: router.asPath, - filters: issuesFilter?.issueFilters?.filters, - }) await issues?.fetchIssues( workspaceSlug.toString(), projectId.toString(), issues?.groupedIssueIds ? "mutation" : "init-loader", moduleId.toString() ); + captureIssuesListOpenedEvent({ + routePath: router.asPath, + filters: issuesFilter?.issueFilters?.filters, + }); } }, { revalidateIfStale: false, revalidateOnFocus: false } @@ -116,7 +116,7 @@ export const ModuleLayoutRoot: React.FC = observer(() => { ) : null} {/* peek overview */} - + )} diff --git a/web/components/issues/issue-layouts/roots/project-view-layout-root.tsx b/web/components/issues/issue-layouts/roots/project-view-layout-root.tsx index 227d0490a..9c0a0de40 100644 --- a/web/components/issues/issue-layouts/roots/project-view-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/project-view-layout-root.tsx @@ -33,16 +33,16 @@ export const ProjectViewLayoutRoot: React.FC = observer(() => { async () => { if (workspaceSlug && projectId && viewId) { await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), viewId.toString()); - captureIssuesListOpenedEvent({ - routePath: router.asPath, - filters: issuesFilter?.issueFilters?.filters, - }); await issues?.fetchIssues( workspaceSlug.toString(), projectId.toString(), issues?.groupedIssueIds ? "mutation" : "init-loader", viewId.toString() ); + captureIssuesListOpenedEvent({ + routePath: router.asPath, + filters: issuesFilter?.issueFilters?.filters, + }); } }, { revalidateIfStale: false, revalidateOnFocus: false } @@ -81,7 +81,7 @@ export const ProjectViewLayoutRoot: React.FC = observer(() => { {/* peek overview */} - + )} diff --git a/web/components/issues/issue-modal/form.tsx b/web/components/issues/issue-modal/form.tsx index dc1f42198..b7aba5606 100644 --- a/web/components/issues/issue-modal/form.tsx +++ b/web/components/issues/issue-modal/form.tsx @@ -425,7 +425,7 @@ export const IssueFormRoot: FC = observer((props) => { // this is done so that the title do not reset after gpt popover closed reset(getValues()); }} - onResponse={(response) => { + onResponse={(_,response) => { handleAiAssistance(response); }} placement="top-end" diff --git a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx index d8855513a..6678590a1 100644 --- a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx +++ b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx @@ -191,14 +191,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { }; try { - await createPage(formData).then(() => { + await createPage(formData).then(() => captureEvent(PAGE_DUPLICATED, { page_id: pageId, access: access == 1 ? "private" : "public", element: "Pages detail page", state: "SUCCESS", - }); - }); + }) + ); } catch (error) { actionCompleteAlert({ title: `Page could not be duplicated`, @@ -211,14 +211,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { const archivePage = async () => { if (!workspaceSlug || !projectId || !pageId) return; try { - await archivePageAction(workspaceSlug as string, projectId as string, pageId as string).then(() => { + await archivePageAction(workspaceSlug as string, projectId as string, pageId as string).then(() => captureEvent(PAGE_ARCHIVED, { page_id: pageId, access: access == 1 ? "private" : "public", element: "Pages detail page", state: "SUCCESS", - }); - }); + }) + ); } catch (error) { actionCompleteAlert({ title: `Page could not be archived`, @@ -231,14 +231,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { const unArchivePage = async () => { if (!workspaceSlug || !projectId || !pageId) return; try { - await restorePageAction(workspaceSlug as string, projectId as string, pageId as string).then(() => { + await restorePageAction(workspaceSlug as string, projectId as string, pageId as string).then(() => captureEvent(PAGE_RESTORED, { page_id: pageId, access: access == 1 ? "private" : "public", element: "Pages detail page", state: "SUCCESS", - }); - }); + }) + ); } catch (error) { actionCompleteAlert({ title: `Page could not be restored`, @@ -251,14 +251,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { const lockPage = async () => { if (!workspaceSlug || !projectId || !pageId) return; try { - await lockPageAction().then(() => { + await lockPageAction().then(() => captureEvent(PAGE_LOCKED, { page_id: pageId, access: access == 1 ? "private" : "public", element: "Pages detail page", state: "SUCCESS", - }); - }); + }) + ); } catch (error) { actionCompleteAlert({ title: `Page could not be locked`, @@ -271,14 +271,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { const unlockPage = async () => { if (!workspaceSlug || !projectId || !pageId) return; try { - await unlockPageAction().then(() => { + await unlockPageAction().then(() => captureEvent(PAGE_UNLOCKED, { page_id: pageId, access: access == 1 ? "private" : "public", element: "Pages detail page", state: "SUCCESS", - }); - }); + }) + ); } catch (error) { actionCompleteAlert({ title: `Page could not be unlocked`, @@ -389,21 +389,21 @@ const PageDetailsPage: NextPageWithLayout = observer(() => { reset(getValues()); }} onResponse={handleAiAssistance} - onGenerateResponse={(question) => { + onGenerateResponse={(question) => captureEvent(AI_TRIGGERED, { page_id: pageId, element: "Pages detail page", question: question, - }); - }} - onReGenerateResponse={(question, response) => { + }) + } + onReGenerateResponse={(question, response) => captureEvent(AI_RES_REGENERATED, { page_id: pageId, element: "Pages detail page", question: question, prev_answer: response, - }); - }} + }) + } placement="top-end" button={