Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Async table component (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Andre-Rivet authored Oct 28, 2019
1 parent f411c40 commit 949f2e1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 20 deletions.
16 changes: 16 additions & 0 deletions dash_table_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@
).format(__version__),
'namespace': package_name,
'dynamic': True
},
{
'relative_package_path': 'async~table.js',
'external_url': (
'https://unpkg.com/dash-table@{}/dash_table/async~table.js'
).format(__version__),
'namespace': package_name,
'async': True
},
{
'relative_package_path': 'async~table.js.map',
'external_url': (
'https://unpkg.com/dash-table@{}/dash_table/async~table.js.map'
).format(__version__),
'namespace': package_name,
'dynamic': True
}
]

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@fortawesome/react-fontawesome": "^0.1.4",
"@percy/storybook": "^3.2.0",
"@plotly/webpack-dash-dynamic-import": "^1.0.0",
"@plotly/dash-component-plugins": "^1.0.1",
"@plotly/webpack-dash-dynamic-import": "^1.1.0",
"@storybook/cli": "^5.1.11",
"@storybook/react": "^5.1.11",
"@types/d3-format": "^1.3.1",
Expand Down Expand Up @@ -124,4 +125,4 @@
"node": ">=8.11.0",
"npm": ">=6.1.0"
}
}
}
4 changes: 4 additions & 0 deletions src/dash-table/LazyLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ export default class LazyLoader {
public static get xlsx() {
return import(/* webpackChunkName: "export", webpackMode: "$${{mode}}" */ 'xlsx');
}

public static table() {
return import(/* webpackChunkName: "table", webpackMode: "$${{mode}}" */ 'dash-table/dash/fragments/DataTable');
}
}
28 changes: 10 additions & 18 deletions src/dash-table/dash/DataTable.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as R from 'ramda';
import React, { Component } from 'react';
import React, { Component, lazy, Suspense } from 'react';
import PropTypes from 'prop-types';

import RealTable from 'dash-table/components/Table';
import { asyncDecorator } from '@plotly/dash-component-plugins';

import Logger from 'core/Logger';

import genRandomId from 'dash-table/utils/generate';
import isValidProps from './validate';
import Sanitizer from './Sanitizer';
import LazyLoader from 'dash-table/LazyLoader';

/**
* Dash DataTable is an interactive table component designed for
Expand All @@ -20,25 +20,17 @@ import Sanitizer from './Sanitizer';
* is completely customizable through its properties.
*/
export default class DataTable extends Component {
constructor(props) {
super(props);
let id;
this.getId = () => (id = id || genRandomId('table-'));
this.sanitizer = new Sanitizer();
}

render() {
if (!isValidProps(this.props)) {
return (<div>Invalid props combination</div>);
}

const sanitizedProps = this.sanitizer.sanitize(this.props);
return this.props.id ?
(<RealTable {...sanitizedProps} />) :
(<RealTable {...sanitizedProps} id={this.getId()} />);
return (
<Suspense fallback={null}>
<RealDataTable {...this.props} />
</Suspense>
);
}
}

const RealDataTable = asyncDecorator(DataTable, LazyLoader.table);

export const defaultProps = {
page_action: 'native',
page_current: 0,
Expand Down
35 changes: 35 additions & 0 deletions src/dash-table/dash/fragments/DataTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as R from 'ramda';
import React, { Component } from 'react';

import RealTable from 'dash-table/components/Table';

import Logger from 'core/Logger';

import genRandomId from 'dash-table/utils/generate';
import isValidProps from '../validate';
import Sanitizer from '../Sanitizer';

import { propTypes, defaultProps } from '../DataTable';

export default class DataTable extends Component {
constructor(props) {
super(props);
let id;
this.getId = () => (id = id || genRandomId('table-'));
this.sanitizer = new Sanitizer();
}

render() {
if (!isValidProps(this.props)) {
return (<div>Invalid props combination</div>);
}

const sanitizedProps = this.sanitizer.sanitize(this.props);
return this.props.id ?
(<RealTable {...sanitizedProps} />) :
(<RealTable {...sanitizedProps} id={this.getId()} />);
}
}

DataTable.defaultProps = defaultProps;
DataTable.propTypes = propTypes;

0 comments on commit 949f2e1

Please sign in to comment.