2025-05-10 02:09:06 +02:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2024 PLANKA Software GmbH
|
|
|
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { call, fork, put, select, take } from 'redux-saga/effects';
|
2022-08-04 13:31:14 +02:00
|
|
|
|
|
|
|
import { goToBoard, goToProject } from './router';
|
2025-05-10 02:09:06 +02:00
|
|
|
import { openModal } from './modals';
|
2022-08-04 13:31:14 +02:00
|
|
|
import request from '../request';
|
|
|
|
import selectors from '../../../selectors';
|
|
|
|
import actions from '../../../actions';
|
|
|
|
import api from '../../../api';
|
|
|
|
import { createLocalId } from '../../../utils/local-id';
|
2025-05-10 02:09:06 +02:00
|
|
|
import ActionTypes from '../../../constants/ActionTypes';
|
|
|
|
import ModalTypes from '../../../constants/ModalTypes';
|
2022-08-04 13:31:14 +02:00
|
|
|
|
2022-12-16 23:48:06 +01:00
|
|
|
export function* createBoard(projectId, { import: boardImport, ...data }) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const localId = yield call(createLocalId);
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
const nextData = {
|
|
|
|
...data,
|
|
|
|
position: yield select(selectors.selectNextBoardPosition, projectId),
|
|
|
|
};
|
|
|
|
|
|
|
|
yield put(
|
|
|
|
actions.createBoard({
|
|
|
|
...nextData,
|
|
|
|
projectId,
|
|
|
|
id: localId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
// TODO: use race instead
|
|
|
|
const watchForCreateBoardActionTask = yield fork(function* watchForCreateBoardAction() {
|
|
|
|
yield take(ActionTypes.BOARD_CREATE);
|
|
|
|
});
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
let board;
|
|
|
|
let boardMemberships;
|
|
|
|
|
|
|
|
try {
|
|
|
|
({
|
|
|
|
item: board,
|
|
|
|
included: { boardMemberships },
|
2022-12-16 23:48:06 +01:00
|
|
|
} = yield boardImport
|
|
|
|
? call(
|
|
|
|
request,
|
|
|
|
api.createBoardWithImport,
|
|
|
|
projectId,
|
|
|
|
{
|
|
|
|
...nextData,
|
|
|
|
importType: boardImport.type,
|
|
|
|
importFile: boardImport.file,
|
|
|
|
},
|
|
|
|
localId,
|
|
|
|
)
|
|
|
|
: call(request, api.createBoard, projectId, nextData));
|
2022-08-04 13:31:14 +02:00
|
|
|
} catch (error) {
|
|
|
|
yield put(actions.createBoard.failure(localId, error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield put(actions.createBoard.success(localId, board, boardMemberships));
|
2025-05-10 02:09:06 +02:00
|
|
|
|
|
|
|
if (watchForCreateBoardActionTask.isRunning()) {
|
|
|
|
yield call(goToBoard, board.id);
|
|
|
|
yield call(openModal, ModalTypes.BOARD_SETTINGS, {
|
|
|
|
id: board.id,
|
|
|
|
openPreferences: true,
|
|
|
|
});
|
|
|
|
}
|
2022-08-04 13:31:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function* createBoardInCurrentProject(data) {
|
|
|
|
const { projectId } = yield select(selectors.selectPath);
|
|
|
|
|
|
|
|
yield call(createBoard, projectId, data);
|
|
|
|
}
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
export function* handleBoardCreate(board, boardMemberships, requestId) {
|
2022-12-16 23:48:06 +01:00
|
|
|
const isExists = yield select(selectors.selectIsBoardWithIdExists, requestId);
|
|
|
|
|
|
|
|
if (!isExists) {
|
2025-05-10 02:09:06 +02:00
|
|
|
yield put(actions.handleBoardCreate(board, boardMemberships));
|
2022-12-16 23:48:06 +01:00
|
|
|
}
|
2022-08-04 13:31:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function* fetchBoard(id) {
|
|
|
|
yield put(actions.fetchBoard(id));
|
|
|
|
|
|
|
|
let board;
|
|
|
|
let users;
|
|
|
|
let projects;
|
|
|
|
let boardMemberships;
|
|
|
|
let labels;
|
|
|
|
let lists;
|
|
|
|
let cards;
|
|
|
|
let cardMemberships;
|
|
|
|
let cardLabels;
|
2025-05-10 02:09:06 +02:00
|
|
|
let taskLists;
|
2022-08-04 13:31:14 +02:00
|
|
|
let tasks;
|
|
|
|
let attachments;
|
2025-05-10 02:09:06 +02:00
|
|
|
let customFieldGroups;
|
|
|
|
let customFields;
|
|
|
|
let customFieldValues;
|
2022-08-04 13:31:14 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
({
|
|
|
|
item: board,
|
|
|
|
included: {
|
|
|
|
users,
|
|
|
|
projects,
|
|
|
|
boardMemberships,
|
|
|
|
labels,
|
|
|
|
lists,
|
|
|
|
cards,
|
|
|
|
cardMemberships,
|
|
|
|
cardLabels,
|
2025-05-10 02:09:06 +02:00
|
|
|
taskLists,
|
2022-08-04 13:31:14 +02:00
|
|
|
tasks,
|
|
|
|
attachments,
|
2025-05-10 02:09:06 +02:00
|
|
|
customFieldGroups,
|
|
|
|
customFields,
|
|
|
|
customFieldValues,
|
2022-08-04 13:31:14 +02:00
|
|
|
},
|
2023-01-05 15:03:06 +01:00
|
|
|
} = yield call(request, api.getBoard, id, true));
|
2022-08-04 13:31:14 +02:00
|
|
|
} catch (error) {
|
|
|
|
yield put(actions.fetchBoard.failure(id, error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield put(
|
|
|
|
actions.fetchBoard.success(
|
|
|
|
board,
|
|
|
|
users,
|
|
|
|
projects,
|
|
|
|
boardMemberships,
|
|
|
|
labels,
|
|
|
|
lists,
|
|
|
|
cards,
|
|
|
|
cardMemberships,
|
|
|
|
cardLabels,
|
2025-05-10 02:09:06 +02:00
|
|
|
taskLists,
|
2022-08-04 13:31:14 +02:00
|
|
|
tasks,
|
|
|
|
attachments,
|
2025-05-10 02:09:06 +02:00
|
|
|
customFieldGroups,
|
|
|
|
customFields,
|
|
|
|
customFieldValues,
|
2022-08-04 13:31:14 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* updateBoard(id, data) {
|
|
|
|
yield put(actions.updateBoard(id, data));
|
|
|
|
|
|
|
|
let board;
|
|
|
|
try {
|
|
|
|
({ item: board } = yield call(request, api.updateBoard, id, data));
|
|
|
|
} catch (error) {
|
|
|
|
yield put(actions.updateBoard.failure(id, error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield put(actions.updateBoard.success(board));
|
|
|
|
}
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
export function* updateCurrentBoard(data) {
|
|
|
|
const { boardId } = yield select(selectors.selectPath);
|
|
|
|
|
|
|
|
yield call(updateBoard, boardId, data);
|
|
|
|
}
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
export function* handleBoardUpdate(board) {
|
|
|
|
yield put(actions.handleBoardUpdate(board));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* moveBoard(id, index) {
|
|
|
|
const { projectId } = yield select(selectors.selectBoardById, id);
|
|
|
|
const position = yield select(selectors.selectNextBoardPosition, projectId, index, id);
|
|
|
|
|
|
|
|
yield call(updateBoard, id, {
|
|
|
|
position,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
export function* updateBoardContext(id, value) {
|
|
|
|
yield put(actions.updateBoardContext(id, value));
|
|
|
|
}
|
2022-08-04 13:31:14 +02:00
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
export function* updateContextInCurrentBoard(value) {
|
|
|
|
const { boardId } = yield select(selectors.selectPath);
|
|
|
|
|
|
|
|
yield call(updateBoardContext, boardId, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* updateBoardView(id, value) {
|
|
|
|
yield put(
|
|
|
|
actions.updateBoard(id, {
|
|
|
|
view: value,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* updateViewInCurrentBoard(value) {
|
|
|
|
const { boardId } = yield select(selectors.selectPath);
|
|
|
|
|
|
|
|
yield call(updateBoardView, boardId, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* searchInCurrentBoard(value) {
|
|
|
|
const { boardId } = yield select(selectors.selectPath);
|
|
|
|
const currentListId = yield select(selectors.selectCurrentListId);
|
|
|
|
|
|
|
|
yield put(actions.searchInBoard(boardId, value, currentListId));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* deleteBoard(id) {
|
|
|
|
const currentBoard = yield select(selectors.selectCurrentBoard);
|
2022-08-04 13:31:14 +02:00
|
|
|
|
|
|
|
yield put(actions.deleteBoard(id));
|
|
|
|
|
2025-05-10 02:09:06 +02:00
|
|
|
if (currentBoard && id === currentBoard.id) {
|
|
|
|
yield call(goToProject, currentBoard.projectId);
|
|
|
|
}
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
let board;
|
|
|
|
try {
|
|
|
|
({ item: board } = yield call(request, api.deleteBoard, id));
|
|
|
|
} catch (error) {
|
|
|
|
yield put(actions.deleteBoard.failure(id, error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield put(actions.deleteBoard.success(board));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function* handleBoardDelete(board) {
|
2025-05-10 02:09:06 +02:00
|
|
|
const { boardId } = yield select(selectors.selectPath);
|
|
|
|
|
|
|
|
yield put(actions.handleBoardDelete(board));
|
2022-08-04 13:31:14 +02:00
|
|
|
|
|
|
|
if (board.id === boardId) {
|
2025-05-10 02:09:06 +02:00
|
|
|
yield call(goToProject, board.projectId);
|
2022-08-04 13:31:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
createBoard,
|
|
|
|
createBoardInCurrentProject,
|
|
|
|
handleBoardCreate,
|
|
|
|
fetchBoard,
|
|
|
|
updateBoard,
|
2025-05-10 02:09:06 +02:00
|
|
|
updateCurrentBoard,
|
2022-08-04 13:31:14 +02:00
|
|
|
handleBoardUpdate,
|
|
|
|
moveBoard,
|
2025-05-10 02:09:06 +02:00
|
|
|
updateBoardContext,
|
|
|
|
updateContextInCurrentBoard,
|
|
|
|
updateBoardView,
|
|
|
|
updateViewInCurrentBoard,
|
|
|
|
searchInCurrentBoard,
|
2022-08-04 13:31:14 +02:00
|
|
|
deleteBoard,
|
|
|
|
handleBoardDelete,
|
|
|
|
};
|