Created component select logic for display and disabled state

This commit is contained in:
soupette 2019-11-27 12:36:33 +01:00
parent 9a6dcb876c
commit ea40cb92a0
4 changed files with 55 additions and 6 deletions

View File

@ -16,7 +16,12 @@ const Value = ({ children, ...props }) => {
category, category,
schema: { name }, schema: { name },
} = selectedComponent; } = selectedComponent;
const {
selectProps: { componentCategory, componentName, isCreatingComponent },
} = props;
console.log({ props });
const displayedCategory = isCreatingComponent ? componentCategory : category;
const displayedName = isCreatingComponent ? componentName : name;
const style = { color: '#333740' }; const style = { color: '#333740' };
return ( return (
@ -24,10 +29,10 @@ const Value = ({ children, ...props }) => {
{!!value && ( {!!value && (
<> <>
<span style={{ fontWeight: 700, ...style }}> <span style={{ fontWeight: 700, ...style }}>
{upperFirst(category)} {upperFirst(displayedCategory)}
</span> </span>
<span style={style}>&nbsp;&nbsp;</span> <span style={style}>&nbsp;&nbsp;</span>
<span style={style}>{name}</span> <span style={style}>{displayedName}</span>
</> </>
)} )}
</SingleValue> </SingleValue>
@ -36,10 +41,20 @@ const Value = ({ children, ...props }) => {
Value.defaultProps = { Value.defaultProps = {
children: null, children: null,
selectProps: {
componentCategory: null,
componentName: null,
isCreatingComponent: false,
},
}; };
Value.propTypes = { Value.propTypes = {
children: PropTypes.string, children: PropTypes.string,
selectProps: PropTypes.shape({
componentCategory: PropTypes.string,
componentName: PropTypes.string,
isCreatingComponent: PropTypes.bool,
}),
}; };
export default Value; export default Value;

View File

@ -4,7 +4,15 @@ import PropTypes from 'prop-types';
import MenuList from './MenuList'; import MenuList from './MenuList';
import Value from './Value'; import Value from './Value';
const ComponentSelect = ({ onChange, name, value, styles }) => { const ComponentSelect = ({
componentCategoryNeededForAddingAfieldWhileCreatingAComponent,
componentNameNeededForAddingAfieldWhileCreatingAComponent,
isCreatingComponentWhileAddingAField,
onChange,
name,
value,
styles,
}) => {
// Create a ref in order to access the StateManager // Create a ref in order to access the StateManager
// So we can close the menu after clicking on a menu item // So we can close the menu after clicking on a menu item
// This allows us to get rid of the menuIsOpen state management // This allows us to get rid of the menuIsOpen state management
@ -22,6 +30,12 @@ const ComponentSelect = ({ onChange, name, value, styles }) => {
return ( return (
<Select <Select
isClearable isClearable
isDisabled={isCreatingComponentWhileAddingAField}
isCreatingComponent={isCreatingComponentWhileAddingAField}
componentCategory={
componentCategoryNeededForAddingAfieldWhileCreatingAComponent
}
componentName={componentNameNeededForAddingAfieldWhileCreatingAComponent}
name={name} name={name}
onChange={handleChange} onChange={handleChange}
onClickOption={onChange} onClickOption={onChange}
@ -39,11 +53,17 @@ const ComponentSelect = ({ onChange, name, value, styles }) => {
}; };
ComponentSelect.defaultProps = { ComponentSelect.defaultProps = {
error: null, componentCategoryNeededForAddingAfieldWhileCreatingAComponent: null,
componentNameNeededForAddingAfieldWhileCreatingAComponent: null,
isCreatingComponentWhileAddingAField: false,
value: null, value: null,
}; };
ComponentSelect.propTypes = { ComponentSelect.propTypes = {
componentCategoryNeededForAddingAfieldWhileCreatingAComponent:
PropTypes.string,
componentNameNeededForAddingAfieldWhileCreatingAComponent: PropTypes.string,
isCreatingComponentWhileAddingAField: PropTypes.bool,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
styles: PropTypes.object.isRequired, styles: PropTypes.object.isRequired,

View File

@ -57,6 +57,7 @@ const FormModal = () => {
componentToCreate, componentToCreate,
formErrors, formErrors,
initialData, initialData,
isCreatingComponentWhileAddingAField,
modifiedData, modifiedData,
} = reducerState.toJS(); } = reducerState.toJS();
@ -608,6 +609,19 @@ const FormModal = () => {
booleanBox: BooleanBox, booleanBox: BooleanBox,
}} }}
isCreating={isCreating} isCreating={isCreating}
isCreatingComponentWhileAddingAField={
isCreatingComponentWhileAddingAField
}
componentCategoryNeededForAddingAfieldWhileCreatingAComponent={get(
componentToCreate,
'category',
null
)}
componentNameNeededForAddingAfieldWhileCreatingAComponent={get(
componentToCreate,
'name',
null
)}
value={value} value={value}
{...input} {...input}
error={ error={

View File

@ -253,7 +253,7 @@
"modalForm.sub-header.chooseAttribute.component": "Select a field for your component", "modalForm.sub-header.chooseAttribute.component": "Select a field for your component",
"modalForm.sub-header.chooseAttribute.contentType": "Select a field for your content type", "modalForm.sub-header.chooseAttribute.contentType": "Select a field for your content type",
"modalForm.sub-header.attribute.create": "Add new {type} field", "modalForm.sub-header.attribute.create": "Add new {type} field",
"modalForm.sub-header.attribute.create.step": "Add new component ({step})/2)", "modalForm.sub-header.attribute.create.step": "Add new component ({step}/2)",
"modalForm.sub-header.attribute.edit": "Edit {name}", "modalForm.sub-header.attribute.edit": "Edit {name}",
"modalForm.components.create-component.category.label": "Select a category or enter a name to create a new one", "modalForm.components.create-component.category.label": "Select a category or enter a name to create a new one",
"modalForm.attributes.select-component": "Select a component", "modalForm.attributes.select-component": "Select a component",