Skip to content

Commit

Permalink
fix: add default disclaimer text to shared component (#3984)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Nov 19, 2024
1 parent 98fce26 commit 68407a3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Disclaimer } from "../shared/Disclaimer";
import { ErrorSummaryContainer } from "../shared/Preview/ErrorSummaryContainer";
import SimpleExpand from "../shared/Preview/SimpleExpand";
import ConstraintsList from "./List";
import { DEFAULT_PLANNING_CONDITIONS_DISCLAIMER } from "./model";
import { InaccurateConstraints } from "./Public";

export type PresentationalProps = {
Expand Down Expand Up @@ -80,7 +81,10 @@ export function Presentational(props: PresentationalProps) {
/>
</SimpleExpand>
)}
<Disclaimer text={disclaimer} />
<Disclaimer
text={disclaimer}
defaultText={DEFAULT_PLANNING_CONDITIONS_DISCLAIMER}
/>
</>
)}
{positiveConstraints.length === 0 && negativeConstraints.length > 0 && (
Expand Down Expand Up @@ -110,7 +114,10 @@ export function Presentational(props: PresentationalProps) {
setInaccurateConstraints={setInaccurateConstraints}
/>
</SimpleExpand>
<Disclaimer text={disclaimer} />
<Disclaimer
text={disclaimer}
defaultText={DEFAULT_PLANNING_CONDITIONS_DISCLAIMER}
/>
</>
)}
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,21 @@ describe("following a FindProperty component", () => {
expect(negativeConstraintsContainer).toBeVisible();
expect(getByRole("heading", { name: /Ecology/ })).toBeVisible();
});

test("default disclaimer text should render if none provided", async () => {
const { queryByText } = setup(
<PlanningConstraints
title="Planning constraints"
description="Things that might affect your project"
fn="property.constraints.planning"
disclaimer=""
handleSubmit={vi.fn()}
/>,
);
expect(
queryByText(
"This page does not include information about historic planning conditions that may apply to this property.",
),
).toBeVisible();
});
});
29 changes: 21 additions & 8 deletions editor.planx.uk/src/@planx/components/shared/Disclaimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ import { WarningContainer } from "@planx/components/shared/Preview/WarningContai
import React from "react";
import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml/ReactMarkdownOrHtml";

export const Disclaimer = ({ text }: { text: string }) => (
<WarningContainer>
<ErrorOutline />
<Typography variant="body2" component="div" ml={2} sx={{ "& p:first-of-type": { marginTop: 0, } }}>
<ReactMarkdownOrHtml source={text} openLinksOnNewTab />
</Typography>
</WarningContainer>
);
export const Disclaimer = ({
text,
defaultText,
}: {
text: string;
defaultText?: string;
}) => {
return (
<WarningContainer>
<ErrorOutline />
<Typography
variant="body2"
component="div"
ml={2}
sx={{ "& p:first-of-type": { marginTop: 0 } }}
>
<ReactMarkdownOrHtml source={text || defaultText} openLinksOnNewTab />
</Typography>
</WarningContainer>
);
};

0 comments on commit 68407a3

Please sign in to comment.