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

Edittitle #610

Merged
merged 4 commits into from
Feb 2, 2024
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
6 changes: 2 additions & 4 deletions frontend/components/Viewing/Collection/Members.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function Members(properties) {
}

const parameters = {
graphs: '',
from: '',
graphPrefix: 'https://synbiohub.org/', // TODO: Maybe get this from somewhere?
collection: properties.uri,
sort: sort,
Expand All @@ -81,10 +81,8 @@ export default function Members(properties) {
limit: ' LIMIT 10000 '
};

const { adminStatus, loading, error } = useStatus(token, dispatch);

if (token) {
parameters.graphs = privateGraph
parameters.from = "FROM <" + privateGraph + ">";
} else {
}

Expand Down
67 changes: 41 additions & 26 deletions frontend/components/Viewing/MetadataInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import axios from 'axios';
import getConfig from "next/config";

import { getAfterThirdSlash } from './ViewHeader';
import { isUriOwner } from './Shell';

const { publicRuntimeConfig } = getConfig();

Expand All @@ -19,10 +20,18 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
const [isEditingSource, setIsEditingSource] = useState(false);
const [newSource, setNewSource] = useState('');
const token = useSelector(state => state.user.token);
const username = useSelector(state => state.user.username);

let objectUriParts = "";
if (uri) {
objectUriParts = getAfterThirdSlash(uri);
}
const objectUri = `${publicRuntimeConfig.backend}/${objectUriParts}`;

const [editSourceIndex, setEditSourceIndex] = useState(null);
const [editedSource, setEditedSource] = useState('');
const [sources, setSources] = useState(processTitle(title)); // Assuming processTitle is your existing function
var isOwner = isUriOwner(objectUri, username);


const handleEditSource = (index, source) => {
Expand All @@ -44,9 +53,6 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
return; // Do not proceed with saving an empty source
}

const objectUriParts = getAfterThirdSlash(uri);
const objectUri = `${publicRuntimeConfig.backend}/${objectUriParts}`;

axios
.post(
`${objectUri}/edit/wasDerivedFrom`,
Expand Down Expand Up @@ -80,8 +86,6 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
};

const handleAddSource = () => {
const objectUriParts = getAfterThirdSlash(uri);
const objectUri = `${publicRuntimeConfig.backend}/${objectUriParts}`;
const editedText = newSource;

axios.post(`${objectUri}/add/wasDerivedFrom`, {
Expand Down Expand Up @@ -109,8 +113,6 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
event.stopPropagation(); // Prevent event from propagating to parent elements

if (window.confirm("Do you want to delete this source?")) {
const objectUriParts = getAfterThirdSlash(uri);
const objectUri = `${publicRuntimeConfig.backend}/${objectUriParts}`;

// Find the index of the source to delete
const indexToDelete = sources.findIndex(source => source === sourceToDelete);
Expand Down Expand Up @@ -141,11 +143,18 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
{(label === "Source") && (
<>
<span style={{ marginRight: '0.5rem' }}></span> {/* Add space */}
<FontAwesomeIcon
icon={faPlus}
onClick={() => setIsEditingSource(true)}
className={styles.plusIcon}
/>
{
isOwner && (
<>
<FontAwesomeIcon
icon={faPlus}
onClick={() => setIsEditingSource(true)}
className={styles.plusIcon}
/>
</>
)
}

</>
)}
</div>
Expand Down Expand Up @@ -178,7 +187,7 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
<tbody>
{sources.map((source, index) => {
let processedSource = source;
if (source.match(urlRegex)) {
if (typeof (source) === 'string' && source.match(urlRegex)) {
processedSource = getAfterThirdSlash(source);
}
return (
Expand All @@ -198,7 +207,7 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
) : (
// Display mode
<a
href={source.match(urlRegex) ? source : `http://localhost:3333/${processedSource}`}
href={typeof source === 'string' && source.match(urlRegex) ? source : `http://localhost:3333/${processedSource}`}
target="_blank"
rel="noopener noreferrer"
>
Expand All @@ -207,18 +216,24 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
)}
</td>
{label === "Source" && source && (
<td>
{editSourceIndex === index ? null : (
<div>
<button onClick={() => handleEditSource(index, source)}>
<FontAwesomeIcon icon={faPencilAlt} />
</button>
<button onClick={(e) => handleDeleteSource(e, source)}>
<FontAwesomeIcon icon={faTrash} />
</button>
</div>
)}
</td>
<td>
{editSourceIndex === index ? null : (
<div>
{
isOwner && (
<>
<button onClick={() => handleEditSource(index, source)}>
<FontAwesomeIcon icon={faPencilAlt} />
</button>
<button onClick={(e) => handleDeleteSource(e, source)}>
<FontAwesomeIcon icon={faTrash} />
</button>
</>
)
}
</div>
)}
</td>
)}
</tr>
);
Expand Down
Loading
Loading