Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix property table not able to change value when empty #322

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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