This repository was archived by the owner on Jul 8, 2025. It is now read-only.
refactor(alerts): consolidate queries#233
Merged
alex-mcgovern merged 3 commits intomainfrom Jan 30, 2025
Merged
Conversation
Contributor
alex-mcgovern
commented
Jan 30, 2025
- A follow on from fix(alerts): memoize selecting alerts #231 and test: alerts summary cards #226
- Continues refactoring data fetching for the alerts table, and queryParam state management to decouple these, and continue building a composable, modular system for data fetching
- Closes [Bug]: Duplicate requests to alerts #230
alex-mcgovern
commented
Jan 30, 2025
Comment on lines
+7
to
+34
| export function SwitchMaliciousAlertsFilter() { | ||
| const { setView, state } = useAlertsFilterSearchParams(); | ||
|
|
||
| return ( | ||
| <TooltipTrigger> | ||
| <Switch | ||
| id="malicious-packages" | ||
| isSelected={state.view === AlertsFilterView.MALICIOUS} | ||
| onChange={(isSelected) => { | ||
| switch (isSelected) { | ||
| case true: | ||
| return setView(AlertsFilterView.MALICIOUS); | ||
| case false: | ||
| return setView(AlertsFilterView.ALL); | ||
| default: | ||
| return isSelected satisfies never; | ||
| } | ||
| }} | ||
| > | ||
| Malicious Packages | ||
| </Switch> | ||
|
|
||
| <Tooltip> | ||
| <p>Filter by malicious packages</p> | ||
| </Tooltip> | ||
| </TooltipTrigger> | ||
| ); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Spoke with James, and we will soon remove this and replace with tabs for "all" | "malicious" | "secrets" | "PII" etc
alex-mcgovern
commented
Jan 30, 2025
Comment on lines
+6
to
+38
| export function doesAlertIncludeSearch( | ||
| alert: V1GetWorkspaceAlertsResponse[number], | ||
| searchQuery: string | null, | ||
| ): alert is AlertConversation { | ||
| if (alert == null) return false; | ||
| if (searchQuery === null) return true; | ||
|
|
||
| const trigger_type: string = alert.trigger_type; | ||
| const trigger_string: string | null = | ||
| typeof alert.trigger_string === "string" ? alert.trigger_string : null; | ||
|
|
||
| let malicious_pkg_name: string | null = null; | ||
| let malicious_pkg_type: string | null = null; | ||
|
|
||
| if ( | ||
| alert.trigger_string !== null && | ||
| typeof alert.trigger_string === "object" && | ||
| "name" in alert.trigger_string && | ||
| typeof alert.trigger_string.name === "string" && | ||
| "type" in alert.trigger_string && | ||
| typeof alert.trigger_string.type === "string" | ||
| ) { | ||
| malicious_pkg_name = alert.trigger_string.name; | ||
| malicious_pkg_type = alert.trigger_string.type; | ||
| } | ||
|
|
||
| return [ | ||
| trigger_type, | ||
| trigger_string, | ||
| malicious_pkg_name, | ||
| malicious_pkg_type, | ||
| ].some((i) => i?.toLowerCase().includes(searchQuery)); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This could be simplified with zod 🤔
Collaborator
There was a problem hiding this comment.
yup this part is a bit tricky, but also for BE too...let's try to figured out it later, maybe we can try to do something in BE too
alex-mcgovern
commented
Jan 30, 2025
Comment on lines
+7
to
+11
| alert?.trigger_category === "critical" && | ||
| alert.trigger_string !== null && | ||
| typeof alert.trigger_string === "object" && | ||
| "status" in alert.trigger_string && | ||
| alert.trigger_string.status === "malicious" |
Contributor
Author
There was a problem hiding this comment.
this could be simplified with zod
Collaborator
Pull Request Test Coverage Report for Build 13051157214Details
💛 - Coveralls |
peppescg
approved these changes
Jan 30, 2025
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.