Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: 1945 Links to projects, subprojects, action items #2025

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
46 changes: 22 additions & 24 deletions frontend/src/pages/Common/Identifier.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import React, { Component } from "react";
import React from "react";

import TextInput from "./TextInput";

import "./index.scss";

class Identifier extends Component {
render() {
return (
<div className="identifier">
<TextInput
label={this.props.nameLabel}
value={this.props.name}
onChange={this.props.nameOnChange}
data-test={this.props.commentId || "nameinput"}
disabled={this.props.disabled}
/>
const Identifier = (props) => {
return (
<div className="identifier">
<TextInput
label={props.nameLabel}
value={props.name}
onChange={props.nameOnChange}
data-test={props.commentId || "nameinput"}
disabled={props.disabled}
/>

<TextInput
label={this.props.commentLabel}
value={this.props.comment}
onChange={this.props.commentOnChange}
multiline={true}
data-test={this.props.commentId || "commentinput"}
disabled={this.props.disabled}
/>
</div>
);
}
}
<TextInput
label={props.commentLabel}
value={props.comment}
onChange={props.commentOnChange}
multiline={true}
data-test={props.commentId || "commentinput"}
disabled={props.disabled}
/>
</div>
);
};

export default Identifier;
33 changes: 33 additions & 0 deletions frontend/src/pages/Common/LinkItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";
import { Link } from "react-router-dom";

import DatasetLinkedIcon from "@mui/icons-material/DatasetLinked";
import { Avatar, ListItem, ListItemAvatar, Typography } from "@mui/material";

const displayLinks = (links) => {
return links.map((link, idx) => (
<Typography variant="body2" mt={2} key={`${link}-${idx}`}>
<Link to={`${link}`} key={`${link}-${idx}`}>
{link}
</Link>
</Typography>
));
};

const LinkItems = ({ projectComment }) => {
const regex = /(?<=\s)\/projects[^\s,\.]*/g;
const matches = projectComment.match(regex);

return matches && matches.length > 0 ? (
<ListItem>
<ListItemAvatar>
<Avatar>
<DatasetLinkedIcon />
</Avatar>
</ListItemAvatar>
<>{displayLinks(matches)}</>
</ListItem>
) : null;
};

export default LinkItems;
65 changes: 65 additions & 0 deletions frontend/src/pages/Common/TextWithLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { useState } from "react";

import { Link, TextField, Typography } from "@mui/material";

const TextWithLinks = ({
label,
helperText,
value,
onChange,
onBlur,
onFocus,
pattern,
multiline = false,
disabled = false,
id,
// eslint-disable-next-line no-useless-computed-key
["data-test"]: dataTest
}) => {
const [inputValue, setInputValue] = useState("");
const [url, setUrl] = useState("");

const handleInputChange = (event) => {
const value = event.target.value;
setInputValue(value);

// Simple URL detection, could use a more robust regex for URL validation
const urlPattern = /https?:\/\/[^\s$.?#].[^\s]*/gi;
const detectedUrl = value.match(urlPattern);
setUrl(detectedUrl ? detectedUrl[0] : "");
};

return (
<>
{/* TextField for input */}
<TextField
variant="standard"
label={label}
onFocus={onFocus}
helperText={helperText}
multiline={multiline}
className="text-field"
disabled={disabled}
value={inputValue}
id={id}
// onChange={(event) => onChange(event.target.value)}
onBlur={onBlur}
pattern={pattern}
data-test={dataTest}
onChange={handleInputChange}
/>

{/* Conditionally render the clickable URL below the TextField */}
{url && (
<Typography variant="body2" mt={2}>
Clickable URL:{" "}
<Link href={url} target="_blank" rel="noopener noreferrer">
{url}
</Link>
</Typography>
)}
</>
);
};

export default TextWithLinks;
7 changes: 5 additions & 2 deletions frontend/src/pages/SubProjects/ProjectDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ import {
import strings from "../../localizeStrings";
import ProjectAnalyticsDialog from "../Analytics/ProjectAnalyticsDialog";
import BudgetEmptyState from "../Common/BudgetEmptyState";
import LinkItems from "../Common/LinkItems.js";

import ProjectAssigneeContainer from "./ProjectAssigneeContainer";

import "./ProjectDetails.scss";

const displayTags = (tags) => {
return tags.map((tag, i) => (
return tags.map((tag, idx) => (
<Chip
key={`${tag}-${i}`}
key={`${tag}-${idx}`}
label={`#${formattedTag(tag)}`}
style={{ margin: "1px" }}
clickable={false}
Expand Down Expand Up @@ -77,6 +78,7 @@ const ProjectDetails = (props) => {
const hasOpenSubprojects = !_isEmpty(subProjects.find((subproject) => subproject.data.status === "open"));
const closeDisabled = !canClose || hasOpenSubprojects || projectStatus === "closed";
const tags = displayTags(projectTags || []);

return (
<div className="project-details-container">
<Card className="project-details-card">
Expand Down Expand Up @@ -107,6 +109,7 @@ const ProjectDetails = (props) => {
<ListItemText primary={tags} />
</ListItem>
) : null}
<LinkItems projectComment={projectComment} />
</List>
<div className="project-projected-budget" data-test="project-projected-budget">
<Typography variant="body1">{strings.common.total_budget}</Typography>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/pages/SubProjects/SubProjectContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ class SubProjectContainer extends Component {
}

componentDidUpdate(prevProps) {
if (this.props.router.location.pathname !== prevProps.router.location.pathname) {
const newProjectId = this.props.router.location.pathname.split("/")[2];
if (newProjectId !== this.projectId) {
this.setState({ isDataFetched: false });
this.projectId = newProjectId;
this.props.setSelectedView(this.projectId, "project");
this.props.fetchAllProjectDetails(this.projectId, true);
this.setState({ isDataFetched: true });
}
}
const searchTermChanges = this.props.searchTerm !== prevProps.searchTerm;
const projectsChange = !_isEqual(this.props.subProjects, prevProps.subProjects);

Expand Down
Loading