Skip to content

Commit

Permalink
more robust fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kristol07 committed Oct 26, 2024
1 parent 41d1a26 commit fbf254d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions playground/src/platform/pc/chat/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ const EditableTable: React.FC<EditableTableProps> = ({ initialData, onUpdate, me
const row = await form.validateFields();
const newData = [...dataSource];
const index = newData.findIndex((item) => key === item.key);

if (index > -1) {
const item = newData[index];
const valueType = metadata[key]?.type || 'string';
const updatedValue = row.value === '' ? null : convertToType(row.value, valueType); // Set to null if empty

newData.splice(index, 1, { ...item, value: updatedValue });
setDataSource(newData);
setEditingKey('');

// Notify the parent component of the update
const updatedData = Object.fromEntries(newData.map(({ key, value }) => [key, value]));
onUpdate(updatedData);
}
} catch (errInfo) {
console.log('Validation Failed:', errInfo);
}
};
};


// Toggle the checkbox for boolean values directly in the table cell
const handleCheckboxChange = (key: string, checked: boolean) => {
Expand Down Expand Up @@ -111,7 +111,7 @@ const EditableTable: React.FC<EditableTableProps> = ({ initialData, onUpdate, me
key: 'value',
render: (_, record: DataType) => {
const valueType = metadata[record.key]?.type || 'string';

// Always display the checkbox for boolean values
if (valueType === 'bool') {
return (
Expand All @@ -121,7 +121,7 @@ const EditableTable: React.FC<EditableTableProps> = ({ initialData, onUpdate, me
/>
);
}

// Inline editing for other types (string, number)
const editable = isEditing(record);
return editable ? (
Expand All @@ -137,13 +137,13 @@ const EditableTable: React.FC<EditableTableProps> = ({ initialData, onUpdate, me
</Form.Item>
) : (
<div onClick={() => edit(record)} style={{ cursor: 'pointer' }}>
{record.value !== null && record.value !== undefined && record.value !== ''
? record.value
{record.value != null && String(record.value).trim() !== ''
? String(record.value)
: <span style={{ color: 'gray' }}>Click to edit</span>}
</div>
);
},
},
},
];

return (
Expand Down

0 comments on commit fbf254d

Please sign in to comment.