Clean code

This commit is contained in:
soupette 2019-07-29 17:44:47 +02:00
parent aa7a41e039
commit 53d0014dc2
12 changed files with 93 additions and 90 deletions

View File

@ -9,9 +9,7 @@ import '@babel/polyfill';
import 'sanitize.css/sanitize.css'; import 'sanitize.css/sanitize.css';
// Third party css library needed // Third party css library needed
// Currently unable to bundle them
// import 'react-select/dist/react-select.css';
import 'react-datetime/css/react-datetime.css'; import 'react-datetime/css/react-datetime.css';
import './styles/main.scss'; import './styles/main.scss';

View File

@ -7,15 +7,12 @@
.buttonContainer { .buttonContainer {
width: 100%; width: 100%;
// width: 358px;
height: 34px; height: 34px;
text-align: center; text-align: center;
background-color: #fafafb; background-color: #fafafb;
// border: 1px solid #E3E9F3;
border-top: 0; border-top: 0;
border-bottom-left-radius: 2px; border-bottom-left-radius: 2px;
border-bottom-right-radius: 2px; border-bottom-right-radius: 2px;
color: #333740; color: #333740;
font-size: 12px; font-size: 12px;
font-weight: 700; font-weight: 700;

View File

@ -101,11 +101,4 @@
margin-right: 7px; margin-right: 7px;
color: #b3b5b9; color: #b3b5b9;
} }
// margin-right: 8px;
// &:before {
// content: '\F08E';
// display: block;
// font-family: 'FontAwesome';
// font-size: 11px;
// }
} }

View File

@ -13,8 +13,6 @@ const ListWrapper = styled.div`
overflow-x: scroll; overflow-x: scroll;
} }
.list-button { .list-button {
// padding: 1rem 3rem 2.5rem 3rem;
padding: 1.4rem 3rem 2.5rem 3rem; padding: 1.4rem 3rem 2.5rem 3rem;
button { button {

View File

@ -36,7 +36,6 @@ const Wrapper = styled.div`
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
// width: calc(100% - 18px);
text-align: center; text-align: center;
margin-bottom: 0; margin-bottom: 0;
margin-top: -1px; margin-top: -1px;

View File

