Skip to content

Commit cd3f986

Browse files
authored
Result list sorting works again and the behavior is improved (#217)
1 parent e82d425 commit cd3f986

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

CHANGELOG.md

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

2525
- Avoided (infinite) display of "The list is loading. Just a moment please." for queries that should show "The result list is empty.", in cases where the user does not have the right to read the involved source(s) (#209).
26+
- Result list sorting works again and the behavior is improved - see the issue for details (#216).
2627

2728
## [1.7.0] - 2025-04-09
2829

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function QueryResultList(props) {
4949
<List
5050
{...props}
5151
disableAuthentication={true} // needed to overrule the default, which is to force logging in
52+
storeKey={false} // do not remember pagination, sorting, ...
5253
title=" "
5354
actions={ <ActionBar />}
5455
empty={false}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link, TableCell, TableHead, TableRow } from "@mui/material";
1+
import { Link, TableCell, TableHead, TableRow, Tooltip } from "@mui/material";
22
import React from "react";
33
import { useListContext } from "react-admin";
44
import "./TableHeader.css";
@@ -24,8 +24,8 @@ function TableHeader({ children }) {
2424
* @param {string} target - the source of the column that was clicked
2525
*/
2626
function handleHeaderClick(target) {
27-
const newSort = { field: target, order: "DESC" };
28-
if (sort) {
27+
const newSort = { field: target, order: "ASC" };
28+
if (sort && sort.field == target) {
2929
if (sort.order === "ASC") {
3030
newSort.order = "DESC";
3131
} else {
@@ -37,23 +37,28 @@ function TableHeader({ children }) {
3737

3838
const query = configManager.getQueryWorkingCopyById(resource);
3939
const variableOntology = query.variableOntology;
40-
40+
const sortingAllowed = query.queryText.startsWith("# Custom sorting is allowed.");
41+
4142
return (
4243
<TableHead>
4344
<TableRow>
4445
{React.Children.map(children, (child) => (
4546
<>
4647
<TableCell
4748
key={child.props.source}
48-
sx={{ height: "100%", "& > *": { verticalAlign: "middle" } }}
49+
sx={{ height: "100%", "font-weight": "bold", "& > *": { verticalAlign: "middle" } }}
4950
>
50-
<span
51+
{sortingAllowed ? <span
5152
role="button"
5253
className="header-button"
5354
onClick={() => handleHeaderClick(child.props.source)}
5455
>
5556
{child.props.label}
56-
</span>
57+
</span> : <Tooltip title="Custom sorting is disabled for queries containing an ORDER clause.">
58+
<span>
59+
{child.props.label}
60+
</span>
61+
</Tooltip>}
5762
{!!variableOntology && variableOntology[child.props.source] && (
5863
<Link
5964
target="_blank"

main/src/dataProvider/SparqlDataProvider.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default {
5151
query.variableValues = meta.variableValues;
5252
}
5353

54-
const hash = JSON.stringify({ resource, variableValues: query.variableValues });
54+
const hash = JSON.stringify({ resource, sort, variableValues: query.variableValues });
5555
// LOG console.log(`hash: ${hash}`);
5656
if (hash == listCache.hash) {
5757
// LOG console.log(`reusing listCache.results: ${JSON.stringify(listCache.results, null, 2)}`);
@@ -151,17 +151,22 @@ async function buildQueryText(query) {
151151
if (!query.variableOntology) {
152152
query.variableOntology = findPredicates(parsedQuery);
153153
}
154-
if (!parsedQuery.order && query.sort && query.sort.field !== "id") {
155-
const { field, order } = query.sort;
156-
parsedQuery.order = [
157-
{
158-
expression: { termType: "Variable", value: field },
159-
descending: order === "DESC",
160-
},
161-
];
162-
}
154+
let comments = "";
155+
if (!parsedQuery.order) {
156+
comments = "Custom sorting is allowed.";
157+
if (query.sort && query.sort.field !== "id") {
158+
const { field, order } = query.sort;
159+
parsedQuery.order = [
160+
{
161+
expression: { termType: "Variable", value: field },
162+
descending: order === "DESC",
163+
},
164+
];
165+
}
166+
}
163167
const generator = new Generator();
164-
return generator.stringify(parsedQuery);
168+
let result = generator.stringify(parsedQuery);
169+
return `# ${comments}\n${result}`;
165170
} catch (error) {
166171
throw new Error(error.message);
167172
}

test/cypress/e2e/sorting.cy.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
describe("Table sorting", () => {
2+
it("Should respond to sorting", () => {
3+
cy.visit("/");
4+
cy.contains("Example queries").click();
5+
cy.contains("A query about musicians").click();
6+
cy.contains("Finished in:");
7+
cy.get(':nth-child(1) > .column-name > span').contains("Antonio Caldara").should("not.exist");
8+
cy.contains("name").click();
9+
cy.get(':nth-child(1) > .column-name > span').contains("Antonio Caldara");
10+
cy.contains("name").click();
11+
cy.get(':nth-child(1) > .column-name > span').contains("Wolfgang Amadeus Mozart");
12+
});
13+
14+
it("Should show that sorting is disabled on queries with an ORDER clause", () => {
15+
cy.visit("/");
16+
cy.contains("Project related examples").click();
17+
cy.contains("Components").click();
18+
cy.contains("Finished in:");
19+
cy.contains(/^component$/).click();
20+
cy.contains("Custom sorting is disabled for queries containing an ORDER clause.").should('exist');
21+
});
22+
});

0 commit comments

Comments
 (0)