@oneblink/apps-react 6.1.0-beta.3 → 6.1.0-beta.4
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.
@@ -29,22 +29,29 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
|
|
29
29
|
autocompleteService.getQueryPredictions({
|
30
30
|
input,
|
31
31
|
}, (predictions, status) => {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
switch (status) {
|
33
|
+
case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: {
|
34
|
+
resolve([]);
|
35
|
+
break;
|
36
|
+
}
|
37
|
+
case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {
|
38
|
+
reject(new OneBlinkAppsError('Google Maps API key has not been configured correctly'));
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
case google.maps.places.PlacesServiceStatus.OK: {
|
42
|
+
resolve(predictions !== null && predictions !== void 0 ? predictions : []);
|
43
|
+
break;
|
44
|
+
}
|
45
|
+
default: {
|
46
|
+
reject(new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.'));
|
47
|
+
}
|
39
48
|
}
|
40
|
-
resolve(predictions !== null && predictions !== void 0 ? predictions : []);
|
41
|
-
return;
|
42
49
|
});
|
43
50
|
}).catch((e) => {
|
44
51
|
if (!abortSignal.aborted) {
|
45
52
|
Sentry.captureException(e);
|
46
53
|
}
|
47
|
-
throw
|
54
|
+
throw e;
|
48
55
|
});
|
49
56
|
if (!abortSignal.aborted) {
|
50
57
|
return predictions.reduce((results, prediction) => {
|
@@ -86,7 +93,7 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
|
|
86
93
|
}, (place, status) => {
|
87
94
|
if (status !== google.maps.places.PlacesServiceStatus.OK ||
|
88
95
|
!place) {
|
89
|
-
reject(`Could not find address details for place with id: ${placeId}`);
|
96
|
+
reject(new OneBlinkAppsError(`Could not find address details for place with id: ${placeId}`));
|
90
97
|
return;
|
91
98
|
}
|
92
99
|
resolve(place);
|
@@ -96,9 +103,7 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
|
|
96
103
|
}
|
97
104
|
catch (newError) {
|
98
105
|
if (isMounted.current) {
|
99
|
-
setError(
|
100
|
-
originalError: newError,
|
101
|
-
}));
|
106
|
+
setError(newError);
|
102
107
|
}
|
103
108
|
}
|
104
109
|
if (isMounted.current) {
|
@@ -119,7 +124,7 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
|
|
119
124
|
' ',
|
120
125
|
React.createElement("img", { src: "https://developers.google.com/static/maps/documentation/images/google_on_white.png" })) })),
|
121
126
|
error && (React.createElement("div", { role: "alert", className: "has-margin-top-8" },
|
122
|
-
React.createElement("div", { className: "has-text-danger ob-error__text cypress-google-address-details-error-message" }, error.
|
127
|
+
React.createElement("div", { className: "has-text-danger ob-error__text cypress-google-address-details-error-message" }, error.message)))));
|
123
128
|
}
|
124
129
|
export default React.memo(FormElementGoogleAddress);
|
125
130
|
//# sourceMappingURL=FormElementGoogleAddress.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FormElementGoogleAddress.js","sourceRoot":"","sources":["../../src/form-elements/FormElementGoogleAddress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAC9E,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAC1C,OAAO,YAAY,MAAM,uBAAuB,CAAA;AAChD,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAa1E,SAAS,wBAAwB,CAAC,EAChC,EAAE,EACF,OAAO,EACP,KAAK,EACL,wBAAwB,EACxB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,UAAU,GAC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AAC,oFAAoF,GAAG,CAC9F,GAEN,CACwB;QAE3B,KAAK,IAAI,CACR,6BAAK,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,kBAAkB;YAC5C,6BAAK,SAAS,EAAC,6EAA6E,IACzF,KAAK,CAAC,QAAQ,EAAE,CACb,CACF,CACP,CACG,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes, GoogleTypes } from '@oneblink/types'\nimport { OneBlinkAppsError, Sentry } from '@oneblink/apps'\n\nimport AutocompleteDropdown from '../components/renderer/AutocompleteDropdown'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport useGoogle from '../hooks/useGoogle'\nimport useIsMounted from '../hooks/useIsMounted'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\n\ntype Props = {\n formId: number\n id: string\n element: FormTypes.GoogleAddressElement\n value: GoogleTypes.GoogleMapsAddress | undefined\n displayValidationMessage: boolean\n validationMessage: string | undefined\n onChange: FormElementValueChangeHandler<GoogleTypes.GoogleMapsAddress>\n} & IsDirtyProps\n\nfunction FormElementGoogleAddress({\n id,\n element,\n value,\n displayValidationMessage,\n validationMessage,\n onChange,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const isMounted = useIsMounted()\n const [label, setLabel] = React.useState('')\n const [error, setError] = React.useState<Error | undefined>()\n const [isLoadingAddressDetails, setIsLoadingAddressDetails] =\n React.useState(false)\n\n const { isLoaded } = useGoogle()\n\n const autocompleteService = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.places.AutocompleteService()\n }\n }, [isLoaded])\n\n const dummyMap = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.Map(document.createElement('div'))\n }\n }, [isLoaded])\n\n const handleSearch = React.useCallback(\n async (input: string, abortSignal: AbortSignal) => {\n setError(undefined)\n if (autocompleteService) {\n const predictions = await new Promise<\n google.maps.places.QueryAutocompletePrediction[]\n >((resolve, reject) => {\n autocompleteService.getQueryPredictions(\n {\n input,\n },\n (predictions, status) => {\n if (\n status === google.maps.places.PlacesServiceStatus.ZERO_RESULTS\n ) {\n resolve([])\n return\n }\n if (status !== google.maps.places.PlacesServiceStatus.OK) {\n reject('Google Places service not available')\n return\n }\n resolve(predictions ?? [])\n return\n },\n )\n }).catch((e) => {\n if (!abortSignal.aborted) {\n Sentry.captureException(e)\n }\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n { originalError: e },\n )\n })\n\n if (!abortSignal.aborted) {\n return predictions.reduce<Array<{ value: string; label: string }>>(\n (results, prediction) => {\n if (prediction.place_id) {\n results.push({\n value: prediction.place_id,\n label: prediction.description,\n })\n }\n return results\n },\n [],\n )\n }\n }\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n )\n },\n [autocompleteService],\n )\n\n const handleChange = React.useCallback(\n async (placeId: string | undefined) => {\n if (!placeId) {\n onChange(element, { value: undefined })\n return\n }\n\n setIsLoadingAddressDetails(true)\n try {\n //this should not happen, we can't get a place Id without google being present\n if (!isLoaded || !dummyMap) {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: new Error(\n 'Google Places library has not be initialised',\n ),\n },\n )\n }\n\n const placeService = new google.maps.places.PlacesService(dummyMap)\n const place = await new Promise<GoogleTypes.GoogleMapsAddress>(\n (resolve, reject) => {\n placeService.getDetails(\n {\n placeId,\n fields: [\n 'place_id',\n 'formatted_address',\n 'geometry',\n 'address_components',\n ],\n },\n (place, status) => {\n if (\n status !== google.maps.places.PlacesServiceStatus.OK ||\n !place\n ) {\n reject(\n `Could not find address details for place with id: ${placeId}`,\n )\n return\n }\n resolve(place)\n },\n )\n },\n )\n onChange(element, { value: place })\n } catch (newError) {\n if (isMounted.current) {\n setError(\n new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: newError as Error,\n },\n ),\n )\n }\n }\n if (isMounted.current) {\n setIsLoadingAddressDetails(false)\n }\n },\n [isMounted, onChange, element, isLoaded, dummyMap],\n )\n\n // Ensure the label is set if the value is set outside of this component\n React.useEffect(() => {\n if (value) {\n const newLabel = value.formatted_address || value.place_id\n setLabel(newLabel ?? '')\n }\n }, [value])\n\n return (\n <div className=\"cypress-google-address-element\">\n <FormElementLabelContainer\n className=\"ob-google-address ob-autocomplete\"\n element={element}\n id={id}\n required={element.required}\n >\n <AutocompleteDropdown\n id={id}\n label={label}\n disabled={element.readOnly || isLoadingAddressDetails}\n placeholder={element.placeholderValue}\n required={element.required}\n value={value}\n validationMessage={validationMessage}\n displayValidationMessage={displayValidationMessage}\n onChangeValue={handleChange}\n isLoading={isLoadingAddressDetails}\n hasError={!!error}\n onChangeLabel={setLabel}\n searchDebounceMs={750}\n searchMinCharacters={4}\n onSearch={handleSearch}\n isDirty={isDirty}\n setIsDirty={setIsDirty}\n aria-describedby={ariaDescribedby}\n branding={\n <a className=\"dropdown-item cypress-powered-by-google ob-autocomplete__drop-down-item-powered-by-google\">\n powered by{' '}\n <img src=\"https://developers.google.com/static/maps/documentation/images/google_on_white.png\" />\n </a>\n }\n />\n </FormElementLabelContainer>\n\n {error && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-google-address-details-error-message\">\n {error.toString()}\n </div>\n </div>\n )}\n </div>\n )\n}\n\nexport default React.memo(FormElementGoogleAddress)\n"]}
|
1
|
+
{"version":3,"file":"FormElementGoogleAddress.js","sourceRoot":"","sources":["../../src/form-elements/FormElementGoogleAddress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,oBAAoB,MAAM,6CAA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AAQ,EAC1B,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,iBAAiB,EACpC,wBAAwB,EAAE,wBAAwB,EAClD,aAAa,EAAE,YAAY,EAC3B,SAAS,EAAE,uBAAuB,EAClC,QAAQ,EAAE,CAAC,CAAC,KAAK,EACjB,aAAa,EAAE,QAAQ,EACvB,gBAAgB,EAAE,GAAG,EACrB,mBAAmB,EAAE,CAAC,EACtB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,sBACJ,eAAe,EACjC,QAAQ,EACN,2BAAG,SAAS,EAAC,2FAA2F;;oBAC3F,GAAG;oBACd,6BAAK,GAAG,EAAC,oFAAoF,GAAG,CAC9F,GAEN,CACwB;QAE3B,KAAK,IAAI,CACR,6BAAK,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,kBAAkB;YAC5C,6BAAK,SAAS,EAAC,6EAA6E,IACzF,KAAK,CAAC,OAAO,CACV,CACF,CACP,CACG,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes, GoogleTypes } from '@oneblink/types'\nimport { OneBlinkAppsError, Sentry } from '@oneblink/apps'\n\nimport AutocompleteDropdown from '../components/renderer/AutocompleteDropdown'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport useGoogle from '../hooks/useGoogle'\nimport useIsMounted from '../hooks/useIsMounted'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\n\ntype Props = {\n formId: number\n id: string\n element: FormTypes.GoogleAddressElement\n value: GoogleTypes.GoogleMapsAddress | undefined\n displayValidationMessage: boolean\n validationMessage: string | undefined\n onChange: FormElementValueChangeHandler<GoogleTypes.GoogleMapsAddress>\n} & IsDirtyProps\n\nfunction FormElementGoogleAddress({\n id,\n element,\n value,\n displayValidationMessage,\n validationMessage,\n onChange,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const isMounted = useIsMounted()\n const [label, setLabel] = React.useState('')\n const [error, setError] = React.useState<Error | undefined>()\n const [isLoadingAddressDetails, setIsLoadingAddressDetails] =\n React.useState(false)\n\n const { isLoaded } = useGoogle()\n\n const autocompleteService = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.places.AutocompleteService()\n }\n }, [isLoaded])\n\n const dummyMap = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.Map(document.createElement('div'))\n }\n }, [isLoaded])\n\n const handleSearch = React.useCallback(\n async (input: string, abortSignal: AbortSignal) => {\n setError(undefined)\n if (autocompleteService) {\n const predictions = await new Promise<\n google.maps.places.QueryAutocompletePrediction[]\n >((resolve, reject) => {\n autocompleteService.getQueryPredictions(\n {\n input,\n },\n (predictions, status) => {\n switch (status) {\n case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: {\n resolve([])\n break\n }\n case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {\n reject(\n new OneBlinkAppsError(\n 'Google Maps API key has not been configured correctly',\n ),\n )\n break\n }\n case google.maps.places.PlacesServiceStatus.OK: {\n resolve(predictions ?? [])\n break\n }\n default: {\n reject(\n new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n ),\n )\n }\n }\n },\n )\n }).catch((e) => {\n if (!abortSignal.aborted) {\n Sentry.captureException(e)\n }\n throw e\n })\n\n if (!abortSignal.aborted) {\n return predictions.reduce<Array<{ value: string; label: string }>>(\n (results, prediction) => {\n if (prediction.place_id) {\n results.push({\n value: prediction.place_id,\n label: prediction.description,\n })\n }\n return results\n },\n [],\n )\n }\n }\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n )\n },\n [autocompleteService],\n )\n\n const handleChange = React.useCallback(\n async (placeId: string | undefined) => {\n if (!placeId) {\n onChange(element, { value: undefined })\n return\n }\n\n setIsLoadingAddressDetails(true)\n try {\n //this should not happen, we can't get a place Id without google being present\n if (!isLoaded || !dummyMap) {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: new Error(\n 'Google Places library has not be initialised',\n ),\n },\n )\n }\n\n const placeService = new google.maps.places.PlacesService(dummyMap)\n const place = await new Promise<GoogleTypes.GoogleMapsAddress>(\n (resolve, reject) => {\n placeService.getDetails(\n {\n placeId,\n fields: [\n 'place_id',\n 'formatted_address',\n 'geometry',\n 'address_components',\n ],\n },\n (place, status) => {\n if (\n status !== google.maps.places.PlacesServiceStatus.OK ||\n !place\n ) {\n reject(\n new OneBlinkAppsError(\n `Could not find address details for place with id: ${placeId}`,\n ),\n )\n return\n }\n resolve(place)\n },\n )\n },\n )\n onChange(element, { value: place })\n } catch (newError) {\n if (isMounted.current) {\n setError(newError as Error)\n }\n }\n if (isMounted.current) {\n setIsLoadingAddressDetails(false)\n }\n },\n [isMounted, onChange, element, isLoaded, dummyMap],\n )\n\n // Ensure the label is set if the value is set outside of this component\n React.useEffect(() => {\n if (value) {\n const newLabel = value.formatted_address || value.place_id\n setLabel(newLabel ?? '')\n }\n }, [value])\n\n return (\n <div className=\"cypress-google-address-element\">\n <FormElementLabelContainer\n className=\"ob-google-address ob-autocomplete\"\n element={element}\n id={id}\n required={element.required}\n >\n <AutocompleteDropdown\n id={id}\n label={label}\n disabled={element.readOnly || isLoadingAddressDetails}\n placeholder={element.placeholderValue}\n required={element.required}\n value={value}\n validationMessage={validationMessage}\n displayValidationMessage={displayValidationMessage}\n onChangeValue={handleChange}\n isLoading={isLoadingAddressDetails}\n hasError={!!error}\n onChangeLabel={setLabel}\n searchDebounceMs={750}\n searchMinCharacters={4}\n onSearch={handleSearch}\n isDirty={isDirty}\n setIsDirty={setIsDirty}\n aria-describedby={ariaDescribedby}\n branding={\n <a className=\"dropdown-item cypress-powered-by-google ob-autocomplete__drop-down-item-powered-by-google\">\n powered by{' '}\n <img src=\"https://developers.google.com/static/maps/documentation/images/google_on_white.png\" />\n </a>\n }\n />\n </FormElementLabelContainer>\n\n {error && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-google-address-details-error-message\">\n {error.message}\n </div>\n </div>\n )}\n </div>\n )\n}\n\nexport default React.memo(FormElementGoogleAddress)\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@oneblink/apps-react",
|
3
3
|
"description": "Helper functions for OneBlink apps in ReactJS.",
|
4
|
-
"version": "6.1.0-beta.
|
4
|
+
"version": "6.1.0-beta.4",
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/oneblink/apps-react/issues"
|
@@ -10,7 +10,7 @@
|
|
10
10
|
"@arcgis/core": "~4.29.10",
|
11
11
|
"@emotion/react": "^11.11.3",
|
12
12
|
"@emotion/styled": "^11.11.0",
|
13
|
-
"@oneblink/sdk-core": "^6.2.0-beta.
|
13
|
+
"@oneblink/sdk-core": "^6.2.0-beta.4",
|
14
14
|
"@react-google-maps/api": "2.19.2",
|
15
15
|
"blueimp-load-image": "^5.16.0",
|
16
16
|
"bulma": "^0.9.4",
|