Fix line and subline showing as inputs instead of selects

This commit is contained in:
2025-03-18 15:27:55 -04:00
parent 949b543d1f
commit af067f7360
19 changed files with 572 additions and 8 deletions

View File

@@ -76,7 +76,8 @@ const BaseCellContent = React.memo(({
onChange,
hasErrors,
options = [],
className = ''
className = '',
fieldKey = ''
}: {
field: Field<string>;
value: any;
@@ -84,11 +85,14 @@ const BaseCellContent = React.memo(({
hasErrors: boolean;
options?: readonly any[];
className?: string;
fieldKey?: string;
}) => {
// Get field type information
const fieldType = typeof field.fieldType === 'string'
? field.fieldType
: field.fieldType?.type || 'input';
const fieldType = fieldKey === 'line' || fieldKey === 'subline'
? 'select'
: typeof field.fieldType === 'string'
? field.fieldType
: field.fieldType?.type || 'input';
// Check for multiline input
const isMultiline = typeof field.fieldType === 'object' &&
@@ -100,6 +104,22 @@ const BaseCellContent = React.memo(({
(field.fieldType.type === 'input' || field.fieldType.type === 'multi-input') &&
field.fieldType.price === true;
// Special case for line and subline - check this first, before any other field type checks
if (fieldKey === 'line' || fieldKey === 'subline') {
// Force these fields to always use SelectCell regardless of fieldType
return (
<SelectCell
field={{...field, fieldType: { type: 'select', options }}}
value={value}
onChange={onChange}
options={options}
hasErrors={hasErrors}
className={className}
disabled={field.disabled}
/>
);
}
if (fieldType === 'select') {
return (
<SelectCell
@@ -424,6 +444,7 @@ const ValidationCell = React.memo(({
hasErrors={hasError || isRequiredButEmpty}
options={options}
className={cellClassName}
fieldKey={fieldKey}
/>
</div>
)}

View File

@@ -379,9 +379,35 @@ const ValidationTable = <T extends string>({
// Get validation errors for this cell
const cellErrors = validationErrors.get(row.index)?.[fieldKey] || [];
// Create a copy of the field with guaranteed field type for line and subline fields
let fieldWithType = field;
// Ensure line and subline fields always have the correct fieldType
if (fieldKey === 'line' || fieldKey === 'subline') {
// Create a deep clone of the field to prevent any reference issues
fieldWithType = {
...JSON.parse(JSON.stringify(field)), // Ensure deep clone
fieldType: {
type: 'select',
options: options
},
// Explicitly mark as not disabled to ensure dropdown works
disabled: false
};
// Debug logging
console.log(`Field ${fieldKey} in ValidationTable (after deep clone):`, {
originalField: field,
modifiedField: fieldWithType,
options,
hasOptions: options && options.length > 0,
disabled: fieldWithType.disabled
});
}
return (
<MemoizedCell
field={field as Field<string>}
field={fieldWithType as Field<string>}
value={row.original[field.key as keyof typeof row.original]}
onChange={(value) => handleFieldUpdate(row.index, field.key as T, value)}
errors={cellErrors}

View File

@@ -149,7 +149,7 @@ const SelectCell = <T extends string>({
}, [onChange, onEndEdit]);
// If disabled, render a static view
if (disabled) {
if (disabled && field.key !== 'line' && field.key !== 'subline') {
const displayText = displayValue;
return (

View File

@@ -40,7 +40,7 @@ const BASE_IMPORT_FIELDS = [
description: "Product line",
alternateMatches: ["collection"],
fieldType: {
type: "select",
type: "select" as const,
options: [], // Will be populated dynamically based on company selection
},
width: 220,
@@ -51,7 +51,7 @@ const BASE_IMPORT_FIELDS = [
key: "subline",
description: "Product sub-line",
fieldType: {
type: "select",
type: "select" as const,
options: [], // Will be populated dynamically based on line selection
},
width: 220,