From ee1442bd23319a9cc3bebe56850a0e06dcff431d Mon Sep 17 00:00:00 2001 From: maxceem Date: Mon, 30 Nov 2020 12:37:24 +0200 Subject: [PATCH 1/2] fix: integers as maximum number of submission ref issue #784 --- .../MaximumSubmissions-Field/index.js | 5 +++-- src/util/format.js | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/util/format.js diff --git a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js index 7d70e3be..e6f4ddd1 100644 --- a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js +++ b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js @@ -4,6 +4,7 @@ import cn from 'classnames' import _ from 'lodash' import styles from './MaximumSubmissions-Field.module.scss' +import { formatInteger } from '../../../util/format' class MaximumSubmissionsField extends Component { render () { @@ -30,7 +31,7 @@ class MaximumSubmissionsField extends Component {
- {readOnly && ( {isUnlimited ? 'Unlimited' : count})} + {readOnly && ( {isUnlimited ? 'Unlimited' : formatInteger(count)})}
{!readOnly && (
@@ -75,7 +76,7 @@ class MaximumSubmissionsField extends Component { placeholder='' value={count} maxLength='200' - onChange={(e) => onUpdateMetadata('submissionLimit', e.target.value, 'count')} + onChange={(e) => onUpdateMetadata('submissionLimit', e.target.value.replace(/[^\d]+/g, ''), 'count')} />
diff --git a/src/util/format.js b/src/util/format.js new file mode 100644 index 00000000..9cb7bffc --- /dev/null +++ b/src/util/format.js @@ -0,0 +1,20 @@ +import _ from 'lodash' + +/** + * Formats number as integer. + * + * Support numbers and string as input. + * + * @param {Number|String} num number + * + * @returns {String} formatted integer + */ +export const formatInteger = (num) => { + // if the value is "empty", then display empty string + if (_.isNil(num) || (_.isString(num) && num.trim() === '')) { + return '' + } + + // otherwise try to display it as integer + return _.isNumber(num) ? num.toFixed(0) : parseInt(num, 10) +} From 42e3bbfb196a08c0da20822a72d005acc5678c8f Mon Sep 17 00:00:00 2001 From: maxceem Date: Mon, 30 Nov 2020 12:45:29 +0200 Subject: [PATCH 2/2] fix: remove formatter to see the real value ref issue #784 --- .../MaximumSubmissions-Field/index.js | 3 +-- src/util/format.js | 20 ------------------- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 src/util/format.js diff --git a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js index e6f4ddd1..03d0fc88 100644 --- a/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js +++ b/src/components/ChallengeEditor/MaximumSubmissions-Field/index.js @@ -4,7 +4,6 @@ import cn from 'classnames' import _ from 'lodash' import styles from './MaximumSubmissions-Field.module.scss' -import { formatInteger } from '../../../util/format' class MaximumSubmissionsField extends Component { render () { @@ -31,7 +30,7 @@ class MaximumSubmissionsField extends Component {
- {readOnly && ( {isUnlimited ? 'Unlimited' : formatInteger(count)})} + {readOnly && ( {isUnlimited ? 'Unlimited' : count})}
{!readOnly && (
diff --git a/src/util/format.js b/src/util/format.js deleted file mode 100644 index 9cb7bffc..00000000 --- a/src/util/format.js +++ /dev/null @@ -1,20 +0,0 @@ -import _ from 'lodash' - -/** - * Formats number as integer. - * - * Support numbers and string as input. - * - * @param {Number|String} num number - * - * @returns {String} formatted integer - */ -export const formatInteger = (num) => { - // if the value is "empty", then display empty string - if (_.isNil(num) || (_.isString(num) && num.trim() === '')) { - return '' - } - - // otherwise try to display it as integer - return _.isNumber(num) ? num.toFixed(0) : parseInt(num, 10) -}