feat: Add ability to move lists between boards (#1208)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { call, put, select } from 'redux-saga/effects';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
import { goToBoard } from './router';
|
||||
import request from '../request';
|
||||
import selectors from '../../../selectors';
|
||||
import actions from '../../../actions';
|
||||
@@ -65,7 +66,71 @@ export function* updateList(id, data) {
|
||||
}
|
||||
|
||||
export function* handleListUpdate(list) {
|
||||
yield put(actions.handleListUpdate(list));
|
||||
const currentCard = yield select(selectors.selectCurrentCard);
|
||||
|
||||
let fetch = false;
|
||||
if (list.boardId) {
|
||||
const isAvailableForCurrentUser = yield select(
|
||||
selectors.selectIsListWithIdAvailableForCurrentUser,
|
||||
list.id,
|
||||
);
|
||||
|
||||
fetch = !isAvailableForCurrentUser;
|
||||
}
|
||||
|
||||
let users;
|
||||
let cards;
|
||||
let cardMemberships;
|
||||
let cardLabels;
|
||||
let taskLists;
|
||||
let tasks;
|
||||
let attachments;
|
||||
let customFieldGroups;
|
||||
let customFields;
|
||||
let customFieldValues;
|
||||
|
||||
if (fetch) {
|
||||
try {
|
||||
({
|
||||
item: list, // eslint-disable-line no-param-reassign
|
||||
included: {
|
||||
users,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
attachments,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
},
|
||||
} = yield call(request, api.getList, list.id));
|
||||
} catch {
|
||||
fetch = false;
|
||||
}
|
||||
}
|
||||
|
||||
yield put(
|
||||
actions.handleListUpdate(
|
||||
list,
|
||||
fetch,
|
||||
users,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
attachments,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
),
|
||||
);
|
||||
|
||||
if (list.boardId === null && currentCard && list.id === currentCard.listId) {
|
||||
yield call(goToBoard, currentCard.boardId);
|
||||
}
|
||||
}
|
||||
|
||||
export function* moveList(id, index) {
|
||||
@@ -77,6 +142,19 @@ export function* moveList(id, index) {
|
||||
});
|
||||
}
|
||||
|
||||
export function* transferList(id, boardId) {
|
||||
const currentCard = yield select(selectors.selectCurrentCard);
|
||||
|
||||
// TODO: hack?
|
||||
if (currentCard && id === currentCard.listId) {
|
||||
yield call(goToBoard, currentCard.boardId);
|
||||
}
|
||||
|
||||
yield call(updateList, id, {
|
||||
boardId,
|
||||
});
|
||||
}
|
||||
|
||||
export function* sortList(id, data) {
|
||||
yield put(actions.sortList(id, data));
|
||||
|
||||
@@ -190,6 +268,7 @@ export default {
|
||||
updateList,
|
||||
handleListUpdate,
|
||||
moveList,
|
||||
transferList,
|
||||
sortList,
|
||||
moveListCardsToArchiveList,
|
||||
clearTrashListInCurrentBoard,
|
||||
|
||||
@@ -28,6 +28,9 @@ export default function* listsWatchers() {
|
||||
takeEvery(EntryActionTypes.LIST_SORT, ({ payload: { id, data } }) =>
|
||||
services.sortList(id, data),
|
||||
),
|
||||
takeEvery(EntryActionTypes.LIST_TRANSFER, ({ payload: { id, boardId, index } }) =>
|
||||
services.transferList(id, boardId, index),
|
||||
),
|
||||
takeEvery(EntryActionTypes.LIST_CARDS_TO_ARCHIVE_LIST_MOVE, ({ payload: { id } }) =>
|
||||
services.moveListCardsToArchiveList(id),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user