diff --git a/packages/dito/app/routes/digitaltauglichkeit.prinzipien.$prinzip.tsx b/packages/dito/app/routes/digitaltauglichkeit.prinzipien.$prinzip.tsx deleted file mode 100644 index 5fdb484..0000000 --- a/packages/dito/app/routes/digitaltauglichkeit.prinzipien.$prinzip.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import Background from "@digitalcheck/shared/components/Background.tsx"; -import Container from "@digitalcheck/shared/components/Container.tsx"; -import { json, useLoaderData, useLocation } from "@remix-run/react"; - -import DetailInfo from "@digitalcheck/shared/components/DetailInfo.tsx"; -import { LoaderFunction } from "@remix-run/node"; -import { getPrinzipBySlug, PrinzipRecord } from "../utils/strapiData.server.ts"; - -export const loader: LoaderFunction = async ({ params }) => { - const slug = params.prinzip; - if (!slug) throw new Response("Prinzip not found", { status: 404 }); - - try { - const response = await getPrinzipBySlug(slug); - if (!response?.data?.length) - throw new Response("Prinzip not found", { status: 404 }); - - const prinzip = response.data[0]; - return json({ prinzip }); - } catch (error) { - throw new Response(`Error fetching Prinzip data: ${error}`, { - status: 500, - }); - } -}; - -export default function Digitaltauglichkeit_Prinzipien_Detail() { - const location = useLocation(); - - const loaderData = useLoaderData<{ prinzip: PrinzipRecord }>(); - const prinzip = - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - (location.state?.prinzip as PrinzipRecord | undefined) || - loaderData.prinzip; - - if (!prinzip) { - return ( - - -

Prinzip not found

-

Sorry, the requested principle could not be found.

-
-
- ); - } - - return ( - <> - - - -

All Properties:

- -
- - ); -} diff --git a/packages/dito/app/routes/digitaltauglichkeit.prinzipien/route.tsx b/packages/dito/app/routes/digitaltauglichkeit.prinzipien/route.tsx index 17f2117..9626525 100644 --- a/packages/dito/app/routes/digitaltauglichkeit.prinzipien/route.tsx +++ b/packages/dito/app/routes/digitaltauglichkeit.prinzipien/route.tsx @@ -1,21 +1,14 @@ import Background from "@digitalcheck/shared/components/Background.tsx"; import Container from "@digitalcheck/shared/components/Container.tsx"; -import DetailInfo from "@digitalcheck/shared/components/DetailInfo.tsx"; -import { json, redirect } from "@remix-run/node"; -import { - MetaFunction, - Outlet, - useLoaderData, - useNavigate, -} from "@remix-run/react"; -import { useState } from "react"; +import { redirect } from "@remix-run/node"; +import { json, Link, MetaFunction, useLoaderData } from "@remix-run/react"; import { ROUTE_LANDING, ROUTE_PRINZIPLES, } from "../../resources/staticRoutes.ts"; import unleash from "../../utils/featureFlags.server.ts"; import prependMetaTitle from "../../utils/metaTitle.ts"; -import { getPrinzips, PrinzipRecord } from "../../utils/strapiData.server.ts"; +import { getPrinzips, Prinzip } from "../../utils/strapiData.server.ts"; export const meta: MetaFunction = ({ matches }) => { return prependMetaTitle(ROUTE_PRINZIPLES.title, matches); @@ -33,52 +26,37 @@ export async function loader() { const prinzipData = await getPrinzips(); - return json({ - prinzips: prinzipData ? prinzipData.data : [], + const test = json({ + prinzips: prinzipData?.data.prinzips, }); + return test; } -export default function Prinzip() { - const { prinzips } = useLoaderData<{ prinzips: PrinzipRecord[] }>(); - - const navigate = useNavigate(); - - const [selectedPrinciple, setSelectedPrinciple] = useState("Alle Prinzipien"); - - const handleSelectChange = (selectedValue: string) => { - const selectedOption = prinzips.find( - (principle: PrinzipRecord) => principle.Name === selectedValue, - ); - - if (selectedOption) { - setSelectedPrinciple(selectedOption.Name); - navigate(selectedOption.slug, { state: { prinzip: selectedOption } }); - } else { - setSelectedPrinciple("Alle Prinzipien"); - } - }; +export default function Prinzipien() { + const { prinzips } = useLoaderData<{ prinzips: Prinzip[] }>(); return ( <> + {/*

{selectedPrinciple}

+*/}
- + {/* prinzip.Name)} + selectOptions={prinzips.map((prinzip: Prinzip) => prinzip.Name)} onChange={(e) => handleSelectChange(e.target.value)} /> - - - {/*
+ */} +

Prinzipien

-
*/} +
+ {/**/} ); } diff --git a/packages/dito/app/utils/strapiData.server.ts b/packages/dito/app/utils/strapiData.server.ts index a4e4c5d..18f2a70 100644 --- a/packages/dito/app/utils/strapiData.server.ts +++ b/packages/dito/app/utils/strapiData.server.ts @@ -1,51 +1,98 @@ -const url = process.env.STRAPI_URL || "http://localhost:1337"; +const url = process.env.STRAPI_URL || "http://localhost:1337/graphql"; -type ChildNode = { - text: string; - type: string; - url?: string; - children?: ChildNode[]; +export type Paragraph = { + Norm: string; + ErlaeuterungDS?: string; + Tags: Tag[]; + Text: string; }; -type Tipp = { - type: string; - format?: string; - children: ChildNode[]; +export enum EinschaetzungReferat { + Ja = "Ja", + Nein = "Nein", + Teilweise = "Teilweise", + NichtRelevant = "Nicht relevant", +} + +export type Prinziperfuellung = { + EinschaetzungReferat: EinschaetzungReferat; + NKRStellungnahme?: string; + Paragraphen: Paragraph[]; }; -type Description = { - type: string; - children: ChildNode[]; +export enum TagEnum { + Tag1 = "Tag1", + Tag2 = "Tag2", +} + +export type Tag = { + Tag?: TagEnum; +}; + +export enum Ressort { + Aa = "AA", + Bmas = "BMAS", + Bmbf = "BMBF", + Bmdv = "BMDV", + Bmel = "BMEL", + Bmf = "BMF", + Bmfsfj = "BMFSFJ", + Bmg = "BMG", + Bmi = "BMI", + Bmj = "BMJ", + Bmuv = "BMUV", + BmVg = "BMVg", + Bmwk = "BMWK", + Bmwsb = "BMWSB", + Bmz = "BMZ", +} + +export enum Rechtsgebiet { + Tbd = "TBD", +} + +export type Prinzipienerfuellung = { + DigitaleKommunikation?: Prinziperfuellung; + Wiederverwendung?: Prinziperfuellung; + Datenschutz?: Prinziperfuellung; + KlareRegelungen?: Prinziperfuellung; + Automatisierung?: Prinziperfuellung; }; -type Regelungsvorhaben = { +export type Regelungsvorhaben = { + documentId: string; + createdAt: Date; + updatedAt: Date; + publishedAt?: Date; Titel: string; Gesetz: boolean; - Ressort: string; + Ressort: Ressort; NKRStellungnahme?: string; DIPVorgang: number; NKRNummer: number; - Prinzipienerfuellung?: object; - slug: string; + Prinzipienerfuellung?: Prinzipienerfuellung; + slug?: string; + Rechtsgebiet?: Rechtsgebiet; }; -export type PrinzipRecord = { - id: number; +export type Prinzip = { documentId: string; Name: string; - Beschreibung: Description[]; - createdAt: string; - updatedAt: string; - publishedAt: string; - locale?: string | null; + Beschreibung: string; Nummer: number; - Tipps?: Tipp[]; - regelungsvorhaben?: Regelungsvorhaben[]; - slug: string; + Tipps?: []; + regelungsvorhaben: { data: Regelungsvorhaben[] }; + slug?: string; +}; + +export type PrinzipResponse = { + data: { + prinzips: Prinzip[]; + }; }; -interface PrinzipResponse { - data: PrinzipRecord[]; +export type RegelungsvorhabenResponse = { + data: Regelungsvorhaben[]; meta: { pagination: { page: number; @@ -54,15 +101,101 @@ interface PrinzipResponse { total: number; }; }; +}; + +const GET_PRINZIPS_QUERY = `query GetPrinzips { + prinzips { + Beschreibung + Name + Nummer + Tipps + regelungsvorhaben { + Gesetz + Prinzipienerfuellung { + Automatisierung { + EinschaetzungReferat + Paragraphen { + ErlaeuterungDS + Norm + Tags { + Tag + } + Text + id + } + id + } + Datenschutz { + EinschaetzungReferat + Paragraphen { + ErlaeuterungDS + Norm + Tags { + Tag + } + Text + id + } + id + } + DigitaleKommunikation { + EinschaetzungReferat + Paragraphen { + ErlaeuterungDS + Norm + Tags { + Tag + } + Text + id + } + id + } + KlareRegelungen { + EinschaetzungReferat + Paragraphen { + ErlaeuterungDS + Norm + Tags { + Tag + } + Text + id + } + id + } + Wiederverwendung { + EinschaetzungReferat + Paragraphen { + ErlaeuterungDS + Norm + Tags { + Tag + } + Text + id + } + id + } + id + } + Rechtsgebiet + Ressort + Titel + documentId + slug + } + slug + } } +`; export async function getPrinzipBySlug(slug: string): Promise { const endpoint = `${url}/api/prinzips?filters[slug][$eqi]=${slug}&populate=regelungsvorhaben`; const response = await fetch(endpoint); if (!response.ok) { - //TODO: logging - console.log(response); + console.error("Failed to fetch Prinzip by slug:", response.statusText); throw new Error("Failed to fetch Prinzip by slug"); } @@ -72,29 +205,65 @@ export async function getPrinzipBySlug(slug: string): Promise { export async function getPrinzips(): Promise { try { - const endpoint = `${url}/api/prinzips?populate=regelungsvorhaben`; - const response = await fetch(endpoint, { - /* headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${STRAPI_API_TOKEN}`, - },*/ + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + query: GET_PRINZIPS_QUERY, + }), }); + if (!response.ok) { + console.error("Failed to fetch Prinzips:", response.statusText); + return null; + } + + const data: PrinzipResponse = await response.json(); + return data; + } catch (error) { + console.error("Error fetching Prinzips:", error); + return null; + } +} + +export async function getRegelungsvorhabens(): Promise { + try { + const endpoint = `${url}/api/regelungsvorhabens?populate[Prinzipienerfuellung]=*`; + const response = await fetch(endpoint); + + if (!response.ok) { + console.error("Failed to fetch Regelungsvorhabens:", response.statusText); + return null; + } + + const data: RegelungsvorhabenResponse = await response.json(); + return data; + } catch (error) { + console.error("Error fetching Regelungsvorhabens:", error); + return null; + } +} + +export async function getRegelungsvorhabensForPrinzip( + prinzipId: number, +): Promise { + try { + const endpoint = `${url}/api/regelungsvorhabens?filters[prinzip][id][$eq]=${prinzipId}&populate[Prinzipienerfuellung]=*`; + const response = await fetch(endpoint); if (!response.ok) { - // TODO: logging console.error( - "Failed request:", + "Failed to fetch Regelungsvorhabens for Prinzip:", response.statusText, - "Status code:", - response.status, ); return null; } - const data: PrinzipResponse = await response.json(); + const data: RegelungsvorhabenResponse = await response.json(); return data; } catch (error) { - console.error("Error fetching data:", error); + console.error("Error fetching Regelungsvorhabens for Prinzip:", error); return null; } }