mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: updated store and added favorite
This commit is contained in:
parent
05e4311e06
commit
088cc8c659
45
packages/types/src/view.d.ts
vendored
45
packages/types/src/view.d.ts
vendored
@ -53,23 +53,36 @@ export type TViewDisplayProperties = {
|
|||||||
updated_on: boolean;
|
updated_on: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TView = {
|
export type TViewFilterProps = {
|
||||||
id: string;
|
|
||||||
workspace: string;
|
|
||||||
project: string | undefined;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
query: string;
|
|
||||||
filters: TViewFilters;
|
filters: TViewFilters;
|
||||||
display_filters: TViewDisplayFilters;
|
display_filters: TViewDisplayFilters;
|
||||||
display_properties: TViewDisplayProperties;
|
display_properties: TViewDisplayProperties;
|
||||||
access: TViewAccess;
|
};
|
||||||
owned_by: string;
|
|
||||||
sort_order: number;
|
export type TViewFilterPartialProps = {
|
||||||
is_locked: boolean;
|
filters: Partial<TViewFilters>;
|
||||||
is_pinned: boolean;
|
display_filters: Partial<TViewDisplayFilters>;
|
||||||
created_by: string;
|
display_properties: Partial<TViewDisplayProperties>;
|
||||||
updated_by: string;
|
};
|
||||||
created_at: Date;
|
|
||||||
updated_at: Date;
|
export type TView = {
|
||||||
|
readonly id: string;
|
||||||
|
readonly workspace: string;
|
||||||
|
readonly project: string | undefined;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
readonly query: string;
|
||||||
|
filters: TViewFilters;
|
||||||
|
display_filters: TViewDisplayFilters;
|
||||||
|
display_properties: TViewDisplayProperties;
|
||||||
|
readonly access: TViewAccess;
|
||||||
|
readonly owned_by: string;
|
||||||
|
readonly sort_order: number;
|
||||||
|
readonly is_locked: boolean;
|
||||||
|
readonly is_pinned: boolean;
|
||||||
|
readonly is_favorite: boolean;
|
||||||
|
readonly created_by: string;
|
||||||
|
readonly updated_by: string;
|
||||||
|
readonly created_at: Date;
|
||||||
|
readonly updated_at: Date;
|
||||||
};
|
};
|
||||||
|
@ -110,4 +110,30 @@ export class ProjectViewService extends APIService implements TViewService {
|
|||||||
throw error?.response;
|
throw error?.response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async makeFavorite(
|
||||||
|
workspaceSlug: string,
|
||||||
|
viewId: string,
|
||||||
|
projectId: string | undefined = undefined
|
||||||
|
): Promise<TView | undefined> {
|
||||||
|
if (!projectId) return undefined;
|
||||||
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/favorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeFavorite(
|
||||||
|
workspaceSlug: string,
|
||||||
|
viewId: string,
|
||||||
|
projectId: string | undefined = undefined
|
||||||
|
): Promise<TView | undefined> {
|
||||||
|
if (!projectId) return undefined;
|
||||||
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/unfavorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,4 +110,30 @@ export class ProjectViewMeService extends APIService implements TViewService {
|
|||||||
throw error?.response;
|
throw error?.response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async makeFavorite(
|
||||||
|
workspaceSlug: string,
|
||||||
|
viewId: string,
|
||||||
|
projectId: string | undefined = undefined
|
||||||
|
): Promise<TView | undefined> {
|
||||||
|
if (!projectId) return undefined;
|
||||||
|
return this.post(`/api/users/me/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/favorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeFavorite(
|
||||||
|
workspaceSlug: string,
|
||||||
|
viewId: string,
|
||||||
|
projectId: string | undefined = undefined
|
||||||
|
): Promise<TView | undefined> {
|
||||||
|
if (!projectId) return undefined;
|
||||||
|
return this.post(`/api/users/me/workspaces/${workspaceSlug}/projects/${projectId}/views/${viewId}/unfavorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
2
web/services/view/types.d.ts
vendored
2
web/services/view/types.d.ts
vendored
@ -14,4 +14,6 @@ export type TViewService = {
|
|||||||
lock: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
lock: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
||||||
unlock: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
unlock: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
||||||
duplicate: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
duplicate: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
||||||
|
makeFavorite: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
||||||
|
removeFavorite: (workspaceSlug: string, viewId: string, projectId?: string) => Promise<TView | undefined>;
|
||||||
};
|
};
|
||||||
|
@ -73,4 +73,20 @@ export class WorkspaceViewService extends APIService implements TViewService {
|
|||||||
throw error?.response;
|
throw error?.response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async makeFavorite(workspaceSlug: string, viewId: string): Promise<TView> {
|
||||||
|
return this.post(`/api/workspaces/${workspaceSlug}/views/${viewId}/favorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeFavorite(workspaceSlug: string, viewId: string): Promise<TView> {
|
||||||
|
return this.post(`/api/workspaces/${workspaceSlug}/views/${viewId}/unfavorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,4 +73,20 @@ export class WorkspaceMeViewService extends APIService implements TViewService {
|
|||||||
throw error?.response;
|
throw error?.response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async makeFavorite(workspaceSlug: string, viewId: string): Promise<TView> {
|
||||||
|
return this.post(`/api/users/me/workspaces/${workspaceSlug}/views/${viewId}/favorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeFavorite(workspaceSlug: string, viewId: string): Promise<TView> {
|
||||||
|
return this.post(`/api/users/me/workspaces/${workspaceSlug}/views/${viewId}/unfavorite/`)
|
||||||
|
.then((response) => response?.data)
|
||||||
|
.catch((error) => {
|
||||||
|
throw error?.response;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1
web/store/view/filters_helpers.ts
Normal file
1
web/store/view/filters_helpers.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export class ViewFilterHelpers {}
|
@ -1,8 +1,8 @@
|
|||||||
// types
|
// types
|
||||||
import { action, computed, makeObservable, observable } from "mobx";
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||||
// stores
|
// stores
|
||||||
import { RootStore } from "store/root.store";
|
import { RootStore } from "store/root.store";
|
||||||
import { Views } from "./view.store";
|
import { ViewsStore } from "./view.store";
|
||||||
// types
|
// types
|
||||||
import { TViewService } from "services/view/types";
|
import { TViewService } from "services/view/types";
|
||||||
import { TView } from "@plane/types";
|
import { TView } from "@plane/types";
|
||||||
@ -12,10 +12,9 @@ export type TLoader = "" | undefined;
|
|||||||
|
|
||||||
type TViewRoot = {
|
type TViewRoot = {
|
||||||
// observables
|
// observables
|
||||||
viewMap: Record<string, Views>;
|
viewMap: Record<string, ViewsStore>;
|
||||||
// computed
|
// computed
|
||||||
viewIds: string[];
|
viewIds: string[];
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
fetch: () => Promise<void>;
|
fetch: () => Promise<void>;
|
||||||
create: (view: Partial<TView>) => Promise<void>;
|
create: (view: Partial<TView>) => Promise<void>;
|
||||||
@ -24,7 +23,7 @@ type TViewRoot = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class ViewRoot implements TViewRoot {
|
export class ViewRoot implements TViewRoot {
|
||||||
viewMap: Record<string, Views> = {};
|
viewMap: Record<string, ViewsStore> = {};
|
||||||
|
|
||||||
constructor(private store: RootStore, private service: TViewService) {
|
constructor(private store: RootStore, private service: TViewService) {
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
@ -51,59 +50,51 @@ export class ViewRoot implements TViewRoot {
|
|||||||
|
|
||||||
// actions
|
// actions
|
||||||
fetch = async () => {
|
fetch = async () => {
|
||||||
try {
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
if (!workspaceSlug) return;
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const views = await this.service.fetch(workspaceSlug, projectId);
|
const views = await this.service.fetch(workspaceSlug, projectId);
|
||||||
if (!views) return;
|
if (!views) return;
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
views.forEach((view) => {
|
views.forEach((view) => {
|
||||||
set(this.viewMap, [view.id], new Views(this.store, view, this.service));
|
set(this.viewMap, [view.id], new ViewsStore(this.store, view, this.service));
|
||||||
});
|
});
|
||||||
} catch (error) {
|
});
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
create = async (_view: Partial<TView>) => {
|
create = async (data: Partial<TView>) => {
|
||||||
try {
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
if (!workspaceSlug) return;
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const view = await this.service.create(workspaceSlug, _view, projectId);
|
const view = await this.service.create(workspaceSlug, data, projectId);
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
|
|
||||||
set(this.viewMap, [view.id], new Views(this.store, view, this.service));
|
runInAction(() => {
|
||||||
} catch (error) {
|
set(this.viewMap, [view.id], new ViewsStore(this.store, view, this.service));
|
||||||
console.log(error);
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
delete = async (viewId: string) => {
|
delete = async (viewId: string) => {
|
||||||
try {
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
if (!workspaceSlug) return;
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
await this.service.remove(workspaceSlug, viewId, projectId);
|
await this.service.remove(workspaceSlug, viewId, projectId);
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
delete this.viewMap[viewId];
|
delete this.viewMap[viewId];
|
||||||
} catch (error) {
|
});
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
duplicate = async (viewId: string) => {
|
duplicate = async (viewId: string) => {
|
||||||
try {
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
if (!workspaceSlug) return;
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const view = await this.service.duplicate(workspaceSlug, viewId, projectId);
|
const view = await this.service.duplicate(workspaceSlug, viewId, projectId);
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
|
|
||||||
set(this.viewMap, [view.id], new Views(this.store, view, this.service));
|
runInAction(() => {
|
||||||
} catch (error) {
|
set(this.viewMap, [view.id], new ViewsStore(this.store, view, this.service));
|
||||||
console.log(error);
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,43 @@
|
|||||||
import { action, computed, makeObservable } from "mobx";
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||||
|
import set from "lodash/set";
|
||||||
// store
|
// store
|
||||||
import { RootStore } from "store/root.store";
|
import { RootStore } from "store/root.store";
|
||||||
// types
|
// types
|
||||||
import { TViewService } from "services/view/types";
|
import { TViewService } from "services/view/types";
|
||||||
import { TView, TViewFilters, TViewDisplayFilters, TViewDisplayProperties, TViewAccess } from "@plane/types";
|
import {
|
||||||
|
TView,
|
||||||
|
TViewFilters,
|
||||||
|
TViewDisplayFilters,
|
||||||
|
TViewDisplayProperties,
|
||||||
|
TViewFilterProps,
|
||||||
|
TViewFilterPartialProps,
|
||||||
|
TViewAccess,
|
||||||
|
} from "@plane/types";
|
||||||
|
|
||||||
export type TViews = TView & {
|
type TLoader = "submitting" | "submit" | undefined;
|
||||||
|
|
||||||
|
export type TViewsStore = TView & {
|
||||||
|
// observables
|
||||||
|
loader: TLoader;
|
||||||
|
filtersToUpdate: TViewFilterPartialProps;
|
||||||
// computed
|
// computed
|
||||||
user: undefined;
|
appliedFilters: TViewFilterProps | undefined;
|
||||||
|
appliedFiltersQueryParams: undefined;
|
||||||
|
// helper actions
|
||||||
|
updateFilters: (filters: Partial<TViewFilters>) => void;
|
||||||
|
updateDisplayFilters: (display_filters: Partial<TViewDisplayFilters>) => void;
|
||||||
|
updateDisplayProperties: (display_properties: Partial<TViewDisplayProperties>) => void;
|
||||||
|
resetFilterChanges: () => void;
|
||||||
|
saveFilterChanges: () => void;
|
||||||
// actions
|
// actions
|
||||||
updateName: (name: string) => Promise<void>;
|
|
||||||
updateDescription: (description: string) => Promise<void>;
|
|
||||||
updateFilters: (filters: Partial<TViewFilters>) => Promise<void>;
|
|
||||||
updateDisplayFilters: (display_filters: Partial<TViewDisplayFilters>) => Promise<void>;
|
|
||||||
updateDisplayProperties: (display_properties: Partial<TViewDisplayProperties>) => Promise<void>;
|
|
||||||
lockView: () => Promise<void>;
|
lockView: () => Promise<void>;
|
||||||
unlockView: () => Promise<void>;
|
unlockView: () => Promise<void>;
|
||||||
|
makeFavorite: () => Promise<void>;
|
||||||
|
removeFavorite: () => Promise<void>;
|
||||||
|
update: (viewData: Partial<TView>) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Views implements TViews {
|
export class ViewsStore implements TViewsStore {
|
||||||
id: string;
|
id: string;
|
||||||
workspace: string;
|
workspace: string;
|
||||||
project: string | undefined;
|
project: string | undefined;
|
||||||
@ -34,11 +52,19 @@ export class Views implements TViews {
|
|||||||
sort_order: number;
|
sort_order: number;
|
||||||
is_locked: boolean;
|
is_locked: boolean;
|
||||||
is_pinned: boolean;
|
is_pinned: boolean;
|
||||||
|
is_favorite: boolean;
|
||||||
created_by: string;
|
created_by: string;
|
||||||
updated_by: string;
|
updated_by: string;
|
||||||
created_at: Date;
|
created_at: Date;
|
||||||
updated_at: Date;
|
updated_at: Date;
|
||||||
|
|
||||||
|
loader: TLoader = undefined;
|
||||||
|
filtersToUpdate: TViewFilterPartialProps = {
|
||||||
|
filters: {},
|
||||||
|
display_filters: {},
|
||||||
|
display_properties: {},
|
||||||
|
};
|
||||||
|
|
||||||
constructor(private store: RootStore, _view: TView, private service: TViewService) {
|
constructor(private store: RootStore, _view: TView, private service: TViewService) {
|
||||||
this.id = _view.id;
|
this.id = _view.id;
|
||||||
this.workspace = _view.workspace;
|
this.workspace = _view.workspace;
|
||||||
@ -54,133 +80,143 @@ export class Views implements TViews {
|
|||||||
this.sort_order = _view.sort_order;
|
this.sort_order = _view.sort_order;
|
||||||
this.is_locked = _view.is_locked;
|
this.is_locked = _view.is_locked;
|
||||||
this.is_pinned = _view.is_pinned;
|
this.is_pinned = _view.is_pinned;
|
||||||
|
this.is_favorite = _view.is_favorite;
|
||||||
this.created_by = _view.created_by;
|
this.created_by = _view.created_by;
|
||||||
this.updated_by = _view.updated_by;
|
this.updated_by = _view.updated_by;
|
||||||
this.created_at = _view.created_at;
|
this.created_at = _view.created_at;
|
||||||
this.updated_at = _view.updated_at;
|
this.updated_at = _view.updated_at;
|
||||||
|
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
|
// observables
|
||||||
|
loader: observable,
|
||||||
|
filtersToUpdate: observable.ref,
|
||||||
// computed
|
// computed
|
||||||
user: computed,
|
appliedFilters: computed,
|
||||||
// actions
|
appliedFiltersQueryParams: computed,
|
||||||
updateName: action,
|
// helper actions
|
||||||
updateDescription: action,
|
|
||||||
updateFilters: action,
|
updateFilters: action,
|
||||||
updateDisplayFilters: action,
|
updateDisplayFilters: action,
|
||||||
updateDisplayProperties: action,
|
updateDisplayProperties: action,
|
||||||
|
resetFilterChanges: action,
|
||||||
|
saveFilterChanges: action,
|
||||||
|
// actions
|
||||||
|
update: action,
|
||||||
lockView: action,
|
lockView: action,
|
||||||
unlockView: action,
|
unlockView: action,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// computed
|
// computed
|
||||||
get user() {
|
get appliedFilters() {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// actions
|
get appliedFiltersQueryParams() {
|
||||||
updateName = async (name: string) => {
|
return undefined;
|
||||||
try {
|
}
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const view = await this.service.update(workspaceSlug, this.id, { name: name }, projectId);
|
// helper actions
|
||||||
if (!view) return;
|
updateFilters = (filters: Partial<TViewFilters>) => {
|
||||||
|
runInAction(() => {
|
||||||
this.name = view.name;
|
this.loader = "submit";
|
||||||
} catch (error) {
|
this.filtersToUpdate.filters = filters;
|
||||||
console.log(error);
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
updateDescription = async (description: string) => {
|
|
||||||
try {
|
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const view = await this.service.update(workspaceSlug, this.id, { description: description }, projectId);
|
|
||||||
if (!view) return;
|
|
||||||
|
|
||||||
this.description = view.description;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
updateFilters = async (filters: Partial<TViewFilters>) => {
|
|
||||||
try {
|
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const viewFilters = this.filters;
|
|
||||||
const _filters = { ...viewFilters, ...filters };
|
|
||||||
|
|
||||||
const view = await this.service.update(workspaceSlug, this.id, { filters: _filters }, projectId);
|
|
||||||
if (!view) return;
|
|
||||||
|
|
||||||
this.filters = view.filters;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updateDisplayFilters = async (display_filters: Partial<TViewDisplayFilters>) => {
|
updateDisplayFilters = async (display_filters: Partial<TViewDisplayFilters>) => {
|
||||||
try {
|
runInAction(() => {
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
this.loader = "submit";
|
||||||
if (!workspaceSlug) return;
|
this.filtersToUpdate.display_filters = display_filters;
|
||||||
|
});
|
||||||
const viewDisplayFilters = this.display_filters;
|
|
||||||
const _filters = { ...viewDisplayFilters, ...display_filters };
|
|
||||||
|
|
||||||
const view = await this.service.update(workspaceSlug, this.id, { display_filters: _filters }, projectId);
|
|
||||||
if (!view) return;
|
|
||||||
|
|
||||||
this.display_filters = view.display_filters;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
updateDisplayProperties = async (display_properties: Partial<TViewDisplayProperties>) => {
|
updateDisplayProperties = async (display_properties: Partial<TViewDisplayProperties>) => {
|
||||||
try {
|
runInAction(() => {
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
this.loader = "submit";
|
||||||
if (!workspaceSlug) return;
|
this.filtersToUpdate.display_properties = display_properties;
|
||||||
|
});
|
||||||
const viewDisplayProperties = this.display_properties;
|
|
||||||
const _filters = { ...viewDisplayProperties, ...display_properties };
|
|
||||||
|
|
||||||
const view = await this.service.update(workspaceSlug, this.id, { display_properties: _filters }, projectId);
|
|
||||||
if (!view) return;
|
|
||||||
|
|
||||||
this.display_properties = view.display_properties;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resetFilterChanges = () => {
|
||||||
|
runInAction(() => {
|
||||||
|
this.loader = undefined;
|
||||||
|
this.filtersToUpdate = {
|
||||||
|
filters: {},
|
||||||
|
display_filters: {},
|
||||||
|
display_properties: {},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
saveFilterChanges = async () => {
|
||||||
|
this.loader = "submitting";
|
||||||
|
if (this.appliedFilters) await this.update(this.appliedFilters);
|
||||||
|
this.loader = undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
// actions
|
||||||
lockView = async () => {
|
lockView = async () => {
|
||||||
try {
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
if (!workspaceSlug) return;
|
||||||
if (!workspaceSlug) return;
|
|
||||||
|
|
||||||
const view = await this.service.lock(workspaceSlug, this.id, projectId);
|
const view = await this.service.lock(workspaceSlug, this.id, projectId);
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
this.is_locked = view.is_locked;
|
this.is_locked = view.is_locked;
|
||||||
} catch (error) {
|
});
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
unlockView = async () => {
|
unlockView = async () => {
|
||||||
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
|
const view = await this.service.unlock(workspaceSlug, this.id, projectId);
|
||||||
|
if (!view) return;
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
|
this.is_locked = view.is_locked;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
makeFavorite = async () => {
|
||||||
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
|
const view = await this.service.makeFavorite(workspaceSlug, this.id, projectId);
|
||||||
|
if (!view) return;
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
|
this.is_favorite = view.is_locked;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
removeFavorite = async () => {
|
||||||
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
|
const view = await this.service.removeFavorite(workspaceSlug, this.id, projectId);
|
||||||
|
if (!view) return;
|
||||||
|
|
||||||
|
runInAction(() => {
|
||||||
|
this.is_favorite = view.is_locked;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
update = async (viewData: Partial<TView>) => {
|
||||||
try {
|
try {
|
||||||
const { workspaceSlug, projectId } = this.store.app.router;
|
const { workspaceSlug, projectId } = this.store.app.router;
|
||||||
if (!workspaceSlug) return;
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
const view = await this.service.unlock(workspaceSlug, this.id, projectId);
|
const view = await this.service.update(workspaceSlug, this.id, viewData, projectId);
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
|
|
||||||
this.is_locked = view.is_locked;
|
runInAction(() => {
|
||||||
|
Object.keys(viewData).forEach((key) => {
|
||||||
|
const _key = key as keyof TView;
|
||||||
|
set(this, _key, viewData[_key]);
|
||||||
|
});
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user