Skip to content

Commit

Permalink
Merge branch 'main' into refactor-css
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikSchmidt committed Jan 14, 2025
2 parents 4a72fb7 + fa72873 commit 0051c5e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 60 deletions.
3 changes: 2 additions & 1 deletion packages/dito/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ENCRYPTION_KEY= #Should be a random alphanumeric string of 32 characters
UNLEASH_KEY= # Get this from Unleash Admin Dashboard
UNLEASH_KEY= # Get this from Unleash Admin Dashboard
TRACKING_DISABLED=true
37 changes: 22 additions & 15 deletions packages/dito/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
isRouteErrorResponse,
useLoaderData,
useRouteError,
useRouteLoaderData,
} from "@remix-run/react";
import { marked, type Tokens } from "marked";
import React, { type ReactNode } from "react";
Expand Down Expand Up @@ -57,6 +58,7 @@ export function loader({ request }: LoaderFunctionArgs) {
BASE_URL,
PLAUSIBLE_DOMAIN,
PLAUSIBLE_SCRIPT,
trackingDisabled: process.env.TRACKING_DISABLED === "true",
featureFlags,
};
}
Expand Down Expand Up @@ -258,7 +260,7 @@ function Document({
}: Readonly<{
children: ReactNode;
error?: boolean;
trackingScript: React.ReactNode;
trackingScript?: React.ReactNode;
}>) {
const nonce = useNonce();

Expand All @@ -267,7 +269,7 @@ function Document({
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{trackingScript}
{trackingScript && trackingScript}
<Meta />
<Links />
</head>
Expand All @@ -283,18 +285,20 @@ function Document({
}

export default function App() {
const { PLAUSIBLE_DOMAIN, PLAUSIBLE_SCRIPT, featureFlags } =
const { PLAUSIBLE_DOMAIN, PLAUSIBLE_SCRIPT, trackingDisabled, featureFlags } =
useLoaderData<typeof loader>();

return (
<Document
trackingScript={
<script
key={"app-tracking"}
defer
data-domain={PLAUSIBLE_DOMAIN}
src={PLAUSIBLE_SCRIPT}
/>
!trackingDisabled && (
<script
key={"app-tracking"}
defer
data-domain={PLAUSIBLE_DOMAIN}
src={PLAUSIBLE_SCRIPT}
/>
)
}
>
{/* .parent-bg-blue can be set by child components to set the background of main to blue (e.g. used for question pages) */}
Expand All @@ -306,6 +310,7 @@ export default function App() {
}

export function ErrorBoundary() {
const loaderData = useRouteLoaderData<typeof loader>("root");
const error = useRouteError();

let errorStatus = `${500}`;
Expand All @@ -331,12 +336,14 @@ Vielen Dank für Ihr Verständnis.`;
<Document
error={true}
trackingScript={
<script
key={"error-tracking"}
defer
data-domain={CLIENT_PLAUSIBLE_DOMAIN}
src={CLIENT_PLAUSIBLE_SCRIPT}
/>
loaderData?.trackingDisabled && (
<script
key={"error-tracking"}
defer
data-domain={CLIENT_PLAUSIBLE_DOMAIN}
src={CLIENT_PLAUSIBLE_SCRIPT}
/>
)
}
>
<main id="error" className="grow">
Expand Down
30 changes: 11 additions & 19 deletions packages/dito/app/routes/beispiele.visualisierungen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,20 @@ export const loader = async () => {
return visualisationsData.visualisierungen;
};

const groupByRegelung = (visualisations: Visualisierung[]) => {
const grouped = new Map<string, Visualisierung[]>();

visualisations.forEach((visualisation) => {
const regelung = visualisation.Digitalcheck?.Regelungsvorhaben;

if (regelung?.Titel) {
if (!grouped.has(regelung.Titel)) {
grouped.set(regelung.Titel, []);
}
grouped.get(regelung.Titel)?.push(visualisation);
}
});

return grouped;
};

export default function BeispieleVisualisierungen() {
const visualisationsData = useLoaderData<typeof loader>();

// Group visualisations by Regelung
const groupedVisualisations = groupByRegelung(visualisationsData);
const groupedVisualisations = visualisationsData.reduce(
(acc, item) => {
const title = item.Digitalcheck?.Regelungsvorhaben?.Titel;
if (!title) return acc;
acc[title] = acc[title] ?? [];
acc[title].push(item);
return acc;
},
{} as Record<string, Visualisierung[]>,
);
return (
<>
<Background backgroundColor="blue">
Expand All @@ -82,7 +74,7 @@ export default function BeispieleVisualisierungen() {
</Container>
</Background>
<Container>
{Array.from(groupedVisualisations.entries()).map(
{Object.entries(groupedVisualisations).map(
([regelungTitle, visualisations]) => (
<div key={regelungTitle} className="ds-stack-8">
<Link
Expand Down
9 changes: 6 additions & 3 deletions packages/dito/app/routes/vorpruefung.ergebnis/ResultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ export default function ResultPage({
<RichText markdown={intro} className="mt-40 first:mt-0" />
<ul className="ds-stack-16 mt-16 pl-0">
{reasons
.toSorted((reason) =>
reason.answer === "yes" ? -1 : 1,
)
.toSorted((a, b) => {
if (a.answer === b.answer) {
return 0; // Keep the original order
}
return a.answer === "yes" ? -1 : 1; // "yes" comes before "no"
})
.map((reason) => getReasonListItem(reason))}
</ul>
</React.Fragment>
Expand Down
7 changes: 5 additions & 2 deletions packages/dito/app/utils/trackCustomEvent.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export default async function trackCustomEvent(
event: { name: string; props?: Record<string, string> },
) {
const startTime = Date.now();
if (process.env.NODE_ENV === "development") {
console.log("TRACKING", event);
if (
process.env.TRACKING_DISABLED === "true" ||
process.env.NODE_ENV === "development"
) {
console.log("Tracking is disabled. Event not sent: ", event);
return;
}

Expand Down
40 changes: 20 additions & 20 deletions packages/dito/tests/a11y/general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import allRoutes from "resources/allRoutes";
import { ROUTE_PRINCIPLES, ROUTE_SUPPORT } from "resources/staticRoutes";

test.describe("basic example a11y test", () => {
test.setTimeout(60000);
test("check a11y of all routes", async ({ page }) => {
for (const route of allRoutes.filter(
allRoutes
.filter(
(allRoute) =>
!allRoute.url.endsWith(".pdf") &&
!allRoute.url.endsWith(ROUTE_SUPPORT.url),
)) {
// Listen for redirects and update URL if needed
const response = await page.goto(route.url);

if (
(response !== null && response.status() === 302) ||
(response !== null && response.status() === 301)
) {
const redirectedUrl = response.headers()["location"];
await page.goto(redirectedUrl);
}

const accessibilityScanResults = await new AxeBuilder({ page }).analyze();
console.log("Checking A11Y on route:", route.url);
expect(accessibilityScanResults.violations).toEqual([]);
}
});
)
.forEach((route) => {
test(`check a11y of ${route.title}`, async ({ page }) => {
// Listen for redirects and update URL if needed
const response = await page.goto(route.url);

if (
(response !== null && response.status() === 302) ||
(response !== null && response.status() === 301)
) {
const redirectedUrl = response.headers()["location"];
await page.goto(redirectedUrl);
}

const accessibilityResults = await new AxeBuilder({ page }).analyze();
expect(accessibilityResults.violations).toEqual([]);
});
});

test("check a11y of example pages", async ({ page }) => {
await page.goto(
Expand Down

0 comments on commit 0051c5e

Please sign in to comment.