diff --git a/awx/ui_next/src/components/Lookup/ApplicationLookup.jsx b/awx/ui_next/src/components/Lookup/ApplicationLookup.jsx index adbc986815..a1ab723c70 100644 --- a/awx/ui_next/src/components/Lookup/ApplicationLookup.jsx +++ b/awx/ui_next/src/components/Lookup/ApplicationLookup.jsx @@ -57,16 +57,17 @@ function ApplicationLookup({ onChange, value, label, fieldName, validate }) { const checkApplicationName = useCallback( async name => { - if (name && name !== '') { - try { - const { - data: { results: nameMatchResults, count: nameMatchCount }, - } = await ApplicationsAPI.read({ name }); - onChange(nameMatchCount ? nameMatchResults[0] : null); - } catch { - onChange(null); - } - } else { + if (!name) { + onChange(null); + return; + } + + try { + const { + data: { results: nameMatchResults, count: nameMatchCount }, + } = await ApplicationsAPI.read({ name }); + onChange(nameMatchCount ? nameMatchResults[0] : null); + } catch { onChange(null); } }, diff --git a/awx/ui_next/src/components/Lookup/CredentialLookup.jsx b/awx/ui_next/src/components/Lookup/CredentialLookup.jsx index 80581dc1da..6ff48d3e6e 100644 --- a/awx/ui_next/src/components/Lookup/CredentialLookup.jsx +++ b/awx/ui_next/src/components/Lookup/CredentialLookup.jsx @@ -114,31 +114,32 @@ function CredentialLookup({ const checkCredentialName = useCallback( async name => { - if (name && name !== '') { - try { - const typeIdParams = credentialTypeId - ? { credential_type: credentialTypeId } - : {}; - const typeKindParams = credentialTypeKind - ? { credential_type__kind: credentialTypeKind } - : {}; - const typeNamespaceParams = credentialTypeNamespace - ? { credential_type__namespace: credentialTypeNamespace } - : {}; + if (!name) { + onChange(null); + return; + } - const { - data: { results: nameMatchResults, count: nameMatchCount }, - } = await CredentialsAPI.read({ - name, - ...typeIdParams, - ...typeKindParams, - ...typeNamespaceParams, - }); - onChange(nameMatchCount ? nameMatchResults[0] : null); - } catch { - onChange(null); - } - } else { + try { + const typeIdParams = credentialTypeId + ? { credential_type: credentialTypeId } + : {}; + const typeKindParams = credentialTypeKind + ? { credential_type__kind: credentialTypeKind } + : {}; + const typeNamespaceParams = credentialTypeNamespace + ? { credential_type__namespace: credentialTypeNamespace } + : {}; + + const { + data: { results: nameMatchResults, count: nameMatchCount }, + } = await CredentialsAPI.read({ + name, + ...typeIdParams, + ...typeKindParams, + ...typeNamespaceParams, + }); + onChange(nameMatchCount ? nameMatchResults[0] : null); + } catch { onChange(null); } }, diff --git a/awx/ui_next/src/components/Lookup/ExecutionEnvironmentLookup.jsx b/awx/ui_next/src/components/Lookup/ExecutionEnvironmentLookup.jsx index 9c83536cbc..2ca14dae42 100644 --- a/awx/ui_next/src/components/Lookup/ExecutionEnvironmentLookup.jsx +++ b/awx/ui_next/src/components/Lookup/ExecutionEnvironmentLookup.jsx @@ -116,16 +116,17 @@ function ExecutionEnvironmentLookup({ const checkExecutionEnvironmentName = useCallback( async name => { - if (name && name !== '') { - try { - const { - data: { results: nameMatchResults, count: nameMatchCount }, - } = await ExecutionEnvironmentsAPI.read({ name }); - onChange(nameMatchCount ? nameMatchResults[0] : null); - } catch { - onChange(null); - } - } else { + if (!name) { + onChange(null); + return; + } + + try { + const { + data: { results: nameMatchResults, count: nameMatchCount }, + } = await ExecutionEnvironmentsAPI.read({ name }); + onChange(nameMatchCount ? nameMatchResults[0] : null); + } catch { onChange(null); } }, diff --git a/awx/ui_next/src/components/Lookup/InventoryLookup.jsx b/awx/ui_next/src/components/Lookup/InventoryLookup.jsx index befefa8a91..66a7bd841f 100644 --- a/awx/ui_next/src/components/Lookup/InventoryLookup.jsx +++ b/awx/ui_next/src/components/Lookup/InventoryLookup.jsx @@ -76,16 +76,17 @@ function InventoryLookup({ const checkInventoryName = useCallback( async name => { - if (name && name !== '') { - try { - const { - data: { results: nameMatchResults, count: nameMatchCount }, - } = await InventoriesAPI.read({ name }); - onChange(nameMatchCount ? nameMatchResults[0] : null); - } catch { - onChange(null); - } - } else { + if (!name) { + onChange(null); + return; + } + + try { + const { + data: { results: nameMatchResults, count: nameMatchCount }, + } = await InventoriesAPI.read({ name }); + onChange(nameMatchCount ? nameMatchResults[0] : null); + } catch { onChange(null); } }, diff --git a/awx/ui_next/src/components/Lookup/OrganizationLookup.jsx b/awx/ui_next/src/components/Lookup/OrganizationLookup.jsx index 750e361467..1741a900ca 100644 --- a/awx/ui_next/src/components/Lookup/OrganizationLookup.jsx +++ b/awx/ui_next/src/components/Lookup/OrganizationLookup.jsx @@ -71,16 +71,17 @@ function OrganizationLookup({ const checkOrganizationName = useCallback( async name => { - if (name && name !== '') { - try { - const { - data: { results: nameMatchResults, count: nameMatchCount }, - } = await OrganizationsAPI.read({ name }); - onChange(nameMatchCount ? nameMatchResults[0] : null); - } catch { - onChange(null); - } - } else { + if (!name) { + onChange(null); + return; + } + + try { + const { + data: { results: nameMatchResults, count: nameMatchCount }, + } = await OrganizationsAPI.read({ name }); + onChange(nameMatchCount ? nameMatchResults[0] : null); + } catch { onChange(null); } }, diff --git a/awx/ui_next/src/components/Lookup/ProjectLookup.jsx b/awx/ui_next/src/components/Lookup/ProjectLookup.jsx index 89ad789550..2774a86eaf 100644 --- a/awx/ui_next/src/components/Lookup/ProjectLookup.jsx +++ b/awx/ui_next/src/components/Lookup/ProjectLookup.jsx @@ -75,16 +75,17 @@ function ProjectLookup({ const checkProjectName = useCallback( async name => { - if (name && name !== '') { - try { - const { - data: { results: nameMatchResults, count: nameMatchCount }, - } = await ProjectsAPI.read({ name }); - onChange(nameMatchCount ? nameMatchResults[0] : null); - } catch { - onChange(null); - } - } else { + if (!name) { + onChange(null); + return; + } + + try { + const { + data: { results: nameMatchResults, count: nameMatchCount }, + } = await ProjectsAPI.read({ name }); + onChange(nameMatchCount ? nameMatchResults[0] : null); + } catch { onChange(null); } },