@inventi/dashboard
TypeScript icon, indicating that this package has built-in type declarations

0.8.3 • Public • Published

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


... and you can also create your own widget

YourCustomWidget



Made with ❤️ and support of INVENTI.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.8.31latest
0.6.1-2.beta.10beta

Version History

VersionDownloads (Last 7 Days)Published
0.8.31
0.8.20
0.8.1-beta.20
0.8.1-beta.10
0.8.1-beta.00
0.8.00
0.7.8-beta.70
0.7.8-beta.60
0.7.8-beta.50
0.7.8-beta.40
0.7.8-beta.30
0.7.8-beta.20
0.7.8-beta.10
0.7.8-beta.00
0.7.80
0.7.70
0.7.60
0.7.50
0.7.41
0.7.30
0.7.20
0.7.10
0.7.00
0.6.160
0.6.150
0.6.140
0.6.130
0.6.1-2.beta.10
0.6.120
0.6.110
0.6.100
0.6.80
0.6.70
0.6.60
0.6.40
0.6.30
0.6.20
0.6.10
0.6.00
0.5.40
0.5.30
0.5.20
0.5.10
0.5.00
0.4.00
0.2.10
0.2.00
0.1.140
0.1.130
0.1.120
0.1.110
0.1.100
0.1.90
0.1.80
0.1.70
0.1.50
0.1.40
0.1.20
0.1.10
0.1.00

Package Sidebar

Install

npm i @inventi/dashboard

Weekly Downloads

2

Version

0.8.3

License

MIT

Unpacked Size

2.05 MB

Total Files

154

Last publish

Collaborators

  • adambisek