Skip to content

Commit 5259da5

Browse files
author
vikasrohit
authored
Merge pull request #882 from appirio-tech/feature/permalink_for_feeds_messages
Permalink for status post and discussions message
2 parents b837273 + 2a0e71a commit 5259da5

File tree

7 files changed

+40
-13
lines changed

7 files changed

+40
-13
lines changed

src/components/Feed/Feed.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import ActionCard from '../ActionCard/ActionCard'
55
import Panel from '../Panel/Panel'
66
import FeedComments from './FeedComments'
77
import { Avatar } from 'appirio-tech-react-components'
8+
import {Link} from 'react-router'
89

910
const Feed = (props) => {
1011
const {
1112
user, currentUser, title, date, html, totalComments, hasMoreComments, onLoadMoreComments, isLoadingComments,
12-
allowComments, comments, unread, children, onNewCommentChange, onAddNewComment, newComment, isAddingComment
13+
allowComments, comments, unread, children, onNewCommentChange, onAddNewComment, newComment, isAddingComment,
14+
permalink
1315
} = props
1416
let authorName = user.firstName
1517
if (authorName && user.lastName) {
@@ -30,7 +32,7 @@ const Feed = (props) => {
3032
{ authorName }
3133
</div>
3234
<div className="card-time">
33-
{moment(date).fromNow()}
35+
<Link to={ permalink }>{moment(date).fromNow()}</Link>
3436
</div>
3537
</div>
3638
<div className="card-body draftjs-post" dangerouslySetInnerHTML={{__html: html}} />

src/projects/detail/Dashboard.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import spinnerWhileLoading from '../../components/LoadingSpinner'
77

88
require('./Dashboard.scss')
99

10-
const DashboardView = ({project, currentMemberRole, route}) => (
10+
const DashboardView = ({project, currentMemberRole, route, params}) => (
1111
<div>
1212
<div className="dashboard-container">
1313
<div className="left-area">
@@ -18,7 +18,7 @@ const DashboardView = ({project, currentMemberRole, route}) => (
1818
</Sticky>
1919
</div>
2020
<div className="right-area">
21-
<FeedContainer currentMemberRole={currentMemberRole} project={project} route={route} />
21+
<FeedContainer currentMemberRole={currentMemberRole} project={project} route={route} params={params} />
2222
</div>
2323
</div>
2424
</div>

src/projects/detail/Messages.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import MessagesContainer from './containers/MessagesContainer'
44

55
require('./Messages.scss')
66

7-
const Messages = ({ location, project, currentMemberRole, route }) => (
7+
const Messages = ({ location, project, currentMemberRole, route, params }) => (
88
<MessagesContainer
99
location={ location }
1010
project={ project }
1111
currentMemberRole={ currentMemberRole }
1212
route={ route }
13+
params={ params }
1314
/>
1415
)
1516
export default Messages

src/projects/detail/containers/FeedContainer.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import ProjectSpecification from '../../../components/ProjectSpecification/Proje
2121
import { loadDashboardFeeds, createProjectTopic, loadFeedComments, addFeedComment } from '../../actions/projectTopics'
2222
import spinnerWhileLoading from '../../../components/LoadingSpinner'
2323

24+
import { Helpers, scroller } from 'react-scroll'
25+
26+
/*eslint-disable new-cap */
27+
const ScrollableFeed = Helpers.Element(Feed)
28+
2429
const SYSTEM_USER = {
2530
firstName: CODER_BOT_USER_FNAME,
2631
lastName: CODER_BOT_USER_LNAME,
@@ -79,7 +84,7 @@ class FeedView extends React.Component {
7984
}
8085

8186
mapFeed(feed, showAll = false, resetNewComment = false) {
82-
const { allMembers } = this.props
87+
const { allMembers, project } = this.props
8388
const item = _.pick(feed, ['id', 'date', 'read', 'tag', 'title', 'totalPosts', 'userId', 'reference', 'referenceId', 'postIds', 'isAddingComment', 'isLoadingComments', 'error'])
8489
// Github issue##623, allow comments on all posts (including system posts)
8590
item.allowComments = true
@@ -125,6 +130,9 @@ class FeedView extends React.Component {
125130
item.newComment = feedFromState ? feedFromState.newComment : ''
126131
}
127132
item.hasMoreComments = item.comments.length !== item.totalComments
133+
// adds permalink for the feed
134+
// item.permalink = `/projects/${project.id}/status/${item.id}`
135+
item.permalink = `/projects/${project.id}#feed-${item.id}`
128136
return item
129137
}
130138

@@ -146,6 +154,18 @@ class FeedView extends React.Component {
146154
const resetNewComment = prevFeed && prevFeed.isAddingComment && !feed.isAddingComment && !feed.error
147155
return this.mapFeed(feed, this.state.showAll.indexOf(feed.id) > -1, resetNewComment)
148156
}).filter(item => item)
157+
}, () => {
158+
const scrollTo = window.location.hash ? window.location.hash.substring(1) : null
159+
// const scrollTo = _.get(props, 'params.statusId', null)
160+
if (scrollTo) {
161+
scroller.scrollTo(scrollTo, {
162+
spy: true,
163+
smooth: true,
164+
offset: -80, // 60px for top bar and 20px for margin from nav bar
165+
duration: 500,
166+
activeClass: 'active'
167+
})
168+
}
149169
})
150170
}
151171

@@ -223,10 +243,12 @@ class FeedView extends React.Component {
223243
if ((item.spec || item.sendForReview) && !showDraftSpec) {
224244
return null
225245
}
246+
const anchorId = 'feed-' + item.id
226247
return (
227248
<div className="feed-action-card" key={item.id}>
228-
<Feed
249+
<ScrollableFeed
229250
{...item}
251+
name={anchorId}
230252
allowComments={ item.allowComments && !!currentMemberRole}
231253
currentUser={currentUser}
232254
onNewCommentChange={this.onNewCommentChange.bind(this, item.id)}
@@ -236,7 +258,7 @@ class FeedView extends React.Component {
236258
{item.sendForReview && <div className="panel-buttons">
237259
<button className="tc-btn tc-btn-primary tc-btn-md">Send for review</button>
238260
</div>}
239-
</Feed>
261+
</ScrollableFeed>
240262
{item.spec && <ProjectSpecification project={ project } currentMemberRole={ currentMemberRole } /> }
241263
</div>
242264
)

src/projects/detail/containers/MessagesContainer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class MessagesView extends React.Component {
141141

142142
init(props, prevProps) {
143143
const { activeThreadId } = this.state
144-
const propsThreadId = _.get(props, 'location.state.threadId', null)
145-
const threadId = activeThreadId ? activeThreadId : propsThreadId
144+
const propsThreadId = _.get(props, 'params.discussionId', null)
145+
const threadId = activeThreadId ? activeThreadId : parseInt(propsThreadId)
146146
const activeThreadIndex = threadId
147147
? _.findIndex(props.threads, (thread) => thread.id === threadId )
148148
: 0
@@ -226,6 +226,8 @@ class MessagesView extends React.Component {
226226
}
227227
return item
228228
})
229+
}, () => {
230+
this.props.router.push(`/projects/${this.props.project.id}/discussions/${thread.id}`)
229231
})
230232
}
231233

src/projects/routes.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ const projectRoutes = (
1616
<IndexRoute components={{topbar: null, main: Projects }} />
1717
<Route path=":projectId" components={{topbar: null, main: ProjectDetail}} >
1818
<IndexRoute component={ Dashboard } />
19+
// <Route path="status/:statusId" component={ Dashboard } />
1920
<Route path="specification" component={ SpecificationContainer } />
20-
<Route path="discussions" component={ ProjectMessages } />
21+
<Route path="discussions(/:discussionId)" component={ ProjectMessages } />
2122
</Route>
2223
</Route>
2324
)

src/routes.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ const redirectToProject = (nextState, replace, callback) => {
5353
replace(`/projects/${projectId}/`)
5454
} else if (topic.tag === PROJECT_FEED_TYPE_MESSAGES) {
5555
replace({
56-
pathname: `/projects/${projectId}/discussions`,
57-
state: { threadId : topic.id }
56+
pathname: `/projects/${projectId}/discussions/${topic.id}`
5857
})
5958
} else {
6059
replace('/projects')

0 commit comments

Comments
 (0)