Skip to content

Commit

Permalink
fix: fix property table not able to change value when empty (TEN-fram…
Browse files Browse the repository at this point in the history
…ework#322)

* fix: fix property table not able to change value when empty

* fix: update playground image
  • Loading branch information
plutoless authored Oct 10, 2024
1 parent 3ac67d6 commit f125173
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
networks:
- astra_network
astra_playground:
image: ghcr.io/ten-framework/astra_playground:v0.4.1-9-g09a1df2
image: ghcr.io/ten-framework/astra_playground:v0.4.1-103-g391e0d0
container_name: astra_playground
restart: always
ports:
Expand Down
26 changes: 14 additions & 12 deletions playground/src/platform/pc/chat/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +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';
newData.splice(index, 1, { ...item, ...row, value: convertToType(row.value, valueType) });
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 @@ -108,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 @@ -118,14 +121,13 @@ const EditableTable: React.FC<EditableTableProps> = ({ initialData, onUpdate, me
/>
);
}

// Inline editing for other types (string, number)
const editable = isEditing(record);
return editable ? (
<Form.Item
name="value"
style={{ margin: 0 }}
rules={[{ required: true, message: 'Please input the value!' }]}
>
<Input
ref={inputRef} // Attach input ref to control focus
Expand All @@ -134,14 +136,14 @@ const EditableTable: React.FC<EditableTableProps> = ({ initialData, onUpdate, me
/>
</Form.Item>
) : (
<div onClick={() => edit(record)}>
{record.value !== null && record.value !== undefined
<div onClick={() => edit(record)} style={{ cursor: 'pointer' }}>
{record.value !== null && record.value !== undefined && record.value !== ''
? record.value
: 'Click to edit'}
</div> // Display placeholder for empty values
: <span style={{ color: 'gray' }}>Click to edit</span>}
</div>
);
},
},
},
];

return (
Expand Down

0 comments on commit f125173

Please sign in to comment.