@abgov/jsonforms-components 1.35.1 → 1.35.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputD
|
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import get$1 from 'lodash/get';
|
|
7
|
-
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl,
|
|
7
|
+
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, isObjectControl, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
|
|
8
8
|
import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
|
|
9
9
|
import { isEqual } from 'lodash';
|
|
10
10
|
import merge from 'lodash/merge';
|
|
@@ -4858,6 +4858,7 @@ styled.h3(_t9$1 || (_t9$1 = _$5`
|
|
|
4858
4858
|
const RightAlignmentDiv = styled.div(_t10$1 || (_t10$1 = _$5`
|
|
4859
4859
|
display: flex;
|
|
4860
4860
|
justify-content: flex-end;
|
|
4861
|
+
margin-bottom: var(--goa-space-l);
|
|
4861
4862
|
`));
|
|
4862
4863
|
|
|
4863
4864
|
var toString$2 = toString$d;
|
|
@@ -6733,8 +6734,10 @@ const AddressInputs = ({
|
|
|
6733
6734
|
address,
|
|
6734
6735
|
handleInputChange,
|
|
6735
6736
|
isAlbertaAddress,
|
|
6736
|
-
|
|
6737
|
+
errors,
|
|
6738
|
+
handleOnBlur
|
|
6737
6739
|
}) => {
|
|
6740
|
+
var _a, _b;
|
|
6738
6741
|
const provinces = [{
|
|
6739
6742
|
value: 'AB',
|
|
6740
6743
|
label: 'Alberta'
|
|
@@ -6792,17 +6795,19 @@ const AddressInputs = ({
|
|
|
6792
6795
|
gap: "s",
|
|
6793
6796
|
children: [jsx(GoAFormItem, {
|
|
6794
6797
|
label: "City",
|
|
6798
|
+
error: (_a = errors === null || errors === void 0 ? void 0 : errors['municipality']) !== null && _a !== void 0 ? _a : '',
|
|
6795
6799
|
children: jsx(GoAInput, {
|
|
6796
6800
|
name: "city",
|
|
6797
6801
|
testId: "address-form-city",
|
|
6798
6802
|
ariaLabel: 'address-form-city',
|
|
6799
6803
|
value: (address === null || address === void 0 ? void 0 : address.city) || '',
|
|
6800
6804
|
onChange: (name, value) => handleInputChange(name, value),
|
|
6805
|
+
onBlur: (name, value) => handleOnBlur('municipality'),
|
|
6801
6806
|
width: "100%"
|
|
6802
6807
|
})
|
|
6803
6808
|
}), jsx(GoAFormItem, {
|
|
6804
6809
|
label: "Postal Code",
|
|
6805
|
-
error:
|
|
6810
|
+
error: (_b = errors === null || errors === void 0 ? void 0 : errors['postalCode']) !== null && _b !== void 0 ? _b : '',
|
|
6806
6811
|
children: jsx(GoAInput, {
|
|
6807
6812
|
name: "postalCode",
|
|
6808
6813
|
testId: "address-form-postal-code",
|
|
@@ -6810,6 +6815,7 @@ const AddressInputs = ({
|
|
|
6810
6815
|
placeholder: "A0A 0A0",
|
|
6811
6816
|
value: (address === null || address === void 0 ? void 0 : address.postalCode) || '',
|
|
6812
6817
|
onChange: (name, value) => handleInputChange(name, value),
|
|
6818
|
+
onBlur: (name, value) => handleOnBlur(name),
|
|
6813
6819
|
width: "100%",
|
|
6814
6820
|
maxLength: 7
|
|
6815
6821
|
})
|
|
@@ -7007,6 +7013,15 @@ const validatePostalCode = values => {
|
|
|
7007
7013
|
const postalCodeRegex = /^[A-Za-z]\d[A-Za-z] \d[A-Za-z]\d$/;
|
|
7008
7014
|
return postalCodeRegex.test(values);
|
|
7009
7015
|
};
|
|
7016
|
+
const handlePostalCodeValidation = (validatePc, message, value, errors) => {
|
|
7017
|
+
const newErrors = Object.assign({}, errors);
|
|
7018
|
+
if (!validatePc && value.length >= 4) {
|
|
7019
|
+
newErrors['postalCode'] = message;
|
|
7020
|
+
} else {
|
|
7021
|
+
delete newErrors['postalCode'];
|
|
7022
|
+
}
|
|
7023
|
+
return newErrors;
|
|
7024
|
+
};
|
|
7010
7025
|
|
|
7011
7026
|
let _ = t => t,
|
|
7012
7027
|
_t;
|
|
@@ -7192,7 +7207,7 @@ const HelpReviewContent = withJsonFormsControlProps(HelpContentReviewComponent);
|
|
|
7192
7207
|
|
|
7193
7208
|
const ADDRESS_PATH = 'api/gateway/v1/address/v1/find';
|
|
7194
7209
|
const AddressLookUpControl = props => {
|
|
7195
|
-
var _a, _b, _c;
|
|
7210
|
+
var _a, _b, _c, _d;
|
|
7196
7211
|
const {
|
|
7197
7212
|
data,
|
|
7198
7213
|
path,
|
|
@@ -7219,7 +7234,7 @@ const AddressLookUpControl = props => {
|
|
|
7219
7234
|
const [searchTerm, setSearchTerm] = useState('');
|
|
7220
7235
|
const [suggestions, setSuggestions] = useState([]);
|
|
7221
7236
|
const [loading, setLoading] = useState(false);
|
|
7222
|
-
const [
|
|
7237
|
+
const [errors, setErrors] = useState({});
|
|
7223
7238
|
const updateFormData = updatedAddress => {
|
|
7224
7239
|
setAddress(updatedAddress);
|
|
7225
7240
|
handleChange(path, updatedAddress);
|
|
@@ -7227,14 +7242,10 @@ const AddressLookUpControl = props => {
|
|
|
7227
7242
|
const handleInputChange = (field, value) => {
|
|
7228
7243
|
var _a, _b;
|
|
7229
7244
|
let newAddress;
|
|
7245
|
+
const postalCodeErrorMessage = (_b = (_a = schema.errorMessage) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.postalCode;
|
|
7230
7246
|
if (field === 'postalCode') {
|
|
7231
7247
|
const validatePc = validatePostalCode(value);
|
|
7232
|
-
|
|
7233
|
-
const postalCodeErrorMessage = (_b = (_a = schema.errorMessage) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.postalCode;
|
|
7234
|
-
setPostalCodeErrorMsg(postalCodeErrorMessage !== null && postalCodeErrorMessage !== void 0 ? postalCodeErrorMessage : '');
|
|
7235
|
-
} else {
|
|
7236
|
-
setPostalCodeErrorMsg('');
|
|
7237
|
-
}
|
|
7248
|
+
setErrors(handlePostalCodeValidation(validatePc, postalCodeErrorMessage ? postalCodeErrorMessage : '', value, errors));
|
|
7238
7249
|
if (value.length >= 4 && value.indexOf(' ') === -1) {
|
|
7239
7250
|
value = value.slice(0, 3) + ' ' + value.slice(3);
|
|
7240
7251
|
}
|
|
@@ -7275,19 +7286,32 @@ const AddressLookUpControl = props => {
|
|
|
7275
7286
|
});
|
|
7276
7287
|
fetchSuggestions();
|
|
7277
7288
|
}, [searchTerm, formUrl, isAlbertaAddress]);
|
|
7278
|
-
const handleDropdownChange = value =>
|
|
7289
|
+
const handleDropdownChange = value => {
|
|
7279
7290
|
setSearchTerm(value);
|
|
7280
7291
|
handleInputChange('addressLine1', value);
|
|
7281
|
-
}
|
|
7292
|
+
};
|
|
7282
7293
|
const handleSuggestionClick = suggestion => {
|
|
7283
7294
|
const suggestAddress = mapSuggestionToAddress(suggestion);
|
|
7284
7295
|
setAddress(suggestAddress);
|
|
7285
7296
|
handleChange(path, suggestAddress);
|
|
7286
7297
|
setSuggestions([]);
|
|
7298
|
+
setErrors({});
|
|
7299
|
+
};
|
|
7300
|
+
const handleRequiredFieldBlur = name => {
|
|
7301
|
+
const requiredFields = schema.required;
|
|
7302
|
+
if (!(data === null || data === void 0 ? void 0 : data[name]) || data[name] === '' || requiredFields.includes(name)) {
|
|
7303
|
+
const err = Object.assign({}, errors);
|
|
7304
|
+
err[name] = name === 'municipality' ? `city is required` : `${name} is required`;
|
|
7305
|
+
setErrors(err);
|
|
7306
|
+
} else {
|
|
7307
|
+
delete errors[name];
|
|
7308
|
+
}
|
|
7287
7309
|
};
|
|
7288
7310
|
return jsxs("div", {
|
|
7289
7311
|
children: [renderHelp(), jsx(GoAFormItem, {
|
|
7290
7312
|
label: label,
|
|
7313
|
+
error: (_d = errors === null || errors === void 0 ? void 0 : errors['addressLine1']) !== null && _d !== void 0 ? _d : '',
|
|
7314
|
+
"data-testId": "form-address-line1",
|
|
7291
7315
|
children: jsxs(SearchBox, {
|
|
7292
7316
|
children: [jsx(GoAInput, {
|
|
7293
7317
|
leadingIcon: autocompletion ? 'search' : undefined,
|
|
@@ -7297,6 +7321,7 @@ const AddressLookUpControl = props => {
|
|
|
7297
7321
|
placeholder: "Start typing the first line of your address",
|
|
7298
7322
|
value: (address === null || address === void 0 ? void 0 : address.addressLine1) || '',
|
|
7299
7323
|
onChange: (name, value) => handleDropdownChange(value),
|
|
7324
|
+
onBlur: (name, value) => handleRequiredFieldBlur(name),
|
|
7300
7325
|
width: "100%"
|
|
7301
7326
|
}), loading && autocompletion && jsx(GoASkeleton, {
|
|
7302
7327
|
type: "text",
|
|
@@ -7312,14 +7337,15 @@ const AddressLookUpControl = props => {
|
|
|
7312
7337
|
})
|
|
7313
7338
|
}), jsx("br", {}), jsx(AddressInputs, {
|
|
7314
7339
|
address: address,
|
|
7340
|
+
errors: errors,
|
|
7315
7341
|
handleInputChange: handleInputChange,
|
|
7316
7342
|
isAlbertaAddress: isAlbertaAddress,
|
|
7317
|
-
|
|
7343
|
+
handleOnBlur: handleRequiredFieldBlur
|
|
7318
7344
|
})]
|
|
7319
7345
|
});
|
|
7320
7346
|
};
|
|
7321
7347
|
|
|
7322
|
-
const AddressLookUpTester = rankWith(3,
|
|
7348
|
+
const AddressLookUpTester = rankWith(3, isObjectControl);
|
|
7323
7349
|
|
|
7324
7350
|
const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
|
|
7325
7351
|
const GoATextCellTester = rankWith(1, isStringControl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
|
|
6
6
|
"repository": "https://github.com/GovAlta/adsp-monorepo",
|
|
@@ -4,7 +4,8 @@ interface AddressInputsProps {
|
|
|
4
4
|
address: Address;
|
|
5
5
|
handleInputChange: (field: string, value: string) => void;
|
|
6
6
|
isAlbertaAddress?: boolean;
|
|
7
|
-
|
|
7
|
+
errors?: any;
|
|
8
|
+
handleOnBlur: (field: string) => void;
|
|
8
9
|
}
|
|
9
10
|
export declare const AddressInputs: React.FC<AddressInputsProps>;
|
|
10
11
|
export {};
|
|
@@ -4,3 +4,6 @@ export declare const filterAlbertaAddresses: (suggestions: Suggestion[]) => Sugg
|
|
|
4
4
|
export declare const filterSuggestionsWithoutAddressCount: (suggestions: Suggestion[]) => Suggestion[];
|
|
5
5
|
export declare const mapSuggestionToAddress: (suggestion: Suggestion) => Address;
|
|
6
6
|
export declare const validatePostalCode: (values: string) => boolean;
|
|
7
|
+
export declare const handlePostalCodeValidation: (validatePc: boolean, message: string, value: string, errors: Record<string, string>) => {
|
|
8
|
+
[x: string]: string;
|
|
9
|
+
};
|