Skip to content

Commit

Permalink
🐛 Adjust custom target edit to reflect api changes (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Oct 27, 2023
1 parent fe11195 commit 4624f4d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
5 changes: 5 additions & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}</1> 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.",
Expand Down Expand Up @@ -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?",
Expand Down
43 changes: 38 additions & 5 deletions client/src/app/pages/identities/identities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -78,6 +79,8 @@ export const Identities: React.FC = () => {
});
};

const { targets } = useFetchTargets();

const onDeleteIdentityError = (error: AxiosError) => {
pushNotification({
title: getAxiosErrorMessage(error),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -223,12 +252,16 @@ export const Identities: React.FC = () => {
{
title: (
<AppTableActionButtons
isDeleteEnabled={trackers.some(
(tracker) => 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export const CustomTargetForm: React.FC<CustomTargetFormProps> = ({
: 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,
Expand Down

0 comments on commit 4624f4d

Please sign in to comment.