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

@inventi/dashboard

v0.8.3

Published

Customizable dashboard inspired by Jira dashboard. Allows you to add, remove and configure _built-in_ or custom widgets.

Downloads

15

Readme

Keep Dashboard

Customizable dashboard inspired by Jira dashboard. Allows you to add, remove and configure built-in or custom widgets.

Key points:

  • Easy integration
  • Supports multiple languages
  • Supports color schemes (TODO)

Requirements:

  • Redux, React

Getting started

  1. Install deps
yarn add @inventi/dashboard react-grid-layout styled-components

yarn add @nivo/pie @nivo/bar @nivo/core
  • Note: @nivo/pie @nivo/bar @nivo/core - are optional and only required if you want to use specific built-in widgets which use @nivo packages

  1. Add reducer to createReducers
import { reducer as dashboardReducer } from '@inventi/dashboard'

export default (history: History) =>
  combineReducers({
    // ... your other reducers
    dashboard: dashboardReducer,
  })

  1. Copy static css file Copy this file: node_modules/react-grid-layout/css/styles.css to your public folder in your app. It should be available by http://your-app.nx/react-grid-layout/css/styles.css

  1. Use Dashboard
  • Note: all types can be imported from index - @inventi/dashboard'
import Dashboard, { PieChart, NumberBox, WidgetConfig, LayoutWidgetItem, WidgetDefinition } from '@inventi/dashboard'

// Define language to use
const language: 'cs' | 'en' = 'en'
// Define widgets you want to use in your dashboard
const widgets: WidgetDefinition[] = [NumberBox, PieChart]
// Define initial (persisted) widgets to display
const initialWidgets: LayoutWidgetItem[] = [{ ...layoutItem1 }, { ...layoutItem2 }]

// Define onChange handler
const onChange = (widgetList: LayoutWidgetItem[]) => {
  // ... persistDashboard(widgetList)
}

const MyPage = () => {
  return <Dashboard lang={language} widgetDefinitions={widgets} initialWidgets={initialWidgets} onChange={onChange} />
}

  1. Confuguring built-in widgets - HoC

Each widget takes in common base props:

  • data - depends on widget, but is generally an array
  • isLoading - boolean value, if true, displays loader
  • error - boolean, if true, displays error message

The recommended approach is to use multiple HOC functions exposed by the Dashboard package. If the behaviour of exposed functions is not to your liking, you can use your own.

  • withFetchHOC

Allows to pass in fetch (base) data. Implementation of fetch is called on each widget config change and on first render. Adds props - data, isLoading and error to widget compoment.

import { withFetchHOC, WidgetConfig } from '@packages/dashboard'

const handleFetch = (cfg?: WidgetConfig) => {
  // fetch logic based on widget config
  // ...
  // payload can specify data only:
  const payloadData = [1, 2, 3]
  // or named data with other props:
  // ...
  const payloadWithProps = { data: [1, 2, 3], otherProp: 'x123' }
  // return promise with data from fetch
  return Promise.resolve(payloadData)
}

const widgets = [ColorBox, withFetchHOC(handleFetch)(PieChart)]
const MyDashboard = () => <Dashboard widgets={widgets} />

Promise has to be returned because loading & error is based on it. Individual widget fetch logic can be further specified in widget config.

  • withConfigHOC

Allows to customize config component of widget. Config component defines sources, filters & other props in MultiConfigProps This HOC passed spreaded config object as props to configComponent. Adds flexibility with each widget source.

import { withConfig } from '@packages/dashboard'

const pieChartConfig = {
  // Define all available widget sources (variants of widget)
  // Can be selected in widget config
  sources: [
    { value: 'source1', label: 'Widget source 1' },
    {
      value: 'source2',
      label: 'Widget source 2',
      // Add filters which can be selected and added to widget config
      filters: [
        {
          // Will be saved as 'status' property in config if selected
          name: 'status',
          label: t({ id: 'homepage.widget.status', message: 'Status' }),
          // Can select multiple values, saved as array if set to true
          isMulti: true,
          options: [
            { value: 'val1', label: 'status option 1' },
            { value: 'val1', label: 'status option 1' },
          ],
        },
      ],
    },
  ],
}

const widgets = [ColorBox, withConfig(pieChartConfig)(PieChart)]
const MyDashboard = () => <Dashboard widgets={widgets} />
  • withPropsHOC

Allows to pass general props - each widget has its own. Eg. title / description of widget etc.

import { withPropsWDefinition as withProps, WidgetConfig } from '@packages/dashboard'

// Pass props based on selected widget variant ~ source
const pieChartProps = ({ config }: WidgetConfig): WidgetConfig =>
  ({
    source1: { title: 'Title od widget based on source 1' },
    source2: { title: 'Title od widget based on source 2', description: 'Desciption of widget ... 2' },
  }[config?.source])

const widgets = [ColorBox, withProps(pieChartProps)(PieChart)]
const MyDashboard = () => <Dashboard widgets={widgets} />

Built-in widgets

There are several predefined widgets which can be used in your Dashboard:

NumberBox

Table

PieChart

BarChart

HorizontalBar

ColorBox

YourCustomWidget


Made with ❤️ and support of INVENTI.