requested changes

This commit is contained in:
Daniel Hougaard
2025-01-15 01:55:10 +01:00
parent ab3ee775bb
commit ff74e020fc
3 changed files with 18 additions and 26 deletions
-8
View File
@@ -1,11 +1,8 @@
/** /**
* Converts a JSON array of objects to CSV format * Converts a JSON array of objects to CSV format
* @param {Array} jsonData - Array of objects to convert * @param {Array} jsonData - Array of objects to convert
* @param {string} filename - Name of the file to download (without extension)
*/ */
export const convertJsonToCsv = (jsonData: Record<string, string | number | boolean>[]) => { export const convertJsonToCsv = (jsonData: Record<string, string | number | boolean>[]) => {
// Get headers from the first object
if (jsonData.length === 0) { if (jsonData.length === 0) {
return new Blob([""], { type: "text/csv;charset=utf-8;" }); return new Blob([""], { type: "text/csv;charset=utf-8;" });
} }
@@ -14,24 +11,19 @@ export const convertJsonToCsv = (jsonData: Record<string, string | number | bool
const csvRows = [ const csvRows = [
headers.join(","), headers.join(","),
// Add all data rows
...jsonData.map((row) => { ...jsonData.map((row) => {
return headers return headers
.map((header) => { .map((header) => {
// Handle special cases in the data
let cell = row[header]; let cell = row[header];
// Convert null/undefined to empty string
if (cell === null || cell === undefined) { if (cell === null || cell === undefined) {
return ""; return "";
} }
// Handle normal values
if (typeof cell === "number" || typeof cell === "boolean") { if (typeof cell === "number" || typeof cell === "boolean") {
return cell; return cell;
} }
// Convert objects/arrays to JSON string
if (typeof cell === "object") { if (typeof cell === "object") {
cell = JSON.stringify(cell); cell = JSON.stringify(cell);
} }
@@ -27,7 +27,7 @@ export const SecretScanningPage = withPermission(
() => { () => {
const queryParams = useSearch({ const queryParams = useSearch({
from: ROUTE_PATHS.Organization.SecretScanning.id from: ROUTE_PATHS.Organization.SecretScanning.id
}) as Record<string, string>; });
const { config } = useServerConfig(); const { config } = useServerConfig();
const { currentOrg } = useOrganization(); const { currentOrg } = useOrganization();
@@ -1,25 +1,25 @@
import { createFileRoute /* stripSearchParams */ } from "@tanstack/react-router"; import { createFileRoute, stripSearchParams } from "@tanstack/react-router";
import { zodValidator } from "@tanstack/zod-adapter";
import { z } from "zod";
// import { zodValidator } from "@tanstack/zod-adapter";
// import { z } from "zod";
import { SecretScanningPage } from "./SecretScanningPage"; import { SecretScanningPage } from "./SecretScanningPage";
// const SecretScanningQueryParams = z.object({ const SecretScanningQueryParams = z.object({
// state: z.string().catch(""), state: z.string().catch(""),
// installation_id: z.string().catch("") installation_id: z.coerce.number().optional()
// }); });
export const Route = createFileRoute( export const Route = createFileRoute(
"/_authenticate/_inject-org-details/organization/_layout/secret-scanning" "/_authenticate/_inject-org-details/organization/_layout/secret-scanning"
)({ )({
component: SecretScanningPage component: SecretScanningPage,
// validateSearch: zodValidator(SecretScanningQueryParams), validateSearch: zodValidator(SecretScanningQueryParams),
// search: { search: {
// middlewares: [ middlewares: [
// stripSearchParams({ stripSearchParams({
// installation_id: "", installation_id: 0,
// state: "" state: ""
// }) })
// ] ]
// } }
}); });