[WEB-1183] fix: updated global issues filter while updating global view (#4357)

* chore: Updated global issues filter while updating global view

* fix: globale view modal clear all

---------

Co-authored-by: gurusainath <gurusainath007@gmail.com>
This commit is contained in:
Anmol Singh Bhatia 2024-05-03 20:29:11 +05:30 committed by GitHub
parent 527ecd7d22
commit c96225c812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 75 additions and 27 deletions

View File

@ -96,12 +96,13 @@ export const GlobalViewsAppliedFiltersRoot = observer((props: Props) => {
...(appliedFilters ?? {}), ...(appliedFilters ?? {}),
}, },
}).then((res) => { }).then((res) => {
captureEvent(GLOBAL_VIEW_UPDATED, { if (res)
view_id: res.id, captureEvent(GLOBAL_VIEW_UPDATED, {
applied_filters: res.filters, view_id: res.id,
state: "SUCCESS", applied_filters: res.filters,
element: "Spreadsheet view", state: "SUCCESS",
}); element: "Spreadsheet view",
});
}); });
}; };

View File

@ -84,17 +84,19 @@ export const CreateUpdateWorkspaceViewModal: React.FC<Props> = observer((props)
await updateGlobalView(workspaceSlug.toString(), data.id, payloadData) await updateGlobalView(workspaceSlug.toString(), data.id, payloadData)
.then((res) => { .then((res) => {
captureEvent(GLOBAL_VIEW_UPDATED, { if (res) {
view_id: res.id, captureEvent(GLOBAL_VIEW_UPDATED, {
applied_filters: res.filters, view_id: res.id,
state: "SUCCESS", applied_filters: res.filters,
}); state: "SUCCESS",
setToast({ });
type: TOAST_TYPE.SUCCESS, setToast({
title: "Success!", type: TOAST_TYPE.SUCCESS,
message: "View updated successfully.", title: "Success!",
}); message: "View updated successfully.",
handleClose(); });
handleClose();
}
}) })
.catch(() => { .catch(() => {
captureEvent(GLOBAL_VIEW_UPDATED, { captureEvent(GLOBAL_VIEW_UPDATED, {

View File

@ -1,11 +1,16 @@
import { set } from "lodash"; import cloneDeep from "lodash/cloneDeep";
import isEmpty from "lodash/isEmpty";
import isEqual from "lodash/isEqual";
import set from "lodash/set";
import { observable, action, makeObservable, runInAction, computed } from "mobx"; import { observable, action, makeObservable, runInAction, computed } from "mobx";
import { computedFn } from "mobx-utils"; import { computedFn } from "mobx-utils";
import { IIssueFilterOptions, IWorkspaceView } from "@plane/types";
// constants
import { EIssueFilterType } from "@/constants/issue";
// services // services
import { WorkspaceService } from "@/services/workspace.service"; import { WorkspaceService } from "@/services/workspace.service";
// types // types
import { RootStore } from "@/store/root.store"; import { RootStore } from "@/store/root.store";
import { IWorkspaceView } from "@plane/types";
export interface IGlobalViewStore { export interface IGlobalViewStore {
// observables // observables
@ -20,7 +25,11 @@ export interface IGlobalViewStore {
fetchGlobalViewDetails: (workspaceSlug: string, viewId: string) => Promise<IWorkspaceView>; fetchGlobalViewDetails: (workspaceSlug: string, viewId: string) => Promise<IWorkspaceView>;
// crud actions // crud actions
createGlobalView: (workspaceSlug: string, data: Partial<IWorkspaceView>) => Promise<IWorkspaceView>; createGlobalView: (workspaceSlug: string, data: Partial<IWorkspaceView>) => Promise<IWorkspaceView>;
updateGlobalView: (workspaceSlug: string, viewId: string, data: Partial<IWorkspaceView>) => Promise<IWorkspaceView>; updateGlobalView: (
workspaceSlug: string,
viewId: string,
data: Partial<IWorkspaceView>
) => Promise<IWorkspaceView | undefined>;
deleteGlobalView: (workspaceSlug: string, viewId: string) => Promise<any>; deleteGlobalView: (workspaceSlug: string, viewId: string) => Promise<any>;
} }
@ -139,14 +148,50 @@ export class GlobalViewStore implements IGlobalViewStore {
workspaceSlug: string, workspaceSlug: string,
viewId: string, viewId: string,
data: Partial<IWorkspaceView> data: Partial<IWorkspaceView>
): Promise<IWorkspaceView> => ): Promise<IWorkspaceView | undefined> => {
await this.workspaceService.updateView(workspaceSlug, viewId, data).then((response) => { const currentViewData = this.getViewDetailsById(viewId) ? cloneDeep(this.getViewDetailsById(viewId)) : undefined;
const viewToUpdate = { ...this.getViewDetailsById(viewId), ...data }; try {
runInAction(() => { Object.keys(data).forEach((key) => {
set(this.globalViewMap, viewId, viewToUpdate); const currentKey = key as keyof IWorkspaceView;
set(this.globalViewMap, [viewId, currentKey], data[currentKey]);
}); });
return response; const currentView = await this.workspaceService.updateView(workspaceSlug, viewId, data);
}); // applying the filters in the global view
if (!isEqual(currentViewData?.filters || {}, currentView?.filters || {})) {
if (isEmpty(currentView?.filters)) {
const currentGlobalViewFilters: IIssueFilterOptions = this.rootStore.issue.workspaceIssuesFilter.filters[
viewId
].filters as IIssueFilterOptions;
const newFilters: IIssueFilterOptions = {};
Object.keys(currentGlobalViewFilters ?? {}).forEach((key) => {
newFilters[key as keyof IIssueFilterOptions] = [];
});
await this.rootStore.issue.workspaceIssuesFilter.updateFilters(
workspaceSlug,
undefined,
EIssueFilterType.FILTERS,
newFilters,
viewId
);
} else {
await this.rootStore.issue.workspaceIssuesFilter.updateFilters(
workspaceSlug,
undefined,
EIssueFilterType.FILTERS,
currentView.filters,
viewId
);
}
this.rootStore.issue.workspaceIssues.fetchIssues(workspaceSlug, viewId, "mutation");
}
return currentView;
} catch {
Object.keys(data).forEach((key) => {
const currentKey = key as keyof IWorkspaceView;
if (currentViewData) set(this.globalViewMap, [viewId, currentKey], currentViewData[currentKey]);
});
}
};
/** /**
* @description delete global view * @description delete global view