From 4911816734adf3b4d64a286a7962a574d7974a82 Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Wed, 9 Oct 2019 18:48:19 +0500 Subject: [PATCH] Allow creating label without name --- client/src/components/Label/Label.jsx | 7 +++--- client/src/components/LabelsStep/AddStep.jsx | 13 +++-------- client/src/components/LabelsStep/EditStep.jsx | 15 ++++--------- client/src/components/LabelsStep/Editor.jsx | 22 ++++--------------- client/src/components/LabelsStep/Item.jsx | 6 ++++- server/api/controllers/labels/create.js | 5 +++-- server/api/controllers/labels/update.js | 5 +++-- server/api/models/Label.js | 5 +++-- .../migrations/20180722003502_create_label.js | 4 ++-- 9 files changed, 31 insertions(+), 51 deletions(-) diff --git a/client/src/components/Label/Label.jsx b/client/src/components/Label/Label.jsx index 2fffba21..3de98477 100644 --- a/client/src/components/Label/Label.jsx +++ b/client/src/components/Label/Label.jsx @@ -48,7 +48,7 @@ const Label = React.memo(({ className={classNames(styles.wrapper, onClick && styles.hoverable)} style={style} > - {name} + {name || '\u00A0'} ); @@ -62,14 +62,15 @@ const Label = React.memo(({ }); Label.propTypes = { - name: PropTypes.string.isRequired, - color: PropTypes.oneOf(LabelColors.KEYS).isRequired, // TODO: without color + name: PropTypes.string, + color: PropTypes.oneOf(LabelColors.KEYS).isRequired, size: PropTypes.oneOf(Object.values(SIZES)), isDisabled: PropTypes.bool, onClick: PropTypes.func, }; Label.defaultProps = { + name: undefined, size: SIZES.MEDIUM, isDisabled: false, onClick: undefined, diff --git a/client/src/components/LabelsStep/AddStep.jsx b/client/src/components/LabelsStep/AddStep.jsx index 8e2c26d1..c98ba7e0 100755 --- a/client/src/components/LabelsStep/AddStep.jsx +++ b/client/src/components/LabelsStep/AddStep.jsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { Button, Form } from 'semantic-ui-react'; @@ -18,19 +18,12 @@ const AddStep = React.memo(({ onCreate, onBack }) => { color: LabelColors.KEYS[0], })); - const editor = useRef(null); - const handleSubmit = useDeepCompareCallback(() => { const cleanData = { ...data, - name: data.name.trim(), + name: data.name.trim() || null, }; - if (!cleanData.name) { - editor.current.selectNameField(); - return; - } - onCreate(cleanData); onBack(); }, [data, onCreate, onBack]); @@ -44,7 +37,7 @@ const AddStep = React.memo(({ onCreate, onBack }) => {
- +