@abgov/jsonforms-components 2.3.8 → 2.3.9
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 +28 -7
- package/package.json +1 -1
- package/src/lib/util/useDebounce.d.ts +9 -0
package/index.esm.js
CHANGED
|
@@ -9816,6 +9816,27 @@ const HelpContentTester = rankWith(1, uiTypeIs('HelpContent'));
|
|
|
9816
9816
|
const HelpContent = withJsonFormsControlProps(HelpContentComponent);
|
|
9817
9817
|
const HelpReviewContent = withJsonFormsControlProps(HelpContentReviewComponent);
|
|
9818
9818
|
|
|
9819
|
+
/**
|
|
9820
|
+
* A helper util to return a value at a certain delay. The delay is reset if the value arg changes
|
|
9821
|
+
* @param value value to be returned after a period of delay
|
|
9822
|
+
* @param delay time in ms to apply the delay
|
|
9823
|
+
* @returns value after the delay timer
|
|
9824
|
+
*/
|
|
9825
|
+
function useDebounce(value, delay) {
|
|
9826
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
9827
|
+
useEffect(() => {
|
|
9828
|
+
// Update debounced value after delay
|
|
9829
|
+
const handler = setTimeout(() => {
|
|
9830
|
+
setDebouncedValue(value);
|
|
9831
|
+
}, delay);
|
|
9832
|
+
// Cancel the timeout if value changes (also on delay change or unmount)
|
|
9833
|
+
return () => {
|
|
9834
|
+
clearTimeout(handler);
|
|
9835
|
+
};
|
|
9836
|
+
}, [value, delay]);
|
|
9837
|
+
return debouncedValue;
|
|
9838
|
+
}
|
|
9839
|
+
|
|
9819
9840
|
const ADDRESS_PATH = 'api/gateway/v1/address/v1/find';
|
|
9820
9841
|
const AddressLookUpControl = props => {
|
|
9821
9842
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -9848,7 +9869,6 @@ const AddressLookUpControl = props => {
|
|
|
9848
9869
|
}
|
|
9849
9870
|
const [address, setAddress] = useState(data || defaultAddress);
|
|
9850
9871
|
const [searchTerm, setSearchTerm] = useState('');
|
|
9851
|
-
const [saveSearchTerm, setSaveSearchTerm] = useState(false);
|
|
9852
9872
|
const [suggestions, setSuggestions] = useState([]);
|
|
9853
9873
|
const [loading, setLoading] = useState(false);
|
|
9854
9874
|
const [errors, setErrors] = useState({});
|
|
@@ -9858,6 +9878,7 @@ const AddressLookUpControl = props => {
|
|
|
9858
9878
|
setAddress(updatedAddress);
|
|
9859
9879
|
handleChange(path, updatedAddress);
|
|
9860
9880
|
};
|
|
9881
|
+
const debouncedRenderAddress = useDebounce(searchTerm, 500);
|
|
9861
9882
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
9862
9883
|
const dropdownRef = useRef(null);
|
|
9863
9884
|
const handleInputChange = (field, value) => {
|
|
@@ -9893,11 +9914,8 @@ const AddressLookUpControl = props => {
|
|
|
9893
9914
|
}));
|
|
9894
9915
|
};
|
|
9895
9916
|
useEffect(() => {
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
setSaveSearchTerm(false);
|
|
9899
|
-
}
|
|
9900
|
-
}, [saveSearchTerm]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
9917
|
+
handleInputChange('addressLine1', searchTerm);
|
|
9918
|
+
}, [debouncedRenderAddress]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
9901
9919
|
useEffect(() => {
|
|
9902
9920
|
const fetchSuggestions = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
9903
9921
|
if (searchTerm.length > 2 && dropdownSelected === false) {
|
|
@@ -9921,7 +9939,6 @@ const AddressLookUpControl = props => {
|
|
|
9921
9939
|
}, [searchTerm]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
9922
9940
|
const handleDropdownChange = value => {
|
|
9923
9941
|
setSearchTerm(value);
|
|
9924
|
-
setSaveSearchTerm(true);
|
|
9925
9942
|
};
|
|
9926
9943
|
const handleSuggestionClick = suggestion => {
|
|
9927
9944
|
const suggestAddress = mapSuggestionToAddress(suggestion);
|
|
@@ -10105,6 +10122,7 @@ const AddressViews = ({
|
|
|
10105
10122
|
children: [jsx(GoAFormItem, {
|
|
10106
10123
|
label: "Address line 1",
|
|
10107
10124
|
error: (data === null || data === void 0 ? void 0 : data.addressLine1) === undefined ? 'addressLine1 is required' : '',
|
|
10125
|
+
requirement: "required",
|
|
10108
10126
|
children: jsx(TextWrap, {
|
|
10109
10127
|
children: data === null || data === void 0 ? void 0 : data.addressLine1
|
|
10110
10128
|
})
|
|
@@ -10120,12 +10138,14 @@ const AddressViews = ({
|
|
|
10120
10138
|
children: [jsx(GoAFormItem, {
|
|
10121
10139
|
error: (data === null || data === void 0 ? void 0 : data.municipality) === undefined ? 'city is required' : '',
|
|
10122
10140
|
label: "City",
|
|
10141
|
+
requirement: "required",
|
|
10123
10142
|
children: jsx(TextWrap, {
|
|
10124
10143
|
children: data === null || data === void 0 ? void 0 : data.municipality
|
|
10125
10144
|
})
|
|
10126
10145
|
}), jsx(GoAFormItem, {
|
|
10127
10146
|
error: (data === null || data === void 0 ? void 0 : data.postalCode) === undefined ? 'postalCode is required' : '',
|
|
10128
10147
|
label: "Postal Code",
|
|
10148
|
+
requirement: "required",
|
|
10129
10149
|
children: jsx(TextWrap, {
|
|
10130
10150
|
children: data === null || data === void 0 ? void 0 : data.postalCode
|
|
10131
10151
|
})
|
|
@@ -10136,6 +10156,7 @@ const AddressViews = ({
|
|
|
10136
10156
|
children: [jsxs(GoAFormItem, {
|
|
10137
10157
|
label: "Province",
|
|
10138
10158
|
error: !isAlbertaAddress && (data === null || data === void 0 ? void 0 : data.subdivisionCode) === undefined ? 'Province is required' : '',
|
|
10159
|
+
requirement: "required",
|
|
10139
10160
|
children: [isAlbertaAddress && jsx("div", {
|
|
10140
10161
|
"data-testid": "address-form-province-view",
|
|
10141
10162
|
children: "Alberta"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.9",
|
|
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",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type DebounceValueType = string | boolean | number | Record<string, unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* A helper util to return a value at a certain delay. The delay is reset if the value arg changes
|
|
4
|
+
* @param value value to be returned after a period of delay
|
|
5
|
+
* @param delay time in ms to apply the delay
|
|
6
|
+
* @returns value after the delay timer
|
|
7
|
+
*/
|
|
8
|
+
export declare function useDebounce(value: DebounceValueType, delay: number): DebounceValueType;
|
|
9
|
+
export {};
|