From 6b3b914ac72644aab5cf009aaf44112d51b82143 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Fri, 19 Jul 2024 10:17:05 +0200 Subject: [PATCH] set property.attachment where dwelling house --- .../FindProperty/Public/Autocomplete.tsx | 1 + .../components/FindProperty/Public/index.tsx | 29 +++++++++++++++++++ .../@planx/components/FindProperty/model.ts | 1 + .../down.sql | 5 ++++ .../up.sql | 3 ++ 5 files changed, 39 insertions(+) create mode 100644 hasura.planx.uk/migrations/1721375965230_update house type blpu code values/down.sql create mode 100644 hasura.planx.uk/migrations/1721375965230_update house type blpu code values/up.sql diff --git a/editor.planx.uk/src/@planx/components/FindProperty/Public/Autocomplete.tsx b/editor.planx.uk/src/@planx/components/FindProperty/Public/Autocomplete.tsx index 9dc263a464..3a568da267 100644 --- a/editor.planx.uk/src/@planx/components/FindProperty/Public/Autocomplete.tsx +++ b/editor.planx.uk/src/@planx/components/FindProperty/Public/Autocomplete.tsx @@ -76,6 +76,7 @@ export default function PickOSAddress(props: PickOSAddressProps): FCReturn { uprn: selectedAddress.UPRN.padStart(12, "0"), usrn: selectedAddress.USRN, // padStart(8, "0") will break /roads API request blpu_code: selectedAddress.BLPU_STATE_CODE, + classification_code: selectedAddress.CLASSIFICATION_CODE, latitude: selectedAddress.LAT, longitude: selectedAddress.LNG, organisation: selectedAddress.ORGANISATION || null, diff --git a/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx b/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx index d3828330cf..8be9a62477 100644 --- a/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx +++ b/editor.planx.uk/src/@planx/components/FindProperty/Public/index.tsx @@ -37,6 +37,23 @@ export const FETCH_BLPU_CODES = gql` } `; +// For automations, these CLASSIFICATION_CODES set `property.type` = `residential.dwelling.house` ONLY +// and the fourth segment is extracted to it's own variable `property.attachment` +export const ATTACHMENT_CLASSIFICATION_CODES = [ + { + code: "RD02", + value: "detached", + }, + { + code: "RD03", + value: "semiDetached", + }, + { + code: "RD04", + value: "terrace", + }, +]; + type Props = PublicProps; const AddressLoadingWrap = styled(Box)(({ theme }) => ({ @@ -146,6 +163,18 @@ function Component(props: Props) { newPassportData["property.type"] = [address.planx_value]; } + if ( + address?.classification_code && + ATTACHMENT_CLASSIFICATION_CODES.map((c) => c.code).includes( + address.classification_code, + ) + ) { + const attachmentValue = ATTACHMENT_CLASSIFICATION_CODES.find( + (c) => c.code === address.classification_code, + )?.value; + newPassportData["property.attachment"] = [attachmentValue]; + } + if (localAuthorityDistricts) { newPassportData["property.localAuthorityDistrict"] = localAuthorityDistricts; diff --git a/editor.planx.uk/src/@planx/components/FindProperty/model.ts b/editor.planx.uk/src/@planx/components/FindProperty/model.ts index 81b7d1f9b9..88093e807b 100644 --- a/editor.planx.uk/src/@planx/components/FindProperty/model.ts +++ b/editor.planx.uk/src/@planx/components/FindProperty/model.ts @@ -51,6 +51,7 @@ export interface SiteAddress extends MinimumSiteAddress { uprn?: string; usrn?: string; blpu_code?: string; + classification_code?: string; organisation?: string | null; sao?: string | null; pao?: string; diff --git a/hasura.planx.uk/migrations/1721375965230_update house type blpu code values/down.sql b/hasura.planx.uk/migrations/1721375965230_update house type blpu code values/down.sql new file mode 100644 index 0000000000..297670124e --- /dev/null +++ b/hasura.planx.uk/migrations/1721375965230_update house type blpu code values/down.sql @@ -0,0 +1,5 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- UPDATE "public"."blpu_codes" +-- SET value = 'residential.dwelling.house' +-- WHERE code IN ('RD02', 'RD03', 'RD04'); diff --git a/hasura.planx.uk/migrations/1721375965230_update house type blpu code values/up.sql b/hasura.planx.uk/migrations/1721375965230_update house type blpu code values/up.sql new file mode 100644 index 0000000000..2d0cd5f77f --- /dev/null +++ b/hasura.planx.uk/migrations/1721375965230_update house type blpu code values/up.sql @@ -0,0 +1,3 @@ +UPDATE "public"."blpu_codes" +SET value = 'residential.dwelling.house' +WHERE code IN ('RD02', 'RD03', 'RD04');