mirror of
https://github.com/plankanban/planka.git
synced 2025-12-27 09:14:59 +03:00
ref: Refactoring
This commit is contained in:
@@ -2,9 +2,12 @@ import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const isAttachmentWithIdExistsSelector = createSelector(
|
||||
export const selectIsAttachmentWithIdExists = createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
({ Attachment }, id) => Attachment.idExists(id),
|
||||
);
|
||||
|
||||
export default {
|
||||
selectIsAttachmentWithIdExists,
|
||||
};
|
||||
@@ -1,2 +1,5 @@
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const accessTokenSelector = ({ auth: { accessToken } }) => accessToken;
|
||||
export const selectAccessToken = ({ auth: { accessToken } }) => accessToken;
|
||||
|
||||
export default {
|
||||
selectAccessToken,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
|
||||
export const makeBoardMembershipByIdSelector = () =>
|
||||
export const makeSelectBoardMembershipById = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -17,4 +17,9 @@ export const makeBoardMembershipByIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const boardMembershipByIdSelector = makeBoardMembershipByIdSelector();
|
||||
export const selectBoardMembershipById = makeSelectBoardMembershipById();
|
||||
|
||||
export default {
|
||||
makeSelectBoardMembershipById,
|
||||
selectBoardMembershipById,
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
import { pathSelector } from './router';
|
||||
import { currentUserIdSelector } from './user';
|
||||
import { selectPath } from './router';
|
||||
import { selectCurrentUserId } from './users';
|
||||
import { isLocalId } from '../utils/local-id';
|
||||
|
||||
export const makeBoardByIdSelector = () =>
|
||||
export const makeSelectBoardById = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -20,11 +20,11 @@ export const makeBoardByIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const boardByIdSelector = makeBoardByIdSelector();
|
||||
export const selectBoardById = makeSelectBoardById();
|
||||
|
||||
export const currentBoardSelector = createSelector(
|
||||
export const selectCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => selectPath(state).boardId,
|
||||
({ Board }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -40,10 +40,10 @@ export const currentBoardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const membershipsForCurrentBoardSelector = createSelector(
|
||||
export const selectMembershipsForCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectPath(state).boardId,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Board }, id, currentUserId) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -69,9 +69,9 @@ export const membershipsForCurrentBoardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const labelsForCurrentBoardSelector = createSelector(
|
||||
export const selectLabelsForCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => selectPath(state).boardId,
|
||||
({ Board }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -90,9 +90,9 @@ export const labelsForCurrentBoardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const listIdsForCurrentBoardSelector = createSelector(
|
||||
export const selectListIdsForCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => selectPath(state).boardId,
|
||||
({ Board }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -111,9 +111,9 @@ export const listIdsForCurrentBoardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const filterUsersForCurrentBoardSelector = createSelector(
|
||||
export const selectFilterUsersForCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => selectPath(state).boardId,
|
||||
({ Board }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -129,9 +129,9 @@ export const filterUsersForCurrentBoardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const filterLabelsForCurrentBoardSelector = createSelector(
|
||||
export const selectFilterLabelsForCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => selectPath(state).boardId,
|
||||
({ Board }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -147,10 +147,10 @@ export const filterLabelsForCurrentBoardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const isCurrentUserMemberForCurrentBoardSelector = createSelector(
|
||||
export const selectIsCurrentUserMemberForCurrentBoard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).boardId,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectPath(state).boardId,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Board }, id, currentUserId) => {
|
||||
if (!id) {
|
||||
return false;
|
||||
@@ -165,3 +165,15 @@ export const isCurrentUserMemberForCurrentBoardSelector = createSelector(
|
||||
return boardModel.hasMemberUser(currentUserId);
|
||||
},
|
||||
);
|
||||
|
||||
export default {
|
||||
makeSelectBoardById,
|
||||
selectBoardById,
|
||||
selectCurrentBoard,
|
||||
selectMembershipsForCurrentBoard,
|
||||
selectLabelsForCurrentBoard,
|
||||
selectListIdsForCurrentBoard,
|
||||
selectFilterUsersForCurrentBoard,
|
||||
selectFilterLabelsForCurrentBoard,
|
||||
selectIsCurrentUserMemberForCurrentBoard,
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
import { pathSelector } from './router';
|
||||
import { currentUserIdSelector } from './user';
|
||||
import { selectPath } from './router';
|
||||
import { selectCurrentUserId } from './users';
|
||||
import { isLocalId } from '../utils/local-id';
|
||||
|
||||
export const makeCardByIdSelector = () =>
|
||||
export const makeSelectCardById = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -24,9 +24,9 @@ export const makeCardByIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const cardByIdSelector = makeCardByIdSelector();
|
||||
export const selectCardById = makeSelectCardById();
|
||||
|
||||
export const makeUsersByCardIdSelector = () =>
|
||||
export const makeSelectUsersByCardId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -41,9 +41,9 @@ export const makeUsersByCardIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const usersByCardIdSelector = makeUsersByCardIdSelector();
|
||||
export const selectUsersByCardId = makeSelectUsersByCardId();
|
||||
|
||||
export const makeLabelsByCardIdSelector = () =>
|
||||
export const makeSelectLabelsByCardId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -58,9 +58,9 @@ export const makeLabelsByCardIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const labelsByCardIdSelector = makeLabelsByCardIdSelector();
|
||||
export const selectLabelsByCardId = makeSelectLabelsByCardId();
|
||||
|
||||
export const makeTasksByCardIdSelector = () =>
|
||||
export const makeSelectTasksByCardId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -75,9 +75,9 @@ export const makeTasksByCardIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const tasksByCardIdSelector = makeTasksByCardIdSelector();
|
||||
export const selectTasksByCardId = makeSelectTasksByCardId();
|
||||
|
||||
export const makeLastActionIdByCardIdSelector = () =>
|
||||
export const makeSelectLastActivityIdByCardId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -88,15 +88,15 @@ export const makeLastActionIdByCardIdSelector = () =>
|
||||
return cardModel;
|
||||
}
|
||||
|
||||
const lastActionModel = cardModel.getFilteredOrderedInCardActionsQuerySet().last();
|
||||
const lastActivityModel = cardModel.getFilteredOrderedInCardActivitiesQuerySet().last();
|
||||
|
||||
return lastActionModel && lastActionModel.id;
|
||||
return lastActivityModel && lastActivityModel.id;
|
||||
},
|
||||
);
|
||||
|
||||
export const lastActionIdByCardIdSelector = makeLastActionIdByCardIdSelector();
|
||||
export const selectLastActivityIdByCardId = makeSelectLastActivityIdByCardId();
|
||||
|
||||
export const makeNotificationsByCardIdSelector = () =>
|
||||
export const makeSelectNotificationsByCardId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -111,9 +111,9 @@ export const makeNotificationsByCardIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const notificationsByCardIdSelector = makeNotificationsByCardIdSelector();
|
||||
export const selectNotificationsByCardId = makeSelectNotificationsByCardId();
|
||||
|
||||
export const makeNotificationsTotalByCardIdSelector = () =>
|
||||
export const makeSelectNotificationsTotalByCardId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -128,11 +128,11 @@ export const makeNotificationsTotalByCardIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const notificationsTotalByCardIdSelector = makeNotificationsTotalByCardIdSelector();
|
||||
export const selectNotificationsTotalByCardId = makeSelectNotificationsTotalByCardId();
|
||||
|
||||
export const currentCardSelector = createSelector(
|
||||
export const selectCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => selectPath(state).cardId,
|
||||
({ Card }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -148,9 +148,9 @@ export const currentCardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const usersForCurrentCardSelector = createSelector(
|
||||
export const selectUsersForCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => selectPath(state).cardId,
|
||||
({ Card }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -166,9 +166,9 @@ export const usersForCurrentCardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const labelsForCurrentCardSelector = createSelector(
|
||||
export const selectLabelsForCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => selectPath(state).cardId,
|
||||
({ Card }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -184,9 +184,9 @@ export const labelsForCurrentCardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const tasksForCurrentCardSelector = createSelector(
|
||||
export const selectTasksForCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => selectPath(state).cardId,
|
||||
({ Card }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -208,9 +208,9 @@ export const tasksForCurrentCardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const attachmentsForCurrentCardSelector = createSelector(
|
||||
export const selectAttachmentsForCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => selectPath(state).cardId,
|
||||
({ Card }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -233,10 +233,10 @@ export const attachmentsForCurrentCardSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const actionsForCurrentCardSelector = createSelector(
|
||||
export const selectActivitiesForCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectPath(state).cardId,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Card }, id, currentUserId) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -249,22 +249,22 @@ export const actionsForCurrentCardSelector = createSelector(
|
||||
}
|
||||
|
||||
return cardModel
|
||||
.getFilteredOrderedInCardActionsQuerySet()
|
||||
.getFilteredOrderedInCardActivitiesQuerySet()
|
||||
.toModelArray()
|
||||
.map((actionModel) => ({
|
||||
...actionModel.ref,
|
||||
isPersisted: !isLocalId(actionModel.id),
|
||||
.map((activityModel) => ({
|
||||
...activityModel.ref,
|
||||
isPersisted: !isLocalId(activityModel.id),
|
||||
user: {
|
||||
...actionModel.user.ref,
|
||||
isCurrent: actionModel.user.id === currentUserId,
|
||||
...activityModel.user.ref,
|
||||
isCurrent: activityModel.user.id === currentUserId,
|
||||
},
|
||||
}));
|
||||
},
|
||||
);
|
||||
|
||||
export const notificationIdsForCurrentCardSelector = createSelector(
|
||||
export const selectNotificationIdsForCurrentCard = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).cardId,
|
||||
(state) => selectPath(state).cardId,
|
||||
({ Card }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -282,3 +282,27 @@ export const notificationIdsForCurrentCardSelector = createSelector(
|
||||
.map((notification) => notification.id);
|
||||
},
|
||||
);
|
||||
|
||||
export default {
|
||||
makeSelectCardById,
|
||||
selectCardById,
|
||||
makeSelectUsersByCardId,
|
||||
selectUsersByCardId,
|
||||
makeSelectLabelsByCardId,
|
||||
selectLabelsByCardId,
|
||||
makeSelectTasksByCardId,
|
||||
selectTasksByCardId,
|
||||
makeSelectLastActivityIdByCardId,
|
||||
selectLastActivityIdByCardId,
|
||||
makeSelectNotificationsByCardId,
|
||||
selectNotificationsByCardId,
|
||||
makeSelectNotificationsTotalByCardId,
|
||||
selectNotificationsTotalByCardId,
|
||||
selectCurrentCard,
|
||||
selectUsersForCurrentCard,
|
||||
selectLabelsForCurrentCard,
|
||||
selectTasksForCurrentCard,
|
||||
selectAttachmentsForCurrentCard,
|
||||
selectActivitiesForCurrentCard,
|
||||
selectNotificationIdsForCurrentCard,
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import isUndefined from 'lodash/isUndefined';
|
||||
import orm from '../orm';
|
||||
import Config from '../constants/Config';
|
||||
|
||||
export const isCoreInitializingSelector = ({ core: { isInitializing } }) => isInitializing;
|
||||
export const selectIsCoreInitializing = ({ core: { isInitializing } }) => isInitializing;
|
||||
|
||||
const nextPosition = (items, index, excludedId) => {
|
||||
const filteredItems = isUndefined(excludedId)
|
||||
@@ -29,7 +29,7 @@ const nextPosition = (items, index, excludedId) => {
|
||||
return prevPosition + (nextItem.position - prevPosition) / 2;
|
||||
};
|
||||
|
||||
export const nextBoardPositionSelector = createSelector(
|
||||
export const selectNextBoardPosition = createSelector(
|
||||
orm,
|
||||
(_, projectId) => projectId,
|
||||
(_, __, index) => index,
|
||||
@@ -45,7 +45,7 @@ export const nextBoardPositionSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const nextListPositionSelector = createSelector(
|
||||
export const selectNextListPosition = createSelector(
|
||||
orm,
|
||||
(_, boardId) => boardId,
|
||||
(_, __, index) => index,
|
||||
@@ -61,7 +61,7 @@ export const nextListPositionSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const nextCardPositionSelector = createSelector(
|
||||
export const selectNextCardPosition = createSelector(
|
||||
orm,
|
||||
(_, listId) => listId,
|
||||
(_, __, index) => index,
|
||||
@@ -77,7 +77,7 @@ export const nextCardPositionSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const nextTaskPositionSelector = createSelector(
|
||||
export const selectNextTaskPosition = createSelector(
|
||||
orm,
|
||||
(_, cardId) => cardId,
|
||||
(_, __, index) => index,
|
||||
@@ -92,3 +92,11 @@ export const nextTaskPositionSelector = createSelector(
|
||||
return nextPosition(cardModel.getOrderedTasksQuerySet().toRefArray(), index, excludedId);
|
||||
},
|
||||
);
|
||||
|
||||
export default {
|
||||
selectIsCoreInitializing,
|
||||
selectNextBoardPosition,
|
||||
selectNextListPosition,
|
||||
selectNextCardPosition,
|
||||
selectNextTaskPosition,
|
||||
};
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
export * from './router';
|
||||
export * from './auth';
|
||||
export * from './core';
|
||||
export * from './modal';
|
||||
export * from './user';
|
||||
export * from './users';
|
||||
export * from './project';
|
||||
export * from './project-manager';
|
||||
export * from './board';
|
||||
export * from './board-membership';
|
||||
export * from './list';
|
||||
export * from './card';
|
||||
export * from './task';
|
||||
export * from './attachment';
|
||||
import router from './router';
|
||||
import auth from './auth';
|
||||
import core from './core';
|
||||
import modals from './modals';
|
||||
import users from './users';
|
||||
import projects from './projects';
|
||||
import projectManagers from './project-managers';
|
||||
import boards from './boards';
|
||||
import boardMemberships from './board-memberships';
|
||||
import lists from './lists';
|
||||
import cards from './cards';
|
||||
import tasks from './tasks';
|
||||
import attachments from './attachments';
|
||||
|
||||
export default {
|
||||
...router,
|
||||
...auth,
|
||||
...core,
|
||||
...modals,
|
||||
...users,
|
||||
...projects,
|
||||
...projectManagers,
|
||||
...boards,
|
||||
...boardMemberships,
|
||||
...lists,
|
||||
...cards,
|
||||
...tasks,
|
||||
...attachments,
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import { createSelector } from 'redux-orm';
|
||||
import orm from '../orm';
|
||||
import { isLocalId } from '../utils/local-id';
|
||||
|
||||
export const makeListByIdSelector = () =>
|
||||
export const makeSelectListById = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -21,9 +21,9 @@ export const makeListByIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const listByIdSelector = makeListByIdSelector();
|
||||
export const selectListById = makeSelectListById();
|
||||
|
||||
export const makeCardIdsByListIdSelector = () =>
|
||||
export const makeSelectCardIdsByListId = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -38,4 +38,11 @@ export const makeCardIdsByListIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const cardIdsByListIdSelector = makeCardIdsByListIdSelector();
|
||||
export const selectCardIdsByListId = makeSelectCardIdsByListId();
|
||||
|
||||
export default {
|
||||
makeSelectListById,
|
||||
selectListById,
|
||||
makeSelectCardIdsByListId,
|
||||
selectCardIdsByListId,
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const currentModalSelector = ({ core: { currentModal } }) => currentModal;
|
||||
5
client/src/selectors/modals.js
Normal file
5
client/src/selectors/modals.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export const selectCurrentModal = ({ core: { currentModal } }) => currentModal;
|
||||
|
||||
export default {
|
||||
selectCurrentModal,
|
||||
};
|
||||
@@ -2,7 +2,7 @@ import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
|
||||
export const makeProjectManagerByIdSelector = () =>
|
||||
export const makeSelectProjectManagerById = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -17,4 +17,9 @@ export const makeProjectManagerByIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const projectManagerByIdSelector = makeProjectManagerByIdSelector();
|
||||
export const selectProjectManagerById = makeSelectProjectManagerById();
|
||||
|
||||
export default {
|
||||
makeSelectProjectManagerById,
|
||||
selectProjectManagerById,
|
||||
};
|
||||
@@ -1,13 +1,13 @@
|
||||
import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
import { pathSelector } from './router';
|
||||
import { currentUserIdSelector } from './user';
|
||||
import { selectPath } from './router';
|
||||
import { selectCurrentUserId } from './users';
|
||||
import { isLocalId } from '../utils/local-id';
|
||||
|
||||
export const currentProjectSelector = createSelector(
|
||||
export const selectCurrentProject = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).projectId,
|
||||
(state) => selectPath(state).projectId,
|
||||
({ Project }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -23,10 +23,10 @@ export const currentProjectSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const managersForCurrentProjectSelector = createSelector(
|
||||
export const selectManagersForCurrentProject = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).projectId,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectPath(state).projectId,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Project }, id, currentUserId) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -52,10 +52,10 @@ export const managersForCurrentProjectSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const boardsForCurrentProjectSelector = createSelector(
|
||||
export const selectBoardsForCurrentProject = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).projectId,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectPath(state).projectId,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Project }, id, currentUserId) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
@@ -74,10 +74,10 @@ export const boardsForCurrentProjectSelector = createSelector(
|
||||
},
|
||||
);
|
||||
|
||||
export const isCurrentUserManagerForCurrentProjectSelector = createSelector(
|
||||
export const selectIsCurrentUserManagerForCurrentProject = createSelector(
|
||||
orm,
|
||||
(state) => pathSelector(state).projectId,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectPath(state).projectId,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Project }, id, currentUserId) => {
|
||||
if (!id) {
|
||||
return false;
|
||||
@@ -92,3 +92,10 @@ export const isCurrentUserManagerForCurrentProjectSelector = createSelector(
|
||||
return projectModel.hasManagerUser(currentUserId);
|
||||
},
|
||||
);
|
||||
|
||||
export default {
|
||||
selectCurrentProject,
|
||||
selectManagersForCurrentProject,
|
||||
selectBoardsForCurrentProject,
|
||||
selectIsCurrentUserManagerForCurrentProject,
|
||||
};
|
||||
@@ -2,24 +2,24 @@ import { createSelector as createReselectSelector } from 'reselect';
|
||||
import { createSelector as createReduxOrmSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
import { currentUserIdSelector } from './user';
|
||||
import { selectCurrentUserId } from './users';
|
||||
import matchPaths from '../utils/match-paths';
|
||||
import Paths from '../constants/Paths';
|
||||
|
||||
export const pathnameSelector = ({
|
||||
export const selectPathname = ({
|
||||
router: {
|
||||
location: { pathname },
|
||||
},
|
||||
}) => pathname;
|
||||
|
||||
export const pathsMatchSelector = createReselectSelector(pathnameSelector, (pathname) =>
|
||||
export const selectPathsMatch = createReselectSelector(selectPathname, (pathname) =>
|
||||
matchPaths(pathname, Object.values(Paths)),
|
||||
);
|
||||
|
||||
export const pathSelector = createReduxOrmSelector(
|
||||
export const selectPath = createReduxOrmSelector(
|
||||
orm,
|
||||
pathsMatchSelector,
|
||||
(state) => currentUserIdSelector(state),
|
||||
selectPathsMatch,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ Project, Board, Card }, pathsMatch, currentUserId) => {
|
||||
if (pathsMatch) {
|
||||
switch (pathsMatch.path) {
|
||||
@@ -105,3 +105,9 @@ export const pathSelector = createReduxOrmSelector(
|
||||
return {};
|
||||
},
|
||||
);
|
||||
|
||||
export default {
|
||||
selectPathname,
|
||||
selectPathsMatch,
|
||||
selectPath,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
|
||||
export const makeTaskByIdSelector = () =>
|
||||
export const makeSelectTaskById = () =>
|
||||
createSelector(
|
||||
orm,
|
||||
(_, id) => id,
|
||||
@@ -17,4 +17,9 @@ export const makeTaskByIdSelector = () =>
|
||||
},
|
||||
);
|
||||
|
||||
export const taskByIdSelector = makeTaskByIdSelector();
|
||||
export const selectTaskById = makeSelectTaskById();
|
||||
|
||||
export default {
|
||||
makeSelectTaskById,
|
||||
selectTaskById,
|
||||
};
|
||||
@@ -1,108 +0,0 @@
|
||||
import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
|
||||
export const currentUserIdSelector = ({ auth: { userId } }) => userId;
|
||||
|
||||
export const currentUserSelector = createSelector(
|
||||
orm,
|
||||
(state) => currentUserIdSelector(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel.ref;
|
||||
},
|
||||
);
|
||||
|
||||
export const projectsForCurrentUserSelector = createSelector(
|
||||
orm,
|
||||
(state) => currentUserIdSelector(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel.getOrderedAvailableProjectsModelArray().map((projectModel) => {
|
||||
const boardsModels = projectModel.getOrderedAvailableBoardsModelArray(userModel.id);
|
||||
|
||||
let notificationsTotal = 0;
|
||||
boardsModels.forEach((boardModel) => {
|
||||
boardModel.cards.toModelArray().forEach((cardModel) => {
|
||||
notificationsTotal += cardModel.getUnreadNotificationsQuerySet().count();
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
...projectModel.ref,
|
||||
notificationsTotal,
|
||||
firstBoardId: boardsModels[0] && boardsModels[0].id,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
export const projectsToListsForCurrentUserSelector = createSelector(
|
||||
orm,
|
||||
(state) => currentUserIdSelector(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel.getOrderedAvailableProjectsModelArray().map((projectModel) => ({
|
||||
...projectModel.ref,
|
||||
boards: projectModel.getOrderedMemberBoardsModelArray(id).map((boardModel) => ({
|
||||
...boardModel.ref,
|
||||
lists: boardModel.getOrderedListsQuerySet().toRefArray(),
|
||||
})),
|
||||
}));
|
||||
},
|
||||
);
|
||||
|
||||
export const notificationsForCurrentUserSelector = createSelector(
|
||||
orm,
|
||||
(state) => currentUserIdSelector(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel
|
||||
.getOrderedUnreadNotificationsQuerySet()
|
||||
.toModelArray()
|
||||
.map((notificationModel) => ({
|
||||
...notificationModel.ref,
|
||||
action: notificationModel.action && {
|
||||
...notificationModel.action.ref,
|
||||
user: notificationModel.action.user.ref,
|
||||
},
|
||||
card: notificationModel.card && notificationModel.card.ref,
|
||||
}));
|
||||
},
|
||||
);
|
||||
@@ -1,15 +1,16 @@
|
||||
import { createSelector } from 'redux-orm';
|
||||
|
||||
import orm from '../orm';
|
||||
import { currentUserIdSelector } from './user';
|
||||
|
||||
export const usersSelector = createSelector(orm, ({ User }) =>
|
||||
export const selectCurrentUserId = ({ auth: { userId } }) => userId;
|
||||
|
||||
export const selectUsers = createSelector(orm, ({ User }) =>
|
||||
User.getOrderedUndeletedQuerySet().toRefArray(),
|
||||
);
|
||||
|
||||
export const usersExceptCurrentSelector = createSelector(
|
||||
export const selectUsersExceptCurrent = createSelector(
|
||||
orm,
|
||||
(state) => currentUserIdSelector(state),
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ User }, id) =>
|
||||
User.getOrderedUndeletedQuerySet()
|
||||
.exclude({
|
||||
@@ -17,3 +18,116 @@ export const usersExceptCurrentSelector = createSelector(
|
||||
})
|
||||
.toRefArray(),
|
||||
);
|
||||
|
||||
export const selectCurrentUser = createSelector(
|
||||
orm,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel.ref;
|
||||
},
|
||||
);
|
||||
|
||||
export const selectProjectsForCurrentUser = createSelector(
|
||||
orm,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel.getOrderedAvailableProjectsModelArray().map((projectModel) => {
|
||||
const boardsModels = projectModel.getOrderedAvailableBoardsModelArray(userModel.id);
|
||||
|
||||
let notificationsTotal = 0;
|
||||
boardsModels.forEach((boardModel) => {
|
||||
boardModel.cards.toModelArray().forEach((cardModel) => {
|
||||
notificationsTotal += cardModel.getUnreadNotificationsQuerySet().count();
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
...projectModel.ref,
|
||||
notificationsTotal,
|
||||
firstBoardId: boardsModels[0] && boardsModels[0].id,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
export const selectProjectsToListsForCurrentUser = createSelector(
|
||||
orm,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel.getOrderedAvailableProjectsModelArray().map((projectModel) => ({
|
||||
...projectModel.ref,
|
||||
boards: projectModel.getOrderedMemberBoardsModelArray(id).map((boardModel) => ({
|
||||
...boardModel.ref,
|
||||
lists: boardModel.getOrderedListsQuerySet().toRefArray(),
|
||||
})),
|
||||
}));
|
||||
},
|
||||
);
|
||||
|
||||
export const selectNotificationsForCurrentUser = createSelector(
|
||||
orm,
|
||||
(state) => selectCurrentUserId(state),
|
||||
({ User }, id) => {
|
||||
if (!id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
const userModel = User.withId(id);
|
||||
|
||||
if (!userModel) {
|
||||
return userModel;
|
||||
}
|
||||
|
||||
return userModel
|
||||
.getOrderedUnreadNotificationsQuerySet()
|
||||
.toModelArray()
|
||||
.map((notificationModel) => ({
|
||||
...notificationModel.ref,
|
||||
activity: notificationModel.activity && {
|
||||
...notificationModel.activity.ref,
|
||||
user: notificationModel.activity.user.ref,
|
||||
},
|
||||
card: notificationModel.card && notificationModel.card.ref,
|
||||
}));
|
||||
},
|
||||
);
|
||||
|
||||
export default {
|
||||
selectCurrentUserId,
|
||||
selectUsers,
|
||||
selectUsersExceptCurrent,
|
||||
selectCurrentUser,
|
||||
selectProjectsForCurrentUser,
|
||||
selectProjectsToListsForCurrentUser,
|
||||
selectNotificationsForCurrentUser,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user