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

Async table component #632

Merged
merged 3 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... is external serving going to work with fingerprints?

).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.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@fortawesome/react-fontawesome": "^0.1.4",
"@percy/storybook": "^3.2.0",
"@plotly/dash-component-plugins": "^1.0.1",
"@plotly/webpack-dash-dynamic-import": "^1.0.0",
"@storybook/cli": "^5.1.11",
"@storybook/react": "^5.1.11",
Expand Down
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;