Commit f1e68942 authored by Matija Obreza's avatar Matija Obreza
Browse files

Safer components

- Page<T> checks for this.content
- ItemsEditor will refuse to render with more than 100 items (paginate!)
- SelectPartner uses pretty item list
parent 7bc82b10
......@@ -130,7 +130,7 @@ export class Page<T> {
if (obj !== null && obj !== undefined) {
const props = Object.keys(obj);
for (const prop of props) { this[prop] = obj[prop]; }
if (this.content !== null && conv !== undefined) {
if (this.content !== null && this.content && conv !== undefined) {
this.content = this.content.map((x) => conv(x));
}
}
......
......@@ -6,6 +6,7 @@ import {Partner} from 'model/partner.model';
import Input, {InputLabel} from 'material-ui/Input';
import {FormControl} from 'material-ui/Form';
import Select from 'material-ui/Select';
import { MenuItem } from 'material-ui/Menu';
const styles = (theme) => ({
root: {
......@@ -55,8 +56,8 @@ class SelectPartner extends React.Component<ISelectPartnerProps, any> {
<Select className={ classes.select } value={ input.value && input.value.uuid } onChange={ this.handleChange }
input={ <Input /> }
>
<option value="" />
{ partners && partners.map((p) => <option key={ p.uuid } value={ p.uuid }>{ p.name }</option>) }
<MenuItem value="" />
{ partners && partners.map((p) => <MenuItem key={ p.uuid } value={ p.uuid }>{ p.name }</MenuItem>) }
</Select>
</FormControl>
);
......
......@@ -17,11 +17,19 @@ const renderMembers = ({ fields, itemLabel, itemEditor, addItem, removeItem }) =
removeItem(member);
};
if (! fields) {
return null;
}
if (fields.length > 100) {
return <div className="error">Don't use the ItemsEditor for more than 100 items!</div>;
}
return (
<div>
{ fields && fields.map((member, index, fields) => (
<div className="items-editor-item">
<Grid container key={ index } justify="space-between" alignItems="flex-end">
<div key={ index } className="items-editor-item">
<Grid container justify="space-between" alignItems="flex-end">
<Grid item xs={ 10 } md={ 11 }>
{ itemEditor(member, index, fields) }
</Grid>
......
......@@ -94,6 +94,9 @@ export function isNumeric(value: any): boolean {
export function dereferenceReferences(content: any[], prop: string, conv: (o: any) => any = (o) => o, id: string = 'uuid', refs: { [key: string]: any; } = {}) {
// Convert cross-references to Partner object
// console.log(`dereferenceReferences for ${prop}`, content, refs);
if (! content) {
return;
}
// deep search first
content.forEach((entry) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment