From 1b7f28a2966c7712250271a8a40135788796fcee Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Tue, 13 Feb 2024 12:48:46 -0500 Subject: [PATCH] :bug: Do not show the code viewer when no code snippet available Signed-off-by: Ian Bolton --- client/public/locales/en/translation.json | 2 ++ .../incident-code-snip-viewer.tsx | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index f97c91fc29..9f6d3f1d40 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -198,6 +198,8 @@ "noDataAvailableTitle": "No data available", "noResultsFoundBody": "No results match the filter criteria. Remove all filters or clear all filters to show results.", "noResultsFoundTitle": "No results found", + "noCodesSnippetAvailableTitle": "No code snippet available", + "noCodesSnippetAvailableBody": "No code snippet was created for this incident.", "overrideAssessmentDescription": "The application {{name}} already is associated with archetypes: {{what}}.", "overrideAssessmentConfirmation": "Do you want to create a dedicated assessment for this application and override the inherited archetype assessment(s)?", "overrideArchetypeReviewDescription": "The application {{name}} already is associated with archetypes: {{what}}.", diff --git a/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/incident-code-snip-viewer.tsx b/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/incident-code-snip-viewer.tsx index e67085ba9e..f6f6467138 100644 --- a/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/incident-code-snip-viewer.tsx +++ b/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/incident-code-snip-viewer.tsx @@ -4,6 +4,15 @@ import { AnalysisIncident } from "@app/api/models"; import "./incident-code-snip-viewer.css"; import { LANGUAGES_BY_FILE_EXTENSION } from "config/monacoConstants"; +import { + EmptyState, + EmptyStateBody, + EmptyStateHeader, + EmptyStateIcon, + EmptyStateVariant, +} from "@patternfly/react-core"; +import { CubesIcon } from "@patternfly/react-icons"; +import { useTranslation } from "react-i18next"; const codeLineRegex = /^\s*([0-9]+)( {2})?(.*)$/; // Pattern: leading whitespace (line number) (2 spaces)? (code) @@ -16,6 +25,22 @@ export const IncidentCodeSnipViewer: React.FC = ({ issueTitle, incident, }) => { + const { t } = useTranslation(); + + if (!incident?.codeSnip.trim()) { + return ( + + } + /> + + {t("message.noCodesSnippetAvailableBody")} + + + ); + } const codeSnipNumberedLines = incident.codeSnip.split("\n"); const codeSnipTrimmedLines: string[] = []; let codeSnipStartLine = 1;