Giter Club home page Giter Club logo

dazzle's Introduction

Dazzle
React Dazzle

Dashboards made easy in React JS

License NPM Version Travis Build Coverage via Codecov


Looking for maintainers #41

Dazzle is a library for building dashboards with React JS. Dazzle does not depend on any front-end libraries but it makes it easier to integrate with them.

Dazzle's goal is to be flexible and simple. Even though there are some UI components readily available out of the box, you have the complete control to override them as you wish with your own styles and layout.

Features

  • Grid based layout
  • Add/Remove widgets
  • Drag and drop widget re-ordering
  • UI framework agnostic
  • Simple yet flexible
  • Well documented (It's a feature! Don't you think?)

Installation

$ npm install react-dazzle --save

Dazzle me

Here is a demo. Widgets shows fake data though but they look so damn cool (At least for me).

Usage

import React, { Component } from 'react';
import Dashboard from 'react-dazzle';

// Your widget. Just another react component.
import CounterWidget from './widgets/CounterWidget';

// Default styles.
import 'react-dazzle/lib/style/style.css';

class App extends Component {
  constructor() {
    this.state = {      
      widgets: {
        WordCounter: {
          type: CounterWidget,
          title: 'Counter widget',
        }
      },
      layout: {
        rows: [{
          columns: [{
            className: 'col-md-12',
            widgets: [{key: 'WordCounter'}],
          }],
        }],
      }
    };
  }

  render() {
    return <Dashboard  widgets={this.state.widgets} layout={this.state.layout}  />
  }
}

Dazzle uses react-dnd. The default Dashboard component of Dazzle is wrapped by DragDropContext of react-dnd. So you may want to use react-dnd in your React component hierarchy upper than where you use the Dashboard component of Dazzle. If you do so then you can't let Dazzle creating the DragDropContext because you want to create it yourself upper in the React component hierarchy of your application. So forth please use the DashboardWithoutDndContext component of Dazzle and wrapped your own component with DragDropContext(HTML5Backend):

import React, { Component } from 'react';
import { DashboardWithoutDndContext } from 'react-dazzle';

// react-dnd
import { DragDropContext } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';

// Your widget. Just another react component.
import CounterWidget from './widgets/CounterWidget';

// Default styles.
import 'react-dazzle/lib/style/style.css';

class App extends Component {
  constructor() {
    this.state = {      
      widgets: {
        WordCounter: {
          type: CounterWidget,
          title: 'Counter widget',
        }
      },
      layout: {
        rows: [{
          columns: [{
            className: 'col-md-12',
            widgets: [{key: 'WordCounter'}],
          }],
        }],
      }
    };
  }

  render() {
    return <DashboardWithoutDndContext  widgets={this.state.widgets} layout={this.state.layout}  />
  }
}

export default DragDropContext(HTML5Backend)(App);

API

Props Type Description Required
layout Object Layout of the dashboard. Yes
widgets Object Widgets that could be added to the dashboard. Yes
editable Boolean Indicates whether the dashboard is in editable mode. No
rowClass String CSS class name(s) that should be given to the row div element. Default is row. No
editableColumnClass String CSS class name(s) that should be used when a column is in editable mode. No
droppableColumnClass String CSS class name(s) that should be used when a widget is about to be dropped in a column. No
frameComponent Component Customized frame component which should be used instead of the default frame. More on custom frame component. No
addWidgetComponent Component Customized add widget component which should be used instead of the default AddWidget component. More on custom add widget component. No
addWidgetComponentText String Text that should be displayed in the Add Widget component. Default is Add Widget. No
onAdd(layout, rowIndex, columnIndex) function Will be called when user clicks the AddWidget component. No
onRemove(layout) function Will be called when a widget is removed. No
onMove(layout) function Will be called when a widget is moved. No

Providing widgets

widgets prop of the dashboard component takes an object. A sample widgets object would look like below. This object holds all the widgets that could be used in the dashboard.

