Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dobri1408 committed Aug 6, 2024
1 parent 65244c7 commit 3f0a5bf
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Widgets/VisualizationWidget.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { useState, useRef, useEffect } from 'react';

import { Modal, Button, Grid } from 'semantic-ui-react';
import { toast } from 'react-toastify';
import { FormFieldWrapper, Icon, Toast } from '@plone/volto/components';

import MapBuilder from '@eeacms/volto-eea-map/Arcgis/Map/MapBuilder';
import {
initEditor,
destroyEditor,
validateEditor,
onPasteEditor,
} from '@eeacms/volto-eea-map/jsoneditor';

import editSVG from '@plone/volto/icons/editing.svg';

import '@eeacms/volto-eea-map/styles/editor.less';
import MapEditor from '../Arcgis/Editor/Editor';
import { debounce } from '../Arcgis/helpers';
Expand Down Expand Up @@ -166,7 +170,7 @@ const VisualizationWidget = (props) => {
const { id, title, description, value } = props;
const [showMapEditor, setShowMapEditor] = useState(false);

const onConnect = useRef(() => {
function onConnect() {
if (controller.current.multiple && !props.block) return;
props.onChange(props.id, {
...value,
Expand All @@ -191,15 +195,16 @@ const VisualizationWidget = (props) => {
);
},
);
}).current;
}

const onDisconnect = useRef(() => {
function onDisconnect() {
if (!controller.current.agReactive) return;
controller.current.agReactive.remove();
}).current;
}

useEffect(() => {
if (!$map.current) return;
const map = $map.current;
if (!map) return;

const widgets = document.querySelectorAll(
'.field-wrapper-map_visualization_data',
Expand All @@ -209,15 +214,15 @@ const VisualizationWidget = (props) => {
controller.current.multiple = true;
}

$map.current.on('connected', onConnect);
$map.current.on('disconnected', onDisconnect);
map.on('connected', onConnect);
map.on('disconnected', onDisconnect);

return () => {
if (!$map.current) return;
$map.current.off('connected', onConnect);
$map.current.off('disconnected', onDisconnect);
if (!map) return;
map.off('connected', onConnect);
map.off('disconnected', onDisconnect);
};
}, [$map, onConnect, onDisconnect]);
}, []);

if (__SERVER__ || !value) return null;

Expand Down

0 comments on commit 3f0a5bf

Please sign in to comment.