Skip to content

Commit 1b0654c

Browse files
authored
Link in table result header is no longer arbitrary if more than one predicate has the same object (#235)
1 parent b1d505c commit 1b0654c

File tree

9 files changed

+100
-18
lines changed

9 files changed

+100
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- Link in table result header is no longer arbitrary if more than one predicate has the same object (#230.)
1617
- Avoided "Error getting variable options..." in templated queries with indirect sources to which the user has no read access (#231).
1718
- Corrected fetch status in templated queries with indirect sources to which the user has no read access (#232).
1819

main/configs/test/config.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,32 @@
581581
"http://localhost:8080/example/favourite-musicians-file-does-not-exist"
582582
]
583583
}
584+
},
585+
{
586+
"id": "9200",
587+
"queryGroupId": "gr-test",
588+
"queryLocation": "schema_name.rq",
589+
"name": "A query that looks for names that are the object of predicate schema:name",
590+
"description": "Tests a single link in the 'name' column header.",
591+
"comunicaContext": {
592+
"sources": [
593+
"http://localhost:8080/example/names-labels"
594+
],
595+
"lenient": true
596+
}
597+
},
598+
{
599+
"id": "9201",
600+
"queryGroupId": "gr-test",
601+
"queryLocation": "schema_name_rdfs_label.rq",
602+
"name": "A query that looks for names that are both the objects of predicates schema:name and rdfs:label",
603+
"description": "Tests two links in the 'name' column header.",
604+
"comunicaContext": {
605+
"sources": [
606+
"http://localhost:8080/example/names-labels"
607+
],
608+
"lenient": true
609+
}
584610
}
585611
]
586612
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PREFIX schema: <http://schema.org/>
2+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
3+
4+
SELECT ?name WHERE {
5+
?s schema:name ?name.
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PREFIX schema: <http://schema.org/>
2+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
3+
4+
SELECT ?name WHERE {
5+
?s schema:name ?name.
6+
?s rdfs:label ?name.
7+
}

main/src/components/ListResultTable/QueryResultList/TableHeader/TableHeader.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ function TableHeader({ children }) {
6060
</span>
6161
</Tooltip>}
6262
{!!variableOntology && variableOntology[child.props.source] && (
63-
<Link
64-
target="_blank"
65-
href={variableOntology[child.props.source]}
66-
sx={{ height: "100%", margin: "0 5px", "& > *": { verticalAlign: "middle" } }}
67-
>
68-
<LinkIcon
69-
fontSize="small"
70-
sx={{ height: "100%", color: "gray" }}
71-
/>
72-
</Link>
63+
variableOntology[child.props.source].map((link) => (
64+
<Link
65+
target="_blank"
66+
href={link}
67+
sx={{ height: "100%", margin: "0 0 0 5px", "& > *": { verticalAlign: "middle" } }}
68+
>
69+
<LinkIcon
70+
fontSize="small"
71+
sx={{ height: "100%", color: "gray" }}
72+
/>
73+
</Link>
74+
))
7375
)}
7476
{sort.field === child.props.source && (
7577
<>

main/src/dataProvider/SparqlDataProvider.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ function replaceVariables(rawText, variableValues) {
189189
}
190190

191191
/**
192-
* Given a query and an object, this function returns the predicate of the object in the query.
192+
* Given a query and an object, this function returns the predicates of the object in the query.
193193
*
194194
* @param {object} query - the parsed query in which the predicate is to be looked for.
195-
* @returns {object} an object with the variable as key and the predicate as value.
195+
* @returns {object} an object with the variable as key and as value an array of predicates.
196196
*/
197197
function findPredicates(query) {
198198
const ontologyMapper = {};
@@ -204,7 +204,11 @@ function findPredicates(query) {
204204
if (part.triples) {
205205
for (const triple of part.triples) {
206206
if (triple.predicate.termType !== "Variable") {
207-
ontologyMapper[triple.object.value] = triple.predicate.value;
207+
if (!ontologyMapper[triple.object.value]) {
208+
ontologyMapper[triple.object.value] = [triple.predicate.value];
209+
} else if (!ontologyMapper[triple.object.value].includes(triple.predicate.value)) {
210+
ontologyMapper[triple.object.value].push(triple.predicate.value);
211+
}
208212
}
209213
}
210214
}
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
describe("Column header", () => {
2-
it("Variables link to ontology", () => {
2+
it("One link to ontology", () => {
33
cy.visit("/");
4-
cy.contains("Example queries").click();
5-
cy.contains("A query about musicians").click();
4+
cy.contains("For testing only").click();
5+
cy.contains("A query that looks for names that are the object of predicate schema:name").click();
66
cy.contains("Finished in:");
7-
cy.get('a[href="http://schema.org/name"]');
8-
})
7+
cy.get('th').contains("name").parent().within(() => {
8+
cy.get('a[href="http://schema.org/name"]');
9+
});
10+
});
11+
12+
it("Two links to ontology", () => {
13+
cy.visit("/");
14+
cy.contains("For testing only").click();
15+
cy.contains("A query that looks for names that are both the objects of predicates schema:name and rdfs:label").click();
16+
cy.contains("Finished in:");
17+
cy.get('th').contains("name").parent().within(() => {
18+
cy.get('a[href="http://schema.org/name"]');
19+
cy.get('a[href="http://www.w3.org/2000/01/rdf-schema#label"]');
20+
});
21+
});
22+
923
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PREFIX schema: <http://schema.org/>
2+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
3+
PREFIX ex: <https://www.example.com/ont/>
4+
5+
ex:1 schema:name "A name, given with predicates schema:name and rdfs:label" ;
6+
rdfs:label "A name, given with predicates schema:name and rdfs:label" .
7+
ex:2 schema:name "A name, given with predicate schema:name" ;
8+
rdfs:label "A name, given with predicate rdfs:label" .
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
2+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
3+
4+
<#public>
5+
a acl:Authorization;
6+
acl:accessTo <./names-labels>;
7+
acl:agentClass foaf:Agent;
8+
acl:mode acl:Read.
9+
10+
<#owner>
11+
a acl:Authorization;
12+
acl:accessTo <./names-labels>;
13+
acl:agent <http://localhost:8080/example/profile/card#me>;
14+
acl:mode acl:Read, acl:Write, acl:Control.

0 commit comments

Comments
 (0)