Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Do not show the code viewer when no code snippet available #1685

Merged
merged 8 commits into from
Feb 26, 2024
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
Loading