question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SIP-4] [Embeddable Charts] Create Superset JS Client

See original GitHub issue

@kristw @conglei @mistercrunch @betodealmeida @hughhhh

cc @john-bodley @michellethomas @graceguo-supercat @timifasubaa

[SIP] [Embeddable Charts] Create Superset Client

This is the first of a few SIPs to progress toward a world where we can embed Superset Charts as React components in other web applications. At a high level this will require @superset/xxx NPM packages with data providers + chart components.

Motivation

This specific SIP is for creating a Superset JS client to handle asynchronous requests for data including authentication.

The motivation for this change is two-fold

  1. address technical debt by moving from ajax to fetch
  2. encapsulate all request logic into a single JS class, which will enable issuing requests for data from other web applications

Proposed Change

Write a single JS SupersetClient class that

  • handles CSRF tokens and verifies authentication
  • supports GET/POST/PUT/DELETE methods
  • supports customization of headers, etc. if needed

After this we can write corresponding React components to handle fetching specific types of Superset data (including in other apps):

  • <DatasourceProvider /> returns available datasources
  • <MetadataProvider /> given a datasource id, returns metadata on all of its columns, metrics, etc.
  • <QuerydataProvider /> given a query, returns the data for that query; this can be uncoupled from visualizations over time.

We can do this in three phases:

  1. Write the client, considering all existing request types
  2. Refactor existing ajax requests to leverage new client
  3. Write react components

New or Changed Public Interfaces

Example usage of the client:

import SupersetClient from 'xxx';

// Singleton instance of the client
const client = SupersetClient.getInstance({
  host: 'http://0.0.0.0:8088',
  cors: 'enable', // talking to the same domain or not
});

// verify authentication and fetch CSRF
client.init()
  .then(...) // now make some requests
  .catch(...); // in another app, link to Superset for Auth

// later
client.get({ endpoint: 'datasources/' });
client.post({ endpoint: 'explore_json/', postPayload: ... });
Authentication and CORS

In order to support requests made from other web applications, we must

  • enable CORS (cross origin request sharing) and
  • ensure authentication

The Superset backend already supports enabling CORS for specific endpoints and resources. This is an example config.py:

# CORS Options
ENABLE_CORS = True
CORS_OPTIONS = { 
  "resources": { 
    "*": {
      "origins": "http://localhost:9001", "supports_credentials": True, 
    }
  }
}

By setting the fetch parameter { credentials: 'include' } we can also forward credentials for the current user.

Proof of concept

This is a proof of concept using the SupersetClient code in another web application (PR to come). It demonstrates

  • ability to verify user authentication
  • ability to fetch and use CSRF token in requests
  • support for GET and POST requests for Superset data that ultimately powers a chart.

supersetclient-v0

New dependencies

This should only require the whatwg-fetch polyfill, which has been added / considered in other PRs (eg #5524) and has no license concerns.

Migration Plan and Compatibility

We don’t anticipate that any migration will be necessary or breaking compatibility changes.

Rejected Alternatives

We considered a client that also handles redux state management, but this seems too complex to start and could be added as another layer in the future if it was needed for embeddable charts (we think it won’t be)

Major open questions

A major open question is WHERE this code (and other future @superset/... JS npm packages) should ultimately live. The options are:

  1. within the apache/incubator-superset repo under a src/packages/ subfolder, or

  2. a separate repository (which?!)

Pros of apache/incubator-superset
  • Centralized, all code in one place
  • Member management in one place
  • Centralized place for all contributions, dependencies, etc.
Cons of apache/incubator-superset
  • Combine issues from all components. (could address with per-package tags)
  • Possible confusion if/when superset app version dependencies differ from the most-up-to-date packages/* version (ie superset app does not pull from local package source code, rather it pulls from npm for a particular version of that source code)
  • Deprecating a package means deleting a code from central repo instead of leaving the git repo alone.
  • Combined git log can be very polluted

Overall it seems we should move packages to a different repsoitory. Where should this be? (note: I grabbed the npm @superset namespace for publishing so we should be good there! 👍

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:20 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
victornoelcommented, Aug 21, 2018

@williaster thanks for your answer, this new endeavour around embeddable charts and chars as plugins is really a great advancement for superset I think 😃

2reactions
williastercommented, Nov 14, 2018

Going to close this as complete: @superset-ui/connection now powers all async requests in the Superset app, and several other modular packages are under active development in @superset-ui to power other ideas described here and captured in other SIPs.

Noting that this SIP was used more as formalizing architecture design and not for any formal voting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Embedding Superset dashboards in your React application
Superset is a no-code web-based interface for building charts quickly. It supports wide range of database and visualizations to showcase your data.
Read more >
Creating Visualization Plugins - Apache Superset
Visualizations in Superset are implemented in JavaScript or TypeScript. Superset comes preinstalled with several visualizations types (hereafter "viz plugins") ...
Read more >
CHANGELOG.md - Superset - Fossies
#20377 feat(standardized form data): keep all columns and metrics (@zhaoyongjie) · #20114 feat(chart): Enable caching per user when user ...
Read more >
Welcome to Everything.js | Everything.js
Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js. bpampuch/pdfmake ...
Read more >
ExtraHop System User Guide
For example, when a client sends an HTTP request to a web server, ... be customized to extract and store specific metadata with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found