diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 0acef3059f470..94f066282588a 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -8609,6 +8609,11 @@ "jed": "^1.1.1" } }, + "@superset-ui/validator": { + "version": "0.12.13", + "resolved": "https://registry.npmjs.org/@superset-ui/validator/-/validator-0.12.13.tgz", + "integrity": "sha512-X6GyXP80uJOhHrSUfS5Zf+jhFCLgiil9Md3YuNwArQN2qDK7qBsgb7vfiAhxPfKQfNgvmFeO5SVPZqdcl53aTw==" + }, "@types/airbnb-prop-types": { "version": "2.13.1", "resolved": "https://registry.npmjs.org/@types/airbnb-prop-types/-/airbnb-prop-types-2.13.1.tgz", diff --git a/superset-frontend/package.json b/superset-frontend/package.json index fe19545c9c89a..632aebd771a9a 100644 --- a/superset-frontend/package.json +++ b/superset-frontend/package.json @@ -92,6 +92,7 @@ "@superset-ui/query": "^0.12.8", "@superset-ui/time-format": "^0.12.10", "@superset-ui/translation": "^0.12.8", + "@superset-ui/validator": "^0.12.13", "@types/classnames": "^2.2.9", "@types/react-json-tree": "^0.6.11", "@types/react-select": "^1.2.1", diff --git a/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx b/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx index b6f2253280ed8..4c68cec6c30c9 100644 --- a/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx +++ b/superset-frontend/src/explore/components/controls/AnnotationLayer.jsx @@ -25,6 +25,7 @@ import { t } from '@superset-ui/translation'; import { SupersetClient } from '@superset-ui/connection'; import { getCategoricalSchemeRegistry } from '@superset-ui/color'; import { getChartMetadataRegistry } from '@superset-ui/chart'; +import { validateNonEmpty } from '@superset-ui/validator'; import SelectControl from './SelectControl'; import TextControl from './TextControl'; @@ -40,7 +41,6 @@ import ANNOTATION_TYPES, { import PopoverSection from '../../../components/PopoverSection'; import ControlHeader from '../ControlHeader'; -import { nonEmpty } from '../../validators'; import './AnnotationLayer.less'; const AUTOMATIC_COLOR = ''; @@ -215,14 +215,18 @@ export default class AnnotationLayer extends React.PureComponent { timeColumn, intervalEndColumn, } = this.state; - const errors = [nonEmpty(name), nonEmpty(annotationType), nonEmpty(value)]; + const errors = [ + validateNonEmpty(name), + validateNonEmpty(annotationType), + validateNonEmpty(value), + ]; if (sourceType !== ANNOTATION_SOURCE_TYPES.NATIVE) { if (annotationType === ANNOTATION_TYPES.EVENT) { - errors.push(nonEmpty(timeColumn)); + errors.push(validateNonEmpty(timeColumn)); } if (annotationType === ANNOTATION_TYPES.INTERVAL) { - errors.push(nonEmpty(timeColumn)); - errors.push(nonEmpty(intervalEndColumn)); + errors.push(validateNonEmpty(timeColumn)); + errors.push(validateNonEmpty(intervalEndColumn)); } } errors.push(this.isValidFormula(value, annotationType)); diff --git a/superset-frontend/src/explore/components/controls/TextControl.jsx b/superset-frontend/src/explore/components/controls/TextControl.jsx index 99212c3daf329..e829aab35f377 100644 --- a/superset-frontend/src/explore/components/controls/TextControl.jsx +++ b/superset-frontend/src/explore/components/controls/TextControl.jsx @@ -19,7 +19,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FormGroup, FormControl } from 'react-bootstrap'; -import * as v from '../../validators'; +import { + legacyValidateNumber, + legacyValidateInteger, +} from '@superset-ui/validator'; import ControlHeader from '../ControlHeader'; const propTypes = { @@ -51,7 +54,7 @@ export default class TextControl extends React.Component { // Validation & casting const errors = []; if (value !== '' && this.props.isFloat) { - const error = v.numeric(value); + const error = legacyValidateNumber(value); if (error) { errors.push(error); } else { @@ -59,7 +62,7 @@ export default class TextControl extends React.Component { } } if (value !== '' && this.props.isInt) { - const error = v.integer(value); + const error = legacyValidateInteger(value); if (error) { errors.push(error); } else { diff --git a/superset-frontend/src/explore/controlPanels/CalHeatmap.js b/superset-frontend/src/explore/controlPanels/CalHeatmap.js index d4292a991de81..a7ded55c101da 100644 --- a/superset-frontend/src/explore/controlPanels/CalHeatmap.js +++ b/superset-frontend/src/explore/controlPanels/CalHeatmap.js @@ -17,12 +17,12 @@ * under the License. */ import { t } from '@superset-ui/translation'; +import { legacyValidateInteger } from '@superset-ui/validator'; import { // formatSelectOptionsForRange, formatSelectOptions, // mainMetric, } from '../../modules/utils'; -import * as v from '.././validators'; import { D3_TIME_FORMAT_OPTIONS, D3_FORMAT_DOCS } from '../controls'; export default { @@ -85,7 +85,7 @@ export default { type: 'TextControl', isInt: true, default: 10, - validators: [v.integer], + validators: [legacyValidateInteger], renderTrigger: true, label: t('Cell Size'), description: t('The size of the square cell, in pixels'), @@ -96,7 +96,7 @@ export default { config: { type: 'TextControl', isInt: true, - validators: [v.integer], + validators: [legacyValidateInteger], renderTrigger: true, default: 2, label: t('Cell Padding'), @@ -110,7 +110,7 @@ export default { config: { type: 'TextControl', isInt: true, - validators: [v.integer], + validators: [legacyValidateInteger], renderTrigger: true, default: 0, label: t('Cell Radius'), @@ -122,7 +122,7 @@ export default { config: { type: 'TextControl', isInt: true, - validators: [v.integer], + validators: [legacyValidateInteger], renderTrigger: true, default: 10, label: t('Color Steps'), diff --git a/superset-frontend/src/explore/controlPanels/Chord.js b/superset-frontend/src/explore/controlPanels/Chord.js index b932c3f0e5039..f32a03b438d77 100644 --- a/superset-frontend/src/explore/controlPanels/Chord.js +++ b/superset-frontend/src/explore/controlPanels/Chord.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; export default { controlPanelSections: [ @@ -49,13 +49,13 @@ export default { groupby: { label: t('Source'), multi: false, - validators: [nonEmpty], + validators: [validateNonEmpty], description: t('Choose a source'), }, columns: { label: t('Target'), multi: false, - validators: [nonEmpty], + validators: [validateNonEmpty], description: t('Choose a target'), }, }, diff --git a/superset-frontend/src/explore/controlPanels/DeckArc.js b/superset-frontend/src/explore/controlPanels/DeckArc.js index 43fc52c248bf9..80c111d52d2d2 100644 --- a/superset-frontend/src/explore/controlPanels/DeckArc.js +++ b/superset-frontend/src/explore/controlPanels/DeckArc.js @@ -17,8 +17,11 @@ * under the License. */ import { t } from '@superset-ui/translation'; +import { + validateNonEmpty, + legacyValidateInteger, +} from '@superset-ui/validator'; import timeGrainSqlaAnimationOverrides from './timeGrainSqlaAnimationOverrides'; -import { nonEmpty, integer } from '../validators'; import { columnChoices, PRIMARY_COLOR } from '../controls'; import { formatSelectOptions } from '../../modules/utils'; import { @@ -47,7 +50,7 @@ export default { config: { type: 'SpatialControl', label: t('Start Longitude & Latitude'), - validators: [nonEmpty], + validators: [validateNonEmpty], description: t('Point to your spatial columns'), mapStateToProps: state => ({ choices: columnChoices(state.datasource), @@ -59,7 +62,7 @@ export default { config: { type: 'SpatialControl', label: t('End Longitude & Latitude'), - validators: [nonEmpty], + validators: [validateNonEmpty], description: t('Point to your spatial columns'), mapStateToProps: state => ({ choices: columnChoices(state.datasource), @@ -112,7 +115,7 @@ export default { type: 'SelectControl', freeForm: true, label: t('Stroke Width'), - validators: [integer], + validators: [legacyValidateInteger], default: null, renderTrigger: true, choices: formatSelectOptions([1, 2, 3, 4, 5]), diff --git a/superset-frontend/src/explore/controlPanels/DeckGeojson.js b/superset-frontend/src/explore/controlPanels/DeckGeojson.js index 37561773f388e..f59c2d0d84ba8 100644 --- a/superset-frontend/src/explore/controlPanels/DeckGeojson.js +++ b/superset-frontend/src/explore/controlPanels/DeckGeojson.js @@ -17,7 +17,10 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty, integer } from '../validators'; +import { + validateNonEmpty, + legacyValidateInteger, +} from '@superset-ui/validator'; import { formatSelectOptions } from '../../modules/utils'; import { columnChoices } from '../controls'; import { @@ -47,7 +50,7 @@ export default { config: { type: 'SelectControl', label: t('GeoJson Column'), - validators: [nonEmpty], + validators: [validateNonEmpty], description: t('Select the geojson column'), mapStateToProps: state => ({ choices: columnChoices(state.datasource), @@ -80,7 +83,7 @@ export default { type: 'SelectControl', freeForm: true, label: t('Point Radius Scale'), - validators: [integer], + validators: [legacyValidateInteger], default: null, choices: formatSelectOptions([0, 100, 200, 300, 500]), }, diff --git a/superset-frontend/src/explore/controlPanels/DeckGrid.js b/superset-frontend/src/explore/controlPanels/DeckGrid.js index 8a48eddbf9586..0482ab14fc4f8 100644 --- a/superset-frontend/src/explore/controlPanels/DeckGrid.js +++ b/superset-frontend/src/explore/controlPanels/DeckGrid.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; import { filterNulls, autozoom, @@ -65,7 +65,7 @@ export default { size: { label: t('Height'), description: t('Metric used to control height'), - validators: [nonEmpty], + validators: [validateNonEmpty], }, }, }; diff --git a/superset-frontend/src/explore/controlPanels/DeckMulti.js b/superset-frontend/src/explore/controlPanels/DeckMulti.js index 119e67259dc9b..b801cdd8a6bb3 100644 --- a/superset-frontend/src/explore/controlPanels/DeckMulti.js +++ b/superset-frontend/src/explore/controlPanels/DeckMulti.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; import { viewport } from './Shared_DeckGL'; export default { @@ -35,7 +35,7 @@ export default { type: 'SelectAsyncControl', multi: true, label: t('deck.gl charts'), - validators: [nonEmpty], + validators: [validateNonEmpty], default: [], description: t( 'Pick a set of deck.gl charts to layer on top of one another', diff --git a/superset-frontend/src/explore/controlPanels/DeckScatter.js b/superset-frontend/src/explore/controlPanels/DeckScatter.js index dcd5e1fbd8311..efb858454724c 100644 --- a/superset-frontend/src/explore/controlPanels/DeckScatter.js +++ b/superset-frontend/src/explore/controlPanels/DeckScatter.js @@ -17,8 +17,8 @@ * under the License. */ import { t } from '@superset-ui/translation'; +import { validateNonEmpty } from '@superset-ui/validator'; import timeGrainSqlaAnimationOverrides from './timeGrainSqlaAnimationOverrides'; -import { nonEmpty } from '../validators'; import { filterNulls, autozoom, @@ -99,7 +99,7 @@ export default { type: 'TextControl', label: t('Minimum Radius'), isFloat: true, - validators: [nonEmpty], + validators: [validateNonEmpty], renderTrigger: true, default: 2, description: t( @@ -114,7 +114,7 @@ export default { type: 'TextControl', label: t('Maximum Radius'), isFloat: true, - validators: [nonEmpty], + validators: [validateNonEmpty], renderTrigger: true, default: 250, description: t( diff --git a/superset-frontend/src/explore/controlPanels/DeckScreengrid.js b/superset-frontend/src/explore/controlPanels/DeckScreengrid.js index eaffd7c6cc796..2cd77787db7c8 100644 --- a/superset-frontend/src/explore/controlPanels/DeckScreengrid.js +++ b/superset-frontend/src/explore/controlPanels/DeckScreengrid.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; import timeGrainSqlaAnimationOverrides from './timeGrainSqlaAnimationOverrides'; import { filterNulls, @@ -69,7 +69,7 @@ export default { size: { label: t('Weight'), description: t("Metric used as a weight for the grid's coloring"), - validators: [nonEmpty], + validators: [validateNonEmpty], }, time_grain_sqla: timeGrainSqlaAnimationOverrides, }, diff --git a/superset-frontend/src/explore/controlPanels/DistBar.js b/superset-frontend/src/explore/controlPanels/DistBar.js index 06f58dffdacd8..891dcfbb5c60a 100644 --- a/superset-frontend/src/explore/controlPanels/DistBar.js +++ b/superset-frontend/src/explore/controlPanels/DistBar.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; export default { controlPanelSections: [ @@ -56,7 +56,7 @@ export default { controlOverrides: { groupby: { label: t('Series'), - validators: [nonEmpty], + validators: [validateNonEmpty], }, columns: { label: t('Breakdowns'), diff --git a/superset-frontend/src/explore/controlPanels/EventFlow.js b/superset-frontend/src/explore/controlPanels/EventFlow.js index 9e67f9104b946..fd6056b999f6a 100644 --- a/superset-frontend/src/explore/controlPanels/EventFlow.js +++ b/superset-frontend/src/explore/controlPanels/EventFlow.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; import { formatSelectOptionsForRange } from '../../modules/utils'; export default { @@ -78,7 +78,7 @@ export default { }, all_columns_x: { label: t('Column containing event names'), - validators: [nonEmpty], + validators: [validateNonEmpty], default: control => control.choices && control.choices.length > 0 ? control.choices[0][0] diff --git a/superset-frontend/src/explore/controlPanels/Heatmap.js b/superset-frontend/src/explore/controlPanels/Heatmap.js index 1586f573943c5..d56c96e6d561a 100644 --- a/superset-frontend/src/explore/controlPanels/Heatmap.js +++ b/superset-frontend/src/explore/controlPanels/Heatmap.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; import { formatSelectOptionsForRange } from '../../modules/utils'; const sortAxisChoices = [ @@ -139,10 +139,10 @@ export default { ], controlOverrides: { all_columns_x: { - validators: [nonEmpty], + validators: [validateNonEmpty], }, all_columns_y: { - validators: [nonEmpty], + validators: [validateNonEmpty], }, normalized: t( 'Whether to apply a normal distribution based on rank on the color scale', diff --git a/superset-frontend/src/explore/controlPanels/Histogram.js b/superset-frontend/src/explore/controlPanels/Histogram.js index d95ff80a2c926..041570ea681b7 100644 --- a/superset-frontend/src/explore/controlPanels/Histogram.js +++ b/superset-frontend/src/explore/controlPanels/Histogram.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; export default { controlPanelSections: [ @@ -48,7 +48,7 @@ export default { label: t('Numeric Columns'), description: t('Select the numeric columns to draw the histogram'), multi: true, - validators: [nonEmpty], + validators: [validateNonEmpty], }, link_length: { label: t('No of Bins'), diff --git a/superset-frontend/src/explore/controlPanels/LineMulti.js b/superset-frontend/src/explore/controlPanels/LineMulti.js index f00c5f76a5700..f0c1e4d9e4257 100644 --- a/superset-frontend/src/explore/controlPanels/LineMulti.js +++ b/superset-frontend/src/explore/controlPanels/LineMulti.js @@ -17,9 +17,9 @@ * under the License. */ import { t } from '@superset-ui/translation'; +import { validateNonEmpty } from '@superset-ui/validator'; import { annotations } from './sections'; import { D3_TIME_FORMAT_OPTIONS } from '../controls'; -import * as v from '../validators'; export default { requiresTime: true, @@ -65,7 +65,7 @@ export default { type: 'SelectAsyncControl', multi: true, label: t('Left Axis chart(s)'), - validators: [v.nonEmpty], + validators: [validateNonEmpty], default: [], description: t('Choose one or more charts for left axis'), dataEndpoint: diff --git a/superset-frontend/src/explore/controlPanels/Partition.jsx b/superset-frontend/src/explore/controlPanels/Partition.jsx index 8cb3b9d4c8236..466a32fec4dd7 100644 --- a/superset-frontend/src/explore/controlPanels/Partition.jsx +++ b/superset-frontend/src/explore/controlPanels/Partition.jsx @@ -18,9 +18,9 @@ */ import React from 'react'; import { t } from '@superset-ui/translation'; +import { validateNonEmpty } from '@superset-ui/validator'; import { NVD3TimeSeries } from './sections'; import OptionDescription from '../../components/OptionDescription'; -import { nonEmpty } from '../validators'; export default { controlPanelSections: [ @@ -35,7 +35,7 @@ export default { config: { type: 'SelectControl', label: t('Options'), - validators: [nonEmpty], + validators: [validateNonEmpty], default: 'not_time', valueKey: 'value', options: [ diff --git a/superset-frontend/src/explore/controlPanels/Shared_DeckGL.jsx b/superset-frontend/src/explore/controlPanels/Shared_DeckGL.jsx index a08ee476c9f66..ddadb47f4efb3 100644 --- a/superset-frontend/src/explore/controlPanels/Shared_DeckGL.jsx +++ b/superset-frontend/src/explore/controlPanels/Shared_DeckGL.jsx @@ -21,12 +21,11 @@ import React from 'react'; import { t } from '@superset-ui/translation'; +import { validateNonEmpty } from '@superset-ui/validator'; import ColumnOption from '../../components/ColumnOption'; import { D3_FORMAT_OPTIONS, columnChoices, PRIMARY_COLOR } from '../controls'; import { DEFAULT_VIEWPORT } from '../../explore/components/controls/ViewportControl'; -import { nonEmpty } from '../validators'; - const timeColumnOption = { verbose_name: 'Time', column_name: '__timestamp', @@ -230,7 +229,7 @@ export const lineColumn = { mapStateToProps: state => ({ choices: columnChoices(state.datasource), }), - validators: [nonEmpty], + validators: [validateNonEmpty], }, }; @@ -336,7 +335,7 @@ export const spatial = { config: { type: 'SpatialControl', label: t('Longitude & Latitude'), - validators: [nonEmpty], + validators: [validateNonEmpty], description: t('Point to your spatial columns'), mapStateToProps: state => ({ choices: columnChoices(state.datasource), diff --git a/superset-frontend/src/explore/controlPanels/Table.js b/superset-frontend/src/explore/controlPanels/Table.js index 4c573357f2932..69d754193393b 100644 --- a/superset-frontend/src/explore/controlPanels/Table.js +++ b/superset-frontend/src/explore/controlPanels/Table.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import * as v from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; import { D3_TIME_FORMAT_OPTIONS } from '../controls'; import { formatSelectOptions } from '../../modules/utils'; @@ -114,7 +114,7 @@ export default { label: t('Table Timestamp Format'), default: '%Y-%m-%d %H:%M:%S', renderTrigger: true, - validators: [v.nonEmpty], + validators: [validateNonEmpty], clearable: false, choices: D3_TIME_FORMAT_OPTIONS, description: t('Timestamp Format'), diff --git a/superset-frontend/src/explore/controlPanels/WordCloud.js b/superset-frontend/src/explore/controlPanels/WordCloud.js index 63bcfbbe3dac1..0851064262e30 100644 --- a/superset-frontend/src/explore/controlPanels/WordCloud.js +++ b/superset-frontend/src/explore/controlPanels/WordCloud.js @@ -17,7 +17,7 @@ * under the License. */ import { t } from '@superset-ui/translation'; -import { nonEmpty } from '../validators'; +import { validateNonEmpty } from '@superset-ui/validator'; export default { controlPanelSections: [ @@ -83,7 +83,7 @@ export default { ], controlOverrides: { series: { - validators: [nonEmpty], + validators: [validateNonEmpty], clearable: false, }, row_limit: { diff --git a/superset-frontend/src/explore/controls.jsx b/superset-frontend/src/explore/controls.jsx index c6404388280c7..83698c74f41c7 100644 --- a/superset-frontend/src/explore/controls.jsx +++ b/superset-frontend/src/explore/controls.jsx @@ -62,13 +62,16 @@ import { getCategoricalSchemeRegistry, getSequentialSchemeRegistry, } from '@superset-ui/color'; +import { + legacyValidateInteger, + validateNonEmpty, +} from '@superset-ui/validator'; import { formatSelectOptionsForRange, formatSelectOptions, mainMetric, } from '../modules/utils'; -import * as v from './validators'; import ColumnOption from '../components/ColumnOption'; import { TIME_FILTER_LABELS } from './constants'; @@ -153,7 +156,7 @@ const metrics = { type: 'MetricsControl', multi: true, label: t('Metrics'), - validators: [v.nonEmpty], + validators: [validateNonEmpty], default: c => { const metric = mainMetric(c.savedMetrics); return metric ? [metric] : null; @@ -423,7 +426,7 @@ export const controls = { type: 'SelectControl', label: t('Longitude'), default: 1, - validators: [v.nonEmpty], + validators: [validateNonEmpty], description: t('Select the longitude column'), mapStateToProps: state => ({ choices: columnChoices(state.datasource), @@ -434,7 +437,7 @@ export const controls = { type: 'SelectControl', label: t('Latitude'), default: 1, - validators: [v.nonEmpty], + validators: [validateNonEmpty], description: t('Select the latitude column'), mapStateToProps: state => ({ choices: columnChoices(state.datasource), @@ -444,7 +447,7 @@ export const controls = { polygon: { type: 'SelectControl', label: t('Polygon Column'), - validators: [v.nonEmpty], + validators: [validateNonEmpty], description: t( 'Select the polygon column. Each row should contain JSON.array(N) of [longitude, latitude] points', ), @@ -677,7 +680,7 @@ export const controls = { type: 'SelectControl', freeForm: true, label: t('Row limit'), - validators: [v.integer], + validators: [legacyValidateInteger], default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), }, @@ -686,7 +689,7 @@ export const controls = { type: 'SelectControl', freeForm: true, label: t('Series limit'), - validators: [v.integer], + validators: [legacyValidateInteger], choices: formatSelectOptions(SERIES_LIMITS), description: t( 'Limits the number of time series that get displayed. A sub query ' + @@ -766,7 +769,7 @@ export const controls = { label: t('Entity'), default: null, multi: false, - validators: [v.nonEmpty], + validators: [validateNonEmpty], description: t('This defines the element to be plotted on the chart'), }, @@ -874,7 +877,7 @@ export const controls = { clearable: false, choices: formatSelectOptions(['markdown', 'html']), default: 'markdown', - validators: [v.nonEmpty], + validators: [validateNonEmpty], description: t('Pick your favorite markup language'), }, @@ -1225,7 +1228,7 @@ export const controls = { column_collection: { type: 'CollectionControl', label: t('Time Series Columns'), - validators: [v.nonEmpty], + validators: [validateNonEmpty], controlName: 'TimeSeriesColumnControl', }, diff --git a/superset-frontend/src/explore/validators.js b/superset-frontend/src/explore/validators.js deleted file mode 100644 index 5cbdb21033c67..0000000000000 --- a/superset-frontend/src/explore/validators.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/* Reusable validator functions used in controls definitions - * - * validator functions receive the v and the configuration of the control - * as arguments and return something that evals to false if v is valid, - * and an error message if not valid. - * */ -import { t } from '@superset-ui/translation'; - -export function numeric(v) { - if (v && isNaN(v)) { - return t('is expected to be a number'); - } - return false; -} - -export function integer(v) { - if (v && (isNaN(v) || parseInt(v, 10) !== +v)) { - return t('is expected to be an integer'); - } - return false; -} - -export function nonEmpty(v) { - if ( - v === null || - v === undefined || - v === '' || - (Array.isArray(v) && v.length === 0) - ) { - return t('cannot be empty'); - } - return false; -}