Skip to content

Default configuration isn't initially passed to the Python plugin #15

@pillowfication

Description

@pillowfication

There seems to be a bug(?) where the configuration object that the Python plugin receives is never set unless handleUpdateModel is called from the UI. This gives me the annoying issue where the default configuration set in the DesignerApi component never reaches the plugin until the user interacts with the UI.

const Tool = (): JSX.Element => {
  return (
    <DesignerApi
      messages={{}}
      defaultConfig={{ Configuration: { foo: 'Hello, world!' } }}
    >
      <AyxAppWrapper>
        <App />
      </AyxAppWrapper>
    </DesignerApi>
  )
}
class MyPlugin(PluginV2):
    def __init__(self, provider: AMPProviderV2):
        self.name = "MyPlugin"
        self.provider = provider

        # This should be "Hello, world!" but the key "foo" doesn't exist
        self.foo = self.provider.tool_config.get("foo") or ""

I'm currently getting around this by forcing an update when the UI loads.

const App = (): JSX.Element => {
  const [model, handleUpdateModel] = useContext(UiSdkContext)
  useEffect(() => handleUpdateModel({ ...model }), [])

  return (
    /* ... */
  )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions