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

View File

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

View File

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

View File

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

View File

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

View File

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