All files / cred-form/inspector cred-form-select.js

100% Statements 3/3
77.27% Branches 17/22
100% Functions 1/1
100% Lines 3/3
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138                                                2x                 2x   2x                                                                                                                                                                                                            
/**
 * The View block ViewSelect component.
 *
 * A "ViewSelect" component is created that is used inside the Toolset View block Inspector component to handle the View
 * selection. A special component is needed in order to support grouping of Posts/Taxonomy/Users Views.
 *
 * @since  2.3
 */
 
/**
 * Block dependencies
 */
import { OptGroup } from '@toolset/common';
 
import { __ } from '@wordpress/i18n';
import { BaseControl } from '@wordpress/components';
import { Component } from '@wordpress/element';
 
export default class CREDFormSelect extends Component {
	render() {
		const {
			attributes,
			className,
			onChangeCredForm,
		} = this.props;
 
		const {
			form,
			newPostForms,
			editPostForms,
			newUserForms,
			editUserForms,
			newRelationshipForms,
		} = attributes;
 
		return (
			(
				'undefined' !== typeof newPostForms &&
				'undefined' !== typeof editPostForms &&
				'undefined' !== typeof newUserForms &&
				'undefined' !== typeof editUserForms &&
				'undefined' !== typeof newRelationshipForms
			) &&
			(
				newPostForms.length > 0 ||
				editPostForms.length > 0 ||
				newUserForms.length > 0 ||
				editUserForms.length > 0 ||
				newRelationshipForms.length > 0
			) ?
				<BaseControl>
					{
						// eslint-disable-next-line jsx-a11y/no-onchange
					} <select
						onChange={ onChangeCredForm }
						value={ form }
						className={ className }
					>
						<option disabled="disabled" value="">{ __( 'Select a Toolset Form' ) }</option>
						{
							newPostForms.length > 0 ?
								<OptGroup
									attributes={
										{
											label: __( 'Add Post Forms' ),
											items: newPostForms,
											valueOrigin: 'object',
										}
									}
								/> :
								null
						}
						{
							editPostForms.length > 0 ?
								<OptGroup
									attributes={
										{
											label: __( 'Edit Post Forms' ),
											items: editPostForms,
											valueOrigin: 'object',
										}
									}
								/> :
								null
						}
						{
							newUserForms.length > 0 ?
								<OptGroup
									attributes={
										{
											label: __( 'Add User Forms' ),
											items: newUserForms,
											valueOrigin: 'object',
										}
									}
								/> :
								null
						}
						{
							editUserForms.length > 0 ?
								<OptGroup
									attributes={
										{
											label: __( 'Edit User Forms' ),
											items: editUserForms,
											valueOrigin: 'object',
										}
									}
								/> :
								null
						}
						{
							newRelationshipForms.length > 0 ?
								<OptGroup
									attributes={
										{
											label: __( 'Add Relationship Forms' ),
											items: newRelationshipForms,
											valueOrigin: 'object',
										}
									}
								/> :
								null
						}
					</select>
				</BaseControl> :
				<BaseControl>
					<select
						disabled="disabled"
						className={ className }
					>
						<option>{ __( 'Create a Toolset Form first' ) }</option>
					</select>
				</BaseControl>
		);
	}
}