[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 ?? {}),
},
}).then((res) => {
captureEvent(GLOBAL_VIEW_UPDATED, {
view_id: res.id,
applied_filters: res.filters,
state: "SUCCESS",
element: "Spreadsheet view",
});
if (res)
captureEvent(GLOBAL_VIEW_UPDATED, {
view_id: res.id,
applied_filters: res.filters,
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)
.then((res) => {
captureEvent(GLOBAL_VIEW_UPDATED, {
view_id: res.id,
applied_filters: res.filters,
state: "SUCCESS",
});
setToast({
type: TOAST_TYPE.SUCCESS,
title: "Success!",
message: "View updated successfully.",
});
handleClose();
if (res) {
captureEvent(GLOBAL_VIEW_UPDATED, {
view_id: res.id,
applied_filters: res.filters,
state: "SUCCESS",
});
setToast({
type: TOAST_TYPE.SUCCESS,
title: "Success!",
message: "View updated successfully.",
});
handleClose();
}
})
.catch(() => {
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 { computedFn } from "mobx-utils";
import { IIssueFilterOptions, IWorkspaceView } from "@plane/types";
// constants
import { EIssueFilterType } from "@/constants/issue";
// services
import { WorkspaceService } from "@/services/workspace.service";
// types
import { RootStore } from "@/store/root.store";
import { IWorkspaceView } from "@plane/types";
export interface IGlobalViewStore {
// observables
@ -20,7 +25,11 @@ export interface IGlobalViewStore {
fetchGlobalViewDetails: (workspaceSlug: string, viewId: string) => Promise<IWorkspaceView>;
// crud actions
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>;
}
@ -139,14 +148,50 @@ export class GlobalViewStore implements IGlobalViewStore {
workspaceSlug: string,
viewId: string,
data: Partial<IWorkspaceView>
): Promise<IWorkspaceView> =>
await this.workspaceService.updateView(workspaceSlug, viewId, data).then((response) => {
const viewToUpdate = { ...this.getViewDetailsById(viewId), ...data };
runInAction(() => {
set(this.globalViewMap, viewId, viewToUpdate);
): Promise<IWorkspaceView | undefined> => {
const currentViewData = this.getViewDetailsById(viewId) ? cloneDeep(this.getViewDetailsById(viewId)) : undefined;
try {
Object.keys(data).forEach((key) => {
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