Skip to content

Commit 098da3e

Browse files
committed
Merge branch 'develop' into feat/auto-revalidation-and-docs
2 parents e39159c + 435fede commit 098da3e

File tree

10 files changed

+162
-237
lines changed

10 files changed

+162
-237
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ jobs:
5050
- name: Build project
5151
run: pnpm build
5252

53-
# # Add a step to run ESLint checks
54-
# - name: Run ESLint
55-
# run: pnpm eslint . --ext .js,.jsx,.ts,.tsx
53+
# Add a step to run ESLint checks
54+
- name: Run ESLint
55+
run: pnpm eslint . --ext .js,.jsx,.ts,.tsx
5656

5757
# Perform CodeQL Analysis
5858
- name: Perform CodeQL Analysis

app/api/generate-schema-doc/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as JsonSchemaStaticDocsLib from "json-schema-static-docs"; // Use names
44
import fs from "fs/promises";
55
import path from "path";
66
import os from "os";
7+
import { createRequire } from "module"; // Import createRequire
78
import prettier from "prettier";
89
import parserTypescript from "prettier/parser-typescript";
910
// import { DocGenerator } from "json-schema-static-docs"; // Removed

app/api/schemas/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function GET() {
2020

2121
console.log(`[API /api/schemas] Mapped schemas:`, schemas);
2222

23-
return NextResponse.json({ schemas: jsonFiles });
23+
return NextResponse.json({ schemas: schemas });
2424
} catch (error: unknown) {
2525
console.error("[API /api/schemas] Error:", error);
2626
const message = error instanceof Error ? error.message : String(error);

app/layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export default function RootLayout({
1515
<html lang="en" suppressHydrationWarning className="dark">
1616
<body className={inter.className}>
1717
<ThemeProvider
18+
attribute="class"
1819
defaultTheme="dark"
20+
enableSystem
21+
disableTransitionOnChange
1922
>
2023
{children}
2124
<Toaster />

components/csv-validator.tsx

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ type WorkerMessageData =
210210
| WorkerMessageComplete
211211
| WorkerMessageError;
212212

213-
// --- Debounce Utility ---
213+
// --- Debounce Utility --- // ADDED
214214
function debounce<F extends (...args: any[]) => any>(
215215
func: F,
216216
waitFor: number,
@@ -880,54 +880,7 @@ export default function CsvValidator() {
880880
[memoizedSetValidationResults, toast],
881881
);
882882

883-
// --- Debounced validation trigger ---
884-
const debouncedValidate = useMemo(() => {
885-
let timeout: NodeJS.Timeout | null = null;
886-
return (csv: string, schema: Record<string, unknown> | string) => {
887-
if (timeout) clearTimeout(timeout);
888-
timeout = setTimeout(() => {
889-
runWorkerValidation(csv, schema);
890-
}, 350);
891-
};
892-
}, [runWorkerValidation]);
893-
894-
// --- CSV edit effect: debounce and use worker ---
895-
useEffect(() => {
896-
const effectiveSchema = useUploadedSchema ? uploadedSchemaContent : selectedSchemaContent;
897-
898-
if (!csvRawText.trim() || !effectiveSchema) { // Combined checks
899-
setValidationResults([]);
900-
setOverallCsvStatus("pending");
901-
setTotalErrorCount(0);
902-
setTotalWarningCount(0);
903-
setVisibleResultCount(20);
904-
// Optionally cancel any pending worker task if schema becomes null
905-
if (workerRef.current && workerBusy) {
906-
workerRef.current.terminate();
907-
workerRef.current = null; // Clear ref
908-
setWorkerBusy(false);
909-
}
910-
if (validationTimeout.current) clearTimeout(validationTimeout.current);
911-
return;
912-
}
913-
// Debounced and use worker on every csvRawText change
914-
// Provide default empty object to satisfy type checker, although the if check prevents null case
915-
debouncedValidate(
916-
csvRawText,
917-
effectiveSchema ?? {},
918-
);
919-
920-
}, [
921-
csvRawText,
922-
selectedSchemaContent,
923-
uploadedSchemaContent,
924-
useUploadedSchema,
925-
debouncedValidate, // Keep debouncedValidate here
926-
workerBusy // ADD workerBusy to dependency array
927-
// No need to include effectiveSchema directly, its parts are dependencies
928-
]);
929-
930-
// --- Manual Validation Trigger --- //
883+
// --- Debounced validation trigger --- // RENAMED & SIMPLIFIED
931884
const triggerValidation = useCallback(async () => {
932885
// Determine the schema to use
933886
const schemaToUse = useUploadedSchema ? uploadedSchemaContent : selectedSchemaContent;
@@ -936,18 +889,21 @@ export default function CsvValidator() {
936889
console.warn("No schema selected for validation");
937890
return;
938891
}
892+
893+
// Mark editor as clean now that validation is explicitly triggered
894+
setIsEditorDirty(false);
939895

940896
// Call the worker validation function
941897
runWorkerValidation(csvRawText, schemaToUse);
942898
}, [csvRawText, selectedSchemaContent, uploadedSchemaContent, useUploadedSchema, runWorkerValidation]);
943899

944-
// --- Debounced Validation --- //
900+
// --- Debounced Validation --- // ADDED FOR AUTO-VALIDATION ON EDIT
945901
// Use useRef to keep the debounced function stable across renders
946902
const debouncedValidationRef = useRef(
947903
debounce(triggerValidation, 750) // Debounce validation by 750ms
948904
);
949905

950-
// --- CSV Content Change Handler --- //
906+
// --- CSV Content Change Handler --- // UPDATED FOR DEBOUNCING
951907
const handleCsvContentChange = useCallback(
952908
(value: string | undefined) => {
953909
const newCsvText = value || "";
@@ -1121,30 +1077,13 @@ export default function CsvValidator() {
11211077
<div className="flex-grow"></div>
11221078

11231079
<Button
1124-
onClick={() => {
1125-
const effectiveSchema = useUploadedSchema
1126-
? uploadedSchemaContent
1127-
: selectedSchemaContent;
1128-
// Only call validate if effectiveSchema is not null
1129-
if (effectiveSchema) {
1130-
debouncedValidate(
1131-
csvRawText,
1132-
effectiveSchema, // Pass the non-null schema
1133-
);
1134-
} else {
1135-
// Optional: Show a toast or log an error if schema is missing
1136-
toast({
1137-
title: "Schema Missing",
1138-
description: "Please select or upload a schema before validating.",
1139-
variant: "destructive",
1140-
});
1141-
}
1142-
}}
1080+
onClick={triggerValidation} // Use direct trigger on button click
11431081
disabled={
11441082
workerBusy ||
11451083
!csvRawText.trim() ||
11461084
(!selectedSchemaName && !useUploadedSchema) ||
1147-
!(useUploadedSchema ? uploadedSchemaContent : selectedSchemaContent)
1085+
!(useUploadedSchema ? uploadedSchemaContent : selectedSchemaContent) ||
1086+
!isEditorDirty // Disable if editor hasn't changed since last validation
11481087
}
11491088
size="sm"
11501089
className="bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 text-white"

0 commit comments

Comments
 (0)