mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
7a21855ab6
* Pragmatic drag and drop implmentation of Kanban * refactor pragmatic dnd implementation and fix bugs * fix dnd for modules, cycles, draft and project views
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import { action, computed, makeObservable, observable } from "mobx";
|
|
import { computedFn } from "mobx-utils";
|
|
import { IssueRootStore } from "./root.store";
|
|
import { TIssueGroupByOptions } from "@plane/types";
|
|
// types
|
|
|
|
export interface IIssueKanBanViewStore {
|
|
kanBanToggle: {
|
|
groupByHeaderMinMax: string[];
|
|
subgroupByIssuesVisibility: string[];
|
|
};
|
|
isDragging: boolean;
|
|
// computed
|
|
getCanUserDragDrop: (
|
|
group_by: TIssueGroupByOptions | undefined,
|
|
sub_group_by: TIssueGroupByOptions | undefined
|
|
) => boolean;
|
|
canUserDragDropVertically: boolean;
|
|
canUserDragDropHorizontally: boolean;
|
|
// actions
|
|
handleKanBanToggle: (toggle: "groupByHeaderMinMax" | "subgroupByIssuesVisibility", value: string) => void;
|
|
setIsDragging: (isDragging: boolean) => void;
|
|
}
|
|
|
|
export class IssueKanBanViewStore implements IIssueKanBanViewStore {
|
|
kanBanToggle: {
|
|
groupByHeaderMinMax: string[];
|
|
subgroupByIssuesVisibility: string[];
|
|
} = { groupByHeaderMinMax: [], subgroupByIssuesVisibility: [] };
|
|
isDragging = false;
|
|
// root store
|
|
rootStore;
|
|
|
|
constructor(_rootStore: IssueRootStore) {
|
|
makeObservable(this, {
|
|
kanBanToggle: observable,
|
|
isDragging: observable.ref,
|
|
// computed
|
|
canUserDragDropVertically: computed,
|
|
canUserDragDropHorizontally: computed,
|
|
|
|
// actions
|
|
handleKanBanToggle: action,
|
|
setIsDragging: action.bound,
|
|
});
|
|
|
|
this.rootStore = _rootStore;
|
|
}
|
|
|
|
setIsDragging = (isDragging: boolean) => {
|
|
this.isDragging = isDragging;
|
|
};
|
|
|
|
getCanUserDragDrop = computedFn(
|
|
(group_by: TIssueGroupByOptions | undefined, sub_group_by: TIssueGroupByOptions | undefined) => {
|
|
if (group_by && ["state", "priority"].includes(group_by)) {
|
|
if (!sub_group_by) return true;
|
|
if (sub_group_by && ["state", "priority"].includes(sub_group_by)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
);
|
|
|
|
get canUserDragDropVertically() {
|
|
return false;
|
|
}
|
|
|
|
get canUserDragDropHorizontally() {
|
|
return false;
|
|
}
|
|
|
|
handleKanBanToggle = (toggle: "groupByHeaderMinMax" | "subgroupByIssuesVisibility", value: string) => {
|
|
this.kanBanToggle = {
|
|
...this.kanBanToggle,
|
|
[toggle]: this.kanBanToggle[toggle].includes(value)
|
|
? this.kanBanToggle[toggle].filter((v) => v !== value)
|
|
: [...this.kanBanToggle[toggle], value],
|
|
};
|
|
};
|
|
}
|