chore: fix rename queries bug for query selector (#39565)

/ok-to-test tags="@tag.Anvil"

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Enhanced error messaging in the query selection process to provide
clearer feedback when a required query is missing.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13673807830>
> Commit: ab6df8677a09a75cf64f379399246f724b48af75
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13673807830&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Anvil`
> Spec:
> <hr>Wed, 05 Mar 2025 10:50:17 UTC
<!-- end of auto-generated comment: Cypress test results  -->
This commit is contained in:
Pawan Kumar 2025-03-05 16:59:55 +05:30 committed by GitHub
parent 1d60545859
commit 832a7062e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -155,6 +155,30 @@ export function useSource(searchText: string) {
return [...widgetOptions, ...filteredQueryOptions];
}, [filteredQueryOptions, widgetOptions]);
const error = useMemo(() => {
if (config.datasource) {
return "";
}
// DROPDOWN_VARIANT.CONNECT_TO_QUERY acts like query selector for us (we use it in AI widget)
// so we need to check if the selected query exists in the queryOptions
// if it does not exist, we need to show error that the query is not found
if (
datasourceDropdownVariant === DROPDOWN_VARIANT.CONNECT_TO_QUERY &&
propertyValue
) {
const selectedQuery = queryOptions.find(
(option) => option.value === propertyValue,
);
if (!selectedQuery) {
return `Chat query is required`;
}
}
return errorMsg;
}, [config.datasource, errorMsg, queryOptions, propertyValue]);
return {
constants,
datasourceOptions: filteredDatasourceOptions,
@ -165,7 +189,7 @@ export function useSource(searchText: string) {
connectToOptions,
isSourceOpen,
onSourceClose,
error: config.datasource ? "" : errorMsg,
error: error,
disabled: isConnecting,
};
}