From 0e1d81f41eaf8c8e3d1726b23dc7c3bfae198ade Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Fri, 23 Sep 2022 16:03:08 +0200 Subject: [PATCH] use proper form for the id input --- app/src/api/config/dataFields.ts | 2 +- ...numeric-data-entry-with-formatted-link.css | 9 +++ ...numeric-data-entry-with-formatted-link.tsx | 57 +++++++++++++++++++ .../building/data-containers/planning.tsx | 26 ++++----- app/src/frontend/config/data-fields-config.ts | 5 +- maintenance/extract_data/README.md | 1 + ...3.redesign_protection_designation.down.sql | 4 -- ...033.redesign_protection_designation.up.sql | 13 +---- 8 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.css create mode 100644 app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.tsx diff --git a/app/src/api/config/dataFields.ts b/app/src/api/config/dataFields.ts index bddc0bcc..646183ec 100644 --- a/app/src/api/config/dataFields.ts +++ b/app/src/api/config/dataFields.ts @@ -205,7 +205,7 @@ export const buildingAttributesConfig = valueType()({ /* eslint edit: true, verify: true, }, - planning_nhle_link: { + planning_list_id: { edit: true, verify: true, }, diff --git a/app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.css b/app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.css new file mode 100644 index 00000000..54525937 --- /dev/null +++ b/app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.css @@ -0,0 +1,9 @@ +.narrow-input-form { + max-width: 40%; + float: left; +} + +.with-margin { + margin-left: 0.7em; + margin-right: 0.7em; +} \ No newline at end of file diff --git a/app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.tsx b/app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.tsx new file mode 100644 index 00000000..8f1c765b --- /dev/null +++ b/app/src/frontend/building/data-components/numeric-data-entry-with-formatted-link.tsx @@ -0,0 +1,57 @@ +import React, { Fragment } from 'react'; + +import { BaseDataEntryProps } from './data-entry'; +import { DataTitleCopyable } from './data-title'; +import './numeric-data-entry-with-formatted-link.css'; +import { FieldRow } from './field-row'; + +interface NumericDataEntryWithFormattedLinkProps extends BaseDataEntryProps { + value?: string; + placeholder?: string; + step?: number; + min?: number; + max?: number; + linkTargetFunction: (val: string) => string; + linkDescriptionFunction: (val: string) => string; +} + +const NumericDataEntryWithFormattedLink: React.FunctionComponent = (props) => { + const slugWithModifier = props.slug + (props.slugModifier ?? ''); + + return ( + + + + + props.onChange( + props.slug, + e.target.value === '' ? null : parseFloat(e.target.value) + ) + } + /> + {props.value == undefined ?
: {props.linkDescriptionFunction(props.value)}} +
+
+ ); +}; + +export default NumericDataEntryWithFormattedLink; diff --git a/app/src/frontend/building/data-containers/planning.tsx b/app/src/frontend/building/data-containers/planning.tsx index d4223dbe..d5dfe2f0 100644 --- a/app/src/frontend/building/data-containers/planning.tsx +++ b/app/src/frontend/building/data-containers/planning.tsx @@ -3,7 +3,7 @@ import React, { Fragment } from 'react'; import InfoBox from '../../components/info-box'; import { dataFields } from '../../config/data-fields-config'; import CheckboxDataEntry from '../data-components/checkbox-data-entry'; -import DataEntry from '../data-components/data-entry'; +import NumericDataEntryWithFormattedLink from '../data-components/numeric-data-entry-with-formatted-link';import DataEntry from '../data-components/data-entry'; import { DataEntryGroup } from '../data-components/data-entry-group'; import SelectDataEntry from '../data-components/select-data-entry'; import Verification from '../data-components/verification'; @@ -126,23 +126,23 @@ const PlanningView: React.FunctionComponent = (props) => ( /> - + linkTargetFunction={(id: String) => { return "https://historicengland.org.uk/listing/the-list/list-entry/" + id + "?section=official-list-entry" } } + linkDescriptionFunction={(id: String) => { return "description at the official site" } } + /> National Heritage List for England?", - example: "", + example: "121436", + //tooltip: , }, planning_list_grade: { category: Category.Planning, diff --git a/maintenance/extract_data/README.md b/maintenance/extract_data/README.md index 3fe92171..5cf53149 100644 --- a/maintenance/extract_data/README.md +++ b/maintenance/extract_data/README.md @@ -70,6 +70,7 @@ This is the main table, containing almost all data collected by Colouring London - `sust_dec`: DEC rating - `sust_retrofit_date`: year of last significant retrofit - `planning_portal_link`: link to an entry on https://www.planningportal.co.uk/ +- `planning_list_id`: National Heritage List for England ID - `planning_in_conservation_area_url`: conservation area appraisal link - `planning_in_conservation_area_url`: conservation area data source link - `planning_list_grade`: National Heritage List for England listing grade diff --git a/migrations/033.redesign_protection_designation.down.sql b/migrations/033.redesign_protection_designation.down.sql index 42fd9eb8..d1364480 100644 --- a/migrations/033.redesign_protection_designation.down.sql +++ b/migrations/033.redesign_protection_designation.down.sql @@ -1,5 +1,4 @@ --into a single link from array of links -ALTER TABLE buildings DROP COLUMN IF EXISTS planning_nhle_link; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_nhle_link text[]; --changed into URL @@ -15,9 +14,6 @@ ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_heritage_at_risk_id int ALTER TABLE buildings DROP COLUMN IF EXISTS planning_in_conservation_area_url; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_in_conservation_area boolean DEFAULT FALSE; --- URL column exists already -ALTER TABLE ADD COLUMN IF NOT EXISTS planning_list_id int DEFAULT NULL; - ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_in_glher boolean DEFAULT FALSE; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_apa_name VARCHAR DEFAULT ''; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_apa_tier smallint DEFAULT NULL; diff --git a/migrations/033.redesign_protection_designation.up.sql b/migrations/033.redesign_protection_designation.up.sql index 5de2b493..28adb65b 100644 --- a/migrations/033.redesign_protection_designation.up.sql +++ b/migrations/033.redesign_protection_designation.up.sql @@ -1,21 +1,13 @@ -- this type of links is expected: -- 'https://historicengland.org.uk/listing/the-list/list-entry/1080446?section=official-list-entry' -UPDATE buildings -SET planning_nhle_link = CONCAT('https://historicengland.org.uk/listing/the-list/list-entry/', planning_list_id, -'?section=official-list-entry') -WHERE planning_nhle_link = '' -AND planning_list_id IS NOT NULL; - - UPDATE buildings SET planning_local_list_url = 'identified as listed: please replace with link' WHERE planning_local_list_url = '' AND planning_in_local_list; ---into a single link from array of links +--no need to store both id and link that can be derived from it ALTER TABLE buildings DROP COLUMN IF EXISTS planning_nhle_link; -ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_nhle_link VARCHAR DEFAULT ''; --changed into URL ALTER TABLE buildings DROP COLUMN IF EXISTS planning_in_apa; @@ -30,9 +22,6 @@ ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_heritage_at_risk_url VAR ALTER TABLE buildings DROP COLUMN IF EXISTS planning_in_conservation_area; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS planning_in_conservation_area_url VARCHAR DEFAULT ''; --- URL column exists already -ALTER TABLE buildings DROP COLUMN IF EXISTS planning_list_id; - --fully removed ALTER TABLE buildings DROP COLUMN IF EXISTS planning_in_glher; ALTER TABLE buildings DROP COLUMN IF EXISTS planning_apa_name;