Skip to content

Commit

Permalink
🐛 Do not show the code viewer when no code snippet available
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 committed Feb 16, 2024
1 parent 046ccf6 commit 1b7f28a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -16,6 +25,22 @@ export const IncidentCodeSnipViewer: React.FC<IIncidentCodeSnipViewerProps> = ({
issueTitle,
incident,
}) => {
const { t } = useTranslation();

if (!incident?.codeSnip.trim()) {
return (
<EmptyState variant={EmptyStateVariant.sm}>
<EmptyStateHeader
titleText={t("message.noCodesSnippetAvailableTitle")}
headingLevel="h4"
icon={<EmptyStateIcon icon={CubesIcon} />}
/>
<EmptyStateBody>
{t("message.noCodesSnippetAvailableBody")}
</EmptyStateBody>
</EmptyState>
);
}
const codeSnipNumberedLines = incident.codeSnip.split("\n");
const codeSnipTrimmedLines: string[] = [];
let codeSnipStartLine = 1;
Expand Down

0 comments on commit 1b7f28a

Please sign in to comment.