mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
feat(filters): add resource type filter for findings (#6524)
This commit is contained in:
@@ -28,7 +28,11 @@ export const getFindings = async ({
|
||||
if (sort) url.searchParams.append("sort", sort);
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (key !== "filter[search]") {
|
||||
const excludedFilters = ["region__in", "service__in", "resource_type__in"];
|
||||
if (
|
||||
key !== "filter[search]" &&
|
||||
!excludedFilters.some((filter) => key.includes(filter))
|
||||
) {
|
||||
url.searchParams.append(key, String(value));
|
||||
}
|
||||
});
|
||||
@@ -51,7 +55,7 @@ export const getFindings = async ({
|
||||
}
|
||||
};
|
||||
|
||||
export const getServicesRegions = async ({
|
||||
export const getMetadataInfo = async ({
|
||||
query = "",
|
||||
sort = "",
|
||||
filters = {},
|
||||
@@ -59,13 +63,18 @@ export const getServicesRegions = async ({
|
||||
const session = await auth();
|
||||
|
||||
const keyServer = process.env.API_BASE_URL;
|
||||
const url = new URL(`${keyServer}/findings/findings_services_regions`);
|
||||
const url = new URL(`${keyServer}/findings/metadata`);
|
||||
|
||||
if (query) url.searchParams.append("filter[search]", query);
|
||||
if (sort) url.searchParams.append("sort", sort);
|
||||
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (key !== "filter[search]") {
|
||||
// Define filters to exclude
|
||||
const excludedFilters = ["region__in", "service__in", "resource_type__in"];
|
||||
if (
|
||||
key !== "filter[search]" &&
|
||||
!excludedFilters.some((filter) => key.includes(filter))
|
||||
) {
|
||||
url.searchParams.append(key, String(value));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Spacer } from "@nextui-org/react";
|
||||
import React, { Suspense } from "react";
|
||||
|
||||
import { getFindings, getServicesRegions } from "@/actions/findings";
|
||||
import { getFindings, getMetadataInfo } from "@/actions/findings";
|
||||
import { getProviders } from "@/actions/providers";
|
||||
import { getScans } from "@/actions/scans";
|
||||
import { filterFindings } from "@/components/filters/data-filters";
|
||||
@@ -47,15 +47,17 @@ export default async function Findings({
|
||||
|
||||
const query = filters["filter[search]"] || "";
|
||||
|
||||
const servicesRegionsData = await getServicesRegions({
|
||||
const metadataInfoData = await getMetadataInfo({
|
||||
query,
|
||||
sort: encodedSort,
|
||||
filters,
|
||||
});
|
||||
|
||||
// Extract unique regions and services from the new endpoint
|
||||
const uniqueRegions = servicesRegionsData?.data?.attributes?.regions || [];
|
||||
const uniqueServices = servicesRegionsData?.data?.attributes?.services || [];
|
||||
const uniqueRegions = metadataInfoData?.data?.attributes?.regions || [];
|
||||
const uniqueServices = metadataInfoData?.data?.attributes?.services || [];
|
||||
const uniqueResourceTypes =
|
||||
metadataInfoData?.data?.attributes?.resource_types || [];
|
||||
// Get findings data
|
||||
const providersData = await getProviders({});
|
||||
const scansData = await getScans({});
|
||||
@@ -72,7 +74,7 @@ export default async function Findings({
|
||||
// Extract scan UUIDs with "completed" state and more than one resource
|
||||
const completedScans = scansData?.data
|
||||
?.filter(
|
||||
(scan: any) =>
|
||||
(scan: ScanProps) =>
|
||||
scan.attributes.state === "completed" &&
|
||||
scan.attributes.unique_resource_count > 1,
|
||||
)
|
||||
@@ -104,6 +106,11 @@ export default async function Findings({
|
||||
labelCheckboxGroup: "Services",
|
||||
values: uniqueServices,
|
||||
},
|
||||
{
|
||||
key: "resource_type__in",
|
||||
labelCheckboxGroup: "Resource Type",
|
||||
values: uniqueResourceTypes,
|
||||
},
|
||||
{
|
||||
key: "provider_uid__in",
|
||||
labelCheckboxGroup: "Provider UID",
|
||||
|
||||
Reference in New Issue
Block a user