console: automatically select the $eq operator when filtering table rows, close 9970

GITHUB_PR_NUMBER: 9971
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/9971

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10455
Co-authored-by: Bert Verhelst <1710840+bertyhell@users.noreply.github.com>
Co-authored-by: Vijay Prasanna <11921040+vijayprasanna13@users.noreply.github.com>
GitOrigin-RevId: 07dd4e46619609178fba982097526b3866d29776
This commit is contained in:
hasura-bot 2024-01-11 12:04:13 +05:30
parent 726842a3f8
commit 0a7e211538
2 changed files with 13 additions and 3 deletions

View File

@ -26,6 +26,15 @@ export const FilterRow = ({
const localOperator = watch(`${name}.operator`);
const localValue = watch(`${name}.value`);
/**
* Set operator to first operator if it is empty
*/
useEffect(() => {
if (!localOperator && operatorOptions[0]?.value) {
setValue(`${name}.operator`, operatorOptions[0].value);
}
}, [localOperator, operatorOptions, setValue, name]);
/**
* Set the default value into the input field depending on the operator type
*/

View File

@ -77,7 +77,7 @@ export const Primary: StoryObj<typeof LegacyRunQuery> = {
expect(await canvas.findAllByDisplayValue('Select a column')).toHaveLength(
2
);
expect(await canvas.findByDisplayValue('Select an operator')).toBeVisible();
expect(await canvas.findByTestId('filters.0.operator')).toBeVisible();
expect(await canvas.findByPlaceholderText('-- value --')).toBeVisible();
// select the value "id" in the "column" select
@ -88,7 +88,7 @@ export const Primary: StoryObj<typeof LegacyRunQuery> = {
// select the value "_eq" in the "operator" select
userEvent.selectOptions(
await canvas.findByDisplayValue('Select an operator'),
await canvas.findByTestId('filters.0.operator'),
'_eq'
);
@ -108,8 +108,9 @@ export const Primary: StoryObj<typeof LegacyRunQuery> = {
);
// select the value "_neq" in the second "operator" select
userEvent.selectOptions(
await canvas.findByDisplayValue('Select an operator'),
await canvas.findByTestId('filters.1.operator'),
'_neq'
);