Refactor functions that check typed text in lookups

This commit is contained in:
mabashian
2021-05-27 11:09:06 -04:00
parent 4ec7ba0107
commit 50de068a02
6 changed files with 80 additions and 74 deletions

View File

@@ -57,7 +57,11 @@ function ApplicationLookup({ onChange, value, label, fieldName, validate }) {
const checkApplicationName = useCallback( const checkApplicationName = useCallback(
async name => { async name => {
if (name && name !== '') { if (!name) {
onChange(null);
return;
}
try { try {
const { const {
data: { results: nameMatchResults, count: nameMatchCount }, data: { results: nameMatchResults, count: nameMatchCount },
@@ -66,9 +70,6 @@ function ApplicationLookup({ onChange, value, label, fieldName, validate }) {
} catch { } catch {
onChange(null); onChange(null);
} }
} else {
onChange(null);
}
}, },
[onChange] [onChange]
); );

View File

@@ -114,7 +114,11 @@ function CredentialLookup({
const checkCredentialName = useCallback( const checkCredentialName = useCallback(
async name => { async name => {
if (name && name !== '') { if (!name) {
onChange(null);
return;
}
try { try {
const typeIdParams = credentialTypeId const typeIdParams = credentialTypeId
? { credential_type: credentialTypeId } ? { credential_type: credentialTypeId }
@@ -138,9 +142,6 @@ function CredentialLookup({
} catch { } catch {
onChange(null); onChange(null);
} }
} else {
onChange(null);
}
}, },
[onChange, credentialTypeId, credentialTypeKind, credentialTypeNamespace] [onChange, credentialTypeId, credentialTypeKind, credentialTypeNamespace]
); );

View File

@@ -116,7 +116,11 @@ function ExecutionEnvironmentLookup({
const checkExecutionEnvironmentName = useCallback( const checkExecutionEnvironmentName = useCallback(
async name => { async name => {
if (name && name !== '') { if (!name) {
onChange(null);
return;
}
try { try {
const { const {
data: { results: nameMatchResults, count: nameMatchCount }, data: { results: nameMatchResults, count: nameMatchCount },
@@ -125,9 +129,6 @@ function ExecutionEnvironmentLookup({
} catch { } catch {
onChange(null); onChange(null);
} }
} else {
onChange(null);
}
}, },
[onChange] [onChange]
); );

View File

@@ -76,7 +76,11 @@ function InventoryLookup({
const checkInventoryName = useCallback( const checkInventoryName = useCallback(
async name => { async name => {
if (name && name !== '') { if (!name) {
onChange(null);
return;
}
try { try {
const { const {
data: { results: nameMatchResults, count: nameMatchCount }, data: { results: nameMatchResults, count: nameMatchCount },
@@ -85,9 +89,6 @@ function InventoryLookup({
} catch { } catch {
onChange(null); onChange(null);
} }
} else {
onChange(null);
}
}, },
[onChange] [onChange]
); );

View File

@@ -71,7 +71,11 @@ function OrganizationLookup({
const checkOrganizationName = useCallback( const checkOrganizationName = useCallback(
async name => { async name => {
if (name && name !== '') { if (!name) {
onChange(null);
return;
}
try { try {
const { const {
data: { results: nameMatchResults, count: nameMatchCount }, data: { results: nameMatchResults, count: nameMatchCount },
@@ -80,9 +84,6 @@ function OrganizationLookup({
} catch { } catch {
onChange(null); onChange(null);
} }
} else {
onChange(null);
}
}, },
[onChange] [onChange]
); );

View File

@@ -75,7 +75,11 @@ function ProjectLookup({
const checkProjectName = useCallback( const checkProjectName = useCallback(
async name => { async name => {
if (name && name !== '') { if (!name) {
onChange(null);
return;
}
try { try {
const { const {
data: { results: nameMatchResults, count: nameMatchCount }, data: { results: nameMatchResults, count: nameMatchCount },
@@ -84,9 +88,6 @@ function ProjectLookup({
} catch { } catch {
onChange(null); onChange(null);
} }
} else {
onChange(null);
}
}, },
[onChange] [onChange]
); );