npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

superset-dashboard-sdk

v1.0.1

Published

Superset Dashboard visualization component with improved specs.

Downloads

398

Readme

Superset Dashboard SDK

Superset Dashboard is a library to help you publish your dashboards outside of the Superset application. This plugin does not use the Superset default @superset-ui/embedded-sdk but my own implementation written starting from the base plugin.

Installation

npm i -S superset-dashboard-sdk

Usage

Superset Dashboard provide a basic Dashboard component that you can use to render a dashboard and a DefaultDataProvider that follows Superset API standards to retrieve and provide a valid guest token. In addition to that, you can create your own DataProvider implementing DataProviderInterface.

The DataProviderInterfacerequires you to implement the following methods:

  • fetchGuestToken: to retrieve a valid guest token and return a Promise with the token string value.

Create a Dashboard

To publish a dashboard, you need to create a Dashboard component and pass required props (described below) to it.

// MyDashboard.tsx

import { Dashboard, DefaultDataProvider } from "superset-dashboard";

const dataProvider = new DataProvider("http://localhost:8088", {
  username: "<guest account>",
  password: "<guest password>",
});

const MyDashboard = () => {
  return (
    <Dashboard
      dataProvider={dataProvider}
      domain="http://localhost:8088"
      guestToken={"<guest token>"}
      uuid={"<embedded dashboard id>"}
      nativeFilters={[
        {
          id: "NATIVE_FILTER_ID",
          value: "NATIVE_FILTER_VALUE",
          operator: "NATIVE_FILTER_OPERATOR",
          value: ["NATIVE_FILTER_VALUE_1", "NATIVE_FILTER_VALUE_2"],
        },
      ]}
    />
  );
};

The Dashboard component requires the following props:

  • dataProvider: an instance of class implementing DataProviderInterface to retrieve data from Superset.
  • domain: the domain where Superset is running.
  • uuid: the uuid of the dashboard to render.
  • guestToken: you can pass a guest token to the component. If not provided, the component will use the dataProvider to retrieve one.
  • nativeFilters: an array of filters to apply to the dashboard. Default: [].

Quering the Dashboard

You can query the dashboard to retrieve basic informations and json_metadata from which you can prepare your custom forms to "pre-filter" dashboards before rendering them.

Using previous instanced dataProvider, you can query the dashboard like in this example:

const guestToken = await dataProvider.fetchGuestToken(["<dashboard id>"]);
const dashboard = await dataProvider.fetchDashboard(guestToken, "<integer id>");

// Extract list of "native filters" from dashboard json_metadata:
const jsonMetadata = dashboard.getJsonMetadata();
const nativeFilters = jsonMetadata?.native_filter_configuration ?? [];

Using that data you can render your custom filter form and use them before rendering the dashboard.

Contributing

Before install switch to node 16.9.1 (the same used in superset):

nvm use

To build the library:

npm run build

To run the tests:

npm run test

To run playground tests:

cd playground
npm start

To use storybook:

npm run storybook

For every command add :watch to run in watch mode.