Skip to content

Commit d16dd9b

Browse files
committed
bug #3273 Show Created By for files and links list in Assets Library 3
1 parent 850bda7 commit d16dd9b

File tree

7 files changed

+80
-11
lines changed

7 files changed

+80
-11
lines changed

src/components/AssetsLibrary/FilesGridView.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const FilesGridView = ({
2929
title,
3030
selectedUsers,
3131
onAddAttachment,
32+
assetsMembers,
3233
isSharingAttachment,
3334
discardAttachments,
3435
onChangePermissions,
@@ -79,7 +80,7 @@ const FilesGridView = ({
7980
link={ subFolderContent }
8081
renderLink={ renderLink }
8182
goBack={goBack}
82-
projectMembers={projectMembers}
83+
assetsMembers={assetsMembers}
8384
onDeletePostAttachment={onDeletePostAttachment}
8485
loggedInUser={loggedInUser}
8586
formatModifyDate={formatModifyDate}
@@ -122,7 +123,7 @@ const FilesGridView = ({
122123
const canEdit = `${link.createdBy}` === `${loggedInUser.userId}`
123124

124125
const changeSubFolder = () => onChangeSubFolder(link)
125-
const owner = _.find(projectMembers, m => m.userId === _.parseInt(link.createdBy))
126+
const owner = _.find(assetsMembers, m => m.userId === _.parseInt(link.createdBy))
126127

127128
if (Array.isArray(link.children) && link.children.length > 0) {
128129
return (

src/components/AssetsLibrary/LinksGridView.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const LinksGridView = ({
2929
title,
3030
formatModifyDate,
3131
formatFolderTitle,
32-
projectMembers,
32+
assetsMembers,
3333
}) => {
3434
const renderLink = (link) => {
3535
if (link.onClick) {
@@ -61,7 +61,7 @@ const LinksGridView = ({
6161
renderLink={ renderLink }
6262
goBack={goBack}
6363
formatModifyDate={formatModifyDate}
64-
projectMembers={projectMembers}
64+
assetsMembers={assetsMembers}
6565
isLinkSubFolder
6666
/>)}
6767
{(!subFolderContent) && (
@@ -91,7 +91,7 @@ const LinksGridView = ({
9191
const onEditCancel = () => onEditIntent(-1)
9292
const handleEditClick = () => onEditIntent(idx)
9393
const changeSubFolder = () => onChangeSubFolder(link)
94-
const owner = _.find(projectMembers, m => m.userId === _.parseInt(link.createdBy))
94+
const owner = _.find(assetsMembers, m => m.userId === _.parseInt(link.createdBy))
9595

9696
if (Array.isArray(link.children) && link.children.length > 0) {
9797
return (

src/components/AssetsLibrary/SubFolder.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SubFolder extends React.Component {
5656
}
5757

5858
render() {
59-
const { link, renderLink, goBack, formatModifyDate, isLinkSubFolder, projectMembers } = this.props
59+
const { link, renderLink, goBack, formatModifyDate, isLinkSubFolder, assetsMembers } = this.props
6060
const { linkToDelete } = this.state
6161
return (
6262
<div styleName={cn({'assets-gridview-container-active': (linkToDelete >= 0)}, '')}>
@@ -79,7 +79,7 @@ class SubFolder extends React.Component {
7979
</li>
8080
{
8181
link.children.map((childLink, i) => {
82-
const owner = _.find(projectMembers, m => m.userId === _.parseInt(childLink.createdBy))
82+
const owner = _.find(assetsMembers, m => m.userId === _.parseInt(childLink.createdBy))
8383
if (linkToDelete === i) {
8484
return (
8585
<li styleName="delete-confirmation-modal" key={'delete-confirmation-post-attachment-' + i}>

src/config/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ export const LOAD_MEMBERS_PENDING = 'LOAD_MEMBERS_PENDING'
328328
export const LOAD_MEMBERS_SUCCESS = 'LOAD_MEMBERS_SUCCESS'
329329
export const LOAD_MEMBERS_FAILURE = 'LOAD_MEMBERS_FAILURE'
330330

331+
export const LOAD_ASSETS_MEMBERS = 'LOAD_ASSETS_MEMBERS'
332+
export const LOAD_ASSETS_MEMBERS_PENDING = 'LOAD_ASSETS_MEMBERS_PENDING'
333+
export const LOAD_ASSETS_MEMBERS_SUCCESS = 'LOAD_ASSETS_MEMBERS_SUCCESS'
334+
export const LOAD_ASSETS_MEMBERS_FAILURE = 'LOAD_ASSETS_MEMBERS_FAILURE'
335+
331336
export const LOAD_MEMBER_SUGGESTIONS = 'LOAD_MEMBER_SUGGESTIONS'
332337
export const LOAD_MEMBER_SUGGESTIONS_PENDING = 'LOAD_MEMBER_SUGGESTIONS_PENDING'
333338
export const LOAD_MEMBER_SUGGESTIONS_SUCCESS = 'LOAD_MEMBER_SUGGESTIONS_SUCCESS'

src/projects/actions/project.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import {
2222
createTimeline,
2323
} from '../../api/timelines'
24+
import { getMembersById } from '../../api/projectMembers'
2425
// import { loadProductTimelineWithMilestones } from './productsTimelines'
2526
import {
2627
LOAD_PROJECT,
@@ -44,6 +45,7 @@ import {
4445
PHASE_STATUS_ACTIVE,
4546
PHASE_DIRTY,
4647
PHASE_DIRTY_UNDO,
48+
LOAD_ASSETS_MEMBERS,
4749
PROJECT_STATUS_IN_REVIEW,
4850
PHASE_STATUS_REVIEWED,
4951
PROJECT_STATUS_REVIEWED,
@@ -331,6 +333,25 @@ export function updateProject(projectId, updatedProps, updateExisting = false) {
331333
}
332334
}
333335

336+
export function loadAssetsMembers(userIds) {
337+
return (dispatch, getState) => {
338+
// check if we need to request data from server
339+
const assetsMembers = getState().projectState.assetsMembers
340+
// this returns ids from userIds that are not in store (members)
341+
const missingUsers = _.difference(userIds, _.keys(assetsMembers))
342+
// dispatch request to load members if we are missing data
343+
if (missingUsers.length) {
344+
return dispatch({
345+
type: LOAD_ASSETS_MEMBERS,
346+
payload: getMembersById(userIds)
347+
})
348+
} else {
349+
// returns empty resolved promise to avoid error when we call then on this action
350+
return Promise.resolve()
351+
}
352+
}
353+
}
354+
334355
export function createScopeChangeRequest(projectId, request) {
335356
const flatNewScope = flatten(request.newScope, { safe: true })
336357
const emptyKeys = _.keys(flatNewScope).filter(key => {

src/projects/detail/containers/AssetsInfoContainer.jsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import moment from 'moment'
99
import LinksGridView from '../../../components/AssetsLibrary/LinksGridView'
1010
import FilesGridView from '../../../components/AssetsLibrary/FilesGridView'
1111
import AssetsStatistics from '../../../components/AssetsLibrary/AssetsStatistics'
12-
import { updateProject, deleteProject } from '../../actions/project'
12+
import { updateProject, deleteProject, loadAssetsMembers } from '../../actions/project'
1313
import { loadDashboardFeeds, loadProjectMessages } from '../../actions/projectTopics'
1414
import { loadTopic } from '../../../actions/topics'
1515
import { loadProjectPlan } from '../../actions/projectPlan'
@@ -397,7 +397,7 @@ class AssetsInfoContainer extends React.Component {
397397
const { project, currentMemberRole, isSuperUser, phases, feeds,
398398
isManageUser, phasesTopics, projectTemplates, hideLinks,
399399
attachmentsAwaitingPermission, addProjectAttachment, discardAttachments, attachmentPermissions,
400-
changeAttachmentPermission, projectMembers, loggedInUser, isSharingAttachment, canAccessPrivatePosts } = this.props
400+
changeAttachmentPermission, projectMembers, loggedInUser, isSharingAttachment, canAccessPrivatePosts, loadAssetsMembers, assetsMembers } = this.props
401401
const { ifModalOpen } = this.state
402402

403403
const canManageLinks = !!currentMemberRole || isSuperUser
@@ -486,6 +486,25 @@ class AssetsInfoContainer extends React.Component {
486486
...this.extractAttachmentLinksFromPosts(phaseFeeds)
487487
]
488488

489+
let tmpUserIds = []
490+
let userIds = []
491+
_.forEach(links, link => {
492+
tmpUserIds = _.union(tmpUserIds, _.map(link.children, 'createdBy'))
493+
tmpUserIds = _.union(tmpUserIds, [link.createdBy])
494+
tmpUserIds = _.union(tmpUserIds, [link.updatedBy])
495+
})
496+
497+
_.forEach(attachments, attachment => {
498+
tmpUserIds = _.union(tmpUserIds, _.map(attachment.children, 'createdBy'))
499+
tmpUserIds = _.union(tmpUserIds, [attachment.createdBy])
500+
})
501+
502+
_.forEach(tmpUserIds, userId => {
503+
userIds = _.union(userIds, [_.parseInt(userId)])
504+
})
505+
_.remove(userIds, i => !i)
506+
loadAssetsMembers(userIds)
507+
489508
const assetsData = []
490509
enableFileUpload && assetsData.push({name: 'Files', total: _.toString(attachments.length)})
491510
!hideLinks && assetsData.push({name: 'Links', total: _.toString(links.length)})
@@ -608,6 +627,7 @@ class AssetsInfoContainer extends React.Component {
608627
onChangePermissions={changeAttachmentPermission}
609628
selectedUsers={attachmentPermissions}
610629
projectMembers={projectMembers}
630+
assetsMembers={assetsMembers}
611631
pendingAttachments={attachmentsAwaitingPermission}
612632
loggedInUser={loggedInUser}
613633
attachmentsStorePath={attachmentsStorePath}
@@ -618,7 +638,7 @@ class AssetsInfoContainer extends React.Component {
618638
{(!hideLinks && activeAssetsType === 'Links') &&
619639
<LinksGridView
620640
links={links}
621-
projectMembers={projectMembers}
641+
assetsMembers={assetsMembers}
622642
canDelete={canManageLinks}
623643
canEdit={canManageLinks}
624644
onDelete={this.onDeleteLink}
@@ -653,12 +673,13 @@ const mapStateToProps = ({ templates, projectState, members, loadUser }) => {
653673
attachmentPermissions: projectState.attachmentPermissions,
654674
isSharingAttachment: projectState.processingAttachments,
655675
projectMembers: _.keyBy(projectMembers, 'userId'),
676+
assetsMembers: _.keyBy(projectState.assetsMembers, 'userId'),
656677
loggedInUser: loadUser.user,
657678
canAccessPrivatePosts
658679
})
659680
}
660681

661-
const mapDispatchToProps = { updateProject, deleteProject, addProjectAttachment, updateProjectAttachment,
682+
const mapDispatchToProps = { updateProject, deleteProject, loadAssetsMembers, addProjectAttachment, updateProjectAttachment,
662683
loadProjectMessages, discardAttachments, uploadProjectAttachments, loadDashboardFeeds, loadTopic, changeAttachmentPermission,
663684
removeProjectAttachment, loadProjectPlan, saveFeedComment }
664685

src/projects/reducers/project.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ACCEPT_OR_REFUSE_INVITE_SUCCESS, ACCEPT_OR_REFUSE_INVITE_FAILURE, ACCEPT_OR_REFUSE_INVITE_PENDING, RELOAD_PROJECT_MEMBERS_SUCCESS,
2424
UPLOAD_PROJECT_ATTACHMENT_FILES, DISCARD_PROJECT_ATTACHMENT, CHANGE_ATTACHMENT_PERMISSION,
2525
CREATE_SCOPE_CHANGE_REQUEST_SUCCESS, APPROVE_SCOPE_CHANGE_SUCCESS, REJECT_SCOPE_CHANGE_SUCCESS, CANCEL_SCOPE_CHANGE_SUCCESS, ACTIVATE_SCOPE_CHANGE_SUCCESS,
26+
LOAD_ASSETS_MEMBERS_SUCCESS, LOAD_ASSETS_MEMBERS_PENDING, LOAD_ASSETS_MEMBERS_FAILURE, CONNECT_USER, CONNECT_USER_HANDLE
2627
} from '../../config/constants'
2728
import _ from 'lodash'
2829
import update from 'react-addons-update'
@@ -40,6 +41,7 @@ const initialState = {
4041
project: {
4142
invites: [] // invites are pushed directly into it hence need to declare first
4243
},
44+
assetsMembers: {},
4345
projectNonDirty: {},
4446
updateExisting: false,
4547
phases: null,
@@ -439,6 +441,25 @@ export const projectState = function (state=initialState, action) {
439441
})
440442
}
441443

444+
case LOAD_ASSETS_MEMBERS_SUCCESS: {
445+
const _members = _.map(_.filter(action.payload, m => m.userId), m => {
446+
if (m.handle) {
447+
return m
448+
}
449+
return { userId: m.userId, ...CONNECT_USER, handle: CONNECT_USER_HANDLE }
450+
})
451+
const userMap = _.keyBy(_members, 'userId')
452+
// merge the 2 data sets
453+
return Object.assign({}, state, {
454+
processing: false,
455+
assetsMembers: update(state.assetsMembers, {$merge: userMap}),
456+
})
457+
}
458+
459+
case LOAD_ASSETS_MEMBERS_PENDING:
460+
case LOAD_ASSETS_MEMBERS_FAILURE:
461+
return state
462+
442463
case DELETE_PROJECT_PHASE_SUCCESS: {
443464
const { phaseId } = action.payload
444465

0 commit comments

Comments
 (0)