From 4624f4d705b59be6829be89dfa8cc5449eb33420 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Fri, 27 Oct 2023 16:52:52 +0000 Subject: [PATCH] :bug: Adjust custom target edit to reflect api changes (#1489) https://issues.redhat.com/browse/MTA-1542 https://issues.redhat.com/browse/MTA-1543 --------- Signed-off-by: ibolton336 --- client/public/locales/en/translation.json | 5 +++ .../src/app/pages/identities/identities.tsx | 43 ++++++++++++++++--- .../components/custom-target-form.tsx | 4 +- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index 3e9c82b5ce..0363a01f83 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -97,6 +97,7 @@ "dialog": { "message": { "applicationsBulkDelete": "The selected application(s) will be deleted.", + "delete": "This action cannot be undone.", "discardAssessment": "The assessment for <1>{{applicationName}} will be discarded, as well as the review result. Do you wish to continue?", "leavePage": "Are you sure you want to leave this page? Be sure to save your changes, or they will be lost.", @@ -155,6 +156,10 @@ "appNotAssessedBody": "In order to review an application it must be assessed first. Assess the application and try again.", "assessmentStakeholderHeader": "Select the stakeholder(s) or stakeholder group(s) associated with this assessment.", "binaryPackaging": "Packaging will default to JAR if left empty.", + "blockedDeleteTracker": "Cannot delete {{what}} because it is associated with a tracker.", + "blockedDeleteApplication": "Cannot delete {{what}} because it is associated with an application.", + "blockedDeleteTarget": "Cannot delete {{what}} because it is associated with a target.", + "defaultBlockedDelete": "Cannot delete {{what}} because it is associated with another object.", "continueConfirmation": "Yes, continue", "copyAssessmentAndReviewBody": "Some of the selected target applications have an in-progress or complete assessment/review. By continuing, the existing assessment(s)/review(s) will be replaced by the copied assessment/review. Do you wish to continue?", "copyAssessmentAndReviewQuestion": "Copy assessment and review?", diff --git a/client/src/app/pages/identities/identities.tsx b/client/src/app/pages/identities/identities.tsx index 88e36a3890..1e897e8774 100644 --- a/client/src/app/pages/identities/identities.tsx +++ b/client/src/app/pages/identities/identities.tsx @@ -48,6 +48,7 @@ import { AppPlaceholder } from "@app/components/AppPlaceholder"; import { AppTableWithControls } from "@app/components/AppTableWithControls"; import { NoDataEmptyState } from "@app/components/NoDataEmptyState"; import { ConfirmDialog } from "@app/components/ConfirmDialog"; +import { useFetchTargets } from "@app/queries/targets"; const ENTITY_FIELD = "entity"; @@ -78,6 +79,8 @@ export const Identities: React.FC = () => { }); }; + const { targets } = useFetchTargets(); + const onDeleteIdentityError = (error: AxiosError) => { pushNotification({ title: getAxiosErrorMessage(error), @@ -186,6 +189,32 @@ export const Identities: React.FC = () => { setFilterValues({}); }; + const getBlockDeleteMessage = (item: Identity) => { + if (trackers.some((tracker) => tracker?.identity?.id === item.id)) { + return t("message.blockedDeleteTracker", { + what: item.name, + }); + } else if ( + applications?.some( + (app) => app?.identities?.some((id) => id.id === item.id) + ) + ) { + return t("message.blockedDeleteApplication", { + what: item.name, + }); + } else if ( + targets?.some((target) => target?.ruleset?.identity?.id === item.id) + ) { + return t("message.blockedDeleteTarget", { + what: item.name, + }); + } else { + return t("message.defaultBlockedDelete", { + what: item.name, + }); + } + }; + const rows: IRow[] = []; currentPageItems?.forEach((item: Identity) => { const typeFormattedString = typeOptions.find( @@ -223,12 +252,16 @@ export const Identities: React.FC = () => { { title: ( tracker?.identity?.id === item.id - )} - tooltipMessage={ - "Cannot delete credential assigned to a JIRA tracker." + isDeleteEnabled={ + trackers.some((tracker) => tracker?.identity?.id === item.id) || + applications?.some( + (app) => app?.identities?.some((id) => id.id === item.id) + ) || + targets?.some( + (target) => target?.ruleset?.identity?.id === item.id + ) } + tooltipMessage={getBlockDeleteMessage(item)} onEdit={() => setCreateUpdateModalState(item)} onDelete={() => { setIdentityToDelete(item); diff --git a/client/src/app/pages/migration-targets/components/custom-target-form.tsx b/client/src/app/pages/migration-targets/components/custom-target-form.tsx index 675661b549..013300964a 100644 --- a/client/src/app/pages/migration-targets/components/custom-target-form.tsx +++ b/client/src/app/pages/migration-targets/components/custom-target-form.tsx @@ -178,7 +178,9 @@ export const CustomTargetForm: React.FC = ({ : target?.ruleset?.rules?.length ? "manual" : "repository", - associatedCredentials: target?.ruleset?.identity?.name, + associatedCredentials: identities.find( + (identity) => identity.id === target?.ruleset?.identity?.id + )?.name, repositoryType: target?.ruleset?.repository?.kind, sourceRepository: target?.ruleset?.repository?.url, branch: target?.ruleset?.repository?.branch,