-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import Card from "@planx/components/shared/Preview/Card"; | |
import CardHeader from "@planx/components/shared/Preview/CardHeader"; | ||
import type { PublicProps } from "@planx/components/ui"; | ||
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator"; | ||
import { GraphError } from "components/Error/GraphError"; | ||
import capitalize from "lodash/capitalize"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import { HandleSubmit } from "pages/Preview/Node"; | ||
|
@@ -63,6 +64,8 @@ function Component(props: Props) { | |
|
||
// PlanningConstraints must come after at least a FindProperty in the graph | ||
const showGraphError = !x || !y || !longitude || !latitude; | ||
if (showGraphError) | ||
throw new GraphError("mapInputFieldMustFollowFindProperty"); | ||
Check failure on line 68 in editor.planx.uk/src/@planx/components/PlanningConstraints/Public.tsx GitHub Actions / Run React Testssrc/@planx/components/PlanningConstraints/Public.test.tsx > renders correctly
Check failure on line 68 in editor.planx.uk/src/@planx/components/PlanningConstraints/Public.tsx GitHub Actions / Run React Testssrc/@planx/components/PlanningConstraints/Public.test.tsx > should not have any accessibility violations
|
||
|
||
// Even though this component will fetch fresh GIS data when coming "back", | ||
// still prepopulate any previously marked inaccurateConstraints | ||
|
@@ -145,8 +148,6 @@ function Component(props: Props) { | |
...roads?.metadata, | ||
}; | ||
|
||
if (showGraphError) return <ConstraintsGraphError {...props} />; | ||
|
||
const isLoading = isValidating || isValidatingRoads; | ||
if (isLoading) | ||
return ( | ||
|
@@ -396,28 +397,3 @@ const ConstraintsFetchError = (props: ConstraintsFetchErrorProps) => ( | |
</ErrorSummaryContainer> | ||
</Card> | ||
); | ||
|
||
interface ConstraintsGraphErrorProps { | ||
title: string; | ||
description: string; | ||
handleSubmit?: HandleSubmit; | ||
} | ||
|
||
const ConstraintsGraphError = (props: ConstraintsGraphErrorProps) => ( | ||
<Card handleSubmit={props.handleSubmit} isValid> | ||
<CardHeader title={props.title} description={props.description} /> | ||
<ErrorSummaryContainer | ||
role="status" | ||
data-testid="error-summary-invalid-graph" | ||
> | ||
<Typography variant="h4" component="h2" gutterBottom> | ||
Invalid graph | ||
</Typography> | ||
<Typography variant="body2"> | ||
Edit this flow so that "Planning constraints" is positioned after "Find | ||
property"; an address or site boundary drawing is required to fetch | ||
data. | ||
</Typography> | ||
</ErrorSummaryContainer> | ||
</Card> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { useQuery } from "@apollo/client"; | ||
import Box from "@mui/material/Box"; | ||
import Link from "@mui/material/Link"; | ||
import Typography from "@mui/material/Typography"; | ||
import { visuallyHidden } from "@mui/utils"; | ||
import Card from "@planx/components/shared/Preview/Card"; | ||
import CardHeader from "@planx/components/shared/Preview/CardHeader"; | ||
import { SummaryListTable } from "@planx/components/shared/Preview/SummaryList"; | ||
import type { PublicProps } from "@planx/components/ui"; | ||
import { GraphError } from "components/Error/GraphError"; | ||
import { Feature } from "geojson"; | ||
import { publicClient } from "lib/graphql"; | ||
import find from "lodash/find"; | ||
|
@@ -17,7 +17,6 @@ import React from "react"; | |
|
||
import type { SiteAddress } from "../FindProperty/model"; | ||
import { FETCH_BLPU_CODES } from "../FindProperty/Public"; | ||
import { ErrorSummaryContainer } from "../shared/Preview/ErrorSummaryContainer"; | ||
import { MapContainer } from "../shared/Preview/MapContainer"; | ||
import type { PropertyInformation } from "./model"; | ||
|
||
|
@@ -32,7 +31,10 @@ function Component(props: PublicProps<PropertyInformation>) { | |
client: publicClient, | ||
}); | ||
|
||
return passport.data?._address ? ( | ||
if (!passport.data?._address) | ||
throw new GraphError("nodeMustFollowFindProperty"); | ||
Check failure on line 35 in editor.planx.uk/src/@planx/components/PropertyInformation/Public.tsx GitHub Actions / Run React Testssrc/@planx/components/PropertyInformation/Public.test.tsx > renders a warning for editors if address data is not in state
|
||
|
||
return ( | ||
<Presentational | ||
title={props.title} | ||
description={props.description} | ||
|
@@ -60,21 +62,6 @@ function Component(props: PublicProps<PropertyInformation>) { | |
}); | ||
}} | ||
/> | ||
) : ( | ||
<Card> | ||
<ErrorSummaryContainer | ||
role="status" | ||
data-testid="error-summary-invalid-graph" | ||
> | ||
<Typography variant="h4" component="h2" gutterBottom> | ||
Invalid graph | ||
</Typography> | ||
<Typography variant="body2"> | ||
Edit this flow so that "Property information" is positioned after | ||
"Find property"; an address is required to render. | ||
</Typography> | ||
</ErrorSummaryContainer> | ||
</Card> | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Typography from "@mui/material/Typography"; | ||
import Card from "@planx/components/shared/Preview/Card"; | ||
import CardHeader from "@planx/components/shared/Preview/CardHeader"; | ||
import { ErrorSummaryContainer } from "@planx/components/shared/Preview/ErrorSummaryContainer"; | ||
import React from "react"; | ||
|
||
type GraphErrorType = | ||
| "nodeMustFollowFindProperty" | ||
| "mapInputFieldMustFollowFindProperty"; | ||
|
||
const GRAPH_ERROR_MESSAGES: Record<GraphErrorType, string> = { | ||
nodeMustFollowFindProperty: | ||
'Edit this flow so that this node is positioned after "Find property"; an address or site boundary drawing is required to fetch data', | ||
mapInputFieldMustFollowFindProperty: | ||
'Edit this flow so that this component is positioned after "FindProperty"; an address is required for schemas that include a "map" field.', | ||
}; | ||
|
||
export class GraphError extends Error { | ||
constructor(public type: GraphErrorType) { | ||
super(); | ||
this.type = type; | ||
} | ||
} | ||
|
||
export const isGraphError = (error: unknown): error is GraphError => | ||
error instanceof GraphError; | ||
|
||
export const GraphErrorComponent: React.FC<{ error: GraphError }> = ({ | ||
error, | ||
}) => ( | ||
<Card> | ||
<CardHeader /> | ||
<ErrorSummaryContainer | ||
role="status" | ||
data-testid="error-summary-invalid-graph" | ||
> | ||
<Typography variant="h4" component="h2" gutterBottom> | ||
Invalid graph | ||
</Typography> | ||
<Typography variant="body2"> | ||
{GRAPH_ERROR_MESSAGES[error.type]} | ||
</Typography> | ||
</ErrorSummaryContainer> | ||
</Card> | ||
); |