1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-23 07:09:44 +02:00

ref: Refactoring

This commit is contained in:
Maksim Eltyshev 2022-08-04 13:31:14 +02:00
parent 1f569bdb61
commit 3714bbc06f
189 changed files with 3781 additions and 3486 deletions

View file

@ -0,0 +1,179 @@
import { createSelector } from 'redux-orm';
import orm from '../orm';
import { selectPath } from './router';
import { selectCurrentUserId } from './users';
import { isLocalId } from '../utils/local-id';
export const makeSelectBoardById = () =>
createSelector(
orm,
(_, id) => id,
({ Board }, id) => {
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel.ref;
},
);
export const selectBoardById = makeSelectBoardById();
export const selectCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel.ref;
},
);
export const selectMembershipsForCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
(state) => selectCurrentUserId(state),
({ Board }, id, currentUserId) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel
.getOrderedMembershipsQuerySet()
.toModelArray()
.map((boardMembershipModel) => ({
...boardMembershipModel.ref,
isPersisted: !isLocalId(boardMembershipModel.id),
user: {
...boardMembershipModel.user.ref,
isCurrent: boardMembershipModel.user.id === currentUserId,
},
}));
},
);
export const selectLabelsForCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel.labels.toRefArray().map((label) => ({
...label,
isPersisted: !isLocalId(label.id),
}));
},
);
export const selectListIdsForCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel
.getOrderedListsQuerySet()
.toRefArray()
.map((list) => list.id);
},
);
export const selectFilterUsersForCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel.filterUsers.toRefArray();
},
);
export const selectFilterLabelsForCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
({ Board }, id) => {
if (!id) {
return id;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return boardModel;
}
return boardModel.filterLabels.toRefArray();
},
);
export const selectIsCurrentUserMemberForCurrentBoard = createSelector(
orm,
(state) => selectPath(state).boardId,
(state) => selectCurrentUserId(state),
({ Board }, id, currentUserId) => {
if (!id) {
return false;
}
const boardModel = Board.withId(id);
if (!boardModel) {
return false;
}
return boardModel.hasMemberUser(currentUserId);
},
);
export default {
makeSelectBoardById,
selectBoardById,
selectCurrentBoard,
selectMembershipsForCurrentBoard,
selectLabelsForCurrentBoard,
selectListIdsForCurrentBoard,
selectFilterUsersForCurrentBoard,
selectFilterLabelsForCurrentBoard,
selectIsCurrentUserMemberForCurrentBoard,
};