Unverified Commit d47f97d1 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by GitHub
Browse files

Update address fields to generalize field names (#246)



* Update address fields to use generic fields

* Remove call that does not exist in production packages

* Update DDL for recreating DB, add JSONb property names in address fields

* Made address label dynamic based on country/region and solved conflicts

* Modified required logic for city field

* Fixed some small issues
Co-authored-by: Zhou Fang's avatarZhou Fang <zhou.fang@eclipse-foundation.org>
parent f8edb543
...@@ -601,15 +601,18 @@ components: ...@@ -601,15 +601,18 @@ components:
address: address:
type: object type: object
properties: properties:
street: address_line_1:
type: string type: string
description: Street address of the organization description: Street address of the organization
city: address_line_2:
type: string type: string
description: The ciy in which the organization is based description: Additional information about the street address of the organization
province_state: locality:
type: string type: string
description: The province/state in which the organization is based description: The city/township in which the organization is based
administrative_area:
type: string
description: The province/state/area in which the organization is based
country: country:
type: string type: string
description: The country in which the organization is based description: The country in which the organization is based
...@@ -638,15 +641,18 @@ components: ...@@ -638,15 +641,18 @@ components:
address: address:
type: object type: object
properties: properties:
street: address_line_1:
type: string type: string
description: Street address of the organization description: Street address of the organization
city: address_line_2:
type: string
description: Additional information about the street address of the organization
locality:
type: string type: string
description: The ciy in which the organization is based description: The city/township in which the organization is based
province_state: administrative_area:
type: string type: string
description: The province/state in which the organization is based description: The province/state/area in which the organization is based
country: country:
type: string type: string
description: The country in which the organization is based description: The country in which the organization is based
......
...@@ -114,11 +114,11 @@ public class DataLoader { ...@@ -114,11 +114,11 @@ public class DataLoader {
o.setEmployeeCount(RandomStringUtils.randomNumeric(5, 10)); o.setEmployeeCount(RandomStringUtils.randomNumeric(5, 10));
o.setOrganizationType(OrganizationTypes.OTHER); o.setOrganizationType(OrganizationTypes.OTHER);
Address a = new Address(); Address a = new Address();
a.setCity(RandomStringUtils.randomAlphabetic(4, 10)); a.setLocality(RandomStringUtils.randomAlphabetic(4, 10));
a.setCountry(RandomStringUtils.randomAlphabetic(4, 10)); a.setCountry(RandomStringUtils.randomAlphabetic(4, 10));
a.setPostalCode(RandomStringUtils.randomAlphabetic(4, 10)); a.setPostalCode(RandomStringUtils.randomAlphabetic(4, 10));
a.setProvinceState(RandomStringUtils.randomAlphabetic(2)); a.setAdministrativeArea(RandomStringUtils.randomAlphabetic(2));
a.setStreet(RandomStringUtils.randomAlphabetic(4, 10)); a.setAddressLine1(RandomStringUtils.randomAlphabetic(4, 10));
a.setOrganization(o); a.setOrganization(o);
o.setAddress(a); o.setAddress(a);
organizations.add(o); organizations.add(o);
......
...@@ -16,6 +16,7 @@ import java.util.Objects; ...@@ -16,6 +16,7 @@ import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.json.bind.annotation.JsonbProperty;
import javax.json.bind.annotation.JsonbTransient; import javax.json.bind.annotation.JsonbTransient;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
...@@ -56,11 +57,14 @@ public class Address extends BareNode implements TargetedClone<Address> { ...@@ -56,11 +57,14 @@ public class Address extends BareNode implements TargetedClone<Address> {
@JoinColumn(name = "organization_id", unique = true) @JoinColumn(name = "organization_id", unique = true)
private FormOrganization organization; private FormOrganization organization;
@NotBlank(message = "Street cannot be blank") @NotBlank(message = "First address line cannot be blank")
private String street; @JsonbProperty("address_line_1")
@NotBlank(message = "City cannot be blank") private String addressLine1;
private String city; @JsonbProperty("address_line_2")
private String provinceState; private String addressLine2;
@NotBlank(message = "Locality cannot be blank")
private String locality;
private String administrativeArea;
@NotBlank(message = "Country cannot be blank") @NotBlank(message = "Country cannot be blank")
private String country; private String country;
private String postalCode; private String postalCode;
...@@ -77,6 +81,7 @@ public class Address extends BareNode implements TargetedClone<Address> { ...@@ -77,6 +81,7 @@ public class Address extends BareNode implements TargetedClone<Address> {
} }
/** @return the organization */ /** @return the organization */
@JsonbTransient
public FormOrganization getOrganization() { public FormOrganization getOrganization() {
return this.organization; return this.organization;
} }
...@@ -86,83 +91,123 @@ public class Address extends BareNode implements TargetedClone<Address> { ...@@ -86,83 +91,123 @@ public class Address extends BareNode implements TargetedClone<Address> {
this.organization = org; this.organization = org;
} }
/** @return the steet */ /**
public String getStreet() { * @return the addressLine1
return street; */
public String getAddressLine1() {
return addressLine1;
}
/**
* @param addressLine1 the addressLine1 to set
*/
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
/**
* @return the addressLine2
*/
public String getAddressLine2() {
return addressLine2;
} }
/** @param street the street to set */ /**
public void setStreet(String street) { * @param addressLine2 the addressLine2 to set
this.street = street; */
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
} }
/** @return the city */ /**
public String getCity() { * @return the locality
return city; */
public String getLocality() {
return locality;
} }
/** @param city the city to set */ /**
public void setCity(String city) { * @param locality the locality to set
this.city = city; */
public void setLocality(String locality) {
this.locality = locality;
} }
/** @return the provinceState */ /**
public String getProvinceState() { * @return the administrativeArea
return provinceState; */
public String getAdministrativeArea() {
return administrativeArea;
} }
/** @param provinceState the provinceState to set */ /**
public void setProvinceState(String provinceState) { * @param administrativeArea the administrativeArea to set
this.provinceState = provinceState; */
public void setAdministrativeArea(String administrativeArea) {
this.administrativeArea = administrativeArea;
} }
/** @return the country */ /**
* @return the country
*/
public String getCountry() { public String getCountry() {
return country; return country;
} }
/** @param country the country to set */ /**
* @param country the country to set
*/
public void setCountry(String country) { public void setCountry(String country) {
this.country = country; this.country = country;
} }
/** @return the postalCode */ /**
* @return the postalCode
*/
public String getPostalCode() { public String getPostalCode() {
return postalCode; return postalCode;
} }
/** @param postalCode the postalCode to set */ /**
* @param postalCode the postalCode to set
*/
public void setPostalCode(String postalCode) { public void setPostalCode(String postalCode) {
this.postalCode = postalCode; this.postalCode = postalCode;
} }
@Override
public Address cloneTo(Address target) {
target.setCity(getCity());
target.setCountry(getCountry());
target.setPostalCode(getPostalCode());
target.setProvinceState(getProvinceState());
target.setStreet(getStreet());
return target;
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(city, country, id, postalCode, provinceState, street); final int prime = 31;
int result = super.hashCode();
result = prime * result
+ Objects.hash(addressLine1, addressLine2, administrativeArea, country, id, locality, postalCode);
return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (!super.equals(obj))
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Address other = (Address) obj; Address other = (Address) obj;
return Objects.equals(city, other.city) && Objects.equals(country, other.country) return Objects.equals(addressLine1, other.addressLine1) && Objects.equals(addressLine2, other.addressLine2)
&& Objects.equals(id, other.id) && Objects.equals(postalCode, other.postalCode) && Objects.equals(administrativeArea, other.administrativeArea)
&& Objects.equals(provinceState, other.provinceState) && Objects.equals(street, other.street); && Objects.equals(country, other.country) && Objects.equals(id, other.id)
&& Objects.equals(locality, other.locality) && Objects.equals(postalCode, other.postalCode);
}
@Override
public Address cloneTo(Address target) {
target.setAddressLine1(getAddressLine1());
target.setAddressLine2(getAddressLine2());
target.setLocality(getLocality());
target.setAdministrativeArea(getAdministrativeArea());
target.setCountry(getCountry());
target.setPostalCode(getPostalCode());
return target;
} }
/** /**
...@@ -200,4 +245,5 @@ public class Address extends BareNode implements TargetedClone<Address> { ...@@ -200,4 +245,5 @@ public class Address extends BareNode implements TargetedClone<Address> {
return Address.class; return Address.class;
} }
} }
} }
...@@ -56,11 +56,12 @@ CREATE TABLE `FormWorkingGroup` ( ...@@ -56,11 +56,12 @@ CREATE TABLE `FormWorkingGroup` (
CREATE TABLE `Address` ( CREATE TABLE `Address` (
`id` varchar(255) NOT NULL, `id` varchar(255) NOT NULL,
`city` varchar(255) DEFAULT NULL, `locality` varchar(255) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL, `country` varchar(255) DEFAULT NULL,
`postalCode` varchar(255) DEFAULT NULL, `postalCode` varchar(255) DEFAULT NULL,
`provinceState` varchar(255) DEFAULT NULL, `administrativeArea` varchar(255) DEFAULT NULL,
`street` varchar(255) DEFAULT NULL, `addressLine1` varchar(255) DEFAULT NULL,
`addressLine2` varchar(255) DEFAULT NULL,
`organization_id` varchar(255) DEFAULT NULL, `organization_id` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `UK_i4vgutrsl3ve37hc8xx7vvslf` (`organization_id`), UNIQUE KEY `UK_i4vgutrsl3ve37hc8xx7vvslf` (`organization_id`),
......
Eclipse Foundation AISBL Membership Application date submitted: {now} Eclipse Foundation AISBL Membership Application date submitted: {now}
{#if includePreamble} {#if includePreamble}
Dear {name}, Dear {name},
...@@ -7,6 +8,8 @@ Meanwhile, if you have any questions, please reach out to us at membership.coord ...@@ -7,6 +8,8 @@ Meanwhile, if you have any questions, please reach out to us at membership.coord
Best regards, Best regards,
Eclipse Foundation Membership Coordination Eclipse Foundation Membership Coordination
{/if} {/if}
New form submission by: {name} ({data.form.userID}) New form submission by: {name} ({data.form.userID})
...@@ -22,8 +25,9 @@ Employee count: {data.org.employeeCount} ...@@ -22,8 +25,9 @@ Employee count: {data.org.employeeCount}
Organization Type: {data.org.organizationType} Organization Type: {data.org.organizationType}
Address Address
{data.org.address.street} {data.org.address.addressLine1}
{data.org.address.city}, {org.address.provinceState} {data.org.address.addressLine2}
{data.org.address.locality}, {data.org.address.administrativeArea}
{data.org.address.country} {data.org.address.country}
{data.org.address.postalCode} {data.org.address.postalCode}
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<div> <div>
<h3>Address</h3> <h3>Address</h3>
<p> <p>
{data.org.address.street}<br /> {data.org.address.city}<br /> {data.org.address.provinceState}<br /> {data.org.address.country}<br /> {data.org.address.postalCode} {data.org.address.addressLine1}<br />{data.org.address.addressLine2}<br />{data.org.address.locality}<br /> {data.org.address.administrativeArea}<br /> {data.org.address.country}<br /> {data.org.address.postalCode}
</p> </p>
</div> </div>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"eclipsefdn-solstice-assets": "^0.0.162", "eclipsefdn-solstice-assets": "^0.0.162",
"formik": "^2.2.6", "formik": "^2.2.6",
"less-watch-compiler": "^1.15.1", "less-watch-compiler": "^1.15.1",
"postal-address-field-names": "^1.0.3",
"react": "^17.0.0", "react": "^17.0.0",
"react-app-polyfill": "^2.0.0", "react-app-polyfill": "^2.0.0",
"react-dom": "^17.0.0", "react-dom": "^17.0.0",
...@@ -54,9 +55,9 @@ ...@@ -54,9 +55,9 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@types/react-router-dom": "^5.1.7",
"@openapi-contrib/openapi-schema-to-json-schema": "^3.1.1", "@openapi-contrib/openapi-schema-to-json-schema": "^3.1.1",
"@stoplight/json-ref-resolver": "^3.1.2", "@stoplight/json-ref-resolver": "^3.1.2",
"@types/react-router-dom": "^5.1.7",
"decamelize": "^5.0.0", "decamelize": "^5.0.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"react-datepicker": "^3.2.2", "react-datepicker": "^3.2.2",
......
...@@ -79,9 +79,10 @@ export function matchCompanyFields(existingOrganizationData) { ...@@ -79,9 +79,10 @@ export function matchCompanyFields(existingOrganizationData) {
type: existingOrganizationData?.organization_type || '', type: existingOrganizationData?.organization_type || '',
address: { address: {
id: existingOrganizationData?.address?.id || '', id: existingOrganizationData?.address?.id || '',
street: existingOrganizationData?.address?.street || '', street: existingOrganizationData?.address?.address_line_1 || '',
city: existingOrganizationData?.address?.city || '', streetTwo: existingOrganizationData?.address?.address_line_2 || '',
provinceOrState: existingOrganizationData?.address?.province_state || '', city: existingOrganizationData?.address?.locality || '',
provinceOrState: existingOrganizationData?.address?.administrative_area || '',
country: existingOrganizationData?.address?.country || '', country: existingOrganizationData?.address?.country || '',
'country-label': { 'country-label': {
label: existingOrganizationData?.address?.country || '', label: existingOrganizationData?.address?.country || '',
...@@ -233,11 +234,12 @@ export function matchWorkingGroupFields( ...@@ -233,11 +234,12 @@ export function matchWorkingGroupFields(
export function matchCompanyFieldsToBackend(organizationData, formId) { export function matchCompanyFieldsToBackend(organizationData, formId) {
var org = { var org = {
address: { address: {
city: organizationData.address.city, locality: organizationData.address.city,
country: organizationData.address.country, country: organizationData.address.country,
postal_code: organizationData.address.postalCode || '', postal_code: organizationData.address.postalCode || '',
province_state: organizationData.address.provinceOrState || '', administrative_area: organizationData.address.provinceOrState || '',
street: organizationData.address.street, address_line_1: organizationData.address.street,
address_line_2: organizationData.address.streetTwo,
}, },
form_id: formId, form_id: formId,
id: organizationData.id, id: organizationData.id,
...@@ -245,7 +247,7 @@ export function matchCompanyFieldsToBackend(organizationData, formId) { ...@@ -245,7 +247,7 @@ export function matchCompanyFieldsToBackend(organizationData, formId) {
twitter: organizationData.twitterHandle || '', twitter: organizationData.twitterHandle || '',
aggregate_revenue: organizationData.revenue, aggregate_revenue: organizationData.revenue,
employee_count: organizationData.employeeCount, employee_count: organizationData.employeeCount,
organization_type: organizationData.type organization_type: organizationData.type,
}; };
if (organizationData.address.id) { if (organizationData.address.id) {
......
...@@ -9,6 +9,8 @@ import { ...@@ -9,6 +9,8 @@ import {
OPTIONS_FOR_EMPLOYEE_COUNT, OPTIONS_FOR_EMPLOYEE_COUNT,
HELPERTEXT_FOR_REVENUE, HELPERTEXT_FOR_REVENUE,
} from '../../../Constants/Constants'; } from '../../../Constants/Constants';
import countryAddressDetails from 'postal-address-field-names';
import { useState } from 'react';
/** /**
* Render Oraganization selector (used React-Select) * Render Oraganization selector (used React-Select)
...@@ -21,18 +23,39 @@ import { ...@@ -21,18 +23,39 @@ import {
const CompanyInformationCompany = ({ formik, useStyles }) => { const CompanyInformationCompany = ({ formik, useStyles }) => {
const classes = useStyles(); const classes = useStyles();
const { organizationName, organizationTwitter, organizationAddress, organizationRevenue, organizationType } = const { organizationName, organizationTwitter, organizationAddress, organizationRevenue, organizationType } = formField;
formField; const [orgAddressObj, setOrgAddressObj] = useState({
street: 'Address 1',
streetTwo: 'Address 2',
city: 'City',
provinceOrState: 'Province',
postalCode: 'Postal Code',
});
// get country list library and map as option pass to the React-Select const countryList = countryAddressDetails.map((item) => ({ label: item.name, value: item.name }));
const countryList = require('country-list')
.getNames()
.map((item) => ({ label: item, value: item }));
const handleFieldChange = (value, fieldName) => { const handleFieldChange = (value, fieldName) => {
formik.setFieldValue(fieldName, value); formik.setFieldValue(fieldName, value);
}; };
const handleCountryOnChange = (ev, value) => {
// this is only for display
formik.setFieldValue(`${organizationAddress.country.name}-label`, value || null);
// this is the data will be actually used
formik.setFieldValue(organizationAddress.country.name, value?.value || null);
if (value) {
const currentAddressObj = countryAddressDetails.find((item) => item.name === value.value).fields;
console.log(currentAddressObj);
setOrgAddressObj({
street: currentAddressObj.addressLine1,
streetTwo: currentAddressObj.addressLine2,
city: currentAddressObj.locality,
provinceOrState: currentAddressObj.administrativeArea,
postalCode: currentAddressObj.postalCode,
});
}
};
return ( return (
<> <>
<h2 className="fw-600 h4" id={organizationName.name}> <h2 className="fw-600 h4" id={organizationName.name}>
...@@ -121,10 +144,10 @@ const CompanyInformationCompany = ({ formik, useStyles }) => { ...@@ -121,10 +144,10 @@ const CompanyInformationCompany = ({ formik, useStyles }) => {
Address Address
</h2> </h2>
<div className="row"> <div className="row">
<div className="col-md-16"> <div className="col-md-12">
<Input <Input
name={organizationAddress.street.name} name={organizationAddress.street.name}
labelName={organizationAddress.street.label} labelName={orgAddressObj.street || 'Address 1'}
placeholder={organizationAddress.street.placeholder} placeholder={organizationAddress.street.placeholder}
requiredMark={true} requiredMark={true}
value={formik.values.organization.address.street} value={formik.values.organization.address.street}
...@@ -134,17 +157,18 @@ const CompanyInformationCompany = ({ formik, useStyles }) => { ...@@ -134,17 +157,18 @@ const CompanyInformationCompany = ({ formik, useStyles }) => {
helperText={formik.errors.organization?.address?.street}