mirror of
https://github.com/plankanban/planka.git
synced 2025-07-25 16:19:47 +02:00
Initial commit
This commit is contained in:
commit
5ffef61fe7
613 changed files with 91659 additions and 0 deletions
80
client/src/selectors/next-position.js
Executable file
80
client/src/selectors/next-position.js
Executable file
|
@ -0,0 +1,80 @@
|
|||
import { createSelector } from 'redux-orm';
|
||||
import isUndefined from 'lodash/isUndefined';
|
||||
|
||||
import orm from '../orm';
|
||||
import { dbSelector } from './common';
|
||||
import Config from '../constants/Config';
|
||||
|
||||
const nextPosition = (items, index, excludedId) => {
|
||||
const filteredItems = isUndefined(excludedId)
|
||||
? items
|
||||
: items.filter((item) => item.id !== excludedId);
|
||||
|
||||
if (isUndefined(index)) {
|
||||
const lastItem = filteredItems[filteredItems.length - 1];
|
||||
|
||||
return (lastItem ? lastItem.position : 0) + Config.POSITION_GAP;
|
||||
}
|
||||
|
||||
const prevItem = filteredItems[index - 1];
|
||||
const nextItem = filteredItems[index];
|
||||
|
||||
const prevPosition = prevItem ? prevItem.position : 0;
|
||||
|
||||
if (!nextItem) {
|
||||
return prevPosition + Config.POSITION_GAP;
|
||||
}
|
||||
|
||||
return prevPosition + (nextItem.position - prevPosition) / 2;
|
||||
};
|
||||
|
||||
export const nextBoardPositionSelector = createSelector(
|
||||
orm,
|
||||
dbSelector,
|
||||
(_, projectId) => projectId,
|
||||
(_, __, index) => index,
|
||||
(_, __, ___, excludedId) => excludedId,
|
||||
({ Project }, projectId, index, excludedId) => {
|
||||
const projectModel = Project.withId(projectId);
|
||||
|
||||
if (!projectModel) {
|
||||
return projectModel;
|
||||
}
|
||||
|
||||
return nextPosition(projectModel.getOrderedBoardsQuerySet().toRefArray(), index, excludedId);
|
||||
},
|
||||
);
|
||||
|
||||
export const nextListPositionSelector = createSelector(
|
||||
orm,
|
||||
dbSelector,
|
||||
(_, boardId) => boardId,
|
||||
(_, __, index) => index,
|
||||
(_, __, ___, excludedId) => excludedId,
|
||||
({ Board }, boardId, index, excludedId) => {
|
||||
const boardModel = Board.withId(boardId);
|
||||
|
||||
if (!boardModel) {
|
||||
return boardModel;
|
||||
}
|
||||
|
||||
return nextPosition(boardModel.getOrderedListsQuerySet().toRefArray(), index, excludedId);
|
||||
},
|
||||
);
|
||||
|
||||
export const nextCardPositionSelector = createSelector(
|
||||
orm,
|
||||
dbSelector,
|
||||
(_, listId) => listId,
|
||||
(_, __, index) => index,
|
||||
(_, __, ___, excludedId) => excludedId,
|
||||
({ List }, listId, index, excludedId) => {
|
||||
const listModel = List.withId(listId);
|
||||
|
||||
if (!listModel) {
|
||||
return listModel;
|
||||
}
|
||||
|
||||
return nextPosition(listModel.getOrderedFilteredCardsModelArray(), index, excludedId);
|
||||
},
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue