Skip to content

Commit

Permalink
Merge branch 'main' into debug-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 11, 2023
2 parents 0fb5416 + 21b7afd commit a7f068e
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 35 deletions.
1 change: 1 addition & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"rootPath": "Root path",
"scheduled": "Scheduled",
"select": "Select",
"section": "Section",
"settingsAllowApps": "Allow reviewing applications without running an assessment first",
"showLess": "Show less",
"showMore": "Show more",
Expand Down
27 changes: 16 additions & 11 deletions client/src/app/components/ExternalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import * as React from "react";
import { Flex, FlexItem, Icon, Text } from "@patternfly/react-core";
import { Button, Icon } from "@patternfly/react-core";
import ExternalLinkAltIcon from "@patternfly/react-icons/dist/esm/icons/external-link-alt-icon";

/**
* Render a link open an external href in another tab with appropriate styling.
*/
export const ExternalLink: React.FC<{
href: string;
isInline?: boolean;
children: React.ReactNode;
}> = ({ href, children }) => (
<Flex spaceItems={{ default: "spaceItemsSm" }}>
<FlexItem>
<Text component="a" href={href} target="_blank">
{children}
</Text>
</FlexItem>
<FlexItem>
}> = ({ href, isInline = false, children }) => (
<Button
variant="link"
isInline={isInline}
component="a"
href={href}
target="_blank"
rel="noreferrer"
icon={
<Icon size="sm" status="info">
<ExternalLinkAltIcon />
</Icon>
</FlexItem>
</Flex>
}
iconPosition="right"
>
{children}
</Button>
);

export default ExternalLink;
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
background-color: var(--pf-v5-global--warning-color--100) !important ;
margin-right: 10px;
}

.actions-col {
vertical-align: middle !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,21 @@ const DynamicAssessmentActionsRow: FunctionComponent<
onDeleteError
);

const determineAction = () => {
const determineAction = React.useCallback(() => {
if (!assessment) {
return AssessmentAction.Take;
} else if (assessment.status === "started") {
return AssessmentAction.Continue;
} else {
return AssessmentAction.Retake;
}
};
}, [assessment]);

const [action, setAction] = React.useState(determineAction());

React.useEffect(() => {
setAction(determineAction());
}, [determineAction, assessment]);

