mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
fix flows, added backfill
This commit is contained in:
parent
7413699e58
commit
9e5141b9df
@ -294,21 +294,20 @@
|
||||
"icon": "home_pin",
|
||||
"color": null,
|
||||
"description": "Requests the items address on update / create",
|
||||
"status": "inactive",
|
||||
"status": "active",
|
||||
"trigger": "event",
|
||||
"accountability": "all",
|
||||
"options": {
|
||||
"type": "filter",
|
||||
"type": "action",
|
||||
"scope": [
|
||||
"items.update",
|
||||
"items.create"
|
||||
"items.create",
|
||||
"items.update"
|
||||
],
|
||||
"collections": [
|
||||
"items"
|
||||
],
|
||||
"return": "$last"
|
||||
]
|
||||
},
|
||||
"operation": "0d18abcf-70f9-4545-b583-e18e5ec533fa",
|
||||
"operation": "717fbd27-7c73-42a9-9408-532d5cd5248d",
|
||||
"_syncId": "e28759ce-3995-4943-bbfc-f1ed08d42497"
|
||||
},
|
||||
{
|
||||
|
||||
@ -19,6 +19,28 @@
|
||||
"flow": "a78d01a4-13b3-46a4-8938-9606bf26e329",
|
||||
"_syncId": "b7241999-bfef-4086-bce1-b77d73323efb"
|
||||
},
|
||||
{
|
||||
"name": "Condition",
|
||||
"key": "condition_8xh1o",
|
||||
"type": "condition",
|
||||
"position_x": 19,
|
||||
"position_y": 1,
|
||||
"options": {
|
||||
"filter": {
|
||||
"$trigger": {
|
||||
"payload": {
|
||||
"position": {
|
||||
"_nempty": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"resolve": "0d18abcf-70f9-4545-b583-e18e5ec533fa",
|
||||
"reject": null,
|
||||
"flow": "e28759ce-3995-4943-bbfc-f1ed08d42497",
|
||||
"_syncId": "717fbd27-7c73-42a9-9408-532d5cd5248d"
|
||||
},
|
||||
{
|
||||
"name": "Condition",
|
||||
"key": "condition_d2q1f",
|
||||
@ -241,20 +263,6 @@
|
||||
"flow": "d8b14c06-fb08-4a27-8a4b-75e6a4cd7216",
|
||||
"_syncId": "d3c50715-47c3-4763-832f-caf92d29331f"
|
||||
},
|
||||
{
|
||||
"name": "Run Script",
|
||||
"key": "exec_dsl0t",
|
||||
"type": "exec",
|
||||
"position_x": 56,
|
||||
"position_y": 1,
|
||||
"options": {
|
||||
"code": "// Your function in the myScript operation\nmodule.exports = function (data) {\n const payload = {...data.$trigger.payload}\n payload.address = data.get_address_string.data.features[0].properties.city;\n return payload;\n};"
|
||||
},
|
||||
"resolve": null,
|
||||
"reject": null,
|
||||
"flow": "e28759ce-3995-4943-bbfc-f1ed08d42497",
|
||||
"_syncId": "d18a1aaf-77a6-453e-8142-5ca4f4181b05"
|
||||
},
|
||||
{
|
||||
"name": "Run Script",
|
||||
"key": "exec_kuwlb",
|
||||
@ -301,7 +309,7 @@
|
||||
"name": "Get Address String",
|
||||
"key": "get_address_string",
|
||||
"type": "request",
|
||||
"position_x": 19,
|
||||
"position_x": 37,
|
||||
"position_y": 1,
|
||||
"options": {
|
||||
"method": "GET",
|
||||
@ -1252,10 +1260,10 @@
|
||||
"name": "Update Data",
|
||||
"key": "item_update_h2lfe",
|
||||
"type": "item-update",
|
||||
"position_x": 38,
|
||||
"position_x": 55,
|
||||
"position_y": 1,
|
||||
"options": {
|
||||
"permissions": "$trigger",
|
||||
"permissions": "$full",
|
||||
"emitEvents": false,
|
||||
"collection": "items",
|
||||
"key": [
|
||||
@ -1265,7 +1273,7 @@
|
||||
"address": "{{$last.data.features[0].properties.city}}"
|
||||
}
|
||||
},
|
||||
"resolve": "d18a1aaf-77a6-453e-8142-5ca4f4181b05",
|
||||
"resolve": null,
|
||||
"reject": null,
|
||||
"flow": "e28759ce-3995-4943-bbfc-f1ed08d42497",
|
||||
"_syncId": "7e6101d2-3d8c-49e2-894e-3121c9eff06b"
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import { MapPinIcon } from '@heroicons/react/24/solid'
|
||||
import { useEffect, useRef } from 'react'
|
||||
|
||||
import { useAuth } from '#components/Auth/useAuth'
|
||||
import { useGeoDistance } from '#components/Map/hooks/useGeoDistance'
|
||||
import { useReverseGeocode } from '#components/Map/hooks/useReverseGeocode'
|
||||
|
||||
@ -20,6 +22,7 @@ export function ItemSubtitle({
|
||||
truncate = true,
|
||||
showDistance = true,
|
||||
}: ItemSubtitleProps) {
|
||||
const { user } = useAuth()
|
||||
const { distance } = useGeoDistance(item.position ?? undefined)
|
||||
const { formatDistance } = useFormatDistance()
|
||||
|
||||
@ -35,6 +38,36 @@ export function ItemSubtitle({
|
||||
const address = item.address && item.address.trim() !== '' ? item.address : geocodedAddress
|
||||
const subtitle = item.subname
|
||||
|
||||
// Track if we've already backfilled this item to avoid duplicate updates
|
||||
const backfilledRef = useRef(new Set<string>())
|
||||
|
||||
// Frontend backfill: Save geocoded address to database for items without address
|
||||
// Only for logged-in users to avoid permission issues with public role
|
||||
useEffect(() => {
|
||||
const itemId = item.id
|
||||
const hasNoAddress = !item.address || item.address.trim() === ''
|
||||
const hasGeocodedAddress = geocodedAddress && geocodedAddress.trim() !== ''
|
||||
const notYetBackfilled = !backfilledRef.current.has(itemId)
|
||||
const isLoggedIn = !!user?.id
|
||||
|
||||
if (
|
||||
hasNoAddress &&
|
||||
hasGeocodedAddress &&
|
||||
notYetBackfilled &&
|
||||
isLoggedIn &&
|
||||
item.layer?.api?.updateItem
|
||||
) {
|
||||
// Mark as backfilled immediately to prevent duplicate calls
|
||||
backfilledRef.current.add(itemId)
|
||||
|
||||
// Asynchronously save to database (silent fail)
|
||||
void item.layer.api.updateItem({ id: itemId, address: geocodedAddress }).catch(() => {
|
||||
// Silent fail - if update fails, remove from backfilled set to retry later
|
||||
backfilledRef.current.delete(itemId)
|
||||
})
|
||||
}
|
||||
}, [geocodedAddress, item.address, item.id, item.layer?.api, user?.id])
|
||||
|
||||
if (mode === 'address' && address) {
|
||||
return (
|
||||
<div className='tw:text-sm tw:flex tw:items-center tw:text-gray-500 tw:w-full'>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user