Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/components/LinksMenu/LinksMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Panel from '../Panel/Panel'
import AddLink from './AddLink'
import DeleteLinkModal from './DeleteLinkModal'
import EditLinkModal from './EditLinkModal'
import LinksMenuAccordion from './LinksMenuAccordion'
import uncontrollable from 'uncontrollable'
import MobileExpandable from '../MobileExpandable/MobileExpandable'
import cn from 'classnames'
Expand Down Expand Up @@ -101,9 +100,7 @@ const LinksMenu = ({
}
const onEditCancel = () => onEditIntent(-1)
const handleEditClick = () => onEditIntent(idx)
if (Array.isArray(link.children) && link.children.length > 0) {
return (<LinksMenuAccordion key={`link-menu-accordion-${idx}`} link={ link } renderLink={ renderLink } />)
} else if (linkToDelete === idx) {
if (linkToDelete === idx) {
return (
<li className="delete-confirmation-modal" key={ 'delete-confirmation-' + idx }>
<DeleteLinkModal
Expand Down
52 changes: 0 additions & 52 deletions src/components/LinksMenu/LinksMenuAccordion.jsx

This file was deleted.

40 changes: 0 additions & 40 deletions src/components/LinksMenu/LinksMenuAccordion.scss

This file was deleted.

121 changes: 3 additions & 118 deletions src/projects/detail/containers/ProjectInfoContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER,
import PERMISSIONS from '../../../config/permissions'
import { checkPermission } from '../../../helpers/permissions'
import ProjectInfo from '../../../components/ProjectInfo/ProjectInfo'
import {
import {
addProjectAttachment, updateProjectAttachment, uploadProjectAttachments, discardAttachments, changeAttachmentPermission,
removeProjectAttachment
} from '../../actions/projectAttachment'
Expand All @@ -38,10 +38,6 @@ class ProjectInfoContainer extends React.Component {
this.onUploadAttachment = this.onUploadAttachment.bind(this)
this.removeAttachment = this.removeAttachment.bind(this)
this.onSubmitForReview = this.onSubmitForReview.bind(this)
this.extractLinksFromPosts = this.extractLinksFromPosts.bind(this)
this.extractMarkdownLink = this.extractMarkdownLink.bind(this)
this.extractHtmlLink = this.extractHtmlLink.bind(this)
this.extractRawLink = this.extractRawLink.bind(this)
}

shouldComponentUpdate(nextProps, nextState) { // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -160,110 +156,13 @@ class ProjectInfoContainer extends React.Component {
updateProject(project.id, { status: 'in_review'})
}

extractHtmlLink(str) {
const links = []
const regex = /<a[^>]+href="(.*?)"[^>]*>([\s\S]*?)<\/a>/gm
const urlRegex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/gm // eslint-disable-line no-useless-escape
const rawLinks = regex.exec(str)

if (Array.isArray(rawLinks)) {
let i = 0
while (i < rawLinks.length) {
const title = rawLinks[i + 2]
const address = rawLinks[i + 1]

if (urlRegex.test(address)) {
links.push({
title,
address
})
}

i = i + 3
}
}

return links
}

extractMarkdownLink(str) {
const links = []
const regex = /(?:__|[*#])|\[(.*?)\]\((.*?)\)/gm
const urlRegex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/gm // eslint-disable-line no-useless-escape
const rawLinks = regex.exec(str)

if (Array.isArray(rawLinks)) {
let i = 0
while (i < rawLinks.length) {
const title = rawLinks[i + 1]
const address = rawLinks[i + 2]

if (urlRegex.test(address)) {
links.push({
title,
address
})
}

i = i + 3
}
}

return links
}

extractRawLink(str) {
let links = []
const regex = /(\s|^)(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,}[\s])(\s|$)/igm // eslint-disable-line no-useless-escape
const rawLinks = str.match(regex)

if (Array.isArray(rawLinks)) {
links = rawLinks
.filter(link => !link.includes(']'))
.map(link => {
const name = link.trim()
const url = !/^https?:\/\//i.test(name) ? 'http://' + name : name

return {
title: name,
address: url
}
})
}

return links
}

extractLinksFromPosts(feeds) {
const links = []
feeds.forEach(feed => {
let childrenLinks = []
feed.posts.forEach(post => {
childrenLinks = childrenLinks.concat([
...this.extractHtmlLink(post.rawContent),
...this.extractMarkdownLink(post.rawContent),
...this.extractRawLink(post.rawContent)
])
})

if (childrenLinks.length > 0) {
links.push({
title: feed.title,
children: childrenLinks
})
}
})

return links
}

render() {
const { duration } = this.state
const { project, currentMemberRole, isSuperUser, phases, feeds,
hideInfo, hideLinks, hideMembers, onChannelClick, activeChannelId, productsTimelines,
isManageUser, phasesTopics, isProjectPlan, isProjectProcessing, projectTemplates,
attachmentsAwaitingPermission, addProjectAttachment, discardAttachments, attachmentPermissions,
changeAttachmentPermission, projectMembers, loggedInUser, isSharingAttachment, canAccessPrivatePosts } = this.props
changeAttachmentPermission, projectMembers, loggedInUser, isSharingAttachment } = this.props
let directLinks = null
// check if direct links need to be added
const isMemberOrCopilot = _.indexOf([PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER], currentMemberRole) > -1
Expand Down Expand Up @@ -352,20 +251,6 @@ class ProjectInfoContainer extends React.Component {
})
}

// extract links from posts
const topicLinks = this.extractLinksFromPosts(feeds)
const publicTopicLinks = topicLinks.filter(link => link.tag !== PROJECT_FEED_TYPE_MESSAGES)
const privateTopicLinks = topicLinks.filter(link => link.tag === PROJECT_FEED_TYPE_MESSAGES)
const phaseLinks = this.extractLinksFromPosts(phaseFeeds)

let links = []
links = links.concat(project.bookmarks)
links = links.concat(publicTopicLinks)
if (canAccessPrivatePosts) {
links = links.concat(privateTopicLinks)
}
links = links.concat(phaseLinks)

return (
<div>
<div className="sideAreaWrapper">
Expand Down Expand Up @@ -415,7 +300,7 @@ class ProjectInfoContainer extends React.Component {
}
{!hideLinks &&
<LinksMenu
links={links}
links={project.bookmarks || []}
canDelete={canManageLinks}
canEdit={canManageLinks}
canAdd={canManageLinks}
Expand Down