@ -47,11 +47,10 @@ const FieldForm = ({
{Object.keys(metadatas) {Object.keys(metadatas)
.filter(meta => meta !== 'visible') .filter(meta => meta !== 'visible')
.map(meta => { .map(meta => {
if (formType === 'group' && meta !== 'label') { if (
return null; (formType === 'group' || formType === 'media') &&
} meta !== 'label'
) {
if (formType === 'media' && !['label'].includes(meta)) {
return null; return null;
} }

View File

@ -5,9 +5,9 @@ const InfoLabel = styled.div`
top: 0; top: 0;
right: 40px; right: 40px;
max-width: 80px; max-width: 80px;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
font-weight: 400; font-weight: 400;
color: #007eff; color: #007eff;
`; `;
@ -40,8 +40,8 @@ const Carret = styled.div`
`; `;
}} }}
height: 30px; height: 30px;
margin-right: 3px;
width: 2px; width: 2px;
margin-right: 3px;
border-radius: 2px; border-radius: 2px;
background: #007eff; background: #007eff;
`; `;
@ -75,11 +75,11 @@ const NameWrapper = styled.div`
} }
.name { .name {
display: inline-block; display: inline-block;
width: calc(100% - 18px);
vertical-align: top; vertical-align: top;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
width: calc(100% - 18px);
} }
${({ isHidden }) => { ${({ isHidden }) => {

View File

@ -77,10 +77,6 @@ const Item = ({
moveRow(dragRow, targetRow); moveRow(dragRow, targetRow);
// Note: we're mutating the monitor item here!
// Generally it's better to avoid mutations,
// but it's good here for the sake of performance
// to avoid expensive index searches.
item.rowIndex = targetRow; item.rowIndex = targetRow;
item.itemIndex = hoverIndex; item.itemIndex = hoverIndex;
@ -116,7 +112,6 @@ const Item = ({
Math.abs(monitor.getClientOffset().x - hoverBoundingRect.left) > Math.abs(monitor.getClientOffset().x - hoverBoundingRect.left) >
hoverBoundingRect.width / 1.8 hoverBoundingRect.width / 1.8
) { ) {
// TODO ADD NEW LINE
moveItem(dragIndex, hoverIndex + 1, dragRow, targetRow); moveItem(dragIndex, hoverIndex + 1, dragRow, targetRow);
item.itemIndex = hoverIndex + 1; item.itemIndex = hoverIndex + 1;
@ -160,6 +155,8 @@ const Item = ({
item: { type: ItemTypes.EDIT_FIELD, itemIndex, rowIndex, name, size }, item: { type: ItemTypes.EDIT_FIELD, itemIndex, rowIndex, name, size },
}); });
// Remove the default preview when the item is being dragged
// The preview is handled by the DragLayer
useEffect(() => { useEffect(() => {
preview(getEmptyImage(), { captureDraggingState: true }); preview(getEmptyImage(), { captureDraggingState: true });
}, [preview]); }, [preview]);

View File

@ -15,8 +15,6 @@ function reducer(state, action) {
list.map(obj => obj.update('isOpen', () => false)) list.map(obj => obj.update('isOpen', () => false))
); );
case 'OPEN_COLLAPSES_THAT_HAVE_ERRORS': case 'OPEN_COLLAPSES_THAT_HAVE_ERRORS':
// TODO fix collapse open
// return state;
return state return state
.update('collapsesToOpen', () => fromJS(action.collapsesToOpen)) .update('collapsesToOpen', () => fromJS(action.collapsesToOpen))
.update('collapses', list => { .update('collapses', list => {

View File

@ -87,7 +87,7 @@ const Item = ({ index, move, name, removeItem }) => {
push={goTo} push={goTo}
ref={ref} ref={ref}
size={12} size={12}
style={{ marginBottom: 6 }} style={{ marginBottom: 6, paddingLeft: 5, paddingRight: 5 }}
/> />
); );
}; };

View File

@ -25,7 +25,7 @@ const getSize = type => {
}; };
const reducer = (state, action) => { const reducer = (state, action) => {
const layoutPath = ['modifiedData', 'layouts', 'edit']; const layoutPathEdit = ['modifiedData', 'layouts', 'edit'];
const { dragIndex, hoverIndex, dragRowIndex, hoverRowIndex } = action; const { dragIndex, hoverIndex, dragRowIndex, hoverRowIndex } = action;
const getFieldType = name => const getFieldType = name =>
state.getIn(['modifiedData', 'schema', 'attributes', name, 'type']); state.getIn(['modifiedData', 'schema', 'attributes', name, 'type']);
@ -39,10 +39,13 @@ const reducer = (state, action) => {
.update('itemFormType', () => action.itemFormType) .update('itemFormType', () => action.itemFormType)
.update('modifiedData', () => fromJS(action.data)); .update('modifiedData', () => fromJS(action.data));
case 'MOVE_ROW': case 'MOVE_ROW':
return state.updateIn(layoutPath, list => { return state.updateIn(layoutPathEdit, list => {
return list return list
.delete(dragRowIndex) .delete(dragRowIndex)
.insert(hoverRowIndex, state.getIn([...layoutPath, dragRowIndex])); .insert(
hoverRowIndex,
state.getIn([...layoutPathEdit, dragRowIndex])
);
}); });
case 'ON_ADD_DATA': { case 'ON_ADD_DATA': {
const size = getSize( const size = getSize(
@ -54,9 +57,9 @@ const reducer = (state, action) => {
'type', 'type',
]) ])
); );
const listSize = state.getIn(layoutPath).size; const listSize = state.getIn(layoutPathEdit).size;
const newList = state const newList = state
.getIn(layoutPath) .getIn(layoutPathEdit)
.updateIn([listSize - 1, 'rowContent'], list => { .updateIn([listSize - 1, 'rowContent'], list => {
if (list) { if (list) {
return list.push({ return list.push({
@ -70,7 +73,7 @@ const reducer = (state, action) => {
const formattedList = formatLayout(newList.toJS()); const formattedList = formatLayout(newList.toJS());
return state return state
.updateIn(layoutPath, () => fromJS(formattedList)) .updateIn(layoutPathEdit, () => fromJS(formattedList))
.update('itemNameToSelect', () => action.name) .update('itemNameToSelect', () => action.name)
.update('itemFormType', () => getFieldType(action.name) || ''); .update('itemFormType', () => getFieldType(action.name) || '');
} }
@ -81,7 +84,11 @@ const reducer = (state, action) => {
); );
case 'REMOVE_FIELD': { case 'REMOVE_FIELD': {
const row = state.getIn([...layoutPath, action.rowIndex, 'rowContent']); const row = state.getIn([
...layoutPathEdit,
action.rowIndex,
'rowContent',
]);
let newState; let newState;
let fieldNameToDelete; let fieldNameToDelete;
// Delete the entire row if length is one or if lenght is equal to 2 and the second element is the hidden div used to make the dnd exp smoother // Delete the entire row if length is one or if lenght is equal to 2 and the second element is the hidden div used to make the dnd exp smoother
@ -90,18 +97,18 @@ const reducer = (state, action) => {
(row.size == 2 && row.getIn([1, 'name']) === '_TEMP_') (row.size == 2 && row.getIn([1, 'name']) === '_TEMP_')
) { ) {
fieldNameToDelete = state.getIn([ fieldNameToDelete = state.getIn([
...layoutPath, ...layoutPathEdit,
action.rowIndex, action.rowIndex,
'rowContent', 'rowContent',
0, 0,
'name', 'name',
]); ]);
newState = state.updateIn(layoutPath, list => newState = state.updateIn(layoutPathEdit, list =>
list.delete(action.rowIndex) list.delete(action.rowIndex)
); );
} else { } else {
fieldNameToDelete = state.getIn([ fieldNameToDelete = state.getIn([
...layoutPath, ...layoutPathEdit,
action.rowIndex, action.rowIndex,
'rowContent', 'rowContent',
action.fieldIndex, action.fieldIndex,
@ -109,13 +116,13 @@ const reducer = (state, action) => {
]); ]);
newState = state.updateIn( newState = state.updateIn(
[...layoutPath, action.rowIndex, 'rowContent'], [...layoutPathEdit, action.rowIndex, 'rowContent'],
list => list.delete(action.fieldIndex) list => list.delete(action.fieldIndex)
); );
} }
const updatedList = fromJS( const updatedList = fromJS(
formatLayout(newState.getIn(layoutPath).toJS()) formatLayout(newState.getIn(layoutPathEdit).toJS())
); );
if (state.get('itemNameToSelect') === fieldNameToDelete) { if (state.get('itemNameToSelect') === fieldNameToDelete) {
@ -123,39 +130,44 @@ const reducer = (state, action) => {
updatedList.getIn([0, 'rowContent', 0, 'name']) || ''; updatedList.getIn([0, 'rowContent', 0, 'name']) || '';
return state return state
.updateIn(layoutPath, () => updatedList) .updateIn(layoutPathEdit, () => updatedList)
.update('itemNameToSelect', () => firstField) .update('itemNameToSelect', () => firstField)
.update('itemFormType', () => getFieldType(firstField) || ''); .update('itemFormType', () => getFieldType(firstField) || '');
} }
return state.updateIn(layoutPath, () => updatedList); return state.updateIn(layoutPathEdit, () => updatedList);
} }
case 'REORDER_DIFF_ROW': { case 'REORDER_DIFF_ROW': {
const newState = state const newState = state
.updateIn([...layoutPath, dragRowIndex, 'rowContent'], list => { .updateIn([...layoutPathEdit, dragRowIndex, 'rowContent'], list => {
return list.remove(dragIndex); return list.remove(dragIndex);
}) })
.updateIn([...layoutPath, hoverRowIndex, 'rowContent'], list => { .updateIn([...layoutPathEdit, hoverRowIndex, 'rowContent'], list => {
return list.insert( return list.insert(
hoverIndex, hoverIndex,
state.getIn([...layoutPath, dragRowIndex, 'rowContent', dragIndex]) state.getIn([
...layoutPathEdit,
dragRowIndex,
'rowContent',
dragIndex,
])
); );
}); });
const updatedList = formatLayout(newState.getIn(layoutPath).toJS()); const updatedList = formatLayout(newState.getIn(layoutPathEdit).toJS());
return state.updateIn(layoutPath, () => fromJS(updatedList)); return state.updateIn(layoutPathEdit, () => fromJS(updatedList));
} }
case 'REORDER_ROW': { case 'REORDER_ROW': {
const newState = state.updateIn( const newState = state.updateIn(
[...layoutPath, dragRowIndex, 'rowContent'], [...layoutPathEdit, dragRowIndex, 'rowContent'],
list => { list => {
return list.delete(dragIndex).insert(hoverIndex, list.get(dragIndex)); return list.delete(dragIndex).insert(hoverIndex, list.get(dragIndex));
} }
); );
const updatedList = formatLayout(newState.getIn(layoutPath).toJS()); const updatedList = formatLayout(newState.getIn(layoutPathEdit).toJS());
return state.updateIn(layoutPath, () => fromJS(updatedList)); return state.updateIn(layoutPathEdit, () => fromJS(updatedList));
} }
case 'RESET': case 'RESET':
return state.update('modifiedData', () => state.get('initialData')); return state.update('modifiedData', () => state.get('initialData'));

View File

@ -57,8 +57,8 @@ const getSize = type => {
}; };
function settingViewModelReducer(state = initialState, action) { function settingViewModelReducer(state = initialState, action) {
const layoutPath = ['modifiedData', 'layouts', 'edit']; const layoutPathEdit = ['modifiedData', 'layouts', 'edit'];
const relationPath = ['modifiedData', 'layouts', 'editRelations']; const layoutPathRelations = ['modifiedData', 'layouts', 'editRelations'];
const { dragIndex, hoverIndex, dragRowIndex, hoverRowIndex } = action; const { dragIndex, hoverIndex, dragRowIndex, hoverRowIndex } = action;
const getFieldType = name => const getFieldType = name =>
state.getIn(['modifiedData', 'schema', 'attributes', name, 'type']); state.getIn(['modifiedData', 'schema', 'attributes', name, 'type']);
@ -70,9 +70,7 @@ function settingViewModelReducer(state = initialState, action) {
); );
case ADD_RELATION: case ADD_RELATION:
return state return state
.updateIn(['modifiedData', 'layouts', 'editRelations'], list => .updateIn(layoutPathRelations, list => list.push(action.name))
list.push(action.name)
)
.update('itemNameToSelect', () => action.name) .update('itemNameToSelect', () => action.name)
.update('itemFormType', () => getFieldType(action.name)); .update('itemFormType', () => getFieldType(action.name));
case GET_DATA_SUCCEEDED: case GET_DATA_SUCCEEDED:
@ -93,17 +91,20 @@ function settingViewModelReducer(state = initialState, action) {
return action.overIndex; return action.overIndex;
}); });
case MOVE_RELATION: { case MOVE_RELATION: {
return state.updateIn(relationPath, list => { return state.updateIn(layoutPathRelations, list => {
return list return list
.delete(dragIndex) .delete(dragIndex)
.insert(hoverIndex, state.getIn([...relationPath, dragIndex])); .insert(hoverIndex, state.getIn([...layoutPathRelations, dragIndex]));
}); });
} }
case MOVE_ROW: case MOVE_ROW:
return state.updateIn(layoutPath, list => { return state.updateIn(layoutPathEdit, list => {
return list return list
.delete(dragRowIndex) .delete(dragRowIndex)
.insert(hoverRowIndex, state.getIn([...layoutPath, dragRowIndex])); .insert(
hoverRowIndex,
state.getIn([...layoutPathEdit, dragRowIndex])
);
}); });
case ON_ADD_DATA: { case ON_ADD_DATA: {
const size = getSize( const size = getSize(
@ -116,9 +117,9 @@ function settingViewModelReducer(state = initialState, action) {
]) ])
); );
const listSize = state.getIn(layoutPath).size; const listSize = state.getIn(layoutPathEdit).size;
const newList = state const newList = state
.getIn(layoutPath) .getIn(layoutPathEdit)
.updateIn([listSize - 1, 'rowContent'], list => { .updateIn([listSize - 1, 'rowContent'], list => {
if (list) { if (list) {
return list.push({ return list.push({
@ -132,7 +133,7 @@ function settingViewModelReducer(state = initialState, action) {
const formattedList = formatLayout(newList.toJS()); const formattedList = formatLayout(newList.toJS());
return state return state
.updateIn(layoutPath, () => fromJS(formattedList)) .updateIn(layoutPathEdit, () => fromJS(formattedList))
.update('itemNameToSelect', () => action.name) .update('itemNameToSelect', () => action.name)
.update('itemFormType', () => getFieldType(action.name)); .update('itemFormType', () => getFieldType(action.name));
} }
@ -169,7 +170,11 @@ function settingViewModelReducer(state = initialState, action) {
.update('modifiedData', () => state.get('initialData')) .update('modifiedData', () => state.get('initialData'))
.update('listFieldToEditIndex', () => 0); .update('listFieldToEditIndex', () => 0);
case REMOVE_FIELD: { case REMOVE_FIELD: {
const row = state.getIn([...layoutPath, action.rowIndex, 'rowContent']); const row = state.getIn([
...layoutPathEdit,
action.rowIndex,
'rowContent',
]);
let newState; let newState;
let fieldName; let fieldName;
@ -179,34 +184,30 @@ function settingViewModelReducer(state = initialState, action) {
(row.size == 2 && row.getIn([1, 'name']) === '_TEMP_') (row.size == 2 && row.getIn([1, 'name']) === '_TEMP_')
) { ) {
fieldName = state.getIn([ fieldName = state.getIn([
'modifiedData', ...layoutPathEdit,
'layouts',
'edit',
action.rowIndex, action.rowIndex,
'rowContent', 'rowContent',
0, 0,
'name', 'name',
]); ]);
newState = state.updateIn(layoutPath, list => newState = state.updateIn(layoutPathEdit, list =>
list.delete(action.rowIndex) list.delete(action.rowIndex)
); );
} else { } else {
fieldName = state.getIn([ fieldName = state.getIn([
'modifiedData', ...layoutPathEdit,
'layouts',
'edit',
action.rowIndex, action.rowIndex,
'rowContent', 'rowContent',
action.fieldIndex, action.fieldIndex,
'name', 'name',
]); ]);
newState = state.updateIn( newState = state.updateIn(
[...layoutPath, action.rowIndex, 'rowContent'], [...layoutPathEdit, action.rowIndex, 'rowContent'],
list => list.delete(action.fieldIndex) list => list.delete(action.fieldIndex)
); );
} }
const updatedList = fromJS( const updatedList = fromJS(
formatLayout(newState.getIn(layoutPath).toJS()) formatLayout(newState.getIn(layoutPathEdit).toJS())
); );
if (state.get('itemNameToSelect') === fieldName) { if (state.get('itemNameToSelect') === fieldName) {
@ -216,29 +217,35 @@ function settingViewModelReducer(state = initialState, action) {
0, 0,
'name', 'name',
]); ]);
const firstRelationFieldToSelect = state.getIn([...relationPath, 0]); const firstRelationFieldToSelect = state.getIn([
...layoutPathRelations,
0,
]);
const fieldToSelect = const fieldToSelect =
firstFieldEditToSelect || firstRelationFieldToSelect || ''; firstFieldEditToSelect || firstRelationFieldToSelect || '';
const fieldToSelectType = getFieldType(fieldToSelect) || ''; const fieldToSelectType = getFieldType(fieldToSelect) || '';
return state return state
.updateIn(layoutPath, () => updatedList) .updateIn(layoutPathEdit, () => updatedList)
.update('itemNameToSelect', () => fieldToSelect) .update('itemNameToSelect', () => fieldToSelect)
.update('itemFormType', () => fieldToSelectType); .update('itemFormType', () => fieldToSelectType);
} }
return state.updateIn(layoutPath, () => updatedList); return state.updateIn(layoutPathEdit, () => updatedList);
} }
case REMOVE_RELATION: { case REMOVE_RELATION: {
let newState = state.updateIn(relationPath, list => let newState = state.updateIn(layoutPathRelations, list =>
list.delete(action.index) list.delete(action.index)
); );
const fieldToDeleteName = state.getIn([...relationPath, action.index]); const fieldToDeleteName = state.getIn([
...layoutPathRelations,
action.index,
]);
if (state.get('itemNameToSelect') === fieldToDeleteName) { if (state.get('itemNameToSelect') === fieldToDeleteName) {
const firstRelation = newState.getIn([...relationPath, 0]); const firstRelation = newState.getIn([...layoutPathRelations, 0]);
const firstEditField = newState.getIn([ const firstEditField = newState.getIn([
...layoutPath, ...layoutPathEdit,
'0', '0',
'rowContent', 'rowContent',
'0', '0',
@ -256,31 +263,36 @@ function settingViewModelReducer(state = initialState, action) {
} }
case REORDER_DIFF_ROW: { case REORDER_DIFF_ROW: {
const newState = state const newState = state
.updateIn([...layoutPath, dragRowIndex, 'rowContent'], list => { .updateIn([...layoutPathEdit, dragRowIndex, 'rowContent'], list => {
return list.remove(dragIndex); return list.remove(dragIndex);
}) })
.updateIn([...layoutPath, hoverRowIndex, 'rowContent'], list => { .updateIn([...layoutPathEdit, hoverRowIndex, 'rowContent'], list => {
return list.insert( return list.insert(
hoverIndex, hoverIndex,
state.getIn([...layoutPath, dragRowIndex, 'rowContent', dragIndex]) state.getIn([
...layoutPathEdit,
dragRowIndex,
'rowContent',
dragIndex,
])
); );
}); });
const updatedList = formatLayout(newState.getIn(layoutPath).toJS()); const updatedList = formatLayout(newState.getIn(layoutPathEdit).toJS());
return state.updateIn(layoutPath, () => fromJS(updatedList)); return state.updateIn(layoutPathEdit, () => fromJS(updatedList));
} }
case REORDER_ROW: { case REORDER_ROW: {
const newState = state.updateIn( const newState = state.updateIn(
[...layoutPath, dragRowIndex, 'rowContent'], [...layoutPathEdit, dragRowIndex, 'rowContent'],
list => { list => {
return list.delete(dragIndex).insert(hoverIndex, list.get(dragIndex)); return list.delete(dragIndex).insert(hoverIndex, list.get(dragIndex));
} }
); );
const updatedList = formatLayout(newState.getIn(layoutPath).toJS()); const updatedList = formatLayout(newState.getIn(layoutPathEdit).toJS());
return state.updateIn(layoutPath, () => fromJS(updatedList)); return state.updateIn(layoutPathEdit, () => fromJS(updatedList));
} }
case RESET_PROPS: case RESET_PROPS:
return initialState; return initialState;