Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/gui2/src/components/GraphEditor/widgets/WidgetFunction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -139,27 +138,31 @@ 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
const info = methodCallInfo.value
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
})

/**
Expand Down
15 changes: 13 additions & 2 deletions app/gui2/src/providers/widgetRegistry/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
Loading