Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export { default as isEqualArray } from './isEqualArray';
export { default as makeSingleton } from './makeSingleton';
export { default as promiseTimeout } from './promiseTimeout';
export { default as removeDuplicates } from './removeDuplicates';
export { default as withLabel } from './withLabel';
export { lruCache } from './lruCache';
export { getSelectedText } from './getSelectedText';
export * from './featureFlags';
Expand Down
41 changes: 41 additions & 0 deletions superset-frontend/packages/superset-ui-core/src/utils/withLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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.
*/

/**
* Wraps a validator function to prepend a label to its error message.
*
* @param validator - The validator function to wrap
* @param label - The label to prepend to error messages
* @returns A new validator function that includes the label in error messages
*
* @example
* validators: [
* withLabel(validateInteger, t('Row limit')),
* ]
* // Returns: "Row limit is expected to be an integer"
*/
export default function withLabel(
validator: (v: unknown, state?: any) => string | false,
label: string,
) {
return (v: unknown, state?: any) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are a bit shallow. Can we improve?

const error = validator(v, state);
return error ? `${label} ${error}` : false;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { t } from '@apache-superset/core';

export default function validateInteger(v: any) {
export default function validateNumber(v: any) {
if (
(typeof v === 'string' &&
v.trim().length > 0 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import { validateMaxValue } from '@superset-ui/core';
Comment thread
FelipeGLopez marked this conversation as resolved.
import './setup';

test('validateInteger returns the warning message if invalid', () => {
test('validateMaxValue returns the warning message if invalid', () => {
expect(validateMaxValue(10.1, 10)).toBeTruthy();
expect(validateMaxValue(1, 0)).toBeTruthy();
expect(validateMaxValue('2', 1)).toBeTruthy();
});

test('validateInteger returns false if the input is valid', () => {
test('validateMaxValue returns false if the input is valid', () => {
expect(validateMaxValue(0, 1)).toBeFalsy();
expect(validateMaxValue(10, 10)).toBeFalsy();
expect(validateMaxValue(undefined, 1)).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
SMART_DATE_ID,
validateMaxValue,
validateServerPagination,
withLabel,
} from '@superset-ui/core';
import { GenericDataType } from '@apache-superset/core/api/core';
import { isEmpty, last } from 'lodash';
Expand Down Expand Up @@ -384,7 +385,7 @@ const config: ControlPanelConfig = {
description: t('Rows per page, 0 means no pagination'),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.server_pagination?.value),
validators: [validateInteger],
validators: [withLabel(validateInteger, t('Server Page Length'))],
},
},
],
Expand All @@ -403,7 +404,7 @@ const config: ControlPanelConfig = {
state?.common?.conf?.SQL_MAX_ROW,
}),
validators: [
validateInteger,
withLabel(validateInteger, t('Row limit')),
(v, state) =>
validateMaxValue(
v,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* under the License.
*/
import { t } from '@apache-superset/core';
import { validateInteger, validateNonEmpty } from '@superset-ui/core';
import {
validateInteger,
validateNonEmpty,
withLabel,
Comment thread
FelipeGLopez marked this conversation as resolved.
} from '@superset-ui/core';
import { GenericDataType } from '@apache-superset/core/api/core';
import {
ControlPanelConfig,
Expand Down Expand Up @@ -66,7 +70,7 @@ const config: ControlPanelConfig = {
default: 5,
choices: formatSelectOptionsForRange(5, 20, 5),
description: t('The number of bins for the histogram'),
validators: [validateInteger],
validators: [withLabel(validateInteger, t('Bins'))],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
SMART_DATE_ID,
validateMaxValue,
validateServerPagination,
withLabel,
} from '@superset-ui/core';
import { GenericDataType } from '@apache-superset/core/api/core';
import { isEmpty, last } from 'lodash';
Expand Down Expand Up @@ -407,7 +408,7 @@ const config: ControlPanelConfig = {
description: t('Rows per page, 0 means no pagination'),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.server_pagination?.value),
validators: [validateInteger],
validators: [withLabel(validateInteger, t('Server Page Length'))],
},
},
],
Expand All @@ -419,14 +420,15 @@ const config: ControlPanelConfig = {
freeForm: true,
label: t('Row limit'),
clearable: false,
mapStateToProps: state => ({
mapStateToProps: (state, controlState) => ({
value: controlState?.value ?? 10000,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config has a default field you can use. Wouldn't that be enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is 10000, but the issue persists even after changing it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then do you think the issue might be in the control or the component?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me revise the control again.

@FelipeGLopez FelipeGLopez Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this issue here with undefined & null. Also, there was another default prop outside the config in a json called override that in this particular case didn't have any effect. I deleted it.

maxValue: state?.common?.conf?.TABLE_VIZ_MAX_ROW_SERVER,
server_pagination: state?.form_data?.server_pagination,
maxValueWithoutServerPagination:
state?.common?.conf?.SQL_MAX_ROW,
}),
validators: [
validateInteger,
withLabel(validateInteger, t('Row limit')),
(v, state) =>
validateMaxValue(
v,
Expand Down
Loading