Skip to content

Commit

Permalink
fixed an issue with sparql queries and from graphs, changed editable …
Browse files Browse the repository at this point in the history
…things so the icons are removed when there is no permissions
  • Loading branch information
danielfang97 committed Feb 2, 2024
1 parent e5e3bb7 commit 9ac1c38
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
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
51 changes: 33 additions & 18 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 @@ -210,12 +219,18 @@ export default function MetadataInfo({ title, link, label, icon, specific, uri }
<td>
{editSourceIndex === index ? null : (
<div>
<button onClick={() => handleEditSource(index, source)}>
<FontAwesomeIcon icon={faPencilAlt} />
</button>
<button onClick={(e) => handleDeleteSource(e, source)}>
<FontAwesomeIcon icon={faTrash} />
</button>
{
isOwner && (
<>
<button onClick={() => handleEditSource(index, source)}>
<FontAwesomeIcon icon={faPencilAlt} />
</button>
<button onClick={(e) => handleDeleteSource(e, source)}>
<FontAwesomeIcon icon={faTrash} />
</button>
</>
)
}
</div>
)}
</td>
Expand Down
17 changes: 12 additions & 5 deletions frontend/components/Viewing/ViewHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,18 @@ export default function ViewHeader(properties) {
) : (
<div className={styles.titleContainer}>
<h1 className={styles.maintitle}>{displayedTitle}</h1>
<FontAwesomeIcon
icon={faPencilAlt}
onClick={handleEditClick}
className={styles.editIcon}
/>
{
isOwner && (
<>
<FontAwesomeIcon
icon={faPencilAlt}
onClick={handleEditClick}
className={styles.editIcon}
/>
</>
)
}

</div>
)}
<Link href={`/search/displayId='${properties.displayId}'&`}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/sparql/CountMembers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const query = `PREFIX sbol2: <http://sbols.org/v2#>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT (COUNT(DISTINCT ?uri) AS ?count)
FROM <$graphs>
$from
WHERE {
<$collection> sbol2:member ?uri .
OPTIONAL { ?uri a ?type . }
Expand Down
2 changes: 1 addition & 1 deletion frontend/sparql/CountMembersSearch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const query = `PREFIX sbol2: <http://sbols.org/v2#>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT (COUNT(DISTINCT ?uri) AS ?count)
FROM <$graphs>
$from
WHERE {
<$collection> sbol2:member ?uri .
OPTIONAL { ?uri a ?type . }
Expand Down
2 changes: 1 addition & 1 deletion frontend/sparql/getCollectionMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SELECT ?uri
?type
?sbolType
?role
FROM <$graphs>
$from
WHERE { {
SELECT DISTINCT ?uri
?displayId
Expand Down

0 comments on commit 9ac1c38

Please sign in to comment.