mirror of
https://github.com/johndoe6345789/low-code-react-app-b.git
synced 2026-04-24 13:44:54 +00:00
Extend delete action selector resolution
This commit is contained in:
@@ -140,6 +140,18 @@ Remove an item from an array.
|
||||
}
|
||||
```
|
||||
|
||||
Example with the selector derived from event data:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "remove-clicked",
|
||||
"type": "delete",
|
||||
"target": "todos",
|
||||
"path": "meta.id",
|
||||
"expression": "event.todoId ?? data.selectedId"
|
||||
}
|
||||
```
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### 1. Input Field Updates
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useCallback } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { Action, JSONUIContext } from '@/types/json-ui'
|
||||
import { evaluateExpression, evaluateTemplate } from '@/lib/json-ui/expression-evaluator'
|
||||
import { getNestedValue } from '@/lib/json-ui/utils'
|
||||
|
||||
export function useActionExecutor(context: JSONUIContext) {
|
||||
const { data, updateData, executeAction: contextExecute } = context
|
||||
@@ -53,13 +54,27 @@ export function useActionExecutor(context: JSONUIContext) {
|
||||
}
|
||||
|
||||
case 'delete': {
|
||||
if (!action.target || !action.value) return
|
||||
if (!action.target) return
|
||||
const currentData = data[action.target] || []
|
||||
|
||||
let selectorValue
|
||||
if (action.compute) {
|
||||
selectorValue = action.compute(data, event)
|
||||
} else if (action.expression) {
|
||||
selectorValue = evaluateExpression(action.expression, evaluationContext)
|
||||
} else if (action.valueTemplate) {
|
||||
selectorValue = evaluateTemplate(action.valueTemplate, evaluationContext)
|
||||
} else {
|
||||
selectorValue = action.value
|
||||
}
|
||||
|
||||
if (selectorValue === undefined) return
|
||||
|
||||
const filtered = currentData.filter((item: any) => {
|
||||
if (action.path) {
|
||||
return item[action.path] !== action.value
|
||||
return getNestedValue(item, action.path) !== selectorValue
|
||||
}
|
||||
return item !== action.value
|
||||
return item !== selectorValue
|
||||
})
|
||||
updateData(action.target, filtered)
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user