From f931195053beaab90837fe2389b59c5031db2d20 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 18 Mar 2021 14:14:35 +0000 Subject: [PATCH 1/5] Add documentation to frontend data fields config --- app/src/frontend/config/data-fields-config.ts | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/frontend/config/data-fields-config.ts b/app/src/frontend/config/data-fields-config.ts index f5b911cc..06c61ba9 100644 --- a/app/src/frontend/config/data-fields-config.ts +++ b/app/src/frontend/config/data-fields-config.ts @@ -7,11 +7,44 @@ import { Category } from './categories-config'; * e.g. dataFields.foo_bar would not be highlighted as an error. */ export interface DataFieldDefinition { + /** + * The primary category to which the field belongs. + * + * A field could be displayed in several categories, but this value will be used + * when a single category needs to be shown in the context of a field, e.g. + * in the case of edit history or the copy-paste tool (multi-edit) + * */ category: Category; + + /** + * The human-readable title of the field to be displayed as label. + */ title: string; + + /** + * Text to be displayed in the hint tooltip next to the input field. + * + * This supports a simple Markdown-like syntax for embedding clickable URLs in the hint + * for example "see [here](http://example.com/info.html) for more information" + */ tooltip?: string; - properties?: { [key: string]: DataFieldDefinition}; - example: any; // the example field is used to automatically determine the type of the properties in the Building interface + + /** + * If the defined type is an array, this describes the fields of each array item. + * The nested fields don't currently need a category field to be defined. + */ + items?: { [key: string]: Omit }; + + /** + * The example is used to determine the runtime type in which the attribute data is stored (e.g. number, string, object) + * This gives the programmer auto-complete of all available building attributes when implementing a category view. + * + * E.g. if the field is a text value, an empty string ("") is the simplest example. + * + * Making it semantically correct is useful but not necessary. + * E.g. for building attachment form, you could use "Detached" as example + */ + example: any; } export const dataFields = { /* eslint-disable @typescript-eslint/camelcase */ From 26a91a229ed46c88b2aa66f3f2dedfa52bba5a8c Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 18 Mar 2021 19:29:42 +0000 Subject: [PATCH 2/5] Add logical (yes/no/?) data entry --- .../logical-data-entry/logical-data-entry.tsx | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 app/src/frontend/building/data-components/logical-data-entry/logical-data-entry.tsx diff --git a/app/src/frontend/building/data-components/logical-data-entry/logical-data-entry.tsx b/app/src/frontend/building/data-components/logical-data-entry/logical-data-entry.tsx new file mode 100644 index 00000000..36f87dea --- /dev/null +++ b/app/src/frontend/building/data-components/logical-data-entry/logical-data-entry.tsx @@ -0,0 +1,100 @@ +import React from 'react'; + +import { BaseDataEntryProps } from '../data-entry'; +import { DataTitleCopyable } from '../data-title'; + +interface ToggleButtonProps { + value: string; + checked: boolean; + disabled: boolean; + onChange: React.ChangeEventHandler; + checkedClassName: string; + uncheckedClassName: string; +} + +const ToggleButton: React.FC = ({ + value, + checked, + disabled, + onChange, + checkedClassName, + uncheckedClassName, + children +}) => { + + return ( + /** + * If the toggle button is both checked and disabled, we can't set disabled CSS class + * because then Bootstrap makes the button look like it wasn't checked. + * So we skip the class and force cursor type manually so it doesn't look clickable. + */ + + ); +} + +interface LogicalDataEntryProps extends BaseDataEntryProps { + value: boolean; + disallowTrue?: boolean; + disallowFalse?: boolean; + disallowNull?: boolean; +} + +export const LogicalDataEntry: React.FC = (props) => { + function handleValueChange(e: React.ChangeEvent) { + props.onChange?.(props.slug, e.target.value === 'null' ? null : e.target.value === 'true'); + } + + const isDisabled = props.mode === 'view' || props.disabled; + + return ( + <> + +
+ Yes + + ? + + No +
+ + ); +}; From 4aa35b94ddb55bccb73b5a1ca5e10bbc6f38d2b5 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Thu, 18 Mar 2021 19:41:28 +0000 Subject: [PATCH 3/5] Add logical toggle for demolished buildings --- app/map_styles/polygon.xml | 4 ++ app/src/api/config/dataFields.ts | 8 +++ .../domainLogic/processBuildingUpdate.ts | 33 ++++++++-- .../dynamics/dynamics-data-entry.tsx | 8 ++- .../data-containers/dynamics/dynamics.tsx | 63 ++++++++++++------- .../frontend/config/category-maps-config.ts | 5 +- app/src/frontend/config/data-fields-config.ts | 6 ++ app/src/helpers.ts | 2 +- app/src/tiles/dataDefinition.ts | 5 +- .../unreleased/0xx.dynamics-bool.down.sql | 1 + .../unreleased/0xx.dynamics-bool.up.sql | 7 +++ 11 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 migrations/unreleased/0xx.dynamics-bool.down.sql create mode 100644 migrations/unreleased/0xx.dynamics-bool.up.sql diff --git a/app/map_styles/polygon.xml b/app/map_styles/polygon.xml index 1debdc17..62a90a1c 100644 --- a/app/map_styles/polygon.xml +++ b/app/map_styles/polygon.xml @@ -508,6 +508,10 @@