diff --git a/src/components/edit/LayerEdit.js b/src/components/edit/LayerEdit.js index 29b71e2e6..4cc84a13c 100644 --- a/src/components/edit/LayerEdit.js +++ b/src/components/edit/LayerEdit.js @@ -73,7 +73,7 @@ const LayerEdit = ({ layer, addLayer, updateLayer, cancelLayer }) => { return null } - const type = layer.layer + const type = layer.layerType || layer.layer const LayerDialog = layerType[type] if (!LayerDialog) { diff --git a/src/components/edit/earthEngine/EarthEngineDialog.js b/src/components/edit/earthEngine/EarthEngineDialog.js index 6be648166..0d78e2c22 100644 --- a/src/components/edit/earthEngine/EarthEngineDialog.js +++ b/src/components/edit/earthEngine/EarthEngineDialog.js @@ -16,8 +16,6 @@ import { } from '../../../constants/layers.js' import { getPeriodFromFilter, - getPeriods, - defaultFilters, translateFilters, } from '../../../util/earthEngine.js' import { incrementDate } from '../../../util/time.js' @@ -59,7 +57,7 @@ const EarthEngineDialog = (props) => { periodType, periodReducer, bands, - filters, // = defaultFilters, + filters, unit, source, sourceUrl, @@ -117,7 +115,7 @@ const EarthEngineDialog = (props) => { setFilter(periodFilter) }, - [periodType, filters, setFilter] + [/* periodType, */ filters, setFilter] ) const noBandSelected = Array.isArray(bands) && (!band || !band.length) @@ -127,41 +125,6 @@ const EarthEngineDialog = (props) => { const hasOrgUnitField = !!orgUnitField && orgUnitField !== NONE - // Load all available periods - /* - useEffect(() => { - let isCancelled = false - - if (periodType) { - getPeriods(datasetId, periodType, filters) - .then((periods) => { - if (!isCancelled) { - setPeriods(periods) - } - }) - .catch((error) => - setError({ - type: 'engine', - message: error.message, - }) - ) - } - - return () => (isCancelled = true) - }, [datasetId, periodType, filters]) - */ - - // Set most recent period by default - /* - useEffect(() => { - if (filter === undefined) { - if (Array.isArray(periods) && periods.length) { - setFilterFromPeriod(periods[0]) - } - } - }, [periods, filter, setFilterFromPeriod]) - */ - // Set default org unit level useEffect(() => { if (!rows) { @@ -289,10 +252,10 @@ const EarthEngineDialog = (props) => { datasetId={datasetId} periodType={periodType} period={period} - // periods={periods} periodReducer={periodReducer} filters={filters} onChange={setFilterFromPeriod} + onError={setError} errorText={ error && error.type === 'period' && error.message } @@ -314,18 +277,24 @@ const EarthEngineDialog = (props) => { EarthEngineDialog.propTypes = { datasetId: PropTypes.string.isRequired, - // layerId: PropTypes.string.isRequired, + layerId: PropTypes.string.isRequired, setBufferRadius: PropTypes.func.isRequired, setFilter: PropTypes.func.isRequired, setOrgUnits: PropTypes.func.isRequired, validateLayer: PropTypes.bool.isRequired, onLayerValidation: PropTypes.func.isRequired, areaRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - band: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), + band: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), // TODO: Why array? + bands: PropTypes.array, + description: PropTypes.string, filter: PropTypes.array, + filters: PropTypes.array, legend: PropTypes.object, + notice: PropTypes.string, orgUnitField: PropTypes.string, orgUnits: PropTypes.object, + periodReducer: PropTypes.string, + periodType: PropTypes.string, style: PropTypes.shape({ max: PropTypes.number, min: PropTypes.number, diff --git a/src/components/edit/earthEngine/PeriodSelect.js b/src/components/edit/earthEngine/PeriodSelect.js index 61620ceb7..83d32f343 100644 --- a/src/components/edit/earthEngine/PeriodSelect.js +++ b/src/components/edit/earthEngine/PeriodSelect.js @@ -6,14 +6,13 @@ import { SelectField } from '../../core/index.js' import { getPeriods } from '../../../util/earthEngine.js' import styles from './styles/PeriodSelect.module.css' -// http://localhost:8080/api/periodTypes.json const EarthEnginePeriodSelect = ({ periodType, period, datasetId, filters, - // periods, onChange, + onError, errorText, className, }) => { @@ -52,23 +51,22 @@ const EarthEnginePeriodSelect = ({ let isCancelled = false if (periodType) { - getPeriods(datasetId, periodType, filters).then((periods) => { - if (!isCancelled) { - setPeriods(periods) - } - }) - /* + getPeriods(datasetId, periodType, filters) + .then((periods) => { + if (!isCancelled) { + setPeriods(periods) + } + }) .catch((error) => - setError({ + onError({ type: 'engine', message: error.message, }) ) - */ } return () => (isCancelled = true) - }, [datasetId, periodType, filters]) + }, [datasetId, periodType, filters, onError]) // Set most recent period by default useEffect(() => { @@ -123,7 +121,6 @@ EarthEnginePeriodSelect.propTypes = { className: PropTypes.string, errorText: PropTypes.string, period: PropTypes.object, - periods: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), } export default EarthEnginePeriodSelect diff --git a/src/components/edit/earthEngine/PeriodTab.js b/src/components/edit/earthEngine/PeriodTab.js index c05d4cefa..448cd68a8 100644 --- a/src/components/edit/earthEngine/PeriodTab.js +++ b/src/components/edit/earthEngine/PeriodTab.js @@ -13,6 +13,7 @@ const EarthEnginePeriodTab = ({ period, periodReducer, onChange, + onError, errorText, className, }) => { @@ -33,6 +34,7 @@ const EarthEnginePeriodTab = ({ filters={filters} period={period} onChange={onChange} + onError={onError} errorText={errorText} /> )} @@ -43,6 +45,7 @@ const EarthEnginePeriodTab = ({ EarthEnginePeriodTab.propTypes = { periodType: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, + onError: PropTypes.func.isRequired, className: PropTypes.string, errorText: PropTypes.string, period: PropTypes.object, diff --git a/src/components/layers/download/DataDownloadDialog.js b/src/components/layers/download/DataDownloadDialog.js index e11eea667..84f410432 100644 --- a/src/components/layers/download/DataDownloadDialog.js +++ b/src/components/layers/download/DataDownloadDialog.js @@ -28,6 +28,8 @@ const DataDownloadDialog = ({ layer, onCloseDialog }) => { const aggregations = useSelector((state) => state.aggregations) + const layerType = layer.layerType || layer.layer + const onChangeFormat = (format) => { setError(null) setSelectedFormat(format) @@ -88,7 +90,7 @@ const DataDownloadDialog = ({ layer, onCloseDialog }) => { 'GeoJSON is supported by most GIS software, including QGIS and ArcGIS Desktop.' )} - {layer.layer === EVENT_LAYER && ( + {layerType === EVENT_LAYER && (