-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add advisory list page #20
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ export interface ConfirmDialogProps { | |
| "danger" | ||
| "warning" | ||
| "info" | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw others eslint inline here and there and again I think those things will be solved in the future so no problem for me. |
||
| React.ComponentType<any>; | ||
message: string | React.ReactNode; | ||
|
||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to get words converted from numbers from the backend? Would future localizations be easier/harder? Should l10n stuff be only in the front-end, leaving the backend simpler?
I don't know nor do I have an opinion, just questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to get words converted from numbers from the backend?
Definitely it would be easier. The current Trustification returns a number. But you're right, this is thing to enhance and leave it to the backend to interpret/convert scores (numbers).
So I'll leave it to the backend .
It seems I will need to redefine my DTOs (mock DTOs, not linked to the backend yet). https://github.com/carlosthe19916/trustify/blob/advisory-list/frontend/client/src/app/api/models.ts#L73
Would future localizations be easier/harder
localyzation should not be affected. It won't make it easier nor harder, just not affect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1