1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Improve PropTypes for PieceListToolbarFilterWidget

This commit is contained in:
Tim Daubenschütz 2015-09-17 10:20:35 +02:00
parent 67e0b34640
commit ace465afad
3 changed files with 31 additions and 18 deletions

View File

@ -17,7 +17,15 @@ let PieceListToolbar = React.createClass({
filterParams: React.PropTypes.arrayOf( filterParams: React.PropTypes.arrayOf(
React.PropTypes.shape({ React.PropTypes.shape({
label: React.PropTypes.string, label: React.PropTypes.string,
items: React.PropTypes.array items: React.PropTypes.arrayOf(
React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.shape({
key: React.PropTypes.string,
label: React.PropTypes.string
})
])
)
}) })
), ),
filterBy: React.PropTypes.object, filterBy: React.PropTypes.object,

View File

@ -3,23 +3,24 @@
import React from 'react'; import React from 'react';
import DropdownButton from 'react-bootstrap/lib/DropdownButton'; import DropdownButton from 'react-bootstrap/lib/DropdownButton';
import MenuItem from 'react-bootstrap/lib/MenuItem';
import { getLangText } from '../../utils/lang_utils.js'; import { getLangText } from '../../utils/lang_utils.js';
let PieceListToolbarFilterWidgetFilter = React.createClass({ let PieceListToolbarFilterWidgetFilter = React.createClass({
propTypes: { propTypes: {
// An array of either strings (which represent acl enums) or objects of the form
//
// {
// key: <acl enum>,
// label: <a human readable string>
// }
//
filterParams: React.PropTypes.arrayOf( filterParams: React.PropTypes.arrayOf(
React.PropTypes.shape({ React.PropTypes.shape({
label: React.PropTypes.string, label: React.PropTypes.string,
items: React.PropTypes.array items: React.PropTypes.arrayOf(
React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.shape({
key: React.PropTypes.string,
label: React.PropTypes.string
})
])
)
}) })
).isRequired, ).isRequired,
filterBy: React.PropTypes.object, filterBy: React.PropTypes.object,
@ -93,8 +94,6 @@ let PieceListToolbarFilterWidgetFilter = React.createClass({
<em>{label}:</em> <em>{label}:</em>
</li> </li>
{items.map((param, j) => { {items.map((param, j) => {
let label;
if(typeof param !== 'string') { if(typeof param !== 'string') {
label = param.label; label = param.label;
param = param.key; param = param.key;

View File

@ -2,8 +2,6 @@
import React from 'react'; import React from 'react';
import { getLangText } from '../utils/lang_utils';
let PieceListFilterDisplay = React.createClass({ let PieceListFilterDisplay = React.createClass({
propTypes: { propTypes: {
@ -11,7 +9,15 @@ let PieceListFilterDisplay = React.createClass({
filterParams: React.PropTypes.arrayOf( filterParams: React.PropTypes.arrayOf(
React.PropTypes.shape({ React.PropTypes.shape({
label: React.PropTypes.string, label: React.PropTypes.string,
items: React.PropTypes.array items: React.PropTypes.arrayOf(
React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.shape({
key: React.PropTypes.string,
label: React.PropTypes.string
})
])
)
}) })
) )
}, },
@ -34,10 +40,10 @@ let PieceListFilterDisplay = React.createClass({
key: item, key: item,
label: item.split('acl_')[1].replace(/_/g, ' '), label: item.split('acl_')[1].replace(/_/g, ' '),
value: filterBy[item] ? filterBy[item] : false value: filterBy[item] ? filterBy[item] : false
} };
} }
}) })
} };
}); });
}, },
@ -55,7 +61,7 @@ let PieceListFilterDisplay = React.createClass({
.join(', '); .join(', ');
if(activeFilterWithLabel) { if(activeFilterWithLabel) {
return filterWithLabel.label + ': ' + activeFilterWithLabel return filterWithLabel.label + ': ' + activeFilterWithLabel;
} }
}) })
.filter((filterText) => !!filterText) .filter((filterText) => !!filterText)