const determineButtonClassName = () => {
const action = determineAction();
Expand Down Expand Up @@ -202,7 +208,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<

return (
<>
<Td>
<Td className="actions-col">
<div>
{isReadonly ? null : !isDeleting && !isFetching && !isMutating ? (
<Button
Expand All @@ -213,7 +219,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
onHandleAssessmentAction();
}}
>
{determineAction()}
{action}
</Button>
) : (
<Spinner role="status" size="md">
Expand Down Expand Up @@ -247,7 +253,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
</div>
</Td>
{assessment ? (
<Td isActionCell>
<Td isActionCell className="actions-col">
<Button
type="button"
variant="plain"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.actions-row {
min-height: 5vh;
}
.actions-col {
vertical-align: middle !important;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./questionnaires-table.css";
import React, { useState } from "react";
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";

Expand Down Expand Up @@ -98,7 +99,7 @@ const QuestionnairesTable: React.FC<QuestionnairesTableProps> = ({
);

return (
<Tr key={questionnaire.name}>
<Tr key={questionnaire.name} className="actions-row">
<TableRowContentWithControls
{...tableControls}
item={questionnaire}
Expand All @@ -107,6 +108,7 @@ const QuestionnairesTable: React.FC<QuestionnairesTableProps> = ({
<Td
width={20}
{...getTdProps({ columnKey: "questionnaires" })}
className="actions-col"
>
{questionnaire.name}
</Td>
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/pages/dependencies/dependency-apps-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ const DependencyVersionColumn = ({
return (
<TextContent>
{mavenCentralLink ? (
<ExternalLink href={mavenCentralLink}>{version}</ExternalLink>
<ExternalLink isInline href={mavenCentralLink}>
{version}
</ExternalLink>
) : (
<Text>{version}</Text>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";
import ReactMarkdown from "react-markdown";
import { TextContent, List, ListItem, Button } from "@patternfly/react-core";
import { TextContent, List, ListItem } from "@patternfly/react-core";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import ExternalLinkSquareAltIcon from "@patternfly/react-icons/dist/esm/icons/external-link-square-alt-icon";

import { AnalysisIssueLink } from "@app/api/models";
import { markdownPFComponents } from "@app/components/markdownPFComponents";
import ExternalLink from "@app/components/ExternalLink";

export interface IIssueDescriptionAndLinksProps {
description: string;
Expand All @@ -26,17 +26,7 @@ export const IssueDescriptionAndLinks: React.FC<
<List isPlain>
{links.map((link) => (
<ListItem key={link.url}>
<Button
variant="link"
component="a"
icon={<ExternalLinkSquareAltIcon />}
iconPosition="right"
href={link.url}
target="_blank"
rel="noreferrer"
>
{link.title}
</Button>
<ExternalLink href={link.url}>{link.title}</ExternalLink>
</ListItem>
))}
</List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const TicketIssue: React.FC<ITicketIssueProps> = ({ ticket }) => {
return (
<Text component={TextVariants.p}>
{ticket?.link ? (
<ExternalLink href={ticket.link}>{ticketIssue}</ExternalLink>
<ExternalLink isInline href={ticket.link}>
{ticketIssue}
</ExternalLink>
) : (
t("terms.unassigned")
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const ApplicationLandscape: React.FC<IApplicationLandscapeProps> = ({
riskLabel={
<Link to={getRisksUrl(["red"])}>{t("terms.highRisk")}</Link>
}
riskTitle={t("terms.highRisk")}
riskDescription={questionnaire?.riskMessages?.red ?? ""}
/>
</FlexItem>
Expand All @@ -163,6 +164,7 @@ export const ApplicationLandscape: React.FC<IApplicationLandscapeProps> = ({
{t("terms.mediumRisk")}
</Link>
}
riskTitle={t("terms.mediumRisk")}
riskDescription={questionnaire?.riskMessages?.yellow ?? ""}
/>
</FlexItem>
Expand All @@ -176,6 +178,7 @@ export const ApplicationLandscape: React.FC<IApplicationLandscapeProps> = ({
riskLabel={
<Link to={getRisksUrl(["green"])}>{t("terms.lowRisk")}</Link>
}
riskTitle={t("terms.lowRisk")}
riskDescription={questionnaire?.riskMessages?.green ?? ""}
/>
</FlexItem>
Expand All @@ -191,6 +194,7 @@ export const ApplicationLandscape: React.FC<IApplicationLandscapeProps> = ({
{`${t("terms.unassessed")}/${t("terms.unknown")}`}
</Link>
}
riskTitle={t("terms.unassessed")}
/>
</FlexItem>
</Flex>
Expand Down
6 changes: 4 additions & 2 deletions client/src/app/pages/reports/components/donut/donut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export interface IDonutProps {
total: number;
color: string;
riskLabel: string | React.ReactElement;
riskDescription?: string | React.ReactElement;
riskDescription?: string;
riskTitle: string;
isAssessment: boolean;
}

Expand All @@ -29,6 +30,7 @@ export const Donut: React.FC<IDonutProps> = ({
color,
riskLabel,
isAssessment,
riskTitle,
}) => {
const { t } = useTranslation();

Expand All @@ -50,7 +52,7 @@ export const Donut: React.FC<IDonutProps> = ({
}
constrainToVisibleArea={true}
data={[
{ x: riskLabel, y: value },
{ x: riskTitle, y: value },
{ x: t("terms.other"), y: total - value },
]}
labels={({ datum }) => `${datum.x}: ${datum.y}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Link } from "react-router-dom";
import { Paths } from "@app/Paths";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import RiskIcon from "@app/components/risk-icon/risk-icon";
import { FilterToolbar, FilterType } from "@app/components/FilterToolbar";

export interface IIdentifiedRisksTableProps {
assessmentRefs?: IdRef[];
Expand Down Expand Up @@ -152,6 +153,7 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
},
variant: "compact",
isPaginationEnabled: true,
isFilterEnabled: true,
isSortEnabled: true,
hasActionsColumn: false,
getSortValues: (item) => ({
Expand All @@ -173,6 +175,86 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
],
isExpansionEnabled: true,
expandableVariant: "single",
filterCategories: [
{
key: "questionnaireName",
title: t("terms.questionnaire"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.questionnaire").toLowerCase(),
}) + "...",
getItemValue: (item) => item.questionnaireName || "",
selectOptions: [
...new Set(
tableData.map((item) => item.questionnaireName).filter(Boolean)
),
].map((name) => ({ key: name, value: name })),
},
{
key: "section",
title: t("terms.section"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.section").toLowerCase(),
}) + "...",
getItemValue: (item) => item.section || "",
selectOptions: [
...new Set(tableData.map((item) => item.section).filter(Boolean)),
].map((name) => ({ key: name, value: name })),
},
{
key: "question",
title: t("terms.question"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.question").toLowerCase(),
}) + "...",
getItemValue: (item) => item.question.text || "",
selectOptions: [
...new Set(
tableData.map((item) => item.question.text).filter(Boolean)
),
].map((name) => ({ key: name, value: name })),
},
{
key: "answer",
title: t("terms.answer"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.answer").toLowerCase(),
}) + "...",
getItemValue: (item) => item.answer.text || "",
selectOptions: [
...new Set(tableData.map((item) => item.answer.text).filter(Boolean)),
].map((name) => ({ key: name, value: name })),
},
{
key: "risk",
title: t("terms.risk"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", { what: t("terms.risk").toLowerCase() }) +
"...",
getItemValue: (item: ITableRowData) => {
const riskKey = item.answer.risk;
const riskValue =
riskLevelMapping[riskKey as keyof typeof riskLevelMapping];
return riskValue.toString();
},
selectOptions: [
{ key: "3", value: "High" },
{ key: "2", value: "Medium" },
{ key: "1", value: "Low" },
{ key: "0", value: "Unknown" },
],
},
],
initialItemsPerPage: 10,
isSelectionEnabled: false,
});

const {
Expand All @@ -181,6 +263,7 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
propHelpers: {
toolbarProps,
paginationToolbarItemProps,
filterToolbarProps,
paginationProps,
tableProps,
getThProps,
Expand All @@ -196,6 +279,8 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
<>
<Toolbar {...toolbarProps}>
<ToolbarContent>
<FilterToolbar<ITableRowData, string> {...filterToolbarProps} />

<ToolbarItem {...paginationToolbarItemProps}>
<SimplePagination
idPrefix={`${"identified-risks-table"}}`}
Expand Down
1 change: 0 additions & 1 deletion client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export const useFetchAssessmentsByItemId = (
};
const assessmentsWithOrder: AssessmentWithSectionOrder[] =
data?.map(addSectionOrderToQuestions) || [];

return {
assessments: assessmentsWithOrder,
isFetching: isLoading,
Expand Down

0 comments on commit a7f068e

Please sign in to comment.