-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add advisory list page * Add advisory details page
- Loading branch information
1 parent
e905565
commit b351d0d
Showing
33 changed files
with
1,316 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
global_palette_purple_400 as criticalColor, | ||
global_danger_color_100 as importantColor, | ||
global_info_color_100 as lowColor, | ||
global_warning_color_100 as moderateColor, | ||
} from "@patternfly/react-tokens"; | ||
|
||
import { Severity } from "./models"; | ||
import { ProgressProps } from "@patternfly/react-core"; | ||
|
||
type ListType = { | ||
[key in Severity]: { | ||
shieldIconColor: { name: string; value: string; var: string }; | ||
progressProps: Pick<ProgressProps, "variant">; | ||
}; | ||
}; | ||
|
||
export const severityList: ListType = { | ||
low: { | ||
shieldIconColor: lowColor, | ||
progressProps: { variant: undefined }, | ||
}, | ||
moderate: { | ||
shieldIconColor: moderateColor, | ||
progressProps: { variant: "warning" }, | ||
}, | ||
important: { | ||
shieldIconColor: importantColor, | ||
progressProps: { variant: "danger" }, | ||
}, | ||
critical: { | ||
shieldIconColor: criticalColor, | ||
progressProps: { variant: "danger" }, | ||
}, | ||
}; | ||
|
||
export const severityFromNumber = (score: number): Severity => { | ||
if (score >= 9.0) { | ||
return "critical"; | ||
} else if (score >= 7.0) { | ||
return "important"; | ||
} else if (score >= 4.0) { | ||
return "moderate"; | ||
} else { | ||
return "low"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,45 @@ | ||
import axios from "axios"; | ||
import { serializeRequestParamsForHub } from "@app/hooks/table-controls"; | ||
import { HubPaginatedResult, HubRequestParams } from "./models"; | ||
import axios from "axios"; | ||
import { Advisory, HubPaginatedResult, HubRequestParams } from "./models"; | ||
|
||
const HUB = "/hub"; | ||
|
||
interface ApiSearchResult<T> { | ||
total: number; | ||
result: T[]; | ||
} | ||
export const ADVISORIES = HUB + "/advisories"; | ||
|
||
export const getHubPaginatedResult = <T>( | ||
url: string, | ||
params: HubRequestParams = {} | ||
): Promise<HubPaginatedResult<T>> => | ||
axios | ||
.get<ApiSearchResult<T>>(url, { | ||
.get<T[]>(url, { | ||
params: serializeRequestParamsForHub(params), | ||
}) | ||
.then(({ data }) => ({ | ||
data: data.result, | ||
total: data.total, | ||
.then(({ data, headers }) => ({ | ||
data, | ||
total: headers["x-total"] | ||
? parseInt(headers["x-total"], 10) | ||
: data.length, | ||
params, | ||
})); | ||
|
||
export const getAdvisories = (params: HubRequestParams = {}) => { | ||
return getHubPaginatedResult<Advisory>(ADVISORIES, params); | ||
}; | ||
|
||
export const getAdvisoryById = (id: number | string) => { | ||
return axios | ||
.get<Advisory>(`${ADVISORIES}/${id}`) | ||
.then((response) => response.data); | ||
}; | ||
|
||
export const getAdvisorySourceById = (id: number | string) => { | ||
return axios | ||
.get<string>(`${ADVISORIES}/${id}/source`) | ||
.then((response) => response.data); | ||
}; | ||
|
||
export const downloadAdvisoryById = (id: number | string) => { | ||
return axios.get<string>(`${ADVISORIES}/${id}/source`, { | ||
responseType: "arraybuffer", | ||
headers: { Accept: "text/plain", responseType: "blob" }, | ||
}); | ||
}; |
35 changes: 35 additions & 0 deletions
35
frontend/client/src/app/components/AdvisoryVulnerabilitiesTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
|
||
import { Flex, FlexItem } from "@patternfly/react-core"; | ||
import ShieldIcon from "@patternfly/react-icons/dist/esm/icons/shield-alt-icon"; | ||
|
||
import { Severity } from "@app/api/models"; | ||
import { severityList } from "@app/api/model-utils"; | ||
|
||
interface SeverityRendererProps { | ||
value: Severity; | ||
showLabel?: boolean; | ||
} | ||
|
||
export const SeverityRenderer: React.FC<SeverityRendererProps> = ({ | ||
value, | ||
showLabel, | ||
}) => { | ||
const severityProps = severityList[value]; | ||
|
||
return ( | ||
<Flex | ||
spaceItems={{ default: "spaceItemsXs" }} | ||
alignItems={{ default: "alignItemsCenter" }} | ||
flexWrap={{ default: "nowrap" }} | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
<FlexItem> | ||
<ShieldIcon color={severityProps.shieldIconColor.value} /> | ||
</FlexItem> | ||
{showLabel && ( | ||
<FlexItem>{value.charAt(0).toUpperCase() + value.slice(1)}</FlexItem> | ||
)} | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import ErrorState from "@patternfly/react-component-groups/dist/esm/ErrorState"; | ||
import { Bullseye, Spinner } from "@patternfly/react-core"; | ||
|
||
export const LoadingWrapper = (props: { | ||
isFetching: boolean; | ||
fetchError?: Error; | ||
children: React.ReactNode; | ||
}) => { | ||
if (props.isFetching) { | ||
return ( | ||
<Bullseye> | ||
<Spinner /> | ||
</Bullseye> | ||
); | ||
} else if (props.fetchError) { | ||
return <ErrorState errorTitle="Error" />; | ||
} else { | ||
return props.children; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
frontend/client/src/app/components/SeverityProgressBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react"; | ||
|
||
import { Progress } from "@patternfly/react-core"; | ||
|
||
import { severityFromNumber, severityList } from "@app/api/model-utils"; | ||
|
||
interface SeverityRendererProps { | ||
value: number; | ||
showLabel?: boolean; | ||
} | ||
|
||
export const SeverityProgressBar: React.FC<SeverityRendererProps> = ({ | ||
value, | ||
}) => { | ||
const severityType = severityFromNumber(value); | ||
const severityProps = severityList[severityType]; | ||
|
||
return ( | ||
<> | ||
<Progress | ||
aria-labelledby="severity" | ||
size="sm" | ||
max={10} | ||
value={value} | ||
label={`${value}/10`} | ||
{...severityProps.progressProps} | ||
/> | ||
</> | ||
); | ||
}; |
46 changes: 46 additions & 0 deletions
46
frontend/client/src/app/components/SeverityShieldAndText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react"; | ||
|
||
import { Flex, FlexItem } from "@patternfly/react-core"; | ||
import ShieldIcon from "@patternfly/react-icons/dist/esm/icons/shield-alt-icon"; | ||
|
||
import { severityFromNumber, severityList } from "@app/api/model-utils"; | ||
import { Severity } from "@app/api/models"; | ||
|
||
interface SeverityShieldAndTextProps { | ||
value: Severity | number; | ||
showLabel?: boolean; | ||
} | ||
|
||
export const SeverityShieldAndText: React.FC<SeverityShieldAndTextProps> = ({ | ||
value, | ||
showLabel, | ||
}) => { | ||
let severity: Severity; | ||
if (typeof value === "number") { | ||
severity = severityFromNumber(value); | ||
} else { | ||
severity = value; | ||
} | ||
|
||
const severityProps = severityList[severity]; | ||
|
||
return ( | ||
<> | ||
<Flex | ||
spaceItems={{ default: "spaceItemsXs" }} | ||
alignItems={{ default: "alignItemsCenter" }} | ||
flexWrap={{ default: "nowrap" }} | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
<FlexItem> | ||
<ShieldIcon color={severityProps.shieldIconColor.value} /> | ||
</FlexItem> | ||
{showLabel && ( | ||
<FlexItem> | ||
{severity.charAt(0).toUpperCase() + severity.slice(1)} | ||
</FlexItem> | ||
)} | ||
</Flex> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.