From 874f2f50220f1536b861b2e728a3407cf37975c8 Mon Sep 17 00:00:00 2001 From: tnagorra Date: Fri, 8 Nov 2024 14:25:13 +0545 Subject: [PATCH] Fix bbox not defined issue - Update turf related packages - Add console.error on PageError --- .npmrc | 1 + package.json | 4 +- patches/@turf+bbox+6.5.0.patch | 17 ------ patches/@turf+circle+6.5.0.patch | 17 ------ pnpm-lock.yaml | 61 +++++++++++-------- src/App/PageError/index.tsx | 10 +++ .../AlertInfo/AreaInfoDetail/index.tsx | 8 +-- .../AlertDetails/CountryAlertMap/index.tsx | 7 ++- src/views/Home/AlertsMap/Map/index.tsx | 13 ++-- tsconfig.json | 4 -- 10 files changed, 66 insertions(+), 76 deletions(-) create mode 100644 .npmrc delete mode 100644 patches/@turf+bbox+6.5.0.patch delete mode 100644 patches/@turf+circle+6.5.0.patch diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..6c59086d --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +enable-pre-post-scripts=true diff --git a/package.json b/package.json index 9d2bca11..235977c3 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "@sentry/react": "^7.81.1", "@togglecorp/fujs": "^2.1.1", "@togglecorp/re-map": "^0.2.0-beta-6", - "@turf/bbox": "^6.5.0", - "@turf/circle": "^6.5.0", + "@turf/bbox": "^7.1.0", + "@turf/circle": "^7.1.0", "graphql": "^16.8.1", "mapbox-gl": "^1.13.0", "patch-package": "^8.0.0", diff --git a/patches/@turf+bbox+6.5.0.patch b/patches/@turf+bbox+6.5.0.patch deleted file mode 100644 index 0b113341..00000000 --- a/patches/@turf+bbox+6.5.0.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/node_modules/@turf/bbox/package.json b/node_modules/@turf/bbox/package.json -index 667487d..609ad20 100644 ---- a/node_modules/@turf/bbox/package.json -+++ b/node_modules/@turf/bbox/package.json -@@ -29,11 +29,11 @@ - "exports": { - "./package.json": "./package.json", - ".": { -+ "types": "./dist/js/index.d.ts", - "import": "./dist/es/index.js", - "require": "./dist/js/index.js" - } - }, -- "types": "dist/js/index.d.ts", - "sideEffects": false, - "files": [ - "dist" diff --git a/patches/@turf+circle+6.5.0.patch b/patches/@turf+circle+6.5.0.patch deleted file mode 100644 index 1d5b9e87..00000000 --- a/patches/@turf+circle+6.5.0.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/node_modules/@turf/circle/package.json b/node_modules/@turf/circle/package.json -index 9842f2f..6dd2af8 100644 ---- a/node_modules/@turf/circle/package.json -+++ b/node_modules/@turf/circle/package.json -@@ -29,11 +29,11 @@ - "exports": { - "./package.json": "./package.json", - ".": { -+ "types": "./dist/js/index.d.ts", - "import": "./dist/es/index.js", - "require": "./dist/js/index.js" - } - }, -- "types": "dist/js/index.d.ts", - "sideEffects": false, - "files": [ - "dist" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5553cde..c4195d5e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,11 +36,11 @@ dependencies: specifier: ^0.2.0-beta-6 version: 0.2.0-beta-6(@mapbox/mapbox-gl-draw@1.4.3)(mapbox-gl@1.13.3)(react-dom@18.2.0)(react@18.2.0) '@turf/bbox': - specifier: ^6.5.0 - version: 6.5.0 + specifier: ^7.1.0 + version: 7.1.0 '@turf/circle': - specifier: ^6.5.0 - version: 6.5.0 + specifier: ^7.1.0 + version: 7.1.0 graphql: specifier: ^16.8.1 version: 16.8.1 @@ -3298,41 +3298,53 @@ packages: resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} dev: true - /@turf/bbox@6.5.0: - resolution: {integrity: sha512-RBbLaao5hXTYyyg577iuMtDB8ehxMlUqHEJiMs8jT1GHkFhr6sYre3lmLsPeYEi/ZKj5TP5tt7fkzNdJ4GIVyw==} + /@turf/bbox@7.1.0: + resolution: {integrity: sha512-PdWPz9tW86PD78vSZj2fiRaB8JhUHy6piSa/QXb83lucxPK+HTAdzlDQMTKj5okRCU8Ox/25IR2ep9T8NdopRA==} dependencies: - '@turf/helpers': 6.5.0 - '@turf/meta': 6.5.0 + '@turf/helpers': 7.1.0 + '@turf/meta': 7.1.0 + '@types/geojson': 7946.0.14 + tslib: 2.6.2 dev: false - /@turf/circle@6.5.0: - resolution: {integrity: sha512-oU1+Kq9DgRnoSbWFHKnnUdTmtcRUMmHoV9DjTXu9vOLNV5OWtAAh1VZ+mzsioGGzoDNT/V5igbFOkMfBQc0B6A==} + /@turf/circle@7.1.0: + resolution: {integrity: sha512-6qhF1drjwH0Dg3ZB9om1JkWTJfAqBcbtIrAj5UPlrAeHP87hGoCO2ZEsFEAL9Q18vntpivT89Uho/nqQUjJhYw==} dependencies: - '@turf/destination': 6.5.0 - '@turf/helpers': 6.5.0 + '@turf/destination': 7.1.0 + '@turf/helpers': 7.1.0 + '@types/geojson': 7946.0.14 + tslib: 2.6.2 dev: false - /@turf/destination@6.5.0: - resolution: {integrity: sha512-4cnWQlNC8d1tItOz9B4pmJdWpXqS0vEvv65bI/Pj/genJnsL7evI0/Xw42RvEGROS481MPiU80xzvwxEvhQiMQ==} + /@turf/destination@7.1.0: + resolution: {integrity: sha512-97XuvB0iaAiMg86hrnZ529WwP44TQAA9mmI5PMlchACiA4LFrEtWjjDzvO6234coieoqhrw6dZYcJvd5O2PwrQ==} dependencies: - '@turf/helpers': 6.5.0 - '@turf/invariant': 6.5.0 + '@turf/helpers': 7.1.0 + '@turf/invariant': 7.1.0 + '@types/geojson': 7946.0.14 + tslib: 2.6.2 dev: false - /@turf/helpers@6.5.0: - resolution: {integrity: sha512-VbI1dV5bLFzohYYdgqwikdMVpe7pJ9X3E+dlr425wa2/sMJqYDhTO++ec38/pcPvPE6oD9WEEeU3Xu3gza+VPw==} + /@turf/helpers@7.1.0: + resolution: {integrity: sha512-dTeILEUVeNbaEeoZUOhxH5auv7WWlOShbx7QSd4s0T4Z0/iz90z9yaVCtZOLbU89umKotwKaJQltBNO9CzVgaQ==} + dependencies: + '@types/geojson': 7946.0.14 + tslib: 2.6.2 dev: false - /@turf/invariant@6.5.0: - resolution: {integrity: sha512-Wv8PRNCtPD31UVbdJE/KVAWKe7l6US+lJItRR/HOEW3eh+U/JwRCSUl/KZ7bmjM/C+zLNoreM2TU6OoLACs4eg==} + /@turf/invariant@7.1.0: + resolution: {integrity: sha512-OCLNqkItBYIP1nE9lJGuIUatWGtQ4rhBKAyTfFu0z8npVzGEYzvguEeof8/6LkKmTTEHW53tCjoEhSSzdRh08Q==} dependencies: - '@turf/helpers': 6.5.0 + '@turf/helpers': 7.1.0 + '@types/geojson': 7946.0.14 + tslib: 2.6.2 dev: false - /@turf/meta@6.5.0: - resolution: {integrity: sha512-RrArvtsV0vdsCBegoBtOalgdSOfkBrTJ07VkpiCnq/491W67hnMWmDu7e6Ztw0C3WldRYTXkg3SumfdzZxLBHA==} + /@turf/meta@7.1.0: + resolution: {integrity: sha512-ZgGpWWiKz797Fe8lfRj7HKCkGR+nSJ/5aKXMyofCvLSc2PuYJs/qyyifDPWjASQQCzseJ7AlF2Pc/XQ/3XkkuA==} dependencies: - '@turf/helpers': 6.5.0 + '@turf/helpers': 7.1.0 + '@types/geojson': 7946.0.14 dev: false /@types/estree@1.0.5: @@ -3341,7 +3353,6 @@ packages: /@types/geojson@7946.0.14: resolution: {integrity: sha512-WCfD5Ht3ZesJUsONdhvm84dmzWOiOzOAqOncN0++w0lBw1o8OuDNJF2McvvCef/yBqb/HYRahp1BYtODFQ8bRg==} - dev: true /@types/history@4.7.11: resolution: {integrity: sha512-qjDJRrmvBMiTx+jyLxvLfJU7UznFuokDv4f3WRuriHKERccVpFU+8XMQUAbDzoiJCsmexxRExQeMwwCdamSKDA==} diff --git a/src/App/PageError/index.tsx b/src/App/PageError/index.tsx index 819968ec..9a5ad391 100644 --- a/src/App/PageError/index.tsx +++ b/src/App/PageError/index.tsx @@ -1,8 +1,18 @@ +import { useEffect } from 'react'; import { useRouteError } from 'react-router-dom'; function PageError() { // eslint-disable-next-line @typescript-eslint/no-explicit-any const error = useRouteError() as unknown as any; + + useEffect( + () => { + // eslint-disable-next-line no-console + console.error(error); + }, + [error], + ); + return (

{error.statusText || error.message} diff --git a/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx b/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx index 18e5e7be..c6074fca 100644 --- a/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx +++ b/src/views/AlertDetails/AlertInfo/AreaInfoDetail/index.tsx @@ -176,7 +176,7 @@ function AreaInfoDetail(props: Props) { const [latStr, lonStr] = centerStr.split(','); const options = { steps: 50, - units: 'kilometers', + units: 'kilometers' as const, }; const point = [+latStr, +lonStr]; @@ -203,13 +203,13 @@ function AreaInfoDetail(props: Props) { [selectedFeatureDetails], ); - const selectedPolygonBounds = useMemo(() => { + const selectedPolygonBounds = useMemo((): LngLatBoundsLike => { if (isDefined(selectedPolygon)) { - return getBbox(selectedPolygon.boundary); + return getBbox(selectedPolygon.boundary) as LngLatBoundsLike; } if (isDefined(selectedCircle)) { - return getBbox(selectedCircle.boundary); + return getBbox(selectedCircle.boundary) as LngLatBoundsLike; } return defaultBounds; diff --git a/src/views/AlertDetails/CountryAlertMap/index.tsx b/src/views/AlertDetails/CountryAlertMap/index.tsx index cf83bed3..07bc9bf0 100644 --- a/src/views/AlertDetails/CountryAlertMap/index.tsx +++ b/src/views/AlertDetails/CountryAlertMap/index.tsx @@ -9,7 +9,10 @@ import { MapLayer, } from '@togglecorp/re-map'; import getBbox from '@turf/bbox'; -import type { FillLayer } from 'mapbox-gl'; +import type { + FillLayer, + LngLatBoundsLike, +} from 'mapbox-gl'; import BaseMap from '#components/domain/BaseMap'; import { AlertDetailsQuery } from '#generated/types/graphql'; @@ -70,7 +73,7 @@ function CountryAlertMap(props: Props) { }, [data]); const bounds = useMemo(() => ( - data?.country ? getBbox(data?.country.bbox) : undefined + data?.country ? getBbox(data.country.bbox) as LngLatBoundsLike : undefined ), [data?.country]); return ( diff --git a/src/views/Home/AlertsMap/Map/index.tsx b/src/views/Home/AlertsMap/Map/index.tsx index a3b0ece8..5ee880d6 100644 --- a/src/views/Home/AlertsMap/Map/index.tsx +++ b/src/views/Home/AlertsMap/Map/index.tsx @@ -25,7 +25,6 @@ import { import getBbox from '@turf/bbox'; import { type FillLayer, - LngLatBoundsLike, MapboxGeoJSONFeature, } from 'mapbox-gl'; @@ -47,7 +46,7 @@ import AlertDataContext from '../../AlertDataContext'; import styles from './styles.module.css'; -const defaultBounds: LngLatBoundsLike = [-160, -60, 190, 80]; +const defaultBounds: [number, number, number, number] = [-160, -60, 190, 80]; interface MapMinZoomProps { zoom: number; @@ -166,16 +165,20 @@ function Map(props: Props) { ); const bounds = useMemo( - () => { + (): [number, number, number, number] => { if (isDefined(activeAdmin1Id) && isDefined(activeAdmin1Details?.public.admin1?.bbox)) { - return getBbox(activeAdmin1Details?.public.admin1?.bbox); + return getBbox( + activeAdmin1Details?.public.admin1?.bbox, + ) as [number, number, number, number]; } if ( isDefined(activeCountryId) && isDefined(activeCountryDetails?.public.country?.bbox) ) { - return getBbox(activeCountryDetails?.public.country?.bbox); + return getBbox( + activeCountryDetails?.public.country?.bbox, + ) as [number, number, number, number]; } return defaultBounds; diff --git a/tsconfig.json b/tsconfig.json index 881ff0d6..50236aba 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,6 @@ { "compilerOptions": { "paths": { - /* Issue with turf library https://github.com/Turfjs/turf/issues/2598#issuecomment-2084656403 */ - "@turf/bbox": ["./node_modules/@turf/bbox/dist/js/index.d.ts"], - "@turf/circle": ["./node_modules/@turf/circle/dist/js/index.d.ts"], - "#generated/*": ["./generated/*"], "#assets/*": ["./src/assets/*"], "#components/*": ["./src/components/*"],