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(
React.PropTypes.shape({
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,

View File

@ -3,23 +3,24 @@
import React from 'react';
import DropdownButton from 'react-bootstrap/lib/DropdownButton';
import MenuItem from 'react-bootstrap/lib/MenuItem';
import { getLangText } from '../../utils/lang_utils.js';
let PieceListToolbarFilterWidgetFilter = React.createClass({
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(
React.PropTypes.shape({
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,
filterBy: React.PropTypes.object,
@ -93,8 +94,6 @@ let PieceListToolbarFilterWidgetFilter = React.createClass({
<em>{label}:</em>
</li>
{items.map((param, j) => {
let label;
if(typeof param !== 'string') {
label = param.label;
param = param.key;

View File

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