From ad1e49ef2bcb75d411277c4210d3c5d493b3e9f3 Mon Sep 17 00:00:00 2001 From: eireland Date: Fri, 26 Jan 2024 14:52:42 -0800 Subject: [PATCH] Fixes isActive formula Sends a global min/max date value based on selected date range for the isActive formula Fixes wrong data context name being sent to create map --- src/components/App.tsx | 11 +++++++---- src/constants.ts | 2 +- src/hooks/use-codap-api.tsx | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 0f28af8..72844bf 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -7,13 +7,13 @@ import { AttributeFilter } from "./attribute-filter"; import { InfoModal } from "./info-modal"; import { useStateContext } from "../hooks/use-state"; import { adjustStationDataset, getWeatherStations } from "../utils/getWeatherStations"; -import { addNotificationHandler, createStationsDataset } from "../utils/codapHelpers"; +import { addNotificationHandler, createStationsDataset, guaranteeGlobal } from "../utils/codapHelpers"; import InfoIcon from "../assets/images/icon-info.svg"; import { useCODAPApi } from "../hooks/use-codap-api"; import { dataTypeStore } from "../utils/noaaDataTypes"; import { composeURL, formatData } from "../utils/noaaApiHelper"; import { IDataType } from "../types"; -import { StationDSName } from "../constants"; +import { StationDSName, globalMaxDate, globalMinDate } from "../constants"; import { geoLocSearch } from "../utils/geonameSearch"; import { DataReturnWarning } from "./data-return-warning"; @@ -37,7 +37,6 @@ export const App = () => { useEffect(() => { initializePlugin({pluginName: kPluginName, version: kVersion, dimensions: kInitialDimensions}); - const stationSelectionHandler = async(req: any) =>{ if (req.values.operation === "selectCases") { const result = req.values.result; @@ -63,9 +62,13 @@ export const App = () => { }, []); useEffect(() => { + const minDate = state.startDate || new Date( -5364662060); + const maxDate = state.endDate || new Date(Date.now()); adjustStationDataset(weatherStations); //change max data to "present" createStationsDataset(weatherStations); //send weather station data to CODAP - },[weatherStations]); + guaranteeGlobal(globalMinDate, Number(minDate)/1000); + guaranteeGlobal(globalMaxDate, Number(maxDate)/1000); + },[state.endDate, state.startDate, weatherStations]); const handleOpenInfo = () => { setState(draft => { diff --git a/src/constants.ts b/src/constants.ts index b833808..55e8a9a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -133,7 +133,7 @@ export const kWeatherStationCollectionAttrs = [ name: "isActive", formula: `(number(maxdate="present" ? date() - : date(split(maxdate,'-',1), split(maxdate, ""-", 2), split(maxdate, "-", 3))) - wxMinDate)>0 and wxMaxDate-number(date(split(mindate,"-",1), split(mindate, "-", 2), split(mindate, "-", 3)))>0`, + : date(split(maxdate,'-',1), split(maxdate, "-", 2), split(maxdate, "-", 3))) - wxMinDate)>0 and wxMaxDate-number(date(split(mindate,"-",1), split(mindate, "-", 2), split(mindate, "-", 3)))>0`, description: "whether the station was active in the Weather Plugin's requested date range", _categoryMap: { __order: [ diff --git a/src/hooks/use-codap-api.tsx b/src/hooks/use-codap-api.tsx index 2d451a7..efb4e9b 100644 --- a/src/hooks/use-codap-api.tsx +++ b/src/hooks/use-codap-api.tsx @@ -1,6 +1,6 @@ import { Attribute, Collection, DataContext, IDataType, IItem } from "../types"; import { IResult, codapInterface, createItems, getDataContext } from "@concord-consortium/codap-plugin-api"; -import { DSCollection1, DSCollection2, DSName, kStationsCollectionName } from "../constants"; +import { DSCollection1, DSCollection2, DSName, kStationsDatasetName } from "../constants"; import { useStateContext } from "./use-state"; import { useEffect } from "react"; import { createMap, selectStations } from "../utils/codapHelpers"; @@ -11,7 +11,7 @@ export const useCODAPApi = () => { useEffect(() => { if (state.weatherStation && state.isMapOpen) { const zoom = state.zoomMap ? 7 : null; - createMap(kStationsCollectionName, {width: 500, height: 350}, [state.weatherStation.latitude, state.weatherStation.longitude], zoom); + createMap(kStationsDatasetName, {width: 500, height: 350}, [state.weatherStation.latitude, state.weatherStation.longitude], zoom); selectStations([state.weatherStation.name]); } }, [state.isMapOpen, state.weatherStation, state.zoomMap]);