sanity-io / sanity-plugin-iframe-pane

Display any URL in a View Pane, along with helpful buttons to copy the URL, display a mobile size, reload the iframe or open in a new tab
MIT License
47 stars 13 forks source link

Propagate url function with client #18

Closed phmasek closed 1 year ago

phmasek commented 1 year ago

The way we are using the client has changed from v2 to v3. Therefore it would be good to provide a client for when resolving the production URL similarly to how you receive context in the document API.

SimeonGriggs commented 1 year ago

Thanks for your efforts here!

However, defaultDocumentNode contains the getClient() function inside the second context parameter. So you could pass the client to your function like this:

export const defaultDocumentNode: DefaultDocumentNodeResolver = (
  S,
  context
) => {
  const client = context.getClient({apiVersion: `2022-11-24`})

  return S.document().views([
    S.view.form(),
    S.view
      .component(Iframe)
      .options({
        url: (doc) => getPreviewUrl(doc, client),
      })
      .title('Preview'),
  ])
}

Would this solve what you're trying to do?

phmasek commented 1 year ago

Aha! That is a much better solution of course. Thank you @SimeonGriggs