Skip to content

Commit c3805fa

Browse files
authored
🐛 Add a fallback for issue title (#1273)
- In the event of a blank ruleReport.description, fallback to use the name or a hardcoded string to prevent an app crash Signed-off-by: ibolton336 <[email protected]>
1 parent 5e9a715 commit c3805fa

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

client/src/app/pages/issues/helpers.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Location, LocationDescriptor } from "history";
2-
import { AnalysisIssueReport, AnalysisRuleReport } from "@app/api/models";
2+
import {
3+
AnalysisIssue,
4+
AnalysisIssueReport,
5+
AnalysisRuleReport,
6+
} from "@app/api/models";
37
import {
48
FilterCategory,
59
FilterType,
@@ -113,11 +117,12 @@ export const getAffectedAppsUrl = ({
113117
.replace("/:rule/", `/${encodeURIComponent(ruleReport.rule)}/`);
114118
const prefix = (key: string) =>
115119
`${TableURLParamKeyPrefix.issuesAffectedApps}:${key}`;
120+
116121
return `${baseUrl}?${trimAndStringifyUrlParams({
117122
newPrefixedSerializedParams: {
118123
[prefix("filters")]: serializeFilterUrlParams(toFilterValues).filters,
119124
[FROM_ISSUES_PARAMS_KEY]: fromIssuesParams,
120-
issueTitle: ruleReport.description.split("\n")[0],
125+
issueTitle: getIssueTitle(ruleReport),
121126
},
122127
})}`;
123128
};
@@ -195,3 +200,10 @@ export const parseReportLabels = (
195200
});
196201
return { sources, targets, otherLabels };
197202
};
203+
204+
export const getIssueTitle = (
205+
issueReport: AnalysisRuleReport | AnalysisIssue | AnalysisIssueReport
206+
) =>
207+
issueReport?.description?.split("\n")[0] ||
208+
issueReport?.name?.split("\n")[0] ||
209+
"*Unnamed*";

client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/file-incidents-detail-modal.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useFetchIncidents } from "@app/queries/issues";
2222
import { IncidentCodeSnipViewer } from "./incident-code-snip-viewer";
2323
import { FileAllIncidentsTable } from "./file-all-incidents-table";
2424
import { IssueDescriptionAndLinks } from "../../components/issue-description-and-links";
25+
import { getIssueTitle } from "../../helpers";
2526

2627
export interface IFileIncidentsDetailModalProps {
2728
issue: AnalysisIssue;
@@ -58,7 +59,7 @@ export const FileIncidentsDetailModal: React.FC<
5859
isFetching ||
5960
(firstFiveIncidents.length > 0 && activeTabIncidentId === undefined);
6061

61-
const issueTitle = issue.description.split("\n")[0];
62+
const issueTitle = getIssueTitle(issue);
6263

6364
return (
6465
<Modal

client/src/app/pages/issues/issue-detail-drawer/issue-detail-drawer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IssueAffectedFilesTable } from "./issue-affected-files-table";
1717
import { useFetchIssue } from "@app/queries/issues";
1818
import { AppPlaceholder } from "@app/components/AppPlaceholder";
1919
import { StateNoData } from "@app/components/StateNoData";
20+
import { getIssueTitle } from "../helpers";
2021

2122
export interface IIssueDetailDrawerProps
2223
extends Pick<IPageDrawerContentProps, "onCloseClick"> {
@@ -61,7 +62,7 @@ export const IssueDetailDrawer: React.FC<IIssueDetailDrawerProps> = ({
6162
{applicationName}
6263
</Text>
6364
<Title headingLevel="h2" size="lg" className={spacing.mtXs}>
64-
<Truncate content={issue.description.split("\n")[0]} />
65+
<Truncate content={getIssueTitle(issue)} />
6566
</Title>
6667
</TextContent>
6768
<Tabs

client/src/app/pages/issues/issues-table.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
parseReportLabels,
5757
getIssuesSingleAppSelectedLocation,
5858
useSharedAffectedApplicationFilterCategories,
59+
getIssueTitle,
5960
} from "./helpers";
6061
import { IssueFilterGroups } from "./issues";
6162
import {
@@ -354,7 +355,7 @@ export const IssuesTable: React.FC<IIssuesTableProps> = ({ mode }) => {
354355
{...getTdProps({ columnKey: "description" })}
355356
modifier="truncate"
356357
>
357-
{report.description.split("\n")[0]}
358+
{getIssueTitle(report)}
358359
</Td>
359360
<Td width={20} {...getTdProps({ columnKey: "category" })}>
360361
{report.category}

0 commit comments

Comments
 (0)