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

Add metadata to dialogs.open() #4377

Open
aress31 opened this issue Nov 6, 2024 · 4 comments
Open

Add metadata to dialogs.open() #4377

aress31 opened this issue Nov 6, 2024 · 4 comments
Labels
component: dialog This is the name of the generic UI component, not the React module! scope: toolpad-core Abbreviated to "core"

Comments

@aress31
Copy link

aress31 commented Nov 6, 2024

Summary

It would be helpful to add a metadata prop to dialogs.open() so that the metadata can be accessed in the associated component—enabling a wide range of use cases.

Examples

No response

Motivation

No response

Search keywords: usedialogs metadata

@aress31 aress31 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 6, 2024
@bharatkashyap
Copy link
Member

What do you mean by metadata? The payload can already take any arbitrary object - we're working on an example to make that clearer in the docs here #4375

@bharatkashyap bharatkashyap added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 7, 2024
@aress31
Copy link
Author

aress31 commented Nov 7, 2024

Semantically, a payload and metadata are distinct. While the payload can be used to pass an object, metadata refers to the data required by the payload.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Nov 7, 2024
@oliviertassinari oliviertassinari added the component: dialog This is the name of the generic UI component, not the React module! label Nov 7, 2024
@Janpot
Copy link
Member

Janpot commented Nov 7, 2024

We don't assign any semantic meaning to naming of the "payload" parameter. All it does is pass some data into the dialog. You are completely free to lay out an object with the exact semantics that make sense for your use-case. You can encode this layout in an interface and use the generic parameter on dialog.open to enforce it:

interface MyPayload {
  data: {/* ... */};
  metadata: {/* ... */};
}

function MyDialog({ payload, open, onClose }: DialogProps<MyPayload>) {
  const { data, metadata } = payload
  // ...
}

// ...

  await dialogs.open<MyPayload>(MyDialog, {
    data: {/* ... */},
    metadata: {/* ... */}
  })

Can you elaborate more on the specific use-case that this feature would unlock, and a concrete proposal for an API?

@aress31
Copy link
Author

aress31 commented Nov 7, 2024

I agree with you that payload is a catch-all prop, however, in my mind, payload is more relevant to the rendered component inside the dialog and meta would be relevant to any parameter consumed by said component. However, that is just a suggestion, feel free to ignore.

@bharatkashyap bharatkashyap removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 8, 2024
@prakhargupta1 prakhargupta1 added the scope: toolpad-core Abbreviated to "core" label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: dialog This is the name of the generic UI component, not the React module! scope: toolpad-core Abbreviated to "core"
Projects
None yet
Development

No branches or pull requests

5 participants