Skip to content

Commit

Permalink
Resolves #7 by adding list of supported properties at the parent comp…
Browse files Browse the repository at this point in the history
…onent that can be passed down to react-table
  • Loading branch information
jovanni-hernandez committed Dec 18, 2018
1 parent 0ab5ed8 commit 551e457
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions public/routes_menu_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
{
"name" : "TabularDataFromAPIWidget",
"props" : {
"pageSizeOptions": [50, 100, 250, 500, 1000],
"defaultPageSize": 500,
"endpoint" : "/sample_nested_table_data_api.json",
"api_response_data_key" : "users",
"sub_component" : {
Expand Down
18 changes: 14 additions & 4 deletions src/Dashboard/Widgets/TabularDataFromAPIWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qs from 'qs';
import { INTERWIDGET_MESSAGE_TYPES } from '../../redux/actions/Dashboard.js';
import { ArrayTabularDataAccessor, BulletedListFormatter, AdditionalDataSubComponent, SubmitAndAdditionalDataSubComponent, UniqueValuesSelectFilter, ArrayValuesSelectFilter } from '../../Helpers/ReactTableHelpers.js'
import { stripQueryStringSeperator } from '../../Helpers/Generic.js'
import pick from 'lodash/pick';

// Data Table Imports
import ReactTable from "react-table";
Expand All @@ -32,6 +33,14 @@ class TabularDataFromAPIWidget extends Component {
data:[]
})

// Enumerates the react-table properties that can be set via props
this.supportedReactTableProps = [
"showPageSizeOptions",
"pageSizeOptions",
"defaultPageSize",
"minRows"
]

}


Expand Down Expand Up @@ -448,11 +457,12 @@ class TabularDataFromAPIWidget extends Component {
default : {
break;
}

}

}


// Fetch the supported react-table properties from the parent component
let reactTableProps = pick(this.props, this.supportedReactTableProps)

return (
<FullWidget settings_button={false} close_button={true} title={this.props.table_name} loading={this.state.loading} {...this.props}>

Expand Down Expand Up @@ -482,7 +492,7 @@ class TabularDataFromAPIWidget extends Component {

defaultFiltered={this.defaultFilters}
defaultSorted={this.defaultSorts}

{...reactTableProps}
{...additionalProps}

/>
Expand Down

0 comments on commit 551e457

Please sign in to comment.