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

feat: public api for embeds #6680

Merged
merged 43 commits into from
Feb 21, 2025
Merged

feat: public api for embeds #6680

merged 43 commits into from
Feb 21, 2025

Conversation

mindspank
Copy link
Contributor

@mindspank mindspank commented Feb 14, 2025

Adds a RPC API for Rill embeds.

methods:

  • setState
  • getState

notifications:

  • stateChange

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!


const instanceId = $page.url.searchParams.get("instance_id");
const runtimeHost = $page.url.searchParams
.get("runtime_host")
.replace("localhost:9091", "localhost:8081");
const accessToken = $page.url.searchParams.get("access_token");

onMount(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept the initializing here if we want to support state for canvas in the future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Though for now I'd propose this code would be easier-to-follow (more co-located) if this went in the initEmbedPublicAPI() function.

@mindspank
Copy link
Contributor Author

Closes #5490

Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the strict JSON-RPC 2.0 interface, I think it's too heavy to ask that host application developers implement their own JSON-RPC 2.0 over postMessage client (since there's no widely adopted NPM library for this). I looked around a little bit and didn't find any other BI tools that take this approach (correct me if I'm wrong).

Instead, I'd propose we either:

  1. Use a simple custom JSON interface, much like what Looker, Sigma, and Metabase offer.
  2. Build a Javascript SDK that hides the JSON-RPC 2.0 exchange under-the-hood.

I'd suggest we do Option 1 in the short-run and explore Option 2 in the long-run.

@mindspank mindspank force-pushed the feat/emit-state-embed branch from 355cd82 to 008d5b8 Compare February 17, 2025 21:59
@mindspank
Copy link
Contributor Author

Regarding the strict JSON-RPC 2.0 interface, I think it's too heavy to ask that host application developers implement their own JSON-RPC 2.0 over postMessage client (since there's no widely adopted NPM library for this). I looked around a little bit and didn't find any other BI tools that take this approach (correct me if I'm wrong).

For ref: removed references to JSON-RPC and made id optional if you do not want a response back.
It diverges slightly from the standard but still maintains the core rpc functionality.


const instanceId = $page.url.searchParams.get("instance_id");
const runtimeHost = $page.url.searchParams
.get("runtime_host")
.replace("localhost:9091", "localhost:8081");
const accessToken = $page.url.searchParams.get("access_token");

onMount(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Though for now I'd propose this code would be easier-to-follow (more co-located) if this went in the initEmbedPublicAPI() function.

Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature. Big thanks – especially for the tests!

Comment on lines +69 to +75
await generateEmbed(
RILL_ORG_NAME,
RILL_PROJECT_NAME,
"bids_explore",
rillServiceToken,
);
const filePath = "file://" + path.resolve(__dirname, "..", "embed.html");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion, so we don't have embed.html hardcoded in two places:

const embedPath = await generateEmbed(
  RILL_ORG_NAME,
  RILL_PROJECT_NAME,
  "bids_explore",
  rillServiceToken
);
const filePath = "file://" + path.resolve(embedPath);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep the two versions for now since resolve is relative to the callers directory. Could make sense to move into a constant though since the file location would always have to be in the root of tests

@mindspank mindspank merged commit e6942b9 into main Feb 21, 2025
9 checks passed
@mindspank mindspank deleted the feat/emit-state-embed branch February 21, 2025 14:00
mindspank added a commit that referenced this pull request Feb 21, 2025
* feat: first rpc stub

* add emit

* feat: embed public api

* fix: better name for state stream

* fix: error handling and better spec conformatiy

* fix: cleanup

* fix: format

* fix: make id optional

* fix: first stub of tests

* Revert "fix: first stub of tests"

This reverts commit 2e33082.

* fix: clear method names

* fix: check input

* fix: gitignore

* fix: ignore

* Revert "fix: ignore"

This reverts commit 46ee2b3.

* Revert "fix: gitignore"

This reverts commit ec97c8e.

* fix: add tests

* Merge remote-tracking branch 'origin/main' into feat/emit-state-embed

* fix: comments

* fix: moving org and project to const

* fix: moving embed to test hook

* fix: format

* fix: read token

* fix: more fixes

* fix: comments

* fix: format

* .gitignore

* delete test file

* fix: pr comments

* fix: cleaner init

* fix: format

* fix: lint

* fix: more lint (in my pocket)

* fix: wait for bids

* fix: format

* fix: nits

* fix: format
grahamplata pushed a commit that referenced this pull request Feb 21, 2025
* feat: first rpc stub

* add emit

* feat: embed public api

* fix: better name for state stream

* fix: error handling and better spec conformatiy

* fix: cleanup

* fix: format

* fix: make id optional

* fix: first stub of tests

* Revert "fix: first stub of tests"

This reverts commit 2e33082.

* fix: clear method names

* fix: check input

* fix: gitignore

* fix: ignore

* Revert "fix: ignore"

This reverts commit 46ee2b3.

* Revert "fix: gitignore"

This reverts commit ec97c8e.

* fix: add tests

* Merge remote-tracking branch 'origin/main' into feat/emit-state-embed

* fix: comments

* fix: moving org and project to const

* fix: moving embed to test hook

* fix: format

* fix: read token

* fix: more fixes

* fix: comments

* fix: format

* .gitignore

* delete test file

* fix: pr comments

* fix: cleaner init

* fix: format

* fix: lint

* fix: more lint (in my pocket)

* fix: wait for bids

* fix: format

* fix: nits

* fix: format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants