diff --git a/Gemfile b/Gemfile index 16f304ac..752303de 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ gem 'resource_api', git: 'https://github.com/performant-software/resource-api.gi gem 'jwt_auth', git: 'https://github.com/performant-software/jwt-auth.git', tag: 'v0.1.3' # Core data -gem 'core_data_connector', git: 'https://github.com/performant-software/core-data-connector.git', tag: 'v0.1.103' +gem 'core_data_connector', git: 'https://github.com/performant-software/core-data-connector.git', tag: 'v0.1.104' # IIIF gem 'triple_eye_effable', git: 'https://github.com/performant-software/triple-eye-effable.git', tag: 'v0.2.7' diff --git a/Gemfile.lock b/Gemfile.lock index a66f8724..8ec38140 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/performant-software/core-data-connector.git - revision: e16f738ed177b6a90943d523849839cd109c1dbb - tag: v0.1.103 + revision: d4a600c56a42b38cddfcabe74e486ae6e6cb8f30 + tag: v0.1.104 specs: core_data_connector (0.1.0) activerecord-postgis-adapter (~> 11.0) diff --git a/client/src/components/PlaceForm.js b/client/src/components/PlaceForm.js index f74f605e..6bd4a96e 100644 --- a/client/src/components/PlaceForm.js +++ b/client/src/components/PlaceForm.js @@ -49,6 +49,11 @@ const PlaceForm = (props: Props) => { */ const [geocoding, setGeocoding] = useState(MapSessionUtils.restoreSession('mapView', localStorage).geocoding); + /** + * Tracks map geometry data independently of props.item + */ + const [mapData, setMapData] = useState(null); + /** * Updates localStorage to persist geocoding setting across pages. */ @@ -108,12 +113,28 @@ const PlaceForm = (props: Props) => { return null; }, []); + /** + * Sets map geometry data on the item, destroying any existing geometry record + * if all geometry is deleted. + */ + useEffect(() => { + if (mapData !== null) { + if (props.item.place_geometry?.id && mapData.geometry_json.features?.length === 0) { + props.onSetState({ + place_geometry: { id: props.item.place_geometry.id, _destroy: true } + }); + } else { + props.onSetState({ place_geometry: mapData }) + } + } + }, [mapData, props.item.place_geometry?.id]); + /** * Sets the new map geometries on the state. * * @type {function(*): *} */ - const onMapChange = useCallback((data) => props.onSetState({ place_geometry: { geometry_json: data } }), []); + const onMapChange = useCallback((data) => setMapData({ geometry_json: data }), []); /** * Sets the uploaded file as the GeoJSON object.