Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing validators module from superset-ui #9465

Merged
merged 10 commits into from
Apr 14, 2020
Merged
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = '';
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -51,15 +54,15 @@ 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 {
value = value.match(/.*(\.)$/g) ? value : parseFloat(value);
}
}
if (value !== '' && this.props.isInt) {
const error = v.integer(value);
const error = legacyValidateInteger(value);
if (error) {
errors.push(error);
} else {
Expand Down
10 changes: 5 additions & 5 deletions superset-frontend/src/explore/controlPanels/CalHeatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'),
Expand All @@ -96,7 +96,7 @@ export default {
config: {
type: 'TextControl',
isInt: true,
validators: [v.integer],
validators: [legacyValidateInteger],
renderTrigger: true,
default: 2,
label: t('Cell Padding'),
Expand All @@ -110,7 +110,7 @@ export default {
config: {
type: 'TextControl',
isInt: true,
validators: [v.integer],
validators: [legacyValidateInteger],
renderTrigger: true,
default: 0,
label: t('Cell Radius'),
Expand All @@ -122,7 +122,7 @@ export default {
config: {
type: 'TextControl',
isInt: true,
validators: [v.integer],
validators: [legacyValidateInteger],
renderTrigger: true,
default: 10,
label: t('Color Steps'),
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/explore/controlPanels/Chord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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'),
},
},
Expand Down
11 changes: 7 additions & 4 deletions superset-frontend/src/explore/controlPanels/DeckArc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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]),
Expand Down
9 changes: 6 additions & 3 deletions superset-frontend/src/explore/controlPanels/DeckGeojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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]),
},
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/controlPanels/DeckGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,7 +65,7 @@ export default {
size: {
label: t('Height'),
description: t('Metric used to control height'),
validators: [nonEmpty],
validators: [validateNonEmpty],
},
},
};
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/controlPanels/DeckMulti.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/explore/controlPanels/DeckScatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,7 +99,7 @@ export default {
type: 'TextControl',
label: t('Minimum Radius'),
isFloat: true,
validators: [nonEmpty],
validators: [validateNonEmpty],
renderTrigger: true,
default: 2,
description: t(
Expand All @@ -114,7 +114,7 @@ export default {
type: 'TextControl',
label: t('Maximum Radius'),
isFloat: true,
validators: [nonEmpty],
validators: [validateNonEmpty],
renderTrigger: true,
default: 250,
description: t(
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/controlPanels/DeckScreengrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/controlPanels/DistBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -56,7 +56,7 @@ export default {
controlOverrides: {
groupby: {
label: t('Series'),
validators: [nonEmpty],
validators: [validateNonEmpty],
},
columns: {
label: t('Breakdowns'),
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/controlPanels/EventFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/explore/controlPanels/Heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/explore/controlPanels/Histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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'),
Expand Down
Loading