diff --git a/app/browser/dataset-browse.tsx b/app/browser/dataset-browse.tsx
index 004f76190..ac2f991c3 100644
--- a/app/browser/dataset-browse.tsx
+++ b/app/browser/dataset-browse.tsx
@@ -626,8 +626,7 @@ const NavSection = ({
(item) => item.label
);
}, [counts, items]);
- const { isOpen, open, close } = useDisclosure();
-
+ const { isOpen, open, close } = useDisclosure(!!currentFilter);
return (
diff --git a/app/rdf/light-cube.ts b/app/rdf/light-cube.ts
index 9a279012f..1f32f4f98 100644
--- a/app/rdf/light-cube.ts
+++ b/app/rdf/light-cube.ts
@@ -10,7 +10,7 @@ import { getCubePreview } from "@/rdf/query-cube-preview";
import {
getCubeComponentTermsets,
getCubeTermsets,
-} from "@/rdf/query-cube-termsets";
+} from "@/rdf/query-termsets";
type LightCubeOptions = {
iri: string;
diff --git a/app/rdf/query-cube-termsets.ts b/app/rdf/query-cube-termsets.ts
deleted file mode 100644
index 4f5f21dd0..000000000
--- a/app/rdf/query-cube-termsets.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-import groupBy from "lodash/groupBy";
-import ParsingClient from "sparql-http-client/ParsingClient";
-
-import { ComponentTermsets, Termset } from "@/domain/data";
-import { buildLocalizedSubQuery } from "@/rdf/query-utils";
-
-export const getCubeTermsets = async (
- iri: string,
- options: {
- locale: string;
- sparqlClient: ParsingClient;
- }
-): Promise => {
- const { sparqlClient, locale } = options;
- const qs = await sparqlClient.query.select(
- `PREFIX cube:
-PREFIX meta:
-PREFIX rdf:
-PREFIX schema:
-PREFIX sh:
-
-SELECT DISTINCT ?termsetIri ?termsetLabel WHERE {
- VALUES (?iri) {(<${iri}>)}
-
- ?iri cube:observationConstraint/sh:property ?dimension .
- ?dimension a cube:KeyDimension .
- ?dimension sh:in/rdf:rest*/rdf:first ?value.
- ?value schema:inDefinedTermSet ?termsetIri .
- ?termsetIri a meta:SharedDimension .
-
- ${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}
-
-}`
- );
-
- return qs.map((result) => ({
- iri: result.termsetIri.value,
- label: result.termsetLabel.value,
- __typename: "Termset",
- }));
-};
-
-export const getCubeComponentTermsets = async (
- iri: string,
- options: {
- locale: string;
- sparqlClient: ParsingClient;
- }
-): Promise => {
- const { sparqlClient, locale } = options;
- const query = `PREFIX cube:
-PREFIX meta:
-PREFIX rdf:
-PREFIX schema:
-PREFIX sh:
-
-SELECT DISTINCT ?dimensionIri ?dimensionLabel ?termsetIri ?termsetLabel WHERE {
- VALUES (?iri) {(<${iri}>)}
-
- ?iri cube:observationConstraint/sh:property ?dimension .
- ?dimension sh:path ?dimensionIri .
- ?dimension a cube:KeyDimension .
- ?dimension sh:in/rdf:rest*/rdf:first ?value.
- ?value schema:inDefinedTermSet ?termsetIri .
- ?termsetIri a meta:SharedDimension .
-
- ${buildLocalizedSubQuery("dimension", "schema:name", "dimensionLabel", { locale })}
- ${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}
-
-}`;
- const qs = await sparqlClient.query.select(query);
-
- const parsed = qs.map((result) => ({
- dimensionIri: result.dimensionIri.value,
- dimensionLabel: result.dimensionLabel.value,
- iri: result.termsetIri.value,
- label: result.termsetLabel.value,
- }));
-
- const grouped = Object.entries(groupBy(parsed, (r) => r.dimensionIri));
-
- return grouped.map(([dimensionIri, termsets]) => ({
- iri: dimensionIri,
- label: termsets[0].dimensionLabel,
- termsets: termsets.map(({ iri, label }) => ({
- iri,
- label,
- __typename: "Termset",
- })),
- }));
-};
diff --git a/app/rdf/query-search.ts b/app/rdf/query-search.ts
index f580715d1..2bdc340dd 100644
--- a/app/rdf/query-search.ts
+++ b/app/rdf/query-search.ts
@@ -213,7 +213,6 @@ const mkScoresQuery = (
sh:path ?dimensionIri ;
cubeMeta:dataKind/time:unitType ?unitType ;
cubeMeta:dataKind/time:unitType <${unitNode}>.
-
${buildLocalizedSubQuery(
"dimension",
"schema:name",
@@ -228,20 +227,7 @@ const mkScoresQuery = (
return `
VALUES (?termsetIri) {${sharedDimensions.map((sd) => `(<${sd}>)`).join(" ")}}
?iri a cube:Cube .
- ?iri cube:observationConstraint/sh:property ?dimension .
- ?dimension a cube:KeyDimension .
- ?dimension sh:in/rdf:first ?value.
- ?dimension sh:path ?dimensionIri .
- ${buildLocalizedSubQuery(
- "dimension",
- "schema:name",
- "dimensionLabel",
- {
- locale,
- }
- )}
-
- ?value schema:inDefinedTermSet ?termsetIri .
+ ?termsetIri meta:isUsedIn ?iri .
${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}`;
}
})
diff --git a/app/rdf/query-termsets.ts b/app/rdf/query-termsets.ts
index 30b1a30ff..1798c5478 100644
--- a/app/rdf/query-termsets.ts
+++ b/app/rdf/query-termsets.ts
@@ -1,6 +1,7 @@
+import groupBy from "lodash/groupBy";
import ParsingClient from "sparql-http-client/ParsingClient";
-import { Termset } from "@/domain/data";
+import { ComponentTermsets, Termset } from "@/domain/data";
import {
buildLocalizedSubQuery,
makeVisualizeDatasetFilter,
@@ -15,30 +16,21 @@ export const queryAllTermsets = async (options: {
const qs = await sparqlClient.query.select(
`PREFIX cube:
PREFIX meta:
-PREFIX rdf:
PREFIX schema:
-PREFIX sh:
-
-SELECT DISTINCT (COUNT(distinct ?iri) as ?count) ?termsetIri ?termsetLabel WHERE {
- ?iri cube:observationConstraint/sh:property ?dimension .
- ?dimension a cube:KeyDimension .
- ?dimension sh:in/rdf:rest*/rdf:first ?value.
- ?value schema:inDefinedTermSet ?termsetIri .
- ?termsetIri a meta:SharedDimension .
- ${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}
-
- ${makeVisualizeDatasetFilter({
- includeDrafts: !!includeDrafts,
- cubeIriVar: "?iri",
- }).toString()}
- } GROUP BY ?termsetIri ?termsetLabel`, {
- operation: "postUrlencoded",
- }
+SELECT DISTINCT (COUNT(DISTINCT ?cubeIri) as ?count) ?termsetIri ?termsetLabel WHERE {
+ ?termsetIri meta:isUsedIn ?cubeIri .
+ ${makeVisualizeDatasetFilter({
+ includeDrafts: !!includeDrafts,
+ cubeIriVar: "?cubeIri",
+ })}
+ ${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}
+} GROUP BY ?termsetIri ?termsetLabel`,
+ { operation: "postUrlencoded" }
);
return qs.map((result) => ({
- count: Number(result.count.value),
+ count: +result.count.value,
termset: {
__typename: "Termset",
iri: result.termsetIri.value,
@@ -46,3 +38,78 @@ SELECT DISTINCT (COUNT(distinct ?iri) as ?count) ?termsetIri ?termsetLabel WHERE
},
}));
};
+
+export const getCubeTermsets = async (
+ iri: string,
+ options: {
+ locale: string;
+ sparqlClient: ParsingClient;
+ }
+): Promise => {
+ const { sparqlClient, locale } = options;
+ const qs = await sparqlClient.query.select(
+ `PREFIX meta:
+PREFIX schema:
+
+SELECT DISTINCT ?termsetIri ?termsetLabel WHERE {
+ ?termsetIri meta:isUsedIn <${iri}> .
+ ${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}
+}`,
+ { operation: "postUrlencoded" }
+ );
+
+ return qs.map((result) => ({
+ iri: result.termsetIri.value,
+ label: result.termsetLabel.value,
+ __typename: "Termset",
+ }));
+};
+
+export const getCubeComponentTermsets = async (
+ iri: string,
+ options: {
+ locale: string;
+ sparqlClient: ParsingClient;
+ }
+): Promise => {
+ const { sparqlClient, locale } = options;
+ const query = `PREFIX cube:
+PREFIX meta:
+PREFIX rdf:
+PREFIX schema:
+PREFIX sh:
+
+SELECT DISTINCT ?dimensionIri ?dimensionLabel ?termsetIri ?termsetLabel WHERE {
+ <${iri}> cube:observationConstraint/sh:property ?dimension .
+ ?dimension
+ sh:path ?dimensionIri ;
+ a cube:KeyDimension ;
+ sh:in/rdf:rest*/rdf:first ?value .
+ ?value schema:inDefinedTermSet ?termsetIri .
+ ?termsetIri a meta:SharedDimension .
+ ${buildLocalizedSubQuery("dimension", "schema:name", "dimensionLabel", { locale })}
+ ${buildLocalizedSubQuery("termsetIri", "schema:name", "termsetLabel", { locale })}
+}`;
+ const qs = await sparqlClient.query.select(query, {
+ operation: "postUrlencoded",
+ });
+
+ const parsed = qs.map((result) => ({
+ dimensionIri: result.dimensionIri.value,
+ dimensionLabel: result.dimensionLabel.value,
+ iri: result.termsetIri.value,
+ label: result.termsetLabel.value,
+ }));
+
+ const grouped = Object.entries(groupBy(parsed, (r) => r.dimensionIri));
+
+ return grouped.map(([dimensionIri, termsets]) => ({
+ iri: dimensionIri,
+ label: termsets[0].dimensionLabel,
+ termsets: termsets.map(({ iri, label }) => ({
+ iri,
+ label,
+ __typename: "Termset",
+ })),
+ }));
+};