WidgetFunction: merge dynamic config for a call with inherited one (#9042)

Fixes #9008

Now, even if we inherit FunctionCall config from parent widget (e.g. drop down), we still ask for config of the current call and try to merge them (preferring the inherited parameters).
This commit is contained in:
Adam Obuchowicz 2024-02-15 00:05:45 +01:00 committed by GitHub
parent f4955815b2
commit 8489316d83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 9 deletions

View File

@ -116,9 +116,8 @@ const selfArgumentExternalId = computed<Opt<ExternalId>>(() => {
})
const visualizationConfig = computed<Opt<NodeVisualizationConfiguration>>(() => {
// If we inherit dynamic config, there is no point in attaching visualization.
if (props.input.dynamicConfig) return null
// Even if we inherit dynamic config in props.input.dynamicConfig, we should also read it for
// the current call and then merge them.
const expressionId = selfArgumentExternalId.value
const astId = props.input.value.id
if (astId == null || expressionId == null) return null
@ -139,8 +138,7 @@ const visualizationConfig = computed<Opt<NodeVisualizationConfiguration>>(() =>
}
})
const visualizationData = project.useVisualizationData(visualizationConfig)
const widgetConfiguration = computed(() => {
const inheritedConfig = computed(() => {
if (props.input.dynamicConfig?.kind === 'FunctionCall') return props.input.dynamicConfig
if (props.input.dynamicConfig?.kind === 'OneOfFunctionCalls' && methodCallInfo.value != null) {
const cfg = props.input.dynamicConfig
@ -148,18 +146,23 @@ const widgetConfiguration = computed(() => {
const name = entryQn(info?.suggestion)
return cfg.possibleFunctions.get(name)
}
return undefined
})
const visualizationData = project.useVisualizationData(visualizationConfig)
const widgetConfiguration = computed(() => {
const data = visualizationData.value
if (data?.ok) {
const parseResult = argsWidgetConfigurationSchema.safeParse(data.value)
if (parseResult.success) {
return functionCallConfiguration(parseResult.data)
return functionCallConfiguration(parseResult.data, inheritedConfig.value)
} else {
console.error('Unable to parse widget configuration.', data, parseResult.error)
}
} else if (data != null && !data.ok) {
data.error.log('Cannot load dynamic configuration')
}
return undefined
return inheritedConfig.value
})
/**

View File

@ -175,10 +175,21 @@ export type ArgumentWidgetConfiguration = z.infer<typeof argumentSchema>
export const argsWidgetConfigurationSchema = z.array(argumentSchema)
export type ArgsWidgetConfiguration = z.infer<typeof argsWidgetConfigurationSchema>
export function functionCallConfiguration(parameters: ArgumentWidgetConfiguration[]): FunctionCall {
/**
* Create {@link WidgetConfiguration} object from parameters received from the engine, possibly
* applying those to an inherited config received from parent widget.
*/
export function functionCallConfiguration(
parameters: ArgumentWidgetConfiguration[],
inherited?: FunctionCall,
): FunctionCall {
const parametersMap = new Map(inherited?.parameters)
for (const [name, param] of parameters) {
parametersMap.set(name, param)
}
return {
kind: 'FunctionCall',
parameters: new Map(parameters),
parameters: parametersMap,
}
}