Skip to content

[ES|QL] Index editor cell validations#224728

Merged
sddonne merged 6 commits intoelastic:feature/lookup-join-uxfrom
sddonne:lookup-join/validations
Jun 26, 2025
Merged

[ES|QL] Index editor cell validations#224728
sddonne merged 6 commits intoelastic:feature/lookup-join-uxfrom
sddonne:lookup-join/validations

Conversation

@sddonne
Copy link
Contributor

@sddonne sddonne commented Jun 20, 2025

Summary

Related issue #207330

Adds simple type validations when editing/adding a new cell in the index editor.

image
@sddonne sddonne changed the base branch from main to feature/lookup-join-ux June 20, 2025 15:25
@sddonne sddonne marked this pull request as ready for review June 25, 2025 07:32
@sddonne sddonne requested a review from a team as a code owner June 25, 2025 07:32
Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Just a code review, I didn't test

Comment on lines 50 to 79
const validateValue = (val: string): string | undefined => {
if (!columnType) return undefined;

let validation;
switch (columnType) {
case 'number':
validation = isNaN(Number(val))
? i18n.translate('indexEditor.cellValueInput.validation.number', {
defaultMessage: 'Value must be a number',
})
: undefined;
break;
case 'boolean':
validation =
val !== 'true' && val !== 'false'
? i18n.translate('indexEditor.cellValueInput.validation.boolean', {
defaultMessage: 'Value must be true or false',
})
: undefined;
break;
default:
validation = undefined;
}
if (validation) {
notifications.toasts.addDanger({
title: validation,
});
}
return validation;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this to be inside the react component? Why don't we declare it outside as a helper function?

Suggested change
const validateValue = (val: string): string | undefined => {
if (!columnType) return undefined;
let validation;
switch (columnType) {
case 'number':
validation = isNaN(Number(val))
? i18n.translate('indexEditor.cellValueInput.validation.number', {
defaultMessage: 'Value must be a number',
})
: undefined;
break;
case 'boolean':
validation =
val !== 'true' && val !== 'false'
? i18n.translate('indexEditor.cellValueInput.validation.boolean', {
defaultMessage: 'Value must be true or false',
})
: undefined;
break;
default:
validation = undefined;
}
if (validation) {
notifications.toasts.addDanger({
title: validation,
});
}
return validation;
};
const validateValue = (val: string, columnType?: string): string | undefined => {
if (!columnType) {
return undefined;
}
let errorMessage: string | undefined;
switch (columnType) {
case 'number':
if (isNaN(Number(val))) {
errorMessage = i18n.translate('indexEditor.cellValueInput.validation.number', {
defaultMessage: 'Value must be a number',
});
}
break;
case 'boolean':
if (!['true', 'false'].includes(val)) {
errorMessage = i18n.translate('indexEditor.cellValueInput.validation.boolean', {
defaultMessage: 'Value must be true or false',
});
}
break;
default:
errorMessage = undefined;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️ 98ffc81

services: { notifications },
} = useKibana<KibanaContextExtra>();
const [editValue, setEditValue] = useState(value);
const [error, setError] = useState<string | undefined>(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
const [error, setError] = useState<string | undefined>(undefined);
const [error, setError] = useState<string | undefined>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

const [error, setError] = useState<string | undefined>(undefined);

const columnType = useMemo(() => {
if (!columns || !columnName) return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!columns || !columnName) return undefined;
if (!columns || !columnName) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import { i18n } from '@kbn/i18n';
import { DatatableColumnType } from '@kbn/expressions-plugin/common';

export const validateCellValue = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should consider a different approach. What do you think about having a factory for the input component based on the data type? Each component could encapsulate its own validation logic, and potentially a different input UI in the future. For example, we could render EuiNumberInput for number, which provides a better UX out of the box

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a bad idea ++

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

I didnt test but it looks very nice now

@sddonne sddonne merged commit 531d80a into elastic:feature/lookup-join-ux Jun 26, 2025
6 of 9 checks passed
@elasticmachine
Copy link
Contributor

elasticmachine commented Jun 26, 2025

💔 Build Failed

Failed CI Steps

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants