From 94577ad562b1339b9b5b80e82b64d8d389fefaa8 Mon Sep 17 00:00:00 2001 From: Limber Mamani <154026979+LimberHope@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:07:22 -0400 Subject: [PATCH] [TM-1467] add default value tu dropwdown analysis (#740) --- .../MonitoredTab/components/DataCard.tsx | 20 ++++++++++--------- .../MonitoredTab/hooks/useMonitoredData.ts | 8 +------- .../extensive/Modal/ModalRunAnalysis.tsx | 18 ++++++++++------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/admin/components/ResourceTabs/MonitoredTab/components/DataCard.tsx b/src/admin/components/ResourceTabs/MonitoredTab/components/DataCard.tsx index 31eb0016..ec11136f 100644 --- a/src/admin/components/ResourceTabs/MonitoredTab/components/DataCard.tsx +++ b/src/admin/components/ResourceTabs/MonitoredTab/components/DataCard.tsx @@ -77,7 +77,15 @@ export interface DataStructure extends React.HTMLAttributes { } const COMMON_COLUMNS: ColumnDef[] = [ - { accessorKey: "poly_name", header: "Polygon Name", meta: { style: { width: "13.30%" } } }, + { + accessorKey: "poly_name", + header: "Polygon Name", + meta: { style: { width: "13.30%" } }, + cell: (props: any) => { + const value = props.getValue(); + return value == "" || value == "-" ? "-" : value; + } + }, { accessorKey: "size", header: "Size (ha)", @@ -100,7 +108,7 @@ const COMMON_COLUMNS: ColumnDef[] = [ header: "Plant Start Date", cell: (props: any) => { const value = props.getValue(); - return format(new Date(value), "dd/MM/yyyy"); + return value == "-" ? "-" : format(new Date(value), "dd/MM/yyyy"); }, meta: { style: { width: "13.65%" } } }, @@ -280,11 +288,6 @@ const DROPDOWN_OPTIONS = [ title: "Hectares Under Restoration By Target Land Use System", value: "5", slug: "restorationByLandUse" - }, - { - title: "Tree Count", - value: "6", - slug: "treeCount" } ]; @@ -561,8 +564,7 @@ const DataCard = ({ treeCoverLossFires: TABLE_COLUMNS_TREE_COVER_LOSS, restorationByEcoRegion: TABLE_COLUMNS_HECTARES_ECO_REGION, restorationByStrategy: TABLE_COLUMNS_HECTARES_STRATEGY, - restorationByLandUse: TABLE_COLUMNS_HECTARES_LAND_USE, - treeCount: [] + restorationByLandUse: TABLE_COLUMNS_HECTARES_LAND_USE }; const handleExport = async () => { diff --git a/src/admin/components/ResourceTabs/MonitoredTab/hooks/useMonitoredData.ts b/src/admin/components/ResourceTabs/MonitoredTab/hooks/useMonitoredData.ts index 1399b982..73c3a466 100644 --- a/src/admin/components/ResourceTabs/MonitoredTab/hooks/useMonitoredData.ts +++ b/src/admin/components/ResourceTabs/MonitoredTab/hooks/useMonitoredData.ts @@ -64,11 +64,6 @@ const DROPDOWN_OPTIONS = [ title: "Hectares Under Restoration By Target Land Use System", value: "5", slug: "restorationByLandUse" - }, - { - title: "Tree Count", - value: "6", - slug: "treeCount" } ]; @@ -100,8 +95,7 @@ export const useMonitoredData = (entity?: EntityName, entity_uuid?: string) => { treeCoverLossFires: [], restorationByEcoRegion: [], restorationByStrategy: [], - restorationByLandUse: [], - treeCount: [] + restorationByLandUse: [] }); const [dropdownAnalysisOptions, setDropdownAnalysisOptions] = useState(DROPDOWN_OPTIONS); diff --git a/src/components/extensive/Modal/ModalRunAnalysis.tsx b/src/components/extensive/Modal/ModalRunAnalysis.tsx index 172bcc5f..534c8ab3 100644 --- a/src/components/extensive/Modal/ModalRunAnalysis.tsx +++ b/src/components/extensive/Modal/ModalRunAnalysis.tsx @@ -1,4 +1,4 @@ -import { FC } from "react"; +import { FC, useState } from "react"; import { When } from "react-if"; import { useMonitoredData } from "@/admin/components/ResourceTabs/MonitoredTab/hooks/useMonitoredData"; @@ -40,24 +40,27 @@ const ModalRunAnalysis: FC = ({ onClose, ...rest }) => { - const { indicatorSlugAnalysis, setIndicatorSlugAnalysis, setLoadingAnalysis } = useMonitoredDataContext(); + const { indicatorSlugAnalysis, setIndicatorSlugAnalysis, setLoadingAnalysis, indicatorSlug } = + useMonitoredDataContext(); const { runAnalysisIndicator, dropdownAnalysisOptions, loadingVerify, analysisToSlug } = useMonitoredData( entityType, entityUuid ); const { openNotification } = useNotificationContext(); + const [selectSlug, setSelectSlug] = useState(); const runAnalysis = async () => { + const indicatorSlugSelected = selectSlug ? indicatorSlugAnalysis : indicatorSlug; setLoadingAnalysis?.(true); - if (analysisToSlug[`${indicatorSlugAnalysis}`]?.message) { + if (analysisToSlug[`${indicatorSlugSelected}`]?.message) { setLoadingAnalysis?.(false); - return openNotification("warning", "Warning", analysisToSlug[`${indicatorSlugAnalysis}`].message); + return openNotification("warning", "Warning", analysisToSlug[`${indicatorSlugSelected}`].message); } await runAnalysisIndicator({ pathParams: { - slug: indicatorSlugAnalysis! + slug: indicatorSlugSelected! }, body: { - uuids: analysisToSlug[`${indicatorSlugAnalysis}`] + uuids: analysisToSlug[`${indicatorSlugSelected}`] } }); setIndicatorSlugAnalysis?.("treeCoverLoss"); @@ -99,12 +102,13 @@ const ModalRunAnalysis: FC = ({ /> option.slug === indicatorSlug)?.title} label="Indicator" options={dropdownAnalysisOptions} onChange={e => { const indicator = dropdownAnalysisOptions.find(option => option.value === e[0])?.slug; setIndicatorSlugAnalysis?.(indicator!); + setSelectSlug(indicator); }} variant={VARIANT_DROPDOWN_DEFAULT} className="!min-h-[44px] !py-[9px]"