Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Updated multiinput submission for ukaddressfield #377

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ import { DetailItem } from "../types";
import { format } from "date-fns";
import config from "server/config";

function flattenMultiInput(rawValue) {
if (!rawValue) return rawValue;
rawValue.forEach((value) => {
Object.keys(value).map((key) => {
if (typeof value[key] == "object" && value[key] !== null) {
value[key] = Object.values(value[key])
.filter((p) => {
return !!p;
})
.join(", ");
}
});
});
return rawValue;
}
Comment on lines +5 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we sort of do this the other way round? Instead of changing the structured object to a string joined by commas, change the other way so that it matches the structured object?

Just in the past seen dates stored as raw strings and then end up getting a requirement or request to re-display specific parts, which ends up in using some library (libpostal) to parse the address or some hacky regex to extract specific parts (i.e postcode) - it'd be better if we store the structured form of the address and then just on any relevant view display it as a comma separated string, or any other display that is requested

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the code on the assess side for rendering is already built for formatting the string that this creates and they are having errors on their side of the json object appearing in the tables so this fixes both of these issues though it may be good to have structure in the future by removing this function

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - how are we handling the state already stored in the database for this component? Do we need a migration script to replicate this change for persisted data with the old structure?


function answerFromDetailItem(item) {
switch (item.dataType) {
case "list":
Expand All @@ -18,7 +34,7 @@ function answerFromDetailItem(item) {
const [month, year] = Object.values(item.rawValue);
return format(new Date(`${year}-${month}-1`), "yyyy-MM");
case "multiInput":
return item.rawValue;
return flattenMultiInput(item.rawValue);
default:
return item.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class RepeatingSummaryPageController extends PageController {
} else if (componentType == "YesNoField") {
return value ? "Yes" : "No";
} else if (componentType == "UkAddressField") {
if (typeof (value === "string")) return value;
return value
? [
value.addressLine1,
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=0.1.187
VERSION=0.1.188