From 96df9517d44812982791b582b626ab8cfde9f6e0 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 10:14:01 +0100 Subject: [PATCH 01/25] change to "Edit History" --- app/src/frontend/building/data-container.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/frontend/building/data-container.tsx b/app/src/frontend/building/data-container.tsx index 4df867d9..5130dc25 100644 --- a/app/src/frontend/building/data-container.tsx +++ b/app/src/frontend/building/data-container.tsx @@ -330,7 +330,7 @@ const withCopyEdit: (wc: React.ComponentType) => DataContaine History + >Edit History Date: Tue, 9 Aug 2022 13:38:02 +0100 Subject: [PATCH 02/25] widen section-header-actions --- app/src/frontend/building/container-header.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/frontend/building/container-header.css b/app/src/frontend/building/container-header.css index e15f38d3..04c81d33 100644 --- a/app/src/frontend/building/container-header.css +++ b/app/src/frontend/building/container-header.css @@ -33,7 +33,7 @@ .section-header .section-header-actions { display: inline-block; - flex-basis: 200px; + flex-basis: 400px; display: flex; flex-flow: row wrap; align-items: center; From cee05b5979cf1ffc3861a7f465162950713aee4a Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 14:09:59 +0100 Subject: [PATCH 03/25] add BuildingEditSummaryBrief to Age category --- .../frontend/building/data-containers/age.tsx | 3 +++ .../edit-history/building-edit-summary.tsx | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index 18804e51..0420e8bf 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -8,6 +8,7 @@ import TextboxDataEntry from '../data-components/textbox-data-entry'; import Verification from '../data-components/verification'; import YearDataEntry from '../data-components/year-data-entry'; import withCopyEdit from '../data-container'; +import BuildingEditSummaryBrief from '../edit-history/building-edit-summary'; import { CategoryViewProps } from './category-view-props'; @@ -22,6 +23,7 @@ const AgeView: React.FunctionComponent = (props) => { ){ return ( + = (props) => { }; return ( + = ( ); }; +const BuildingEditSummaryBrief: React.FunctionComponent = ({ + historyEntry, + showBuildingId = false, + hyperlinkCategories = false +}) => { + const entriesWithMetadata = enrichHistoryEntries(historyEntry.forward_patch, historyEntry.reverse_patch); + const entriesByCategory = arrayToDictionary(entriesWithMetadata, x => x.category); + + const categoryHyperlinkTemplate = hyperlinkCategories && historyEntry.building_id != undefined ? + `/edit/$category/${historyEntry.building_id}` : + undefined; + + return ( +
+

Edited on {formatDate(parseDate(historyEntry.revision_timestamp))}

+
+ ); +}; + export { BuildingEditSummary }; + +export { + BuildingEditSummaryBrief +}; + From 292c75238c5162de48837abe7ce2cb764961edc5 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 14:49:19 +0100 Subject: [PATCH 04/25] add EditHistory to Age --- app/src/frontend/building/data-containers/age.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index 0420e8bf..add84210 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -8,7 +8,7 @@ import TextboxDataEntry from '../data-components/textbox-data-entry'; import Verification from '../data-components/verification'; import YearDataEntry from '../data-components/year-data-entry'; import withCopyEdit from '../data-container'; -import BuildingEditSummaryBrief from '../edit-history/building-edit-summary'; +import { EditHistory } from '../../edit-history/edit-history'; import { CategoryViewProps } from './category-view-props'; @@ -23,7 +23,7 @@ const AgeView: React.FunctionComponent = (props) => { ){ return ( - + = (props) => { }; return ( - + Date: Tue, 9 Aug 2022 14:50:26 +0100 Subject: [PATCH 05/25] revert cee05b5979cf1ffc3861a7f465162950713aee4a --- .../edit-history/building-edit-summary.tsx | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/app/src/frontend/building/edit-history/building-edit-summary.tsx b/app/src/frontend/building/edit-history/building-edit-summary.tsx index 8a2d545b..1c8f336e 100644 --- a/app/src/frontend/building/edit-history/building-edit-summary.tsx +++ b/app/src/frontend/building/edit-history/building-edit-summary.tsx @@ -82,30 +82,6 @@ const BuildingEditSummary: React.FunctionComponent = ( ); }; -const BuildingEditSummaryBrief: React.FunctionComponent = ({ - historyEntry, - showBuildingId = false, - hyperlinkCategories = false -}) => { - const entriesWithMetadata = enrichHistoryEntries(historyEntry.forward_patch, historyEntry.reverse_patch); - const entriesByCategory = arrayToDictionary(entriesWithMetadata, x => x.category); - - const categoryHyperlinkTemplate = hyperlinkCategories && historyEntry.building_id != undefined ? - `/edit/$category/${historyEntry.building_id}` : - undefined; - - return ( -
-

Edited on {formatDate(parseDate(historyEntry.revision_timestamp))}

-
- ); -}; - export { BuildingEditSummary }; - -export { - BuildingEditSummaryBrief -}; - From eb41f9cfb317c983b64c49153e414122c32a2fb4 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 14:52:08 +0100 Subject: [PATCH 06/25] fix EditHistory path --- app/src/frontend/building/data-containers/age.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index add84210..465b2fbc 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -8,7 +8,7 @@ import TextboxDataEntry from '../data-components/textbox-data-entry'; import Verification from '../data-components/verification'; import YearDataEntry from '../data-components/year-data-entry'; import withCopyEdit from '../data-container'; -import { EditHistory } from '../../edit-history/edit-history'; +import { EditHistory } from '../edit-history/edit-history'; import { CategoryViewProps } from './category-view-props'; From 3270804b1b45c948d389f00329d4f090ee73d8a5 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 14:54:27 +0100 Subject: [PATCH 07/25] add props.building to EditHistory --- app/src/frontend/building/data-containers/age.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index 465b2fbc..8aa8a9e1 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -23,7 +23,9 @@ const AgeView: React.FunctionComponent = (props) => { ){ return ( - + = (props) => { }; return ( - + Date: Tue, 9 Aug 2022 15:05:36 +0100 Subject: [PATCH 08/25] add EditHistoryLatest --- .../frontend/building/data-containers/age.tsx | 6 +- .../edit-history/building-edit-latest.tsx | 69 +++++++++++++++++++ .../edit-history/edit-history-latest.tsx | 48 +++++++++++++ 3 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 app/src/frontend/building/edit-history/building-edit-latest.tsx create mode 100644 app/src/frontend/building/edit-history/edit-history-latest.tsx diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index 8aa8a9e1..7134661f 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -8,7 +8,7 @@ import TextboxDataEntry from '../data-components/textbox-data-entry'; import Verification from '../data-components/verification'; import YearDataEntry from '../data-components/year-data-entry'; import withCopyEdit from '../data-container'; -import { EditHistory } from '../edit-history/edit-history'; +import { EditHistoryLatest } from '../edit-history/edit-history'; import { CategoryViewProps } from './category-view-props'; @@ -23,7 +23,7 @@ const AgeView: React.FunctionComponent = (props) => { ){ return ( - = (props) => { }; return ( - { + const { + title = `Unknown field (${key})`, + category = undefined + } = dataFields[key] as DataFieldDefinition ?? {}; + + return { + title, + category, + value, + oldValue: reversePatch && reversePatch[key] + }; + }); +} + +const BuildingEditLatest: React.FunctionComponent = ({ + historyEntry, + showBuildingId = false, + hyperlinkCategories = false +}) => { + const entriesWithMetadata = enrichHistoryEntries(historyEntry.forward_patch, historyEntry.reverse_patch); + const entriesByCategory = arrayToDictionary(entriesWithMetadata, x => x.category); + + const categoryHyperlinkTemplate = hyperlinkCategories && historyEntry.building_id != undefined ? + `/edit/$category/${historyEntry.building_id}` : + undefined; + + return ( +
+

Edited on {formatDate(parseDate(historyEntry.revision_timestamp))}

+
+ ); +}; + +export { + BuildingEditLatest +}; diff --git a/app/src/frontend/building/edit-history/edit-history-latest.tsx b/app/src/frontend/building/edit-history/edit-history-latest.tsx new file mode 100644 index 00000000..b44fbf9e --- /dev/null +++ b/app/src/frontend/building/edit-history/edit-history-latest.tsx @@ -0,0 +1,48 @@ +import React, { useEffect, useState } from 'react'; + +import './edit-history.css'; + +import { apiGet } from '../../apiHelpers'; +import { Building } from '../../models/building'; +import { EditHistoryEntry } from '../../models/edit-history-entry'; +import ContainerHeader from '../container-header'; + +import { BuildingEditLatest } from './building-edit-latest'; + +interface EditHistoryLatestProps { + building: Building; +} + +const EditHistory: React.FunctionComponent = (props) => { + const [history, setHistory] = useState(undefined); + + useEffect(() => { + const fetchData = async () => { + const {history} = await apiGet(`/api/buildings/${props.building.building_id}/history.json`); + + setHistory(history); + }; + + if (props.building != undefined) { // only call fn if there is a building provided + fetchData(); // define and call, because effect cannot return anything and an async fn always returns a Promise + } + }, [props.building]); // only re-run effect on building prop change + + return ( + <> + + +
    + {history && history.map(entry => ( +
  • + +
  • + ))} +
+ + ); +}; + +export { + EditHistoryLatest +}; From 03d4dab8fb773e8a0ef9588b2b6b6476a7b9ddda Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 15:06:12 +0100 Subject: [PATCH 09/25] fix import --- app/src/frontend/building/data-containers/age.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/frontend/building/data-containers/age.tsx b/app/src/frontend/building/data-containers/age.tsx index 7134661f..ce3c6e3c 100644 --- a/app/src/frontend/building/data-containers/age.tsx +++ b/app/src/frontend/building/data-containers/age.tsx @@ -8,7 +8,7 @@ import TextboxDataEntry from '../data-components/textbox-data-entry'; import Verification from '../data-components/verification'; import YearDataEntry from '../data-components/year-data-entry'; import withCopyEdit from '../data-container'; -import { EditHistoryLatest } from '../edit-history/edit-history'; +import { EditHistoryLatest } from '../edit-history/edit-history-latest'; import { CategoryViewProps } from './category-view-props'; From a8e239992433add535e238f3511bf8fa1c28b209 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 15:06:57 +0100 Subject: [PATCH 10/25] fix const name --- app/src/frontend/building/edit-history/edit-history-latest.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/frontend/building/edit-history/edit-history-latest.tsx b/app/src/frontend/building/edit-history/edit-history-latest.tsx index b44fbf9e..bd891c12 100644 --- a/app/src/frontend/building/edit-history/edit-history-latest.tsx +++ b/app/src/frontend/building/edit-history/edit-history-latest.tsx @@ -13,7 +13,7 @@ interface EditHistoryLatestProps { building: Building; } -const EditHistory: React.FunctionComponent = (props) => { +const EditHistoryLatest: React.FunctionComponent = (props) => { const [history, setHistory] = useState(undefined); useEffect(() => { From 0b9598f47b2acff74f30b690a38497f62466b90a Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 9 Aug 2022 15:09:07 +0100 Subject: [PATCH 11/25] remove edit hist title --- app/src/frontend/building/edit-history/edit-history-latest.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/frontend/building/edit-history/edit-history-latest.tsx b/app/src/frontend/building/edit-history/edit-history-latest.tsx index bd891c12..af477cb1 100644 --- a/app/src/frontend/building/edit-history/edit-history-latest.tsx +++ b/app/src/frontend/building/edit-history/edit-history-latest.tsx @@ -30,8 +30,6 @@ const EditHistoryLatest: React.FunctionComponent = (prop return ( <> - -