From a3490f0f47397c49f197f2589b375cc93ab033e0 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Fri, 18 Nov 2022 19:54:49 +0530 Subject: [PATCH 1/8] fix: if particular platlocation is already selected than disable pop up --- src/features/projects/components/ProjectsMap.tsx | 6 +++++- src/features/projects/components/maps/Location.tsx | 2 +- src/features/projects/styles/PlantLocation.module.scss | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index a06f6f70e5..258036bb91 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -204,7 +204,11 @@ export default function ProjectsMap(): ReactElement { offsetTop={-5} tipSize={0} > -
{t('clickForDetails')}
+ {selectedPl?.hid !== hoveredPl?.hid && ( +
+ {t('clickForDetails')} +
+ )} )} diff --git a/src/features/projects/components/maps/Location.tsx b/src/features/projects/components/maps/Location.tsx index 29f4cdd28c..5d2186a9eb 100644 --- a/src/features/projects/components/maps/Location.tsx +++ b/src/features/projects/components/maps/Location.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Layer, Marker, Source } from 'react-map-gl'; +import { Marker } from 'react-map-gl'; import styles from '../../styles/ProjectsMap.module.scss'; import ProjectPolygon from './ProjectPolygon'; diff --git a/src/features/projects/styles/PlantLocation.module.scss b/src/features/projects/styles/PlantLocation.module.scss index da1f31e337..0b93013fcf 100644 --- a/src/features/projects/styles/PlantLocation.module.scss +++ b/src/features/projects/styles/PlantLocation.module.scss @@ -131,7 +131,7 @@ position: absolute; z-index: 1; &.singleSelected { - background-color: rgba(0, 122, 73, 1); + background-color: rgb(2, 90, 55); } } From 4c1700afa1438ad021b52245216fd66cb1143090 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Sun, 20 Nov 2022 20:36:26 +0530 Subject: [PATCH 2/8] fix: samplePlantLocation bug --- src/features/projects/components/maps/PlantLocations.tsx | 3 ++- src/features/projects/components/maps/Project.tsx | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/features/projects/components/maps/PlantLocations.tsx b/src/features/projects/components/maps/PlantLocations.tsx index 2654e9a4a3..a5d19c6ee2 100644 --- a/src/features/projects/components/maps/PlantLocations.tsx +++ b/src/features/projects/components/maps/PlantLocations.tsx @@ -25,6 +25,7 @@ export default function PlantLocations({}: Props): ReactElement { const { i18n, t } = useTranslation(['maps', 'common']); const openPl = (pl: any) => { + console.log('i ran'); setSelectedPl(pl); }; @@ -186,7 +187,7 @@ export default function PlantLocations({}: Props): ReactElement {
{ - if (plantLocations && selectedPl) { - setPlantPolygonCoordinates(selectedPl?.geometry.coordinates[0]); + if (!selectedPl?.parent) { + if (plantLocations && selectedPl) { + setPlantPolygonCoordinates(selectedPl?.geometry.coordinates[0]); + } } }, [router, selectedPl, plantLocations]); @@ -78,6 +81,7 @@ export default function Project({ 4000 ); } else if ( + !selectedPl?.parent && plantPolygonCoordinates && plantLocations && router.query.ploc && From 140c9f4bb4096f063d8e4aa11b4d203ce9af580a Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Thu, 24 Nov 2022 18:22:05 +0530 Subject: [PATCH 3/8] fix: sample tree appear only on hover --- .../common/Layout/ProjectPropsContext.tsx | 5 +++++ .../PlantLocation/PlantLocationDetails.tsx | 4 ++-- .../projects/components/ProjectsMap.tsx | 17 +++++++++++------ .../projects/components/maps/PlantLocations.tsx | 9 ++++----- .../projects/components/maps/Project.tsx | 6 +++--- .../projects/screens/SingleProjectDetails.tsx | 7 ++++++- .../projects/styles/PlantLocation.module.scss | 2 +- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/features/common/Layout/ProjectPropsContext.tsx b/src/features/common/Layout/ProjectPropsContext.tsx index 59ec1b8372..6b7fa8f08e 100644 --- a/src/features/common/Layout/ProjectPropsContext.tsx +++ b/src/features/common/Layout/ProjectPropsContext.tsx @@ -61,6 +61,8 @@ export const ProjectPropsContext = React.createContext({ setPlantLocations: (value: []) => {}, selectedPl: {}, setSelectedPl: (value: {}) => {}, + samplePlantLocation: {}, + setSamplePlantLocation: (value: {}) => {}, zoomLevel: 1, setZoomLevel: (value: number) => {}, satellite: false, @@ -88,6 +90,7 @@ function ProjectPropsProvider({ children }: any): ReactElement { const [project, setProject] = React.useState(null); const [plantLocations, setPlantLocations] = React.useState(null); const [selectedPl, setSelectedPl] = React.useState(null); + const [samplePlantLocation, setSamplePlantLocation] = React.useState(null); const [zoomLevel, setZoomLevel] = React.useState(1); const [showProjects, setShowProjects] = React.useState(true); const [showSingleProject, setShowSingleProject] = React.useState(false); @@ -281,6 +284,8 @@ function ProjectPropsProvider({ children }: any): ReactElement { setPlantLocations, selectedPl, setSelectedPl, + samplePlantLocation, + setSamplePlantLocation, zoomLevel, setZoomLevel, satellite, diff --git a/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx b/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx index d30dd750da..8ded556893 100644 --- a/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx +++ b/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx @@ -31,7 +31,7 @@ interface Props { export default function PlantLocationDetails({ plantLocation, }: Props): ReactElement { - const { setSelectedPl, plantLocations } = + const { setSelectedPl, plantLocations, setSamplePlantLocation } = React.useContext(ProjectPropsContext); const { t, i18n } = useTranslation(['maps']); const [treeCount, setTreeCount] = React.useState(1); @@ -102,7 +102,7 @@ export default function PlantLocationDetails({ ) ) { const element = plantLocation.samplePlantLocations[key]; - if (element.id === id) setSelectedPl(element); + if (element.id === id) setSamplePlantLocation(element); } } } diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index 258036bb91..ffaf08889f 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -43,6 +43,8 @@ export default function ProjectsMap(): ReactElement { hoveredPl, setIsPolygonMenuOpen, setFilterOpen, + setSamplePlantLocation, + samplePlantLocation, } = React.useContext(ProjectPropsContext); const { t } = useTranslation(['maps']); @@ -90,10 +92,9 @@ export default function ProjectsMap(): ReactElement { mapState, setMapState, }; - + // console.log(selectedPl, samplePlantLocation, 'step1'); const onMapClick = (e: MapEvent) => { - setSelectedPl(null); - setHoveredPl(null); + setSamplePlantLocation(null); setPopupData({ ...popupData, show: false }); setIsPolygonMenuOpen(false); setFilterOpen(false); @@ -103,7 +104,11 @@ export default function ProjectsMap(): ReactElement { if (Object.prototype.hasOwnProperty.call(plantLocations, key)) { const element = plantLocations[key]; if (element.id === e.features[0].layer?.source) { - setSelectedPl(element); + if (element?.tag) { + setSamplePlantLocation(element); + } else { + setSelectedPl(element); + } break; } @@ -167,7 +172,7 @@ export default function ProjectsMap(): ReactElement { onViewportChange={_onViewportChange} onStateChange={_onStateChange} onClick={onMapClick} - onHover={plIds ? onMapHover : undefined} + onHover={onMapHover} onLoad={() => setLoaded(true)} interactiveLayerIds={plIds ? plIds : undefined} > @@ -204,7 +209,7 @@ export default function ProjectsMap(): ReactElement { offsetTop={-5} tipSize={0} > - {selectedPl?.hid !== hoveredPl?.hid && ( + {!(selectedPl?.hid === hoveredPl?.hid) && (
{t('clickForDetails')}
diff --git a/src/features/projects/components/maps/PlantLocations.tsx b/src/features/projects/components/maps/PlantLocations.tsx index a5d19c6ee2..d0a42b18f4 100644 --- a/src/features/projects/components/maps/PlantLocations.tsx +++ b/src/features/projects/components/maps/PlantLocations.tsx @@ -2,7 +2,6 @@ import React, { ReactElement } from 'react'; import { Layer, Marker } from 'react-map-gl'; import { Source } from 'react-map-gl'; import { ProjectPropsContext } from '../../../common/Layout/ProjectPropsContext'; -import { useRouter } from 'next/router'; import styles from '../../styles/PlantLocation.module.scss'; import * as turf from '@turf/turf'; import { localizedAbbreviatedNumber } from '../../../../utils/getFormattedNumber'; @@ -11,7 +10,6 @@ import { useTranslation } from 'next-i18next'; interface Props {} export default function PlantLocations({}: Props): ReactElement { - const router = useRouter(); const { plantLocations, hoveredPl, @@ -20,13 +18,14 @@ export default function PlantLocations({}: Props): ReactElement { setHoveredPl, viewport, satellite, + setSamplePlantLocation, + samplePlantLocation, } = React.useContext(ProjectPropsContext); const { i18n, t } = useTranslation(['maps', 'common']); const openPl = (pl: any) => { - console.log('i ran'); - setSelectedPl(pl); + setSamplePlantLocation(pl); }; const onHover = (pl: Object) => { @@ -187,7 +186,7 @@ export default function PlantLocations({}: Props): ReactElement {
{ - if (selectedPl && plantPolygonCoordinates) { + if (selectedPl && plantPolygonCoordinates && !selectedPl?.parent) { router.push(`/${project.slug}?ploc=${selectedPl?.hid}`); } }, [selectedPl, plantPolygonCoordinates]); diff --git a/src/features/projects/screens/SingleProjectDetails.tsx b/src/features/projects/screens/SingleProjectDetails.tsx index 603184aa04..25182f66dc 100644 --- a/src/features/projects/screens/SingleProjectDetails.tsx +++ b/src/features/projects/screens/SingleProjectDetails.tsx @@ -49,6 +49,7 @@ function SingleProjectDetails({}: Props): ReactElement { selectedPl, setHoveredPl, setSelectedPl, + samplePlantLocation, } = useContext(ProjectPropsContext); const screenWidth = window.innerWidth; const screenHeight = window.innerHeight; @@ -82,7 +83,11 @@ function SingleProjectDetails({}: Props): ReactElement { }; const ProjectProps = { - plantLocation: hoveredPl ? hoveredPl : selectedPl, + plantLocation: hoveredPl + ? hoveredPl + : samplePlantLocation + ? samplePlantLocation + : selectedPl, }; const goBack = () => { diff --git a/src/features/projects/styles/PlantLocation.module.scss b/src/features/projects/styles/PlantLocation.module.scss index 0b93013fcf..c992476791 100644 --- a/src/features/projects/styles/PlantLocation.module.scss +++ b/src/features/projects/styles/PlantLocation.module.scss @@ -131,7 +131,7 @@ position: absolute; z-index: 1; &.singleSelected { - background-color: rgb(2, 90, 55); + background-color: rgba(0, 122, 73, 1); } } From e9feeadb31d35b12db1abc681ce77dcf5c16b27a Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Thu, 24 Nov 2022 18:39:57 +0530 Subject: [PATCH 4/8] fix: sample plant location --- src/features/projects/components/ProjectsMap.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index ffaf08889f..b22593f638 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -92,7 +92,7 @@ export default function ProjectsMap(): ReactElement { mapState, setMapState, }; - // console.log(selectedPl, samplePlantLocation, 'step1'); + const onMapClick = (e: MapEvent) => { setSamplePlantLocation(null); setPopupData({ ...popupData, show: false }); @@ -172,7 +172,7 @@ export default function ProjectsMap(): ReactElement { onViewportChange={_onViewportChange} onStateChange={_onStateChange} onClick={onMapClick} - onHover={onMapHover} + onHover={selectedPl ? undefined : onMapHover} onLoad={() => setLoaded(true)} interactiveLayerIds={plIds ? plIds : undefined} > From 9f01715873b0218914b4bfd3d2ebd9b8e6da9ee2 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:45:24 +0530 Subject: [PATCH 5/8] fix: click on detail popup --- .../components/PlantLocation/PlantLocationDetails.tsx | 10 ++++++++-- src/features/projects/components/ProjectsMap.tsx | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx b/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx index 8ded556893..dc3757a33e 100644 --- a/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx +++ b/src/features/projects/components/PlantLocation/PlantLocationDetails.tsx @@ -31,8 +31,12 @@ interface Props { export default function PlantLocationDetails({ plantLocation, }: Props): ReactElement { - const { setSelectedPl, plantLocations, setSamplePlantLocation } = - React.useContext(ProjectPropsContext); + const { + setSelectedPl, + plantLocations, + setSamplePlantLocation, + setHoveredPl, + } = React.useContext(ProjectPropsContext); const { t, i18n } = useTranslation(['maps']); const [treeCount, setTreeCount] = React.useState(1); const [plantationArea, setPlantationArea] = React.useState(0); @@ -93,6 +97,7 @@ export default function PlantLocationDetails({ }, [plantLocation]); const openSampleTree = (id: any) => { + setHoveredPl(null); if (plantLocation && plantLocation.samplePlantLocations) { for (const key in plantLocation.samplePlantLocations) { if ( @@ -102,6 +107,7 @@ export default function PlantLocationDetails({ ) ) { const element = plantLocation.samplePlantLocations[key]; + if (element.id === id) setSamplePlantLocation(element); } } diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index b22593f638..70d879d98d 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -172,7 +172,7 @@ export default function ProjectsMap(): ReactElement { onViewportChange={_onViewportChange} onStateChange={_onStateChange} onClick={onMapClick} - onHover={selectedPl ? undefined : onMapHover} + onHover={onMapHover} onLoad={() => setLoaded(true)} interactiveLayerIds={plIds ? plIds : undefined} > @@ -209,7 +209,7 @@ export default function ProjectsMap(): ReactElement { offsetTop={-5} tipSize={0} > - {!(selectedPl?.hid === hoveredPl?.hid) && ( + {hoveredPl?.hid && selectedPl?.hid !== hoveredPl?.hid && (
{t('clickForDetails')}
From 96e48e4069778e62e4d2fa87d41029aa318d568a Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Mon, 28 Nov 2022 20:16:20 +0530 Subject: [PATCH 6/8] typescript for samplePlantlocation --- .../common/Layout/ProjectPropsContext.tsx | 8 +- src/features/common/types/project.d.ts | 117 ++++++++++++++++++ .../projects/components/ProjectsMap.tsx | 10 +- .../projects/components/maps/Project.tsx | 1 - 4 files changed, 123 insertions(+), 13 deletions(-) diff --git a/src/features/common/Layout/ProjectPropsContext.tsx b/src/features/common/Layout/ProjectPropsContext.tsx index 6b7fa8f08e..50f14f1db5 100644 --- a/src/features/common/Layout/ProjectPropsContext.tsx +++ b/src/features/common/Layout/ProjectPropsContext.tsx @@ -1,5 +1,6 @@ import React, { ReactElement } from 'react'; import { ParamsContext } from './QueryParamsContext'; +import { SamplePlantLocation } from '../../../../src/features/common/types/project'; interface Props {} @@ -61,8 +62,8 @@ export const ProjectPropsContext = React.createContext({ setPlantLocations: (value: []) => {}, selectedPl: {}, setSelectedPl: (value: {}) => {}, - samplePlantLocation: {}, - setSamplePlantLocation: (value: {}) => {}, + samplePlantLocation: {} || null, + setSamplePlantLocation: (value: SamplePlantLocation) => undefined, zoomLevel: 1, setZoomLevel: (value: number) => {}, satellite: false, @@ -90,7 +91,8 @@ function ProjectPropsProvider({ children }: any): ReactElement { const [project, setProject] = React.useState(null); const [plantLocations, setPlantLocations] = React.useState(null); const [selectedPl, setSelectedPl] = React.useState(null); - const [samplePlantLocation, setSamplePlantLocation] = React.useState(null); + const [samplePlantLocation, setSamplePlantLocation] = + React.useState(null); const [zoomLevel, setZoomLevel] = React.useState(1); const [showProjects, setShowProjects] = React.useState(true); const [showSingleProject, setShowSingleProject] = React.useState(false); diff --git a/src/features/common/types/project.d.ts b/src/features/common/types/project.d.ts index 4d333cc03c..d8e52da6bf 100644 --- a/src/features/common/types/project.d.ts +++ b/src/features/common/types/project.d.ts @@ -50,3 +50,120 @@ export interface LastUpdated { } +// for sample plant location + + export interface DeviceLocation { + coordinates: number[]; + type: string; + } + + export interface App { + appVersion: string; + deviceSystemName: string; + deviceSystemVersion: string; + deviceModel: string; + deviceManufacturer: string; + deviceBrand: string; + deviceLocation: DeviceLocation; + } + + export interface Metadata { + app: App; + private: any[]; + public: any[]; + } + + export interface Measurements { + width: number; + height: number; + } + + export interface Coordinate { + image: string; + created: string; + coordinateIndex: string; + id: string; + updated: string; + status: string; + } + + export interface EventDate { + date: string; + timezone: string; + timezone_type: number; + } + + export interface Measurements2 { + width: number; + height: number; + } + + export interface History { + image: string; + statusReason?: any; + created: string; + eventName: string; + classification?: any; + eventDate: EventDate; + measurements: Measurements2; + status: string; + } + + export interface OriginalGeometry { + coordinates: number[]; + type: string; + } + + export interface Geometry { + coordinates: number[]; + type: string; + } + + export interface LastMeasurementDate { + date: string; + timezone: string; + timezone_type: number; + } + + export interface DeviceLocation2 { + coordinates: number[]; + type: string; + } + + export interface NextMeasurementDate { + date: string; + timezone: string; + timezone_type : number; +} + + export interface SamplePlantLocation { + parent: string; + nextMeasurementDate?: NextMeasurementDate | null; + metadata: Metadata; + hid: string; + scientificName: string; + otherSpecies?: any; + description?: any; + geometryUpdatesCount: number; + type: string; + plantProjectSite?: any; + statusReason?: any; + registrationDate: string; + id: string; + tag: string; + plantDate: string; + measurements: Measurements; + image?: any; + idempotencyKey: string; + profile: string; + coordinates: Coordinate[]; + scientificSpecies: string; + history: History[]; + originalGeometry: OriginalGeometry; + captureMode: string; + geometry: Geometry; + lastMeasurementDate: LastMeasurementDate; + captureStatus: string; + deviceLocation: DeviceLocation2; + status?: any; + } \ No newline at end of file diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index 70d879d98d..f61a916050 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -15,18 +15,13 @@ import { ParamsContext } from '../../common/Layout/QueryParamsContext'; export default function ProjectsMap(): ReactElement { const { project, - showSingleProject, showProjects, - setShowProjects, searchedProject, viewport, setViewPort, - setExploreProjects, mapState, setMapState, isMobile, - exploreProjects, - loaded, setLoaded, mapRef, defaultMapCenter, @@ -44,7 +39,6 @@ export default function ProjectsMap(): ReactElement { setIsPolygonMenuOpen, setFilterOpen, setSamplePlantLocation, - samplePlantLocation, } = React.useContext(ProjectPropsContext); const { t } = useTranslation(['maps']); @@ -104,9 +98,7 @@ export default function ProjectsMap(): ReactElement { if (Object.prototype.hasOwnProperty.call(plantLocations, key)) { const element = plantLocations[key]; if (element.id === e.features[0].layer?.source) { - if (element?.tag) { - setSamplePlantLocation(element); - } else { + if (!element?.tag) { setSelectedPl(element); } diff --git a/src/features/projects/components/maps/Project.tsx b/src/features/projects/components/maps/Project.tsx index 15d4df4b93..bb6e42f3ec 100644 --- a/src/features/projects/components/maps/Project.tsx +++ b/src/features/projects/components/maps/Project.tsx @@ -30,7 +30,6 @@ export default function Project({ setRasterData, isMobile, setSiteViewPort, - samplePlantLocation, } = React.useContext(ProjectPropsContext); const { handleError } = React.useContext(ErrorHandlingContext); From 61c36a844518e6caf62044f0bee98f012c756181 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Fri, 13 Jan 2023 08:56:51 +0530 Subject: [PATCH 7/8] Revert "typescript for samplePlantlocation" This reverts commit 96e48e4069778e62e4d2fa87d41029aa318d568a. --- .../common/Layout/ProjectPropsContext.tsx | 8 +- src/features/common/types/project.d.ts | 117 ------------------ .../projects/components/ProjectsMap.tsx | 10 +- .../projects/components/maps/Project.tsx | 1 + 4 files changed, 13 insertions(+), 123 deletions(-) diff --git a/src/features/common/Layout/ProjectPropsContext.tsx b/src/features/common/Layout/ProjectPropsContext.tsx index 50f14f1db5..6b7fa8f08e 100644 --- a/src/features/common/Layout/ProjectPropsContext.tsx +++ b/src/features/common/Layout/ProjectPropsContext.tsx @@ -1,6 +1,5 @@ import React, { ReactElement } from 'react'; import { ParamsContext } from './QueryParamsContext'; -import { SamplePlantLocation } from '../../../../src/features/common/types/project'; interface Props {} @@ -62,8 +61,8 @@ export const ProjectPropsContext = React.createContext({ setPlantLocations: (value: []) => {}, selectedPl: {}, setSelectedPl: (value: {}) => {}, - samplePlantLocation: {} || null, - setSamplePlantLocation: (value: SamplePlantLocation) => undefined, + samplePlantLocation: {}, + setSamplePlantLocation: (value: {}) => {}, zoomLevel: 1, setZoomLevel: (value: number) => {}, satellite: false, @@ -91,8 +90,7 @@ function ProjectPropsProvider({ children }: any): ReactElement { const [project, setProject] = React.useState(null); const [plantLocations, setPlantLocations] = React.useState(null); const [selectedPl, setSelectedPl] = React.useState(null); - const [samplePlantLocation, setSamplePlantLocation] = - React.useState(null); + const [samplePlantLocation, setSamplePlantLocation] = React.useState(null); const [zoomLevel, setZoomLevel] = React.useState(1); const [showProjects, setShowProjects] = React.useState(true); const [showSingleProject, setShowSingleProject] = React.useState(false); diff --git a/src/features/common/types/project.d.ts b/src/features/common/types/project.d.ts index d8e52da6bf..4d333cc03c 100644 --- a/src/features/common/types/project.d.ts +++ b/src/features/common/types/project.d.ts @@ -50,120 +50,3 @@ export interface LastUpdated { } -// for sample plant location - - export interface DeviceLocation { - coordinates: number[]; - type: string; - } - - export interface App { - appVersion: string; - deviceSystemName: string; - deviceSystemVersion: string; - deviceModel: string; - deviceManufacturer: string; - deviceBrand: string; - deviceLocation: DeviceLocation; - } - - export interface Metadata { - app: App; - private: any[]; - public: any[]; - } - - export interface Measurements { - width: number; - height: number; - } - - export interface Coordinate { - image: string; - created: string; - coordinateIndex: string; - id: string; - updated: string; - status: string; - } - - export interface EventDate { - date: string; - timezone: string; - timezone_type: number; - } - - export interface Measurements2 { - width: number; - height: number; - } - - export interface History { - image: string; - statusReason?: any; - created: string; - eventName: string; - classification?: any; - eventDate: EventDate; - measurements: Measurements2; - status: string; - } - - export interface OriginalGeometry { - coordinates: number[]; - type: string; - } - - export interface Geometry { - coordinates: number[]; - type: string; - } - - export interface LastMeasurementDate { - date: string; - timezone: string; - timezone_type: number; - } - - export interface DeviceLocation2 { - coordinates: number[]; - type: string; - } - - export interface NextMeasurementDate { - date: string; - timezone: string; - timezone_type : number; -} - - export interface SamplePlantLocation { - parent: string; - nextMeasurementDate?: NextMeasurementDate | null; - metadata: Metadata; - hid: string; - scientificName: string; - otherSpecies?: any; - description?: any; - geometryUpdatesCount: number; - type: string; - plantProjectSite?: any; - statusReason?: any; - registrationDate: string; - id: string; - tag: string; - plantDate: string; - measurements: Measurements; - image?: any; - idempotencyKey: string; - profile: string; - coordinates: Coordinate[]; - scientificSpecies: string; - history: History[]; - originalGeometry: OriginalGeometry; - captureMode: string; - geometry: Geometry; - lastMeasurementDate: LastMeasurementDate; - captureStatus: string; - deviceLocation: DeviceLocation2; - status?: any; - } \ No newline at end of file diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index f61a916050..70d879d98d 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -15,13 +15,18 @@ import { ParamsContext } from '../../common/Layout/QueryParamsContext'; export default function ProjectsMap(): ReactElement { const { project, + showSingleProject, showProjects, + setShowProjects, searchedProject, viewport, setViewPort, + setExploreProjects, mapState, setMapState, isMobile, + exploreProjects, + loaded, setLoaded, mapRef, defaultMapCenter, @@ -39,6 +44,7 @@ export default function ProjectsMap(): ReactElement { setIsPolygonMenuOpen, setFilterOpen, setSamplePlantLocation, + samplePlantLocation, } = React.useContext(ProjectPropsContext); const { t } = useTranslation(['maps']); @@ -98,7 +104,9 @@ export default function ProjectsMap(): ReactElement { if (Object.prototype.hasOwnProperty.call(plantLocations, key)) { const element = plantLocations[key]; if (element.id === e.features[0].layer?.source) { - if (!element?.tag) { + if (element?.tag) { + setSamplePlantLocation(element); + } else { setSelectedPl(element); } diff --git a/src/features/projects/components/maps/Project.tsx b/src/features/projects/components/maps/Project.tsx index bb6e42f3ec..15d4df4b93 100644 --- a/src/features/projects/components/maps/Project.tsx +++ b/src/features/projects/components/maps/Project.tsx @@ -30,6 +30,7 @@ export default function Project({ setRasterData, isMobile, setSiteViewPort, + samplePlantLocation, } = React.useContext(ProjectPropsContext); const { handleError } = React.useContext(ErrorHandlingContext); From 27222c1a5329f6c0f8a092cefb1689f098401a7b Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Fri, 13 Jan 2023 14:21:19 +0530 Subject: [PATCH 8/8] refactor: remove unwanted condition --- src/features/projects/components/ProjectsMap.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/features/projects/components/ProjectsMap.tsx b/src/features/projects/components/ProjectsMap.tsx index 70d879d98d..70b39d821d 100644 --- a/src/features/projects/components/ProjectsMap.tsx +++ b/src/features/projects/components/ProjectsMap.tsx @@ -104,11 +104,7 @@ export default function ProjectsMap(): ReactElement { if (Object.prototype.hasOwnProperty.call(plantLocations, key)) { const element = plantLocations[key]; if (element.id === e.features[0].layer?.source) { - if (element?.tag) { - setSamplePlantLocation(element); - } else { - setSelectedPl(element); - } + setSelectedPl(element); break; }