fix: filter event logic

This commit is contained in:
LAKHAN BAHETI 2024-03-12 09:40:54 +05:30
parent f6fd579742
commit 967f9c9232
17 changed files with 79 additions and 92 deletions

View File

@ -16,9 +16,9 @@ type Props = {
isOpen: boolean; isOpen: boolean;
projectId: string; projectId: string;
handleClose: () => void; handleClose: () => void;
onResponse: (question: string, response: any) => void; onResponse: (query: string, response: any) => void;
onGenerateResponse?: (question: string, response: any) => void; onGenerateResponse?: (query: string, response: any) => void;
onReGenerateResponse?: (question: string, response: any) => void; onReGenerateResponse?: (query: string, response: any) => void;
onError?: (error: any) => void; onError?: (error: any) => void;
placement?: Placement; placement?: Placement;
prompt?: string; prompt?: string;

View File

@ -44,7 +44,7 @@ export const WidgetIssuesList: React.FC<WidgetIssuesListProps> = (props) => {
element_id: tab, element_id: tab,
mode: "peek", mode: "peek",
filters: { filters: {
due_date: issue.target_date, target_date: issue.target_date,
}, },
}); });
}; };

View File

@ -122,22 +122,19 @@ export const CycleIssuesHeader: React.FC = observer(() => {
(key: keyof IIssueFilterOptions, value: string | string[]) => { (key: keyof IIssueFilterOptions, value: string | string[]) => {
if (!workspaceSlug || !projectId) return; if (!workspaceSlug || !projectId) return;
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
let isFilterRemoved = false;
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((val) => { value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val); if (!newValues.includes(val)) newValues.push(val);
else isFilterRemoved = true;
}); });
} else { } else {
if (issueFilters?.filters?.[key]?.includes(value)) { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
newValues.splice(newValues.indexOf(value), 1); else newValues.push(value);
isFilterRemoved = true;
} else newValues.push(value);
} }
updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }, cycleId).then(() => updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }, cycleId).then(() =>
captureIssuesFilterEvent({ captureIssuesFilterEvent({
eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED,
payload: { payload: {
routePath: router.asPath, routePath: router.asPath,
filters: issueFilters, filters: issueFilters,
@ -254,7 +251,9 @@ export const CycleIssuesHeader: React.FC = observer(() => {
className="ml-1.5 flex-shrink-0" className="ml-1.5 flex-shrink-0"
placement="bottom-start" placement="bottom-start"
> >
{currentProjectCycleIds?.map((cycleId) => <CycleDropdownOption key={cycleId} cycleId={cycleId} />)} {currentProjectCycleIds?.map((cycleId) => (
<CycleDropdownOption key={cycleId} cycleId={cycleId} />
))}
</CustomMenu> </CustomMenu>
} }
/> />

View File

@ -62,18 +62,14 @@ export const GlobalIssuesHeader: React.FC<Props> = observer((props) => {
(key: keyof IIssueFilterOptions, value: string | string[]) => { (key: keyof IIssueFilterOptions, value: string | string[]) => {
if (!workspaceSlug || !globalViewId) return; if (!workspaceSlug || !globalViewId) return;
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
let isFilterRemoved = false;
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((val) => { value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val); if (!newValues.includes(val)) newValues.push(val);
else isFilterRemoved = true;
}); });
} else { } else {
if (issueFilters?.filters?.[key]?.includes(value)) { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
isFilterRemoved = true; else newValues.push(value);
newValues.splice(newValues.indexOf(value), 1);
} else newValues.push(value);
} }
updateFilters( updateFilters(
@ -84,7 +80,7 @@ export const GlobalIssuesHeader: React.FC<Props> = observer((props) => {
globalViewId.toString() globalViewId.toString()
).then(() => { ).then(() => {
captureIssuesFilterEvent({ captureIssuesFilterEvent({
eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED,
payload: { payload: {
routePath: router.asPath, routePath: router.asPath,
filters: issueFilters, filters: issueFilters,

View File

@ -123,22 +123,19 @@ export const ModuleIssuesHeader: React.FC = observer(() => {
(key: keyof IIssueFilterOptions, value: string | string[]) => { (key: keyof IIssueFilterOptions, value: string | string[]) => {
if (!projectId) return; if (!projectId) return;
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
let isFilterRemoved = false;
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((val) => { value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val); if (!newValues.includes(val)) newValues.push(val);
else isFilterRemoved = true;
}); });
} else { } else {
if (issueFilters?.filters?.[key]?.includes(value)) { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
isFilterRemoved = true; else newValues.push(value);
newValues.splice(newValues.indexOf(value), 1);
} else newValues.push(value);
} }
updateFilters(projectId.toString(), EIssueFilterType.FILTERS, { [key]: newValues }).then(() => { updateFilters(projectId.toString(), EIssueFilterType.FILTERS, { [key]: newValues }).then(() => {
captureIssuesFilterEvent({ captureIssuesFilterEvent({
eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED,
payload: { payload: {
routePath: router.asPath, routePath: router.asPath,
filters: issueFilters, filters: issueFilters,

View File

@ -70,22 +70,19 @@ export const ProjectIssuesHeader: React.FC = observer(() => {
(key: keyof IIssueFilterOptions, value: string | string[]) => { (key: keyof IIssueFilterOptions, value: string | string[]) => {
if (!workspaceSlug || !projectId) return; if (!workspaceSlug || !projectId) return;
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
let isFilterRemoved = false;
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((val) => { value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val); if (!newValues.includes(val)) newValues.push(val);
else isFilterRemoved = true;
}); });
} else { } else {
if (issueFilters?.filters?.[key]?.includes(value)) { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
newValues.splice(newValues.indexOf(value), 1); else newValues.push(value);
isFilterRemoved = true;
} else newValues.push(value);
} }
updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }).then(() => updateFilters(workspaceSlug, projectId, EIssueFilterType.FILTERS, { [key]: newValues }).then(() =>
captureIssuesFilterEvent({ captureIssuesFilterEvent({
eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED,
payload: { payload: {
routePath: router.asPath, routePath: router.asPath,
filters: issueFilters, filters: issueFilters,

View File

@ -90,17 +90,14 @@ export const ProjectViewIssuesHeader: React.FC = observer(() => {
(key: keyof IIssueFilterOptions, value: string | string[]) => { (key: keyof IIssueFilterOptions, value: string | string[]) => {
if (!workspaceSlug || !projectId || !viewId) return; if (!workspaceSlug || !projectId || !viewId) return;
const newValues = issueFilters?.filters?.[key] ?? []; const newValues = issueFilters?.filters?.[key] ?? [];
let isFilterRemoved = false;
if (Array.isArray(value)) { if (Array.isArray(value)) {
value.forEach((val) => { value.forEach((val) => {
if (!newValues.includes(val)) newValues.push(val); if (!newValues.includes(val)) newValues.push(val);
else isFilterRemoved = true;
}); });
} else { } else {
if (issueFilters?.filters?.[key]?.includes(value)) { if (issueFilters?.filters?.[key]?.includes(value)) newValues.splice(newValues.indexOf(value), 1);
isFilterRemoved = true; else newValues.push(value);
newValues.splice(newValues.indexOf(value), 1);
} else newValues.push(value);
} }
updateFilters( updateFilters(
@ -111,7 +108,7 @@ export const ProjectViewIssuesHeader: React.FC = observer(() => {
viewId.toString() viewId.toString()
).then(() => { ).then(() => {
captureIssuesFilterEvent({ captureIssuesFilterEvent({
eventName: isFilterRemoved ? FILTER_REMOVED : FILTER_APPLIED, eventName: (issueFilters?.filters?.[key] ?? []).length > newValues.length ? FILTER_REMOVED : FILTER_APPLIED,
payload: { payload: {
routePath: router.asPath, routePath: router.asPath,
filters: issueFilters, filters: issueFilters,

View File

@ -249,7 +249,7 @@ export const CreateInboxIssueModal: React.FC<Props> = observer((props) => {
// this is done so that the title do not reset after gpt popover closed // this is done so that the title do not reset after gpt popover closed
reset(getValues()); reset(getValues());
}} }}
onResponse={(response) => { onResponse={(_,response) => {
handleAiAssistance(response); handleAiAssistance(response);
}} }}
button={ button={

View File

@ -92,14 +92,14 @@ export const ProjectViewAppliedFiltersRoot: React.FC = observer(() => {
filters: { filters: {
...(appliedFilters ?? {}), ...(appliedFilters ?? {}),
}, },
}).then((res) => { }).then((res) =>
captureEvent(VIEW_UPDATED, { captureEvent(VIEW_UPDATED, {
view_id: res.id, view_id: res.id,
filters: res.filters, filters: res.filters,
element: "View Navbar", element: "View Navbar",
state: "SUCCESS", state: "SUCCESS",
}); })
}); );
}; };
return ( return (

View File

@ -92,11 +92,12 @@ export const AllIssueLayoutRoot: React.FC = observer(() => {
if (workspaceSlug && globalViewId) { if (workspaceSlug && globalViewId) {
await fetchAllGlobalViews(workspaceSlug.toString()); await fetchAllGlobalViews(workspaceSlug.toString());
await fetchFilters(workspaceSlug.toString(), globalViewId.toString()); await fetchFilters(workspaceSlug.toString(), globalViewId.toString());
captureIssuesListOpenedEvent({
routePath: router.asPath,
});
await fetchIssues(workspaceSlug.toString(), globalViewId.toString(), issueIds ? "mutation" : "init-loader"); await fetchIssues(workspaceSlug.toString(), globalViewId.toString(), issueIds ? "mutation" : "init-loader");
routerFilterParams(); routerFilterParams();
captureIssuesListOpenedEvent({
filters: globalViewId ? filters?.[globalViewId.toString()] : undefined,
routePath: router.asPath,
});
} }
}, },
{ revalidateIfStale: false, revalidateOnFocus: false } { revalidateIfStale: false, revalidateOnFocus: false }

View File

@ -28,15 +28,15 @@ export const ArchivedIssueLayoutRoot: React.FC = observer(() => {
async () => { async () => {
if (workspaceSlug && projectId) { if (workspaceSlug && projectId) {
await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString()); await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString());
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
await issues?.fetchIssues( await issues?.fetchIssues(
workspaceSlug.toString(), workspaceSlug.toString(),
projectId.toString(), projectId.toString(),
issues?.groupedIssueIds ? "mutation" : "init-loader" issues?.groupedIssueIds ? "mutation" : "init-loader"
); );
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
} }
}, },
{ revalidateIfStale: false, revalidateOnFocus: false } { revalidateIfStale: false, revalidateOnFocus: false }

View File

@ -41,16 +41,16 @@ export const CycleLayoutRoot: React.FC = observer(() => {
async () => { async () => {
if (workspaceSlug && projectId && cycleId) { if (workspaceSlug && projectId && cycleId) {
await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), cycleId.toString()); await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), cycleId.toString());
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
await issues?.fetchIssues( await issues?.fetchIssues(
workspaceSlug.toString(), workspaceSlug.toString(),
projectId.toString(), projectId.toString(),
issues?.groupedIssueIds ? "mutation" : "init-loader", issues?.groupedIssueIds ? "mutation" : "init-loader",
cycleId.toString() cycleId.toString()
); );
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
} }
}, },
{ revalidateIfStale: false, revalidateOnFocus: false } { revalidateIfStale: false, revalidateOnFocus: false }
@ -131,7 +131,7 @@ export const CycleLayoutRoot: React.FC = observer(() => {
) : null} ) : null}
</div> </div>
{/* peek overview */} {/* peek overview */}
<IssuePeekOverview issuesFilter={issuesFilter.issueFilters}/> <IssuePeekOverview issuesFilter={issuesFilter.issueFilters} />
</Fragment> </Fragment>
)} )}
</div> </div>

View File

@ -28,15 +28,15 @@ export const DraftIssueLayoutRoot: React.FC = observer(() => {
async () => { async () => {
if (workspaceSlug && projectId) { if (workspaceSlug && projectId) {
await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString()); await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString());
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
await issues?.fetchIssues( await issues?.fetchIssues(
workspaceSlug.toString(), workspaceSlug.toString(),
projectId.toString(), projectId.toString(),
issues?.groupedIssueIds ? "mutation" : "init-loader" issues?.groupedIssueIds ? "mutation" : "init-loader"
); );
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
} }
}, },
{ revalidateIfStale: false, revalidateOnFocus: false } { revalidateIfStale: false, revalidateOnFocus: false }

View File

@ -37,16 +37,16 @@ export const ModuleLayoutRoot: React.FC = observer(() => {
async () => { async () => {
if (workspaceSlug && projectId && moduleId) { if (workspaceSlug && projectId && moduleId) {
await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), moduleId.toString()); await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), moduleId.toString());
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
})
await issues?.fetchIssues( await issues?.fetchIssues(
workspaceSlug.toString(), workspaceSlug.toString(),
projectId.toString(), projectId.toString(),
issues?.groupedIssueIds ? "mutation" : "init-loader", issues?.groupedIssueIds ? "mutation" : "init-loader",
moduleId.toString() moduleId.toString()
); );
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
} }
}, },
{ revalidateIfStale: false, revalidateOnFocus: false } { revalidateIfStale: false, revalidateOnFocus: false }
@ -116,7 +116,7 @@ export const ModuleLayoutRoot: React.FC = observer(() => {
) : null} ) : null}
</div> </div>
{/* peek overview */} {/* peek overview */}
<IssuePeekOverview issuesFilter={issuesFilter.issueFilters}/> <IssuePeekOverview issuesFilter={issuesFilter.issueFilters} />
</Fragment> </Fragment>
)} )}
</div> </div>

View File

@ -33,16 +33,16 @@ export const ProjectViewLayoutRoot: React.FC = observer(() => {
async () => { async () => {
if (workspaceSlug && projectId && viewId) { if (workspaceSlug && projectId && viewId) {
await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), viewId.toString()); await issuesFilter?.fetchFilters(workspaceSlug.toString(), projectId.toString(), viewId.toString());
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
await issues?.fetchIssues( await issues?.fetchIssues(
workspaceSlug.toString(), workspaceSlug.toString(),
projectId.toString(), projectId.toString(),
issues?.groupedIssueIds ? "mutation" : "init-loader", issues?.groupedIssueIds ? "mutation" : "init-loader",
viewId.toString() viewId.toString()
); );
captureIssuesListOpenedEvent({
routePath: router.asPath,
filters: issuesFilter?.issueFilters?.filters,
});
} }
}, },
{ revalidateIfStale: false, revalidateOnFocus: false } { revalidateIfStale: false, revalidateOnFocus: false }
@ -81,7 +81,7 @@ export const ProjectViewLayoutRoot: React.FC = observer(() => {
</div> </div>
{/* peek overview */} {/* peek overview */}
<IssuePeekOverview issuesFilter={issuesFilter.issueFilters}/> <IssuePeekOverview issuesFilter={issuesFilter.issueFilters} />
</Fragment> </Fragment>
)} )}
</div> </div>

View File

@ -425,7 +425,7 @@ export const IssueFormRoot: FC<IssueFormProps> = observer((props) => {
// this is done so that the title do not reset after gpt popover closed // this is done so that the title do not reset after gpt popover closed
reset(getValues()); reset(getValues());
}} }}
onResponse={(response) => { onResponse={(_,response) => {
handleAiAssistance(response); handleAiAssistance(response);
}} }}
placement="top-end" placement="top-end"

View File

@ -191,14 +191,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
}; };
try { try {
await createPage(formData).then(() => { await createPage(formData).then(() =>
captureEvent(PAGE_DUPLICATED, { captureEvent(PAGE_DUPLICATED, {
page_id: pageId, page_id: pageId,
access: access == 1 ? "private" : "public", access: access == 1 ? "private" : "public",
element: "Pages detail page", element: "Pages detail page",
state: "SUCCESS", state: "SUCCESS",
}); })
}); );
} catch (error) { } catch (error) {
actionCompleteAlert({ actionCompleteAlert({
title: `Page could not be duplicated`, title: `Page could not be duplicated`,
@ -211,14 +211,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
const archivePage = async () => { const archivePage = async () => {
if (!workspaceSlug || !projectId || !pageId) return; if (!workspaceSlug || !projectId || !pageId) return;
try { 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, { captureEvent(PAGE_ARCHIVED, {
page_id: pageId, page_id: pageId,
access: access == 1 ? "private" : "public", access: access == 1 ? "private" : "public",
element: "Pages detail page", element: "Pages detail page",
state: "SUCCESS", state: "SUCCESS",
}); })
}); );
} catch (error) { } catch (error) {
actionCompleteAlert({ actionCompleteAlert({
title: `Page could not be archived`, title: `Page could not be archived`,
@ -231,14 +231,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
const unArchivePage = async () => { const unArchivePage = async () => {
if (!workspaceSlug || !projectId || !pageId) return; if (!workspaceSlug || !projectId || !pageId) return;
try { 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, { captureEvent(PAGE_RESTORED, {
page_id: pageId, page_id: pageId,
access: access == 1 ? "private" : "public", access: access == 1 ? "private" : "public",
element: "Pages detail page", element: "Pages detail page",
state: "SUCCESS", state: "SUCCESS",
}); })
}); );
} catch (error) { } catch (error) {
actionCompleteAlert({ actionCompleteAlert({
title: `Page could not be restored`, title: `Page could not be restored`,
@ -251,14 +251,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
const lockPage = async () => { const lockPage = async () => {
if (!workspaceSlug || !projectId || !pageId) return; if (!workspaceSlug || !projectId || !pageId) return;
try { try {
await lockPageAction().then(() => { await lockPageAction().then(() =>
captureEvent(PAGE_LOCKED, { captureEvent(PAGE_LOCKED, {
page_id: pageId, page_id: pageId,
access: access == 1 ? "private" : "public", access: access == 1 ? "private" : "public",
element: "Pages detail page", element: "Pages detail page",
state: "SUCCESS", state: "SUCCESS",
}); })
}); );
} catch (error) { } catch (error) {
actionCompleteAlert({ actionCompleteAlert({
title: `Page could not be locked`, title: `Page could not be locked`,
@ -271,14 +271,14 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
const unlockPage = async () => { const unlockPage = async () => {
if (!workspaceSlug || !projectId || !pageId) return; if (!workspaceSlug || !projectId || !pageId) return;
try { try {
await unlockPageAction().then(() => { await unlockPageAction().then(() =>
captureEvent(PAGE_UNLOCKED, { captureEvent(PAGE_UNLOCKED, {
page_id: pageId, page_id: pageId,
access: access == 1 ? "private" : "public", access: access == 1 ? "private" : "public",
element: "Pages detail page", element: "Pages detail page",
state: "SUCCESS", state: "SUCCESS",
}); })
}); );
} catch (error) { } catch (error) {
actionCompleteAlert({ actionCompleteAlert({
title: `Page could not be unlocked`, title: `Page could not be unlocked`,
@ -389,21 +389,21 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
reset(getValues()); reset(getValues());
}} }}
onResponse={handleAiAssistance} onResponse={handleAiAssistance}
onGenerateResponse={(question) => { onGenerateResponse={(question) =>
captureEvent(AI_TRIGGERED, { captureEvent(AI_TRIGGERED, {
page_id: pageId, page_id: pageId,
element: "Pages detail page", element: "Pages detail page",
question: question, question: question,
}); })
}} }
onReGenerateResponse={(question, response) => { onReGenerateResponse={(question, response) =>
captureEvent(AI_RES_REGENERATED, { captureEvent(AI_RES_REGENERATED, {
page_id: pageId, page_id: pageId,
element: "Pages detail page", element: "Pages detail page",
question: question, question: question,
prev_answer: response, prev_answer: response,
}); })
}} }
placement="top-end" placement="top-end"
button={ button={
<button <button