Offer settings from other nodes, help with cron, follow the ports
Suggest a parameter's value from the nodes of the same type in every flow, the way message names are already offered; secrets stay out of it. Explain the cron fields, and derive the expression an interval asks for. Keep an untouched function scaffold in step with the node's ports. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H7LwYgJfpkbLCTeiAf8U4A
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import {
|
||||
type UseMutationResult,
|
||||
useMutation,
|
||||
useQueries,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query"
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
@@ -62,6 +64,51 @@ export const messageHistoryQueryOptions = (name: string, message: string) => ({
|
||||
queryFn: () => FlowsService.readMessageHistory({ name, message }),
|
||||
})
|
||||
|
||||
/** Other flows change rarely; suggestions do not need them fresh to the second. */
|
||||
const SUGGEST_STALE = 5 * 60 * 1000
|
||||
|
||||
/**
|
||||
* Values already in use by nodes of the same type, keyed by parameter.
|
||||
*
|
||||
* The second MQTT node points at the same broker as the first one, so the
|
||||
* settings are worth offering rather than making someone type them again.
|
||||
*
|
||||
* Only plain values are collected: a secret is stored as a reference object
|
||||
* and stays out of this, which is the point of the secret picker.
|
||||
*/
|
||||
export function useParamSuggestions(
|
||||
type: string | undefined,
|
||||
): Record<string, string[]> {
|
||||
const { data: flows } = useQuery({
|
||||
...flowsQueryOptions(),
|
||||
staleTime: SUGGEST_STALE,
|
||||
})
|
||||
// ponytail: reads every flow to collect them, sharing the editor's own cache
|
||||
// entries; an aggregate endpoint if a big installation makes that hurt.
|
||||
const details = useQueries({
|
||||
queries: (type ? (flows?.data ?? []) : []).map((flow) => ({
|
||||
...flowQueryOptions(flow.name),
|
||||
staleTime: SUGGEST_STALE,
|
||||
})),
|
||||
})
|
||||
|
||||
const seen: Record<string, Set<string>> = {}
|
||||
for (const { data } of details) {
|
||||
for (const node of data?.definition.nodes ?? []) {
|
||||
if (node.type !== type) continue
|
||||
for (const [key, value] of Object.entries(node.params ?? {})) {
|
||||
if (value === null || value === "" || typeof value === "object")
|
||||
continue
|
||||
if (!seen[key]) seen[key] = new Set()
|
||||
seen[key].add(String(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
return Object.fromEntries(
|
||||
Object.entries(seen).map(([key, values]) => [key, [...values].sort()]),
|
||||
)
|
||||
}
|
||||
|
||||
const AUTOSAVE_DELAY = 800
|
||||
/** How long to wait for a save in flight before sending the next one. */
|
||||
const RETRY_DELAY = 100
|
||||
|
||||
Reference in New Issue
Block a user