Skip to content

Commit

Permalink
[WEB-1183] fix: updated global issues filter while updating global vi…
Browse files Browse the repository at this point in the history
…ew (makeplane#4357)

* chore: Updated global issues filter while updating global view

* fix: globale view modal clear all

---------

Co-authored-by: gurusainath <[email protected]>
  • Loading branch information
anmolsinghbhatia and gurusainath authored May 3, 2024
1 parent 527ecd7 commit c96225c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
});
};

Expand Down
24 changes: 13 additions & 11 deletions web/components/workspace/views/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
65 changes: 55 additions & 10 deletions web/store/global-view.store.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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>;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c96225c

Please sign in to comment.