From 26d8b9d63046a24930ffb9d0dde96ecc02c5e441 Mon Sep 17 00:00:00 2001 From: Irwan Fathurrahman Date: Fri, 1 Nov 2024 15:51:57 +0700 Subject: [PATCH] Multi references bug fixing (#316) * Fix view selector for available layers * Update centroid --- .../src/components/Input/Autocomplete.jsx | 7 +++-- .../index.jsx | 23 +++++++++++----- .../pages/Admin/ModalSelector/GeorepoView.jsx | 27 ++++++++++++------- .../ModalSelector/InputSelector/index.js | 4 ++- .../src/pages/Admin/ModalSelector/style.scss | 19 ++++++++----- .../MapLibre/ReferenceLayerCentroid/index.jsx | 15 ++++++++--- 6 files changed, 66 insertions(+), 29 deletions(-) diff --git a/django_project/frontend/src/components/Input/Autocomplete.jsx b/django_project/frontend/src/components/Input/Autocomplete.jsx index 95766ac49..ea88a6e0b 100644 --- a/django_project/frontend/src/components/Input/Autocomplete.jsx +++ b/django_project/frontend/src/components/Input/Autocomplete.jsx @@ -16,10 +16,13 @@ import React from 'react'; import ReactAutocomplete from '@mui/material/Autocomplete'; import { ArrowDownwardIcon } from "../Icons"; +import { isArray } from "chart.js/helpers"; export default function Autocomplete({ ...props }) { - if (props.value && !props.options.includes(props.value)) { - props.options.push(props.value) + if (!isArray((props.value))) { + if (props.value && !props.options.includes(props.value)) { + props.options.push(props.value) + } } return { if (datasetLevels) { let updated = false - let levels = data.levels ? data.levels : [] + + // Update levels + let levels = data.levels ? datasetLevels.filter( + datasetLevel => data.levels.includes(datasetLevel.level) + ).map(level => level.level) : []; + let default_level = data.default_level ? data.default_level : 0 - if (!data.levels) { + + // Check levels is on the dataset levels + if (JSON.stringify(data.levels) !== JSON.stringify(levels)) { levels = datasetLevels.map(level => level.level) updated = true } @@ -99,8 +106,10 @@ export const ViewLevelConfiguration = forwardRef( ableToSelectReferenceLayer ?
- + - +
{ - if (sourceType === 'remote') { + if (sourceType === VALUE_REMOTE) { if (!reference && references[0]) { setReference(references[0].value) } @@ -108,7 +111,7 @@ export default function GeorepoViewSelector( useEffect( () => { // Change to local module - if (sourceType === 'local') { + if (sourceType === VALUE_LOCAL) { setReference(LocalReferenceDatasetIdentifier) } else { if (references[0]) { @@ -167,7 +170,8 @@ export default function GeorepoViewSelector( isMultiple={isMultiple} showSelected={showSelected} beforeChildren={ - <> +
{ localReferenceDatasetEnabled ? @@ -176,15 +180,20 @@ export default function GeorepoViewSelector( onChange={evt => setSourceType(evt.target.value)} > } label="Local"/> + control={} + value={VALUE_LOCAL} + label={VALUE_LOCAL} + /> } label="Remote"/> + control={} + value={VALUE_REMOTE} + label={VALUE_REMOTE}/> : null } { - !localReferenceDatasetEnabled || sourceType === 'remote' ? - + !localReferenceDatasetEnabled || sourceType === VALUE_REMOTE ? + : null } - +
} /> {otherContent ? otherContent : null} diff --git a/django_project/frontend/src/pages/Admin/ModalSelector/InputSelector/index.js b/django_project/frontend/src/pages/Admin/ModalSelector/InputSelector/index.js index 18ce6c93f..15f5ecdf8 100644 --- a/django_project/frontend/src/pages/Admin/ModalSelector/InputSelector/index.js +++ b/django_project/frontend/src/pages/Admin/ModalSelector/InputSelector/index.js @@ -166,7 +166,9 @@ export function GeorepoViewInputSelector( } ) { return { const currGeometries = {} @@ -142,8 +141,7 @@ export default function ReferenceLayerCentroid({ map }) { showIndicatorMapLabel ]); - // When everything changed - useEffect(() => { + const updateCentroid = () => { if (!map) { return; } @@ -373,17 +371,26 @@ export default function ReferenceLayerCentroid({ map }) { renderLabel(map, [], labelConfig) return; } + const currRequest = new Date().getTime() + lastRequest = currRequest + ExecuteWebWorker( worker, { geometriesData, mapGeometryValue, usedFilteredGeometries }, (features) => { - renderLabel(map, features, labelConfig) + if (currRequest === lastRequest) { + renderLabel(map, features, labelConfig) + } } ) } + } + // When everything changed + useEffect(() => { + updateCentroid() }, [ geometries, filteredGeometries, indicatorsData, indicatorShow, indicatorLayers,