Skip to content

Commit

Permalink
Merge pull request #530 from diggsweden/DIGG-483
Browse files Browse the repository at this point in the history
DIGG-483: Uppdating url structure for concepts, terminologies and specifications
  • Loading branch information
MikaMunterud authored Dec 9, 2024
2 parents d5558ea + 4277fa6 commit bfcc06a
Show file tree
Hide file tree
Showing 29 changed files with 349 additions and 520 deletions.
11 changes: 2 additions & 9 deletions features/entryscape/concept-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,17 @@ import { EntrystoreContext } from "@/providers/entrystore-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { linkBase } from "@/utilities";

export const ConceptPage: FC<{ curi?: string; uri?: string }> = ({
curi,
uri,
}) => {
export const ConceptPage: FC = () => {
const { setBreadcrumb, iconSize } = useContext(SettingsContext);
const entry = useContext(EntrystoreContext);
const { lang, t } = useTranslation();
const { pathname } = useRouter() || {};
const isTerminology =
pathname.startsWith("/terminology") ||
pathname.startsWith("/externalterminology");
const isTerminology = pathname.startsWith("/terminology");

useEntryScapeBlocks({
entrystoreBase: entry.entrystore.getBaseURI(),
env: entry.env,
lang,
curi,
uri,
iconSize,
pageType: isTerminology ? "terminology" : "concept",
context: entry.context,
Expand Down
4 changes: 1 addition & 3 deletions features/entryscape/dataset-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import { SettingsContext } from "@/providers/settings-provider";
import { linkBase } from "@/utilities";

export const DatasetPage: FC = () => {
const { pathname, query } = useRouter() || {};
const { pathname } = useRouter() || {};
const { setBreadcrumb, iconSize } = useContext(SettingsContext);
const entry = useContext(EntrystoreContext);
const { lang, t } = useTranslation();
const { dataSet } = query || {};
const [showText, setShowText] = useState(false);
const [descriptionHeight, setDescriptionHeight] = useState(0);
const [showAllSpecs, setShowAllSpecs] = useState(false);
Expand All @@ -34,7 +33,6 @@ export const DatasetPage: FC = () => {
entrystoreBase: entry.entrystore.getBaseURI(),
env: entry.env,
lang,
curi: dataSet as string,
iconSize,
pageType: "dataset",
context: entry.context,
Expand Down
7 changes: 1 addition & 6 deletions features/entryscape/specification-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import { EntrystoreContext } from "@/providers/entrystore-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { linkBase } from "@/utilities";

export const SpecificationPage: FC<{ curi?: string; uri?: string }> = ({
curi,
uri,
}) => {
export const SpecificationPage: FC = () => {
const { setBreadcrumb, iconSize } = useContext(SettingsContext);
const entry = useContext(EntrystoreContext);
const { lang, t } = useTranslation();
Expand All @@ -34,8 +31,6 @@ export const SpecificationPage: FC<{ curi?: string; uri?: string }> = ({
entrystoreBase: entry.entrystore.getBaseURI(),
env: entry.env,
lang,
curi,
uri,
iconSize,
pageType: "specification",
context: entry.context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ interface HitSpecification {
path: string;
titleResource: string;
descriptionResource: string;
// eslint-disable-next-line no-unused-vars
pathResolver?: (hitMeta: ResourceMeta) => string;
}

interface SearchProviderConfig {
Expand All @@ -42,49 +40,6 @@ interface SearchProviderConfig {
}[];
};
}
interface ResourceMeta {
getResourceURI: () => string;
}

interface PathResolverConfig {
externalPath: string;
internalPath: string;
domainLength: number;
}

function createPathResolver(config: PathResolverConfig) {
return (hitMeta: ResourceMeta) => {
const resourceUri = hitMeta.getResourceURI();

if (!resourceUri) return "";

if (!resourceUri.includes("dataportal.se")) {
return `${config.externalPath}?resource=${encodeURIComponent(
resourceUri,
)}`;
}

if (resourceUri.includes(config.internalPath)) {
return resourceUri.slice(
resourceUri.lastIndexOf("dataportal.se/") + config.domainLength,
);
}

return resourceUri;
};
}

const specsPathResolver = createPathResolver({
externalPath: "/externalspecification",
internalPath: "dataportal.se/specifications",
domainLength: 13,
});

const termsPathResolver = createPathResolver({
externalPath: "/externalconcept",
internalPath: "dataportal.se/concepts",
domainLength: 13,
});

export function createSearchProviderSettings(env: EnvSettings, lang: string) {
return {
Expand Down Expand Up @@ -161,7 +116,6 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) {
indexOrder: 4,
group: "distribution",
},

{
resource: "http://data.europa.eu/r5r/applicableLegislation",
type: ESType.uri,
Expand Down Expand Up @@ -202,13 +156,11 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) {
path: `/specifications/`,
titleResource: "dcterms:title",
descriptionResource: "dcterms:description",
pathResolver: specsPathResolver,
},
"http://purl.org/dc/terms/Standard": {
path: `/specifications/`,
titleResource: "dcterms:title",
descriptionResource: "dcterms:description",
pathResolver: specsPathResolver,
},
},
facetSpecification: {
Expand Down Expand Up @@ -291,7 +243,6 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) {
path: `/concepts/`,
titleResource: "http://www.w3.org/2004/02/skos/core#prefLabel",
descriptionResource: "http://www.w3.org/2004/02/skos/core#definition",
pathResolver: termsPathResolver,
},
},
facetSpecification: {
Expand Down
4 changes: 0 additions & 4 deletions hooks/use-entry-scape-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export const useEntryScapeBlocks = ({
entrystoreBase,
env,
lang,
curi,
uri,
iconSize,
pageType,
context,
Expand Down Expand Up @@ -72,8 +70,6 @@ export const useEntryScapeBlocks = ({
entrystoreBase,
env,
lang,
curi,
uri,
iconSize,
t,
pageType,
Expand Down
40 changes: 15 additions & 25 deletions pages/concepts/[concept]/[param].tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { useRouter } from "next/router";
import { useContext } from "react";
import { GetServerSidePropsContext } from "next/types";

import { ConceptPage } from "@/features/entryscape/concept-page";
import { EntrystoreProvider } from "@/providers/entrystore-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { handleEntryStoreRedirect } from "@/utilities/entryscape/entrystore-redirect";

export default function Concept() {
const { env } = useContext(SettingsContext);
const { query } = useRouter() || {};
const { concept, param } = query || {};
const curi = `${concept}/${param}`;
let entryUri = "";

if (env.ENTRYSCAPE_TERMS_PATH.includes("sandbox"))
entryUri = `https://www-sandbox.dataportal.se/concepts/${curi}`;
else entryUri = `https://dataportal.se/concepts/${curi}`;

return (
<EntrystoreProvider
env={env}
entryUri={entryUri}
entrystoreUrl={env.ENTRYSCAPE_TERMS_PATH}
pageType="concept"
>
<ConceptPage curi={curi} />
</EntrystoreProvider>
);
return null;
}

export const getServerSideProps = async (
context: GetServerSidePropsContext,
) => {
return handleEntryStoreRedirect(context, {
pathPrefix: "/concepts",
redirectPath: "/concepts",
entrystorePathKey: "ENTRYSCAPE_TERMS_PATH",
paramName: "concept",
secondParamName: "param",
});
};
27 changes: 19 additions & 8 deletions pages/concepts/[concept]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import { useRouter } from "next/router";
import { GetServerSidePropsContext } from "next/types";
import { useContext } from "react";

import { ConceptPage } from "@/features/entryscape/concept-page";
import { EntrystoreProvider } from "@/providers/entrystore-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { handleEntryStoreRedirect } from "@/utilities/entryscape/entrystore-redirect";

export default function Concept() {
const { env } = useContext(SettingsContext);
const { query } = useRouter() || {};
const { concept } = query || {};
const curi = concept;
let entryUri = "";

if (env.ENTRYSCAPE_TERMS_PATH.includes("sandbox"))
entryUri = `https://www-sandbox.dataportal.se/concepts/${curi}`;
else entryUri = `https://dataportal.se/concepts/${curi}`;
const ids = (typeof concept === "string" && concept.split("_")) || [];
const eid = ids.pop() || "";
const cid = ids.join("_");

return (
<EntrystoreProvider
env={env}
entryUri={entryUri}
cid={cid}
eid={eid}
entrystoreUrl={env.ENTRYSCAPE_TERMS_PATH}
pageType="concept"
>
<ConceptPage {...(typeof curi === "string" ? { curi } : {})} />
<ConceptPage />
</EntrystoreProvider>
);
}

export const getServerSideProps = async (
context: GetServerSidePropsContext,
) => {
return handleEntryStoreRedirect(context, {
pathPrefix: "/concepts",
redirectPath: "/concepts",
entrystorePathKey: "ENTRYSCAPE_TERMS_PATH",
paramName: "concept",
});
};
35 changes: 13 additions & 22 deletions pages/externalconcept/[...concept].tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import { GetServerSideProps } from "next/types";
import { GetServerSidePropsContext } from "next/types";

export const getServerSideProps: GetServerSideProps = async ({ params }) => {
const concept = (params?.concept as string[]) || [];
const scheme = concept[0];

if (scheme != "http" && scheme != "https") {
return {
notFound: true,
};
}

// Reconstruct the original URI and redirect to the new format
const curi = concept.slice(1).join("/");
const uri = `${scheme}://${curi}`;

return {
redirect: {
destination: `/externalconcept?resource=${encodeURIComponent(uri)}`,
permanent: true,
},
};
};
import { handleEntryStoreRedirect } from "@/utilities/entryscape/entrystore-redirect";

export default function Concept() {
return null;
}

export const getServerSideProps = async (
context: GetServerSidePropsContext,
) => {
return handleEntryStoreRedirect(context, {
pathPrefix: "/concepts",
redirectPath: "/concepts",
entrystorePathKey: "ENTRYSCAPE_TERMS_PATH",
paramName: "concept",
});
};
43 changes: 16 additions & 27 deletions pages/externalconcept/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { useRouter } from "next/router";
import { GetServerSideProps } from "next/types";
import { useContext } from "react";
import { GetServerSidePropsContext } from "next/types";

import { ConceptPage } from "@/features/entryscape/concept-page";
import { EntrystoreProvider } from "@/providers/entrystore-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { handleEntryStoreRedirect } from "@/utilities/entryscape/entrystore-redirect";

export default function Concept() {
const { env } = useContext(SettingsContext);
const { resource } = useRouter().query;

if (!resource) return null;

return (
<EntrystoreProvider
env={env}
entryUri={decodeURIComponent(resource as string)}
entrystoreUrl={env.ENTRYSCAPE_TERMS_PATH}
pageType="concept"
>
<ConceptPage uri={resource as string} />
</EntrystoreProvider>
);
return null;
}

export const getServerSideProps: GetServerSideProps = async ({
query: { resource },
}) => ({
notFound: !resource,
props: {},
});
export const getServerSideProps = async (
context: GetServerSidePropsContext,
) => {
return handleEntryStoreRedirect(
context,
{
pathPrefix: "/concepts",
redirectPath: "/concepts",
entrystorePathKey: "ENTRYSCAPE_TERMS_PATH",
},
context.query.resource as string,
);
};
Loading

0 comments on commit bfcc06a

Please sign in to comment.