{
  HelloWorldWidget: {
    type: HelloWorld,
    title: 'Hello World Title',
    props: {
      text: 'Hello Humans!'
    }
  },
  AnotherWidget: {
    type: AnotherWidget,
    title: 'Another Widget Title'
  }
 }
  • type property - Should be a React component function or class.
  • title property - Title of the widget that should be displayed on top of the widget.
  • props property - Props that should be provided to the widget.

Dashboard layout

The layout prop takes the current layout of the dashboard. Layout could have multiple rows and columns. A sample layout object with a single row and two columns would look like below.

{
  rows: [{
    columns: [{
      className: 'col-md-6 col-sm-6 col-xs-12',
      widgets: [{key: 'HelloWorldWidget'}]
    }, {
      className: 'col-md-6 col-sm-6 col-xs-12',
      widgets: [{key: 'AnotherWidget'}]
    }]
  }]
}
  • className property - CSS class(es) that should be given to the column in the grid layout. Above sample layout uses the classes from bootstrap library. You could use the classes of your CSS library.
  • widgets property - An array of widgets that should be rendered in that particular column. key property of the widgets array should be a key from the widgets object.

Edit mode

Setting editable prop to true will make the dashboard editable.

Add new widget

When user tries to add a new widget, the onAdd callback will be called. More info here on how to handle widget addition.

Remove a widget

When a widget is removed, onRemove method will be called and new layout (The layout with the widget removed) will be available as an argument of onRemove method. Set the provided layout again to the dashboard to complete the widget removal. The Sample repository has the this feature implemented.

Customization

Implementing custom WidgetFrame component

A frame is the component which surrounds a widget. A frame has the title and the close button. Dazzle provides a default frame out of the box. But if you want, you can customize the frame as you like. More info here.

Implementing custom AddWidget component

Dazzle also allows you to customize the Add Widget component which appears when you enter edit mode. More info here.

