From 9cc405322e385ffbba8a8e80a54c8fe97fe57bcb Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 26 Feb 2024 09:21:59 -0500 Subject: [PATCH] :bug: Do not show the code viewer when no code snippet available (#1685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves https://github.com/konveyor/tackle2-ui/issues/1472 - Adds an empty state to the codeviewer when the codesnip is not populated / is an empty string or whitespace characters. Screenshot 2024-02-13 at 12 43 05 PM Signed-off-by: Ian Bolton Signed-off-by: Cherry Picker --- 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 f97c91fc2..9f6d3f1d4 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 e67085ba9..f6f646713 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;