Skip to content
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

refactor(alerts): consolidate queries #233

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

alex-mcgovern
Copy link
Collaborator

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>
);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke with James, and we will soon remove this and replace with tabs for "all" | "malicious" | "secrets" | "PII" etc

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));
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified with zod 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simplified with zod

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 13051157214

Details

  • 51 of 52 (98.08%) changed or added relevant lines in 12 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.6%) to 73.18%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/features/alerts/components/switch-malicious-alerts-filter.tsx 4 5 80.0%
Files with Coverage Reduction New Missed Lines %
src/hooks/useAlertSearch.ts 2 60.0%
Totals Coverage Status
Change from base Build 13048988032: 0.6%
Covered Lines: 767
Relevant Lines: 982

💛 - Coveralls

@alex-mcgovern alex-mcgovern merged commit acf1293 into main Jan 30, 2025
8 checks passed
@alex-mcgovern alex-mcgovern deleted the refactor/alerts/consolidate-queries branch January 30, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Duplicate requests to alerts
3 participants