From fe963b41cbe9b3cbf1931e6af1c70141bb3da607 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 16:36:51 +0800 Subject: [PATCH 1/7] fix actions with private topics --- .../detail/containers/FeedContainer.js | 41 ++++++++++++------- src/routes.jsx | 8 +--- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/projects/detail/containers/FeedContainer.js b/src/projects/detail/containers/FeedContainer.js index 75e9367f3..cc291b038 100644 --- a/src/projects/detail/containers/FeedContainer.js +++ b/src/projects/detail/containers/FeedContainer.js @@ -254,8 +254,8 @@ class FeedView extends React.Component { } onShowAllComments(feedId) { - const { feeds } = this.props - const feed = _.find(feeds, feed => feed.id === feedId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) const stateFeedIdx = _.findIndex(this.state.feeds, (f) => f.id === feedId) // in case we have already have all comments for that feed from the server, // just change the state to show all comments for that FeedId. @@ -271,7 +271,7 @@ class FeedView extends React.Component { showAll: { $push: [feedId] }, feeds: { $splice: [[stateFeedIdx, 1, updatedFeed ]] } })) - this.props.loadFeedComments(feedId, PROJECT_FEED_TYPE_PRIMARY, commentIdsToRetrieve) + this.props.loadFeedComments(feedId, feed.tag, commentIdsToRetrieve) } else { this.setState(update(this.state, { showAll: { $push: [feedId] }, @@ -281,13 +281,14 @@ class FeedView extends React.Component { } onAddNewComment(feedId, content) { - const { currentUser } = this.props + const { currentUser, feeds } = this.props + const feed = _.find(feeds, { id: feedId }) const newComment = { date: new Date(), userId: parseInt(currentUser.id), content } - this.props.addFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newComment) + this.props.addFeedComment(feedId, feed.tag, newComment) } onSaveMessageChange(feedId, messageId, content, editMode) { @@ -309,28 +310,34 @@ class FeedView extends React.Component { onSaveMessage(feedId, message, content) { const newMessage = {...message} + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) newMessage.content = content - this.props.saveFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newMessage) + this.props.saveFeedComment(feedId, feed.tag, newMessage) } onDeleteMessage(feedId, postId) { - this.props.deleteFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.deleteFeedComment(feedId, feed.tag, postId) } onEditMessage(feedId, postId) { - const thread = _.find(this.state.feeds, t => feedId === t.id) - const comment = _.find(thread.comments, message => message.id === postId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + const comment = _.find(feed.comments, message => message.id === postId) if (!comment.rawContent) { - this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) + this.props.getFeedComment(feedId, feed.tag, postId) } this.onSaveMessageChange(feedId, postId, null, true) } onEditTopic(feedId) { - const thread = _.find(this.state.feeds, t => feedId === t.id) - const comment = thread.topicMessage + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + const comment = feed.topicMessage if (!comment.rawContent) { - this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, comment.id) + this.props.getFeedComment(feedId, feed.tag, comment.id) } this.onTopicChange(feedId, comment.id, null, null, true) } @@ -350,11 +357,15 @@ class FeedView extends React.Component { } onSaveTopic(feedId, postId, title, content) { - this.props.saveProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY, {postId, title, content}) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.saveProjectTopic(feedId, feed.tag, {postId, title, content}) } onDeleteTopic(feedId) { - this.props.deleteProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.deleteProjectTopic(feedId, feed.tag) } onRefreshFeeds() { diff --git a/src/routes.jsx b/src/routes.jsx index f28d622de..19274b59b 100644 --- a/src/routes.jsx +++ b/src/routes.jsx @@ -77,12 +77,8 @@ class RedirectToProject extends React.Component { if (resp.topic) { const topic = resp.topic const projectId = topic.referenceId - if (topic.tag === PROJECT_FEED_TYPE_PRIMARY) { - history.replace(`/projects/${projectId}/`) - } else if (topic.tag === PROJECT_FEED_TYPE_MESSAGES) { - history.replace({ - pathname: `/projects/${projectId}/discussions/${topic.id}` - }) + if (topic.tag === PROJECT_FEED_TYPE_PRIMARY || topic.tag === PROJECT_FEED_TYPE_MESSAGES) { + history.replace(`/projects/${projectId}#feed-${topic.id}`) } else { history.replace('/projects') } From be78210197d0f206ec77fc2556cfc72845f62acc Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 16:42:35 +0800 Subject: [PATCH 2/7] fix: should be able to delete the first post in the topic, which in reverse order is last one --- src/components/Feed/FeedComments.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Feed/FeedComments.jsx b/src/components/Feed/FeedComments.jsx index 6f47bfa52..da73a6984 100644 --- a/src/components/Feed/FeedComments.jsx +++ b/src/components/Feed/FeedComments.jsx @@ -324,7 +324,7 @@ class FeedComments extends React.Component { allMembers={allMembers} projectMembers={projectMembers} noInfo={item.noInfo} - canDelete={idx !== 0} + canDelete={idx !== comments.length - 1} // cannot delete the first post which is now shown as a last one commentAnchorPrefix={commentAnchorPrefix} >
From 828bf6a66223b25adf3b26f9e8671d08801fdb55 Mon Sep 17 00:00:00 2001 From: RishiRajSahu Date: Wed, 24 Apr 2019 14:55:14 +0530 Subject: [PATCH 3/7] Revert "[PROD] Hotfix/fix private topics" --- src/components/Feed/FeedComments.jsx | 2 +- .../detail/containers/FeedContainer.js | 41 +++++++------------ src/routes.jsx | 8 +++- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/components/Feed/FeedComments.jsx b/src/components/Feed/FeedComments.jsx index da73a6984..6f47bfa52 100644 --- a/src/components/Feed/FeedComments.jsx +++ b/src/components/Feed/FeedComments.jsx @@ -324,7 +324,7 @@ class FeedComments extends React.Component { allMembers={allMembers} projectMembers={projectMembers} noInfo={item.noInfo} - canDelete={idx !== comments.length - 1} // cannot delete the first post which is now shown as a last one + canDelete={idx !== 0} commentAnchorPrefix={commentAnchorPrefix} >
diff --git a/src/projects/detail/containers/FeedContainer.js b/src/projects/detail/containers/FeedContainer.js index cc291b038..75e9367f3 100644 --- a/src/projects/detail/containers/FeedContainer.js +++ b/src/projects/detail/containers/FeedContainer.js @@ -254,8 +254,8 @@ class FeedView extends React.Component { } onShowAllComments(feedId) { - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) + const { feeds } = this.props + const feed = _.find(feeds, feed => feed.id === feedId) const stateFeedIdx = _.findIndex(this.state.feeds, (f) => f.id === feedId) // in case we have already have all comments for that feed from the server, // just change the state to show all comments for that FeedId. @@ -271,7 +271,7 @@ class FeedView extends React.Component { showAll: { $push: [feedId] }, feeds: { $splice: [[stateFeedIdx, 1, updatedFeed ]] } })) - this.props.loadFeedComments(feedId, feed.tag, commentIdsToRetrieve) + this.props.loadFeedComments(feedId, PROJECT_FEED_TYPE_PRIMARY, commentIdsToRetrieve) } else { this.setState(update(this.state, { showAll: { $push: [feedId] }, @@ -281,14 +281,13 @@ class FeedView extends React.Component { } onAddNewComment(feedId, content) { - const { currentUser, feeds } = this.props - const feed = _.find(feeds, { id: feedId }) + const { currentUser } = this.props const newComment = { date: new Date(), userId: parseInt(currentUser.id), content } - this.props.addFeedComment(feedId, feed.tag, newComment) + this.props.addFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newComment) } onSaveMessageChange(feedId, messageId, content, editMode) { @@ -310,34 +309,28 @@ class FeedView extends React.Component { onSaveMessage(feedId, message, content) { const newMessage = {...message} - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) newMessage.content = content - this.props.saveFeedComment(feedId, feed.tag, newMessage) + this.props.saveFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newMessage) } onDeleteMessage(feedId, postId) { - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) - this.props.deleteFeedComment(feedId, feed.tag, postId) + this.props.deleteFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) } onEditMessage(feedId, postId) { - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) - const comment = _.find(feed.comments, message => message.id === postId) + const thread = _.find(this.state.feeds, t => feedId === t.id) + const comment = _.find(thread.comments, message => message.id === postId) if (!comment.rawContent) { - this.props.getFeedComment(feedId, feed.tag, postId) + this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) } this.onSaveMessageChange(feedId, postId, null, true) } onEditTopic(feedId) { - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) - const comment = feed.topicMessage + const thread = _.find(this.state.feeds, t => feedId === t.id) + const comment = thread.topicMessage if (!comment.rawContent) { - this.props.getFeedComment(feedId, feed.tag, comment.id) + this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, comment.id) } this.onTopicChange(feedId, comment.id, null, null, true) } @@ -357,15 +350,11 @@ class FeedView extends React.Component { } onSaveTopic(feedId, postId, title, content) { - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) - this.props.saveProjectTopic(feedId, feed.tag, {postId, title, content}) + this.props.saveProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY, {postId, title, content}) } onDeleteTopic(feedId) { - const { feeds } = this.state - const feed = _.find(feeds, { id: feedId }) - this.props.deleteProjectTopic(feedId, feed.tag) + this.props.deleteProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY) } onRefreshFeeds() { diff --git a/src/routes.jsx b/src/routes.jsx index 19274b59b..f28d622de 100644 --- a/src/routes.jsx +++ b/src/routes.jsx @@ -77,8 +77,12 @@ class RedirectToProject extends React.Component { if (resp.topic) { const topic = resp.topic const projectId = topic.referenceId - if (topic.tag === PROJECT_FEED_TYPE_PRIMARY || topic.tag === PROJECT_FEED_TYPE_MESSAGES) { - history.replace(`/projects/${projectId}#feed-${topic.id}`) + if (topic.tag === PROJECT_FEED_TYPE_PRIMARY) { + history.replace(`/projects/${projectId}/`) + } else if (topic.tag === PROJECT_FEED_TYPE_MESSAGES) { + history.replace({ + pathname: `/projects/${projectId}/discussions/${topic.id}` + }) } else { history.replace('/projects') } From e5b2c376708b1bd61dc2a665d96047117f049438 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 16:36:51 +0800 Subject: [PATCH 4/7] fix actions with private topics --- .../detail/containers/FeedContainer.js | 41 ++++++++++++------- src/routes.jsx | 8 +--- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/projects/detail/containers/FeedContainer.js b/src/projects/detail/containers/FeedContainer.js index 75e9367f3..cc291b038 100644 --- a/src/projects/detail/containers/FeedContainer.js +++ b/src/projects/detail/containers/FeedContainer.js @@ -254,8 +254,8 @@ class FeedView extends React.Component { } onShowAllComments(feedId) { - const { feeds } = this.props - const feed = _.find(feeds, feed => feed.id === feedId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) const stateFeedIdx = _.findIndex(this.state.feeds, (f) => f.id === feedId) // in case we have already have all comments for that feed from the server, // just change the state to show all comments for that FeedId. @@ -271,7 +271,7 @@ class FeedView extends React.Component { showAll: { $push: [feedId] }, feeds: { $splice: [[stateFeedIdx, 1, updatedFeed ]] } })) - this.props.loadFeedComments(feedId, PROJECT_FEED_TYPE_PRIMARY, commentIdsToRetrieve) + this.props.loadFeedComments(feedId, feed.tag, commentIdsToRetrieve) } else { this.setState(update(this.state, { showAll: { $push: [feedId] }, @@ -281,13 +281,14 @@ class FeedView extends React.Component { } onAddNewComment(feedId, content) { - const { currentUser } = this.props + const { currentUser, feeds } = this.props + const feed = _.find(feeds, { id: feedId }) const newComment = { date: new Date(), userId: parseInt(currentUser.id), content } - this.props.addFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newComment) + this.props.addFeedComment(feedId, feed.tag, newComment) } onSaveMessageChange(feedId, messageId, content, editMode) { @@ -309,28 +310,34 @@ class FeedView extends React.Component { onSaveMessage(feedId, message, content) { const newMessage = {...message} + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) newMessage.content = content - this.props.saveFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, newMessage) + this.props.saveFeedComment(feedId, feed.tag, newMessage) } onDeleteMessage(feedId, postId) { - this.props.deleteFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.deleteFeedComment(feedId, feed.tag, postId) } onEditMessage(feedId, postId) { - const thread = _.find(this.state.feeds, t => feedId === t.id) - const comment = _.find(thread.comments, message => message.id === postId) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + const comment = _.find(feed.comments, message => message.id === postId) if (!comment.rawContent) { - this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, postId) + this.props.getFeedComment(feedId, feed.tag, postId) } this.onSaveMessageChange(feedId, postId, null, true) } onEditTopic(feedId) { - const thread = _.find(this.state.feeds, t => feedId === t.id) - const comment = thread.topicMessage + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + const comment = feed.topicMessage if (!comment.rawContent) { - this.props.getFeedComment(feedId, PROJECT_FEED_TYPE_PRIMARY, comment.id) + this.props.getFeedComment(feedId, feed.tag, comment.id) } this.onTopicChange(feedId, comment.id, null, null, true) } @@ -350,11 +357,15 @@ class FeedView extends React.Component { } onSaveTopic(feedId, postId, title, content) { - this.props.saveProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY, {postId, title, content}) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.saveProjectTopic(feedId, feed.tag, {postId, title, content}) } onDeleteTopic(feedId) { - this.props.deleteProjectTopic(feedId, PROJECT_FEED_TYPE_PRIMARY) + const { feeds } = this.state + const feed = _.find(feeds, { id: feedId }) + this.props.deleteProjectTopic(feedId, feed.tag) } onRefreshFeeds() { diff --git a/src/routes.jsx b/src/routes.jsx index f28d622de..19274b59b 100644 --- a/src/routes.jsx +++ b/src/routes.jsx @@ -77,12 +77,8 @@ class RedirectToProject extends React.Component { if (resp.topic) { const topic = resp.topic const projectId = topic.referenceId - if (topic.tag === PROJECT_FEED_TYPE_PRIMARY) { - history.replace(`/projects/${projectId}/`) - } else if (topic.tag === PROJECT_FEED_TYPE_MESSAGES) { - history.replace({ - pathname: `/projects/${projectId}/discussions/${topic.id}` - }) + if (topic.tag === PROJECT_FEED_TYPE_PRIMARY || topic.tag === PROJECT_FEED_TYPE_MESSAGES) { + history.replace(`/projects/${projectId}#feed-${topic.id}`) } else { history.replace('/projects') } From dbd5fb41c2b378a739b0d4eb45aa50743ecbcc2b Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 16:42:35 +0800 Subject: [PATCH 5/7] fix: should be able to delete the first post in the topic, which in reverse order is last one --- src/components/Feed/FeedComments.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Feed/FeedComments.jsx b/src/components/Feed/FeedComments.jsx index 6f47bfa52..da73a6984 100644 --- a/src/components/Feed/FeedComments.jsx +++ b/src/components/Feed/FeedComments.jsx @@ -324,7 +324,7 @@ class FeedComments extends React.Component { allMembers={allMembers} projectMembers={projectMembers} noInfo={item.noInfo} - canDelete={idx !== 0} + canDelete={idx !== comments.length - 1} // cannot delete the first post which is now shown as a last one commentAnchorPrefix={commentAnchorPrefix} >
From 7ff06cf24361e14273041bdcf885bb21599ca141 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 17:21:02 +0800 Subject: [PATCH 6/7] fix --- src/components/Feed/FeedComments.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Feed/FeedComments.jsx b/src/components/Feed/FeedComments.jsx index da73a6984..c4aa2ef10 100644 --- a/src/components/Feed/FeedComments.jsx +++ b/src/components/Feed/FeedComments.jsx @@ -324,7 +324,7 @@ class FeedComments extends React.Component { allMembers={allMembers} projectMembers={projectMembers} noInfo={item.noInfo} - canDelete={idx !== comments.length - 1} // cannot delete the first post which is now shown as a last one + canDelete={comments && (idx !== comments.length - 1)} // cannot delete the first post which is now shown as a last one commentAnchorPrefix={commentAnchorPrefix} >
From ffc7ce1dbe927bf3d2af4b787bebbbd4d0ac45c8 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 24 Apr 2019 17:34:24 +0800 Subject: [PATCH 7/7] fix 2 --- src/projects/detail/containers/FeedContainer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/projects/detail/containers/FeedContainer.js b/src/projects/detail/containers/FeedContainer.js index cc291b038..a2ad10de6 100644 --- a/src/projects/detail/containers/FeedContainer.js +++ b/src/projects/detail/containers/FeedContainer.js @@ -254,7 +254,7 @@ class FeedView extends React.Component { } onShowAllComments(feedId) { - const { feeds } = this.state + const { feeds } = this.props const feed = _.find(feeds, { id: feedId }) const stateFeedIdx = _.findIndex(this.state.feeds, (f) => f.id === feedId) // in case we have already have all comments for that feed from the server,