Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(board): allow column moves while sorting by task number (#1816)

Tin Sever5db34f01c769
diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsx
index 1146c855c..0e12e9400 100644
--- a/apps/web/src/components/kanban-board/index.tsx
+++ b/apps/web/src/components/kanban-board/index.tsx
@@ -32,11 +32,16 @@ import TaskCard from "./task-card";
type KanbanBoardProps = {
project: ProjectWithTasks;
disableDragDrop?: boolean;
+ sortedByNumber?: boolean;
};
-function KanbanBoard({ project, disableDragDrop = false }: KanbanBoardProps) {
+function KanbanBoard({
+ project,
+ disableDragDrop = false,
+ sortedByNumber = false,
+}: KanbanBoardProps) {
const queryClient = useQueryClient();
- const { setProject } = useProjectStore();
+ const { project: storedProject, setProject } = useProjectStore();
const {
setAvailableTasks,
focusNext,
@@ -144,6 +149,62 @@ function KanbanBoard({ project, disableDragDrop = false }: KanbanBoardProps) {
const activeId = active.id.toString();
const overId = over.id.toString();
+ if (sortedByNumber) {
+ const sourceColumn = project.columns.find((column) =>
+ column.tasks.some((task) => task.id === activeId),
+ );
+ const destinationColumn = project.columns.find(
+ (column) =>
+ column.id === overId ||
+ column.tasks.some((task) => task.id === overId),
+ );
+
+ if (
+ !sourceColumn ||
+ !destinationColumn ||
+ sourceColumn.id === destinationColumn.id
+ ) {
+ return;
+ }
+
+ const currentProject = storedProject ?? project;
+ const currentDestination = currentProject.columns.find(
+ (column) => column.id === destinationColumn.id,
+ );
+ const position =
+ Math.max(
+ -1,
+ ...(currentDestination?.tasks.map((task) => task.position ?? -1) ??
+ []),
+ ) + 1;
+ const updatedProject = produce(currentProject, (draft) => {
+ const source = draft.columns.find((column) =>
+ column.tasks.some((task) => task.id === activeId),
+ );
+ const destination = draft.columns.find(
+ (column) => column.id === destinationColumn.id,
+ );
+ if (!source || !destination) return;
+
+ const taskIndex = source.tasks.findIndex(
+ (task) => task.id === activeId,
+ );
+ const [task] = source.tasks.splice(taskIndex, 1);
+ task.status = destination.slug;
+ task.position = position;
+ destination.tasks.push(task);
+ });
+
+ const movedTask = updatedProject.columns
+ .find((column) => column.id === destinationColumn.id)
+ ?.tasks.find((task) => task.id === activeId);
+ if (!movedTask) return;
+
+ setProject(updatedProject);
+ updateTask(movedTask);
+ return;
+ }
+
const updatedProject = produce(project, (draft) => {
const sourceColumn = draft?.columns?.find((col) =>
col.tasks.some((task) => task.id === activeId),
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx
index 34b22d965..00190d305 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/project/$projectId/board.tsx
@@ -309,7 +309,10 @@ function RouteComponent() {
viewMode === "board" ? (
<KanbanBoard
project={sortedProject}
- disableDragDrop={sort.field !== "position"}
+ disableDragDrop={
+ sort.field !== "position" && sort.field !== "number"
+ }
+ sortedByNumber={sort.field === "number"}
/>
) : (
<ListView