From 8f3df7e45d47a6b05b464ed3b1bee255669dde94 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Thu, 9 Jan 2025 17:37:33 +0100 Subject: [PATCH] fix(BC: NextUI): fix BC from NextUI, resolve ESLint warnings and optimize hooks dependencies (#6404) --- ui/.eslintrc.cjs | 10 +- ui/actions/providers/providers.ts | 1 + ui/actions/services/services.ts | 6 +- ui/actions/users/users.ts | 2 + ui/app/(prowler)/compliance/page.tsx | 2 + ui/app/(prowler)/error.tsx | 7 +- ui/app/(prowler)/providers/page.tsx | 16 +- ui/app/(prowler)/services/page.tsx | 11 +- .../select-scan-compliance-data.tsx | 3 + .../filters/custom-account-selection.tsx | 3 + .../custom-checkbox-muted-findings.tsx | 5 +- .../filters/custom-region-selection.tsx | 4 +- ui/components/filters/custom-search-input.tsx | 7 +- .../filters/custom-select-provider.tsx | 3 + .../findings/table/column-findings.tsx | 43 +- ui/components/invitations/forms/edit-form.tsx | 3 + .../workflow/forms/send-invitation-form.tsx | 3 + .../findings-by-status-chart.tsx | 27 +- .../table/column-new-findings-to-date.tsx | 43 +- .../workflow/forms/connect-account-form.tsx | 1 + .../roles/workflow/forms/add-role-form.tsx | 2 + .../roles/workflow/forms/edit-role-form.tsx | 2 + .../launch-workflow/select-scan-provider.tsx | 3 + ui/components/scans/no-providers-added.tsx | 4 +- .../scans/table/scans/column-get-scans.tsx | 38 +- .../table/scans/data-table-row-details.tsx | 1 + .../ui/custom/custom-alert-modal.tsx | 7 +- .../ui/custom/custom-dropdown-filter.tsx | 23 +- .../ui/custom/custom-dropdown-selection.tsx | 16 +- ui/components/ui/sidebar/sidebar-wrap.tsx | 2 +- ui/components/ui/sidebar/sidebar.tsx | 242 +++---- .../ui/table/data-table-pagination.tsx | 3 +- ui/components/users/forms/edit-form.tsx | 3 + ui/hooks/useLocalStorage.ts | 2 + ui/package-lock.json | 588 +++++++++++++----- ui/package.json | 3 +- ui/styles/globals.css | 4 + 37 files changed, 765 insertions(+), 378 deletions(-) diff --git a/ui/.eslintrc.cjs b/ui/.eslintrc.cjs index 6f1426da12..8c32ae0804 100644 --- a/ui/.eslintrc.cjs +++ b/ui/.eslintrc.cjs @@ -12,6 +12,7 @@ module.exports = { "plugin:jsx-a11y/recommended", "eslint-config-prettier", "prettier", + "next/core-web-vitals", ], parserOptions: { ecmaVersion: "latest", @@ -37,7 +38,14 @@ module.exports = { "eol-last": ["error", "always"], "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", - "jsx-a11y/anchor-is-valid": "error", + "jsx-a11y/anchor-is-valid": [ + "error", + { + components: ["Link"], + specialLink: ["hrefLeft", "hrefRight"], + aspects: ["invalidHref", "preferButton"], + }, + ], "jsx-a11y/alt-text": "error", "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }], }, diff --git a/ui/actions/providers/providers.ts b/ui/actions/providers/providers.ts index cd9e021696..3b2ea126d3 100644 --- a/ui/actions/providers/providers.ts +++ b/ui/actions/providers/providers.ts @@ -42,6 +42,7 @@ export const getProviders = async ({ revalidatePath("/providers"); return parsedData; } catch (error) { + // eslint-disable-next-line no-console console.error("Error fetching providers:", error); return undefined; } diff --git a/ui/actions/services/services.ts b/ui/actions/services/services.ts index c4ab342f01..cfd295e1cb 100644 --- a/ui/actions/services/services.ts +++ b/ui/actions/services/services.ts @@ -1,13 +1,10 @@ "use server"; import { revalidatePath } from "next/cache"; -import { redirect } from "next/navigation"; -import { parse } from "path"; import { auth } from "@/auth.config"; -import { getErrorMessage, parseStringify } from "@/lib"; -export const getServices = async ({}) => { +export const getServices = async () => { const session = await auth(); const keyServer = process.env.API_BASE_URL; @@ -90,6 +87,7 @@ export const getServices = async ({}) => { fail_findings: failFindings, }); } catch (error) { + // eslint-disable-next-line no-console console.error(`Error fetching data for service ${service.id}:`, error); } } diff --git a/ui/actions/users/users.ts b/ui/actions/users/users.ts index 3d06ccc801..ce80221da3 100644 --- a/ui/actions/users/users.ts +++ b/ui/actions/users/users.ts @@ -42,6 +42,7 @@ export const getUsers = async ({ revalidatePath("/users"); return parsedData; } catch (error) { + // eslint-disable-next-line no-console console.error("Error fetching users:", error); return undefined; } @@ -200,6 +201,7 @@ export const getProfileInfo = async () => { revalidatePath("/profile"); return parsedData; } catch (error) { + // eslint-disable-next-line no-console console.error("Error fetching profile:", error); return undefined; } diff --git a/ui/app/(prowler)/compliance/page.tsx b/ui/app/(prowler)/compliance/page.tsx index 108433a7c7..ce5fe18e5d 100644 --- a/ui/app/(prowler)/compliance/page.tsx +++ b/ui/app/(prowler)/compliance/page.tsx @@ -1,3 +1,5 @@ +export const dynamic = "force-dynamic"; + import { Spacer } from "@nextui-org/react"; import { Suspense } from "react"; diff --git a/ui/app/(prowler)/error.tsx b/ui/app/(prowler)/error.tsx index 980e681220..d5083d9d33 100644 --- a/ui/app/(prowler)/error.tsx +++ b/ui/app/(prowler)/error.tsx @@ -24,11 +24,10 @@ export default function Error({ An unexpected error occurred - We're sorry for the inconvenience. Please try again or contact support - if the problem persists. + We're sorry for the inconvenience. Please try again or contact + support if the problem persists. - - {" "} + Go to the homepage diff --git a/ui/app/(prowler)/providers/page.tsx b/ui/app/(prowler)/providers/page.tsx index b41c049202..3851c75f0d 100644 --- a/ui/app/(prowler)/providers/page.tsx +++ b/ui/app/(prowler)/providers/page.tsx @@ -72,15 +72,15 @@ const SSRDataTable = async ({ return acc; }, {}) || {}; - const enrichedProviders = providersData?.data.map( - (provider: ProviderProps) => { - const groupNames = provider.relationships.provider_groups.data.map( - (group: { id: string }) => - providerGroupDict[group.id] || "Unknown Group", - ); + const enrichedProviders = + providersData?.data?.map((provider: ProviderProps) => { + const groupNames = + provider.relationships?.provider_groups?.data?.map( + (group: { id: string }) => + providerGroupDict[group.id] || "Unknown Group", + ) || []; return { ...provider, groupNames }; - }, - ); + }) || []; return ( }> - + ); } -const SSRServiceGrid = async ({ - searchParams, -}: { - searchParams: SearchParamsProps; -}) => { - const servicesData = await getServices(searchParams); - const [services] = await Promise.all([servicesData]); +const SSRServiceGrid = async () => { + const services = await getServices(); return (
diff --git a/ui/components/compliance/data-compliance/select-scan-compliance-data.tsx b/ui/components/compliance/data-compliance/select-scan-compliance-data.tsx index 5ebc36515d..6bbfd3d4e0 100644 --- a/ui/components/compliance/data-compliance/select-scan-compliance-data.tsx +++ b/ui/components/compliance/data-compliance/select-scan-compliance-data.tsx @@ -15,6 +15,9 @@ export const SelectScanComplianceData = ({