Issues

  • Improve drag and drop experience (#1)

License

MIT © Raathigeshan

Sponsor

dazzle's People

Contributors

adifelice-godaddy avatar adrianocola avatar elhay-av avatar guillaumev avatar hartmamt avatar johncmckim avatar khelkun avatar lalitaphalak avatar pcross616 avatar philmander avatar raathigesh avatar wanhongfu avatar xavier630 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dazzle's Issues

Improve drag and drop experience

The drag and drop functionality to reorder the widgets. But it's not smooth enough.

Should be improved to make the experience a lot better.

Duplication of Widgets

Hi,

Really liking this library over react-grid-layout.

However, not sure if it's been picked up before, but it looks like widgets get duplicated if they are dragged and dropped on widgets of the same type.

Will have a look but if it's a know issue, would love to have a fix.

Thanks!

Update: Odd. It seems that:

  • The duplication is not consistently occuring
  • The duplication can also occur when not dragged over the same type

Cannot resolve 'file' or 'directory' ./widgets/CounterWidget

When I try the example in the README, it gives me this error:

/mydazzle/src/index.js
  1:1  error  Parsing error: The keyword 'import' is reserved

✖ 1 problem (1 error, 0 warnings)


ERROR in ./src/components/Dashboard.jsx
Module not found: Error: Cannot resolve 'file' or 'directory' ./widgets/CounterWidget in /mydazzle/src/components
 @ ./src/components/Dashboard.jsx 15:21-55
Child html-webpack-plugin for "index.html":
    chunk    {0} index.html 541 kB [rendered]
        [0] ./~/html-webpack-plugin/lib/loader.js!./src/index.html 704 bytes {0} [built]
        [1] ./~/lodash/lodash.js 540 kB {0} [built]
        [2] (webpack)/buildin/module.js 251 bytes {0} [built]
^C

If you mean the user to supply it, can you change it to HelloWorldWidget which you already list in the README.

Plotly.js?

In your example, you use charts.js to create the graphs. Does your library currently support plotly.js (https://plot.ly/javascript/)? I am asking because my current graphs come out blank when shown using your dashboard....

Update react-dnd

There was so many hopes for 1.2.6 release that we won't see this warning anymore:

Warning: Accessing PropTypes via the main React package is deprecated, and will be removed in React v16.0. Use the latest available v15.* prop-types package from npm instead. For info on usage, compatibility, migration and more, see https://fb.me/prop-types-docs

Unfortunatelly react-dnd and react-dnd-html5-backend are pinned to old versions which wasn't aware about React 15.

Is there a reason why react-dnd and react-dnd-html5-backend are pinned to specific old version? Is it possible to use latest versions instead?

DragDropContext HMLT5Backend at top level of my app

Dazzle wraps its Dashboard Component with react-dnd's DragDropContext(HMLT5Backend)

I wish to use Dazzle in my application but also use react-dnd in another part of my component hierarchy which is not under the Dashboard component of Dazzle. So I would need to wrap my top most component in my React application with DragDropContext(HMLT5Backend). But whatever I do I will get the "Error: Cannot have two HTML5 backends at the same time" from react-dnd.

I think I'll not be able to do this without modifying Dazzle to not instantiate the DragDropContext in the Dashboard component. Am I right or is there a workaround that would not imply to modify Dazzle?

Integration Suggestion

Hey, I love what you've built so far. Great work.

I'd like to suggest integrating with react-grid-layout. They do a great job with responsiveness while preserving the drag-and-drop functionality. Doing so could help make react-dazzle a one-stop-shop for laying widgets out.

If I get a chance I'll fork and see if I can get a working example going.

Dashboard re-creates widgets when edit mode changed

Just checking if this is the supposed behavior: when the dashboard goes to edit mode, the widgets are re-created.

Is there a way to prevent the Dashboard column components from re-creating their widget components?

Many thanks.

example in readme not working.

Example in the readme gives compile error.

Error in ./src/App.js Syntax error: C:/data/projects/test-admin/src/App.js: 'this' is not allowed before super() 10 | class App extends Component {
11 | constructor() {

12 | this.state = {
| ^
13 | widgets: {
14 | WordCounter: {
15 | type: CounterWidget, @ ./src/index.js 13:11-27

Multi-row components

Hey, am I able to make widgets that take up multiple rows like this?
image

I've tried nesting rows within columns but it doesn't seem to work. It may be that I have messed up the object as the nested arrays and curly braces get really complex. If you have an example, could you please post it?

Unable to get dashboard to render using npm install

Hi I tried using your example you have in the readme for "usage" after installing to my project with npm. The problem is that the dashboard will not render.

I brought in some of you sample widgets to see if that was the issue but I still do not get anything to render using the sample you provided.

// Dashboard
const Dashboard = ('react-dazzle');

// Your widget
import BarChart from './widgets/BarChart';
import LineChart from './widgets/LineChart';
import DoughnutChart from './widgets/DoughnutChart';

// Default styles.
import 'react-dazzle/lib/style/style.css';

setting state...

                            ```
widgets: {
                                        EngineTelemetricsWidget: {
                                  type: BarChart,
                                  title: 'Engine',
                                },
                                PerformanceWidget: {
                                  type: DoughnutChart,
                                  title: 'Reactor Temp',
                                },
                                ShipVitalTelemetricsWidget: {
                                  type: LineChart,
                                  title: 'Reactor Telemetrics',
                                },
                              },
                              llayout: {
                                rows: [{
                                  columns: [{
                                    className: 'col-md-12 col-sm-12 col-xs-12',
                                    widgets: [{key: 'ShipVitalTelemetricsWidget'}],
                                  }],
                                }, {
                                  columns: [{
                                    className: 'col-md-8 col-sm-8 col-xs-8',
                                    widgets: [{key: 'EngineTelemetricsWidget'}],
                                  }, {
                                    className: 'col-md-4 col-sm-4 col-xs-4',
                                    widgets: [{key: 'PerformanceWidget'}],
                                  }],
                                }],
                              }};

(this is inside my render)


<div id="dashboard">
                    <Dashboard  widgets={this.state.widgets} layout={this.state.layout}  />
                </div>

Custom Frame Suggestion

It would be good if there was a styles or background prop which you could pass to the custom frame.

I'd quite like to create a metro themed dashboard with different background colors on the widgets

Support React 16

Hi guys,

Is Dazzle already supports React 16? I saw a closed issue about this, but I can't figure out if it is already in React 16.

Cannot read property 'map' of undefined

@lalitaphalak When I integrate react-dazzle-starter-kit into my project this error is produced,I downgraded dazzle but it also didn't work .Anyone having clue what is getting wrong here?

c
F:/mern-auth-Sagita/client/node_modules/react-dazzle/dist/lib.js:5035
  5032 |   g = e.addWidgetComponent,
  5033 |   v = e.onAdd,
  5034 |   y = e.onMove,
> 5035 |   b = n.map(function (e, t) {
       | ^  5036 | return r.default.createElement(a.default, {
  5037 |   key: t,
  5038 |   className: e.className,

Scalable Dynamic dashboard widgets

At the moment its impossible to use this dashboard dynamicly.
Where can exist widgets that are not included in the wiedgetList...
Should have a error prevent check here:
Check here: https://github.com/Raathigesh/dazzle/blob/master/lib/components/Widgets.js

and maybe even replace the widget with a Not Found for the user to delete intead of a dashboard crash.
It is not relieable to get a widget from the current layout and expect it to be in the widgets list.
I cant contribute no problem

My current Idea:
If layout widget does not exist on the widget list:
Present a not found widget that instead of complete crash(here the user can now remove thsi widget from his dashboard),
this not found widget can be either get from prop from the developer or we have a default

Resizing

Can't find it in demo. Is it possible to resize rows/columns?

React Dazzle V2 Roadmap

Following are the ideas I have for the next major version of dazzle.

Plugins

Modularize certain UI components as plugins. The plugins I could think of right now are

  • Add widget dialog
  • Widget full-screen mode
  • Widget configuration dialog

Do you have any ideas or improvements? Let discuss!

Who uses Dazzle?

Hi all,

Curious to know who is using Dazzle. If you could share some info, it would be really awesome!

Error building with UglifyJS: "Super expression must either be null or a function, not defined"

Dupe of #49 & #51, but with reproduction: https://github.com/samsch/test-dazzle

I forked and modified the build to fix this. https://github.com/samsch/dazzle/tree/1.4.0-cjs

There's no real need to build with Webpack for CommonJS modules, none of the features in the config are being used, so this does the build with just Babel and outputs the compiled modules to dist/.

You can directly install from the .tzg file attached to the release to get this fix now.

npm i https://github.com/samsch/dazzle/releases/download/1.4.0-cjs/react-dazzle-1.4.0.tgz

I changed the package main to point to dist/index.js, but the package also includes the umd build as dist/dazzle.min.js.

Swap widgets on drop?

Would there be a way such that when a widget is dropped on another container already container a widget they would swap instead of being in the same container? ex. user drops widget A (container A) on widget b (container b), widget A would then be on container B and widget B would be on container A.

List of user submitted widgets

I think it would be nice to maintain, as part of this repo, a list of example widgets submitted by the community. This would allow to showcase what can be achieved with Dazzle and would make a great foundation for people building their own dashboards and widgets.

This could be achieved using the repo Wiki, in a form similar to what's done by Smashing: https://github.com/Smashing/smashing/wiki/Additional-Widgets

One limitation is that given Dazzle's flexibility in terms of dashboard styling, most widgets will probably need to be tweaked slightly to make them fit in one's dashboard.

User submissions

For user submissions, I would suggest the following ground rules:

  • MUST include a comprehensive README.md
  • MUST include a screenshot of the widget
  • SHOULD be as self-contained as possible (~1 .js file)

For example: https://gist.github.com/vlaurin/34685a2fc8159ba95f2831aef637c6ef

How to pass parameters to the widget list components

example:

widgets: {
                RecordPanel:{
                    type: ZcForm,
                    title: 'ZcForm',
                    props:{}
                },
        }

My component RecordPanel need props initialze state, have many RecordPanel ,How to pass different props to different RecordPanel

Look forward to your favourable reply,

Typings?

I'm working on some typings for this as we'll likely be using it for our project.

However, I'm just wondering whether you've started the typings already or whether you're interested in creating Typings for this to support Typescript?

Unable to copy text in widgets to clipboard

Hello,

I noticed that when a component is rendered as a widget in the dashboard text cannot be copied to a clipboard. I was wondering is this a limitation due to drag and drop. Please let me know if there are any workarounds or if I am missing anything!

Thanks in advance!

Row Class should be on Columns parent

I am trying to use Dazzle with React Material Design Light but I am having issues with the grid structure. Dazzle generates the following html:

html

There is an extra div between mdl-grid and mdl-cell. React MDL uses flexbox. The extra div between the grid and the cells causes the cells to collapse.

result

I've looked at the code. The reason the extra <div /> is created in Columns.js. I assume it is there because React render requires a single element at the root. It seems to me that the rowClass should be on that div rather than in Row.js.

IMO, Row.js is not really performing any useful task. The rowClass should be in Columns.js which makes Row.js redundant. I could be missing something though?

I would propose that rowClass is moved to Columns.js and Row.js is removed. Columns.js could even be renamed to Row.js if that makes more sense.

Thoughts? Happy to submit a PR if you want one.

Looking for maintainers

I'm looking for maintainers to keep an eye on this project and answer questions. I don't use this project at the moment personally and I'm focused on few other projects, so I don't have the required time to answer questions, fix bugs and merge PRs.

If you are interested, please comment below.

Error on Bundle.js: "Super expression must either be null or a function, not defined"

Currently Getting the following error in my bundle.js

The package runs perfectly in development mode but as soon as I build my bundle I get the following error: "Super expression must either be null or a function, not defined"

Tracking the error takes to thi section in the lib.js

if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t)

*Note: Using React 16.3.2, webpack 4.8.4 and react-dazzle 1.4.0

SourceMap Error

I have recently started to use this package for a project I am working on. When running the code locally, I am getting:

./packages/dashboard/node_modules/react-dazzle/dist/lib.js
(Emitted value instead of an instance of Error) Cannot find SourceMap 'lib.js.map': Error: Can't resolve './lib.js.map' in '/Users/h318669/Desktop/Code/scuf/packages/dashboard/node_modules/react-dazzle/dist'

Steps to reproduce is too NPM install and run the package in a new project created with CRA. Also I do not see this when running the sample app.

Thank you.

Modifying props of widgets from Dashboard

How would I go about altering the state of a widget from the dashboard component?
I have tried changing the dashboard state to give new props to the widget, and the dashboard state is successfully changed and re-rendered, but the state of the widget never changes.
Perhaps something similar to how props are passed to widgets, a ref could be created for each widget:
widget:{
type: Widget,
title: 'Widget',
props: data,
refs: 'child'
}
Thank you.

create-react-app run build command

Just created an app using create-react-app then tried to add dazzle to my project.
Dev build works fine, but when we are creating the deployment builds running the create-react-app command "npm run build" we get an error when browsing the application. Error message shown in browser console is: "Uncaught TypeError: Super expression must either be null or a function, not undefined".
Is there anyway to fix it?

2018-11-24 20_18_16-case management

Duplicate widgets

The issue happened when drag a widget from same column index but different row.
It is also existing in demo, http://raathigesh.com/dazzle/
The reproduce steps:

  1. drag 'reactor temp' to top 1st row 1st column
  2. drag the 'reactor temp' to 2nd row 1st column

we can add
monitor.getItem().rowIndex===rowIndex
in WidgetFrame line 63 to fix this temporarily.
But it only can support change the order in a same column, do you want to support move a widget from different column or row and change the order at the same time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.