diff --git a/api.planx.uk/modules/gis/routes.ts b/api.planx.uk/modules/gis/routes.ts index 057a812bb6..28599716ce 100644 --- a/api.planx.uk/modules/gis/routes.ts +++ b/api.planx.uk/modules/gis/routes.ts @@ -1,10 +1,12 @@ import { Router } from "express"; import { locationSearch } from "./service"; +import { hasArticle4Schema } from "./service/article4Schema"; import { classifiedRoadsSearch } from "./service/classifiedRoads"; const router = Router(); router.get("/gis/:localAuthority", locationSearch); +router.get("/gis/:localAuthority/article4-schema", hasArticle4Schema); router.get("/roads", classifiedRoadsSearch); export default router; diff --git a/api.planx.uk/modules/gis/service/article4Schema.ts b/api.planx.uk/modules/gis/service/article4Schema.ts new file mode 100644 index 0000000000..890a18a09e --- /dev/null +++ b/api.planx.uk/modules/gis/service/article4Schema.ts @@ -0,0 +1,43 @@ +import { NextFunction, Request, Response } from "express"; + +import { localAuthorityMetadata } from "./digitalLand"; + +/** + * @swagger + * /gis/{localAuthority}/article4-schema: + * get: + * summary: Returns whether Article 4 schema variables are configured for this local authority + * description: Returns whether Article 4 schema variables are configured for this local authority. A positive "status" from this endpoint is a proxy for marking this PlanX onboarding step "complete". + * tags: + * - gis + * parameters: + * - $ref: '#/components/parameters/localAuthority' + * description: Name of the Local Authority, usually the same as Planx `team`. Required until Planning Data is available for any council o article 4 variables are generalised based on permitted development rights removed rather than council + */ +export async function hasArticle4Schema( + req: Request, + res: Response, + next: NextFunction, +) { + try { + if (!req.params.localAuthority) { + return next({ + status: 401, + message: "Missing param local authority", + }); + } + + const status = Object.keys(localAuthorityMetadata).includes( + req.params.localAuthority, + ); + res.status(200).send({ + message: `${status ? "Found" : "Did not find"} Article 4 schema for ${req.params.localAuthority}`, + status: status, + }); + } catch (error) { + next({ + status: 500, + message: `Error getting Article 4 schema for ${req.params.localAuthority}: ${error}`, + }); + } +} diff --git a/api.planx.uk/modules/gis/service/digitalLand.ts b/api.planx.uk/modules/gis/service/digitalLand.ts index 209714e447..9298eefd31 100644 --- a/api.planx.uk/modules/gis/service/digitalLand.ts +++ b/api.planx.uk/modules/gis/service/digitalLand.ts @@ -18,7 +18,7 @@ export interface LocalAuthorityMetadata { } /** When a team publishes their granular Article 4 data, add them to this list. Key must match team slug */ -const localAuthorityMetadata: Record = { +export const localAuthorityMetadata: Record = { "barking-and-dagenham": require("./local_authorities/metadata/barkingAndDagenham"), barnet: require("./local_authorities/metadata/barnet"), birmingham: require("./local_authorities/metadata/birmingham"), diff --git a/editor.planx.uk/src/pages/PlatformAdminPanel.tsx b/editor.planx.uk/src/pages/PlatformAdminPanel.tsx index 8acb58c27f..30fcd5456b 100644 --- a/editor.planx.uk/src/pages/PlatformAdminPanel.tsx +++ b/editor.planx.uk/src/pages/PlatformAdminPanel.tsx @@ -10,6 +10,7 @@ import Typography from "@mui/material/Typography"; import { SummaryListTable } from "@planx/components/shared/Preview/SummaryList"; import { useStore } from "pages/FlowEditor/lib/store"; import React from "react"; +import useSWR from "swr"; import { AdminPanelData } from "types"; import Caret from "ui/icons/Caret"; @@ -54,6 +55,13 @@ const NotConfigured: React.FC = () => ; const Configured: React.FC = () => ; const TeamData: React.FC = ({ data }) => { + const a4Endpoint = `${process.env.REACT_APP_API_URL}/gis/${data.slug}/article4-schema`; + const fetcher = (url: string) => fetch(url).then((r) => r.json()); + const { data: a4Check, isValidating } = useSWR( + () => data.slug ? a4Endpoint : null, + fetcher, + ); + return ( = ({ data }) => { <> - {"Article 4s"} - {"?"} + {"Article 4s (API)"} + {!isValidating && a4Check?.status ? : } <> {"Reference code"}