Skip to content

Commit f556ef5

Browse files
fix(Charts): Set max row limit + removed the option to use an empty row limit value (apache#25579)
1 parent be3714e commit f556ef5

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import {
4747
isDefined,
4848
hasGenericChartAxes,
4949
NO_TIME_RANGE,
50+
validateNonEmpty,
51+
validateMaxValue,
5052
} from '@superset-ui/core';
5153

5254
import {
@@ -243,7 +245,12 @@ const row_limit: SharedControlConfig<'SelectControl'> = {
243245
type: 'SelectControl',
244246
freeForm: true,
245247
label: t('Row limit'),
246-
validators: [legacyValidateInteger],
248+
clearable: false,
249+
validators: [
250+
validateNonEmpty,
251+
legacyValidateInteger,
252+
v => validateMaxValue(v, 100000),
253+
],
247254
default: 10000,
248255
choices: formatSelectOptions(ROW_LIMIT_OPTIONS),
249256
description: t(

superset-frontend/packages/superset-ui-core/src/validator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export { default as legacyValidateNumber } from './legacyValidateNumber';
2222
export { default as validateInteger } from './validateInteger';
2323
export { default as validateNumber } from './validateNumber';
2424
export { default as validateNonEmpty } from './validateNonEmpty';
25+
export { default as validateMaxValue } from './validateMaxValue';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { t } from '../translation';
2+
3+
export default function validateMaxValue(v: unknown, max: Number) {
4+
if (Number(v) > +max) {
5+
return t('Value cannot exceed %s', max);
6+
}
7+
return false;
8+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { validateMaxValue } from '@superset-ui/core';
21+
import './setup';
22+
23+
describe('validateInteger()', () => {
24+
it('returns the warning message if invalid', () => {
25+
expect(validateMaxValue(10.1, 10)).toBeTruthy();
26+
expect(validateMaxValue(1, 0)).toBeTruthy();
27+
expect(validateMaxValue('2', 1)).toBeTruthy();
28+
});
29+
it('returns false if the input is valid', () => {
30+
expect(validateMaxValue(0, 1)).toBeFalsy();
31+
expect(validateMaxValue(10, 10)).toBeFalsy();
32+
expect(validateMaxValue(undefined, 1)).toBeFalsy();
33+
expect(validateMaxValue(NaN, NaN)).toBeFalsy();
34+
expect(validateMaxValue(null, 1)).toBeFalsy();
35+
expect(validateMaxValue('1', 1)).toBeFalsy();
36+
expect(validateMaxValue('a', 1)).toBeFalsy();
37+
});
38+
});

0 commit comments

Comments
 (0)