All files / src/viewcontrols BrowseView.tsx

50% Statements 9/18
0% Branches 0/4
20% Functions 1/5
43.75% Lines 7/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88        1x   1x 1x                                   1x                                           1x                       1x                                                       1x
/**
 * @module ViewControls
 * 
 *//** */
import * as React from 'react'
 
import { Row, Col } from 'react-materialize'
import { styles } from './BrowseViewStyles'
 
/**
 * Interface for BrowseView properties
 */
interface IBrowseViewProps {
    content,
    schema
}
 
/**
 * View Control for browsing a Content, works with a single Content and based on the ReactControlMapper
 * 
 * Usage:
 * ```html
 *  <BrowseView content={content} schema={schema} history={history} onSubmit={createSubmitClick} />
 * ```
 */
export class BrowseView extends React.Component<IBrowseViewProps, {}> {
    /**
     * constructor
     * @param {object} props
     */
    constructor(props: any) {
        super(props);
        /**
         * @type {object}
         * @property {any} content selected Content
         * @property {any} schema schema object of the selected Content's Content Type
         */
        this.state = {
            content: this.props.content,
            schema: this.props.schema
        };
    }
    /**
     * returns a value of an input
     * @param {string} name name of the input
     * @return {any} value of the input or null
     */
    getFieldValue(name) {
        if (this.props.content[name]) {
            return this.props.content[name]
        }
        else {
            return null
        }
    }
    /**
     * render
     * @return {ReactElement} markup
     */
    render() {
        const fieldSettings = this.props.schema.FieldMappings;
        const that = this;
        return (
            <Row>
                <div style={styles.container}>
                    <h4>{this.props.content.DisplayName}</h4>
                    {
                        fieldSettings.map(function (e, i) {
                            return (
                                <Col s={12} m={12} l={12} key={fieldSettings[i].ClientSettings.name}>
                                    {
                                        React.createElement(
                                            fieldSettings[i].ControlType,
                                            {
                                                ...fieldSettings[i].ClientSettings,
                                                'data-actionName': 'browse',
                                                'data-fieldValue': that.getFieldValue(fieldSettings[i].ClientSettings.name)
                                            })
                                    }
                                </Col>)
 
                        })
                    }
                </div>
            </Row>
        )
    }
}