Skip to content

Commit

Permalink
Multi references bug fixing (#316)
Browse files Browse the repository at this point in the history
* Fix view selector for available layers

* Update centroid
  • Loading branch information
meomancer authored Nov 1, 2024
1 parent 088d47a commit 26d8b9d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
7 changes: 5 additions & 2 deletions django_project/frontend/src/components/Input/Autocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ReactAutocomplete
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@ export const ViewLevelConfiguration = forwardRef(
useEffect(() => {
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
}
Expand Down Expand Up @@ -99,8 +106,10 @@ export const ViewLevelConfiguration = forwardRef(
ableToSelectReferenceLayer ?
<div className="ReferenceLayerLevelConfigurationView">
<label className="form-label" htmlFor="group">View</label>
<Grid container spacing={2}
className='ReferenceLayerLevelConfigurationCheckbox'>
<Grid
container spacing={2}
className='ReferenceLayerLevelConfigurationCheckbox'
>
<Grid item>
<FormGroup>
<FormControlLabel
Expand All @@ -116,8 +125,10 @@ export const ViewLevelConfiguration = forwardRef(
label=''/>
</FormGroup>
</Grid>
<Grid item
className='ReferenceLayerLevelConfigurationViewSelector'>
<Grid
item
className='ReferenceLayerLevelConfigurationViewSelector'
>
<div className="BasicFormSection">
<div className='ReferenceDatasetSection'>
<GeorepoViewInputSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { Session } from "../../../utils/Sessions";
import './style.scss';


const VALUE_REMOTE = 'Remote'
const VALUE_LOCAL = 'Local'

const columns = [
{ field: 'id', headerName: 'id', hide: true },
{ field: 'name', headerName: 'Name', flex: 1 },
Expand Down Expand Up @@ -62,7 +65,7 @@ export default function GeorepoViewSelector(
otherContent = null
}
) {
const [sourceType, setSourceType] = useState(localReferenceDatasetEnabled ? 'local' : 'remote')
const [sourceType, setSourceType] = useState(localReferenceDatasetEnabled ? VALUE_LOCAL : VALUE_REMOTE)
const [inputData, setInputData] = useState(null)

// This is for remote data
Expand Down Expand Up @@ -96,7 +99,7 @@ export default function GeorepoViewSelector(
/** On references loaded */
useEffect(
() => {
if (sourceType === 'remote') {
if (sourceType === VALUE_REMOTE) {
if (!reference && references[0]) {
setReference(references[0].value)
}
Expand All @@ -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]) {
Expand Down Expand Up @@ -167,7 +170,8 @@ export default function GeorepoViewSelector(
isMultiple={isMultiple}
showSelected={showSelected}
beforeChildren={
<>
<div
className={'ReferenceLayerSelector ' + (localReferenceDatasetEnabled ? 'localReferenceDatasetEnabled' : '')}>
{
localReferenceDatasetEnabled ?
<FormControl className='RadioButtonControl'>
Expand All @@ -176,15 +180,20 @@ export default function GeorepoViewSelector(
onChange={evt => setSourceType(evt.target.value)}
>
<FormControlLabel
value="local" control={<Radio/>} label="Local"/>
control={<Radio/>}
value={VALUE_LOCAL}
label={VALUE_LOCAL}
/>
<FormControlLabel
value="remote" control={<Radio/>} label="Remote"/>
control={<Radio/>}
value={VALUE_REMOTE}
label={VALUE_REMOTE}/>
</RadioGroup>
</FormControl> : null
}
{
!localReferenceDatasetEnabled || sourceType === 'remote' ?
<FormControl className='InputControl'>
!localReferenceDatasetEnabled || sourceType === VALUE_REMOTE ?
<FormControl className='InputControl DatasetSelector'>
<SelectWithList
placeholder={references ? 'Select dataset' : 'Loading'}
list={references}
Expand All @@ -195,7 +204,7 @@ export default function GeorepoViewSelector(
/>
</FormControl> : null
}
</>
</div>
}
/>
{otherContent ? otherContent : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ export function GeorepoViewInputSelector(
}
) {
return <ModalInputSelector
placeholder={'Select view ' + (isMultiple ? '(s)' : '')}
placeholder={
data[0] ? 'Loading' : 'Select view ' + (isMultiple ? '(s)' : '')
}
data={data}
setData={setData}
isMultiple={isMultiple}
Expand Down
19 changes: 12 additions & 7 deletions django_project/frontend/src/pages/Admin/ModalSelector/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@
}
}

.RadioButtonControl {
background-color: unset !important;
.ReferenceLayerSelector {
&.localReferenceDatasetEnabled .DatasetSelector {
margin-top: 1rem !important;
}

.RadioButtonControl {
background-color: unset !important;

.MuiRadioGroup-root {
flex-direction: row;
margin-bottom: 1rem;
.MuiRadioGroup-root {
flex-direction: row;

label {
margin-left: 0;
label {
margin-left: 0;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default function ReferenceLayerCentroid({ map }) {
const [geometries, setGeometries] = useState({});

const where = returnWhere(filtersData ? filtersData : [])

// When reference layer changed, fetch features
useEffect(() => {
const currGeometries = {}
Expand Down Expand Up @@ -142,8 +141,7 @@ export default function ReferenceLayerCentroid({ map }) {
showIndicatorMapLabel
]);

// When everything changed
useEffect(() => {
const updateCentroid = () => {
if (!map) {
return;
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 26d8b9d

Please sign in to comment.