Clean up linter errors and add sequential thinking
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import { Field, ErrorType } from '../../../types'
|
||||
import { Loader2, AlertCircle, ArrowDown, Check, X } from 'lucide-react'
|
||||
import { Loader2, AlertCircle, ArrowDown, X } from 'lucide-react'
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
@@ -454,7 +454,6 @@ const ValidationCell = React.memo(({
|
||||
isValidating,
|
||||
fieldKey,
|
||||
options = [],
|
||||
itemNumber,
|
||||
width,
|
||||
copyDown,
|
||||
rowIndex,
|
||||
@@ -466,7 +465,6 @@ const ValidationCell = React.memo(({
|
||||
|
||||
// Use the optimized processErrors function to avoid redundant filtering
|
||||
const {
|
||||
filteredErrors,
|
||||
hasError,
|
||||
isRequiredButEmpty,
|
||||
shouldShowErrorIcon,
|
||||
|
||||
@@ -10,7 +10,7 @@ import SearchableTemplateSelect from './SearchableTemplateSelect'
|
||||
import { useAiValidation } from '../hooks/useAiValidation'
|
||||
import { AiValidationDialogs } from './AiValidationDialogs'
|
||||
import config from '@/config'
|
||||
import { Fields, ErrorSources, ErrorType } from '../../../types'
|
||||
import { Fields } from '../../../types'
|
||||
import { SearchProductTemplateDialog } from '@/components/templates/SearchProductTemplateDialog'
|
||||
import { TemplateForm } from '@/components/templates/TemplateForm'
|
||||
import axios from 'axios'
|
||||
@@ -73,7 +73,7 @@ const ValidationContainer = <T extends string>({
|
||||
const [lineSublineCache, setLineSublineCache] = useState<Record<string, any[]>>({});
|
||||
|
||||
// Add UPC validation state
|
||||
const [isValidatingUpc, setIsValidatingUpc] = useState(false);
|
||||
const [, setIsValidatingUpc] = useState(false);
|
||||
const [validatingUpcRows, setValidatingUpcRows] = useState<Set<number>>(new Set());
|
||||
|
||||
// Add state for tracking cells in loading state
|
||||
@@ -258,7 +258,6 @@ const ValidationContainer = <T extends string>({
|
||||
// Process the response
|
||||
if (response.status === 409) {
|
||||
// UPC already exists - show validation error
|
||||
const errorData = await response.json();
|
||||
|
||||
// We need to trigger validation for this row to update the validation errors
|
||||
// This will update the validationErrors Map in useValidationState
|
||||
|
||||
@@ -11,7 +11,7 @@ import { RowData, Template } from '../hooks/useValidationState'
|
||||
import ValidationCell, { CopyDownContext } from './ValidationCell'
|
||||
import { useRsi } from '../../../hooks/useRsi'
|
||||
import SearchableTemplateSelect from './SearchableTemplateSelect'
|
||||
import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell } from '@/components/ui/table'
|
||||
import { Table, TableBody, TableRow, TableCell } from '@/components/ui/table'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -408,7 +408,7 @@ const ValidationTable = <T extends string>({
|
||||
enableRowSelection: true,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getRowId: useCallback((row: RowData<T>, index: number) => String(index), []),
|
||||
getRowId: useCallback((_row: RowData<T>, index: number) => String(index), []),
|
||||
});
|
||||
|
||||
// Calculate total table width for stable horizontal scrolling
|
||||
@@ -500,7 +500,7 @@ const ValidationTable = <T extends string>({
|
||||
style={{ width: `${totalWidth}px` }}
|
||||
>
|
||||
<div className="flex">
|
||||
{table.getFlatHeaders().map((header, index) => {
|
||||
{table.getFlatHeaders().map((header) => {
|
||||
const width = header.getSize();
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -226,15 +226,11 @@ export const useValidation = <T extends string>(
|
||||
// Run complete validation
|
||||
const validateData = useCallback(async (data: RowData<T>[]) => {
|
||||
// Step 1: Run field and row validation for each row
|
||||
const rowValidations = await Promise.all(
|
||||
data.map((row, index) => validateRow(row, index, data))
|
||||
);
|
||||
|
||||
// Step 2: Run unique validations
|
||||
const uniqueValidations = validateUnique(data);
|
||||
|
||||
// Step 3: Run table hook
|
||||
const tableValidations = await validateTable(data);
|
||||
|
||||
// Create a map to store all validation errors
|
||||
const validationErrors = new Map<number, Record<string, InfoWithSource>>();
|
||||
@@ -291,7 +287,7 @@ export const useValidation = <T extends string>(
|
||||
});
|
||||
|
||||
return {
|
||||
data: data.map((row, index) => {
|
||||
data: data.map((row) => {
|
||||
// Return the original data without __errors
|
||||
return { ...row };
|
||||
}),
|
||||
|
||||
@@ -8,12 +8,6 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import config from "@/config";
|
||||
|
||||
// Helper function to check if a value is empty
|
||||
const isEmpty = (val: any): boolean =>
|
||||
val === undefined ||
|
||||
val === null ||
|
||||
val === '' ||
|
||||
(Array.isArray(val) && val.length === 0) ||
|
||||
(typeof val === 'object' && !Array.isArray(val) && Object.keys(val).length === 0);
|
||||
|
||||
// Use the ValidationError type from types.ts instead of defining ErrorType here
|
||||
// type ErrorType = {
|
||||
@@ -89,7 +83,6 @@ export const getApiUrl = () => config.apiUrl;
|
||||
|
||||
// Add debounce utility
|
||||
const DEBOUNCE_DELAY = 0; // No delay
|
||||
const BATCH_SIZE = 50; // Larger batch size
|
||||
|
||||
function debounce<T extends (...args: any[]) => any>(
|
||||
func: T,
|
||||
@@ -156,36 +149,6 @@ export const useValidationState = <T extends string>({
|
||||
})
|
||||
|
||||
// Function to clean price fields in data
|
||||
const cleanPriceFields = useCallback((dataToClean: RowData<T>[]): RowData<T>[] => {
|
||||
return dataToClean.map(row => {
|
||||
const updatedRow = { ...row } as Record<string, any>;
|
||||
let needsUpdate = false;
|
||||
|
||||
// Clean MSRP
|
||||
if (typeof updatedRow.msrp === 'string' && updatedRow.msrp.includes('$')) {
|
||||
updatedRow.msrp = updatedRow.msrp.replace(/[$,]/g, '');
|
||||
// Convert to number if possible
|
||||
const numValue = parseFloat(updatedRow.msrp);
|
||||
if (!isNaN(numValue)) {
|
||||
updatedRow.msrp = numValue.toFixed(2);
|
||||
}
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
// Clean cost_each
|
||||
if (typeof updatedRow.cost_each === 'string' && updatedRow.cost_each.includes('$')) {
|
||||
updatedRow.cost_each = updatedRow.cost_each.replace(/[$,]/g, '');
|
||||
// Convert to number if possible
|
||||
const numValue = parseFloat(updatedRow.cost_each);
|
||||
if (!isNaN(numValue)) {
|
||||
updatedRow.cost_each = numValue.toFixed(2);
|
||||
}
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
return needsUpdate ? (updatedRow as RowData<T>) : row;
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Row selection state
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
||||
@@ -746,8 +709,6 @@ export const useValidationState = <T extends string>({
|
||||
let hasErrors = false;
|
||||
|
||||
// Track if row has changes to original values
|
||||
const originalRow = row.__original || {};
|
||||
const changedFields = row.__changes || {};
|
||||
|
||||
// Use a more efficient approach - only validate fields that need validation
|
||||
fields.forEach(field => {
|
||||
@@ -1249,7 +1210,6 @@ export const useValidationState = <T extends string>({
|
||||
|
||||
// Pre-cache field validations
|
||||
const requiredFields = fields.filter(f => f.validations?.some(v => v.rule === 'required'));
|
||||
const requiredFieldKeys = new Set(requiredFields.map(f => String(f.key)));
|
||||
|
||||
// Pre-process the supplier and company fields checks
|
||||
const hasSupplierField = fields.some(field => String(field.key) === 'supplier');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { InfoWithSource, ErrorLevel, ErrorSources, ErrorType as ValidationErrorType } from "../../../types"
|
||||
import { ErrorLevel, ErrorSources, ErrorType as ValidationErrorType } from "../../../types"
|
||||
|
||||
// Define our own Error type that's compatible with the original
|
||||
export interface ErrorType {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Data, Fields, Info, RowHook, TableHook } from "../../../types"
|
||||
import type { Meta, Error, Errors } from "../types"
|
||||
import type { Meta, Errors } from "../types"
|
||||
import { v4 } from "uuid"
|
||||
import { ErrorSources, ErrorType } from "../../../types"
|
||||
|
||||
@@ -128,7 +128,7 @@ export const addErrorsAndRunHooks = async <T extends string>(
|
||||
})
|
||||
})
|
||||
|
||||
return processedData.map((value, index) => {
|
||||
return processedData.map((value) => {
|
||||
// This is required only for table. Mutates to prevent needless rerenders
|
||||
const result: DataWithMeta<T> = { ...value }
|
||||
if (!result.__index) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import config from "../config";
|
||||
import { Loader2, Box } from "lucide-react";
|
||||
import { motion } from "motion/react";
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
export function Login() {
|
||||
const [username, setUsername] = useState("");
|
||||
|
||||
Reference in New Issue
Block a user