You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.3 KiB
JavaScript
102 lines
2.3 KiB
JavaScript
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 selectCurrentProject = createSelector(
|
|
orm,
|
|
(state) => selectPath(state).projectId,
|
|
({ Project }, id) => {
|
|
if (!id) {
|
|
return id;
|
|
}
|
|
|
|
const projectModel = Project.withId(id);
|
|
|
|
if (!projectModel) {
|
|
return projectModel;
|
|
}
|
|
|
|
return projectModel.ref;
|
|
},
|
|
);
|
|
|
|
export const selectManagersForCurrentProject = createSelector(
|
|
orm,
|
|
(state) => selectPath(state).projectId,
|
|
(state) => selectCurrentUserId(state),
|
|
({ Project }, id, currentUserId) => {
|
|
if (!id) {
|
|
return id;
|
|
}
|
|
|
|
const projectModel = Project.withId(id);
|
|
|
|
if (!projectModel) {
|
|
return projectModel;
|
|
}
|
|
|
|
return projectModel
|
|
.getOrderedManagersQuerySet()
|
|
.toModelArray()
|
|
.map((projectManagerModel) => ({
|
|
...projectManagerModel.ref,
|
|
isPersisted: !isLocalId(projectManagerModel.id),
|
|
user: {
|
|
...projectManagerModel.user.ref,
|
|
isCurrent: projectManagerModel.user.id === currentUserId,
|
|
},
|
|
}));
|
|
},
|
|
);
|
|
|
|
export const selectBoardsForCurrentProject = createSelector(
|
|
orm,
|
|
(state) => selectPath(state).projectId,
|
|
(state) => selectCurrentUserId(state),
|
|
({ Project }, id, currentUserId) => {
|
|
if (!id) {
|
|
return id;
|
|
}
|
|
|
|
const projectModel = Project.withId(id);
|
|
|
|
if (!projectModel) {
|
|
return projectModel;
|
|
}
|
|
|
|
return projectModel.getOrderedAvailableBoardsModelArray(currentUserId).map((boardModel) => ({
|
|
...boardModel.ref,
|
|
isPersisted: !isLocalId(boardModel.id),
|
|
}));
|
|
},
|
|
);
|
|
|
|
export const selectIsCurrentUserManagerForCurrentProject = createSelector(
|
|
orm,
|
|
(state) => selectPath(state).projectId,
|
|
(state) => selectCurrentUserId(state),
|
|
({ Project }, id, currentUserId) => {
|
|
if (!id) {
|
|
return false;
|
|
}
|
|
|
|
const projectModel = Project.withId(id);
|
|
|
|
if (!projectModel) {
|
|
return false;
|
|
}
|
|
|
|
return projectModel.hasManagerUser(currentUserId);
|
|
},
|
|
);
|
|
|
|
export default {
|
|
selectCurrentProject,
|
|
selectManagersForCurrentProject,
|
|
selectBoardsForCurrentProject,
|
|
selectIsCurrentUserManagerForCurrentProject,
|
|
};
|