Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

refactor(alerts): consolidate queries - #233

Merged
lxmcgvrn merged 3 commits into
mainfrom
refactor/alerts/consolidate-queries
Jan 30, 2025
Merged

refactor(alerts): consolidate queries#233
lxmcgvrn merged 3 commits into
mainfrom
refactor/alerts/consolidate-queries

Conversation

@lxmcgvrn

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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 CoverageCovered LinesChanged/Added Lines%
src/features/alerts/components/switch-malicious-alerts-filter.tsx4580.0%
Files with Coverage ReductionNew Missed Lines%
src/hooks/useAlertSearch.ts260.0%
TotalsCoverage Status
Change from base Build 13048988032:0.6%
Covered Lines:767
Relevant Lines:982

💛 - Coveralls

@lxmcgvrn
lxmcgvrn merged commit acf1293 into mainJan 30, 2025
@lxmcgvrn
lxmcgvrn deleted the refactor/alerts/consolidate-queries branch January 30, 2025 11:37
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Duplicate requests to alerts

3 participants

@lxmcgvrn@coveralls@peppescg