Skip to content

Commit 9df029d

Browse files
committed
Allow editing sheet entry
1 parent 6d8a717 commit 9df029d

File tree

3 files changed

+77
-45
lines changed

3 files changed

+77
-45
lines changed

llmstack/client/src/components/sheets/SheetFromTemplateDialog.jsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,23 @@ export function SheetFromTemplateDialog({
3030
setOpen(false);
3131
};
3232

33-
const createSheet = () => {
33+
const handleSave = () => {
3434
const payload = {
3535
name: sheetName,
36-
data: {
37-
description: sheetDescription,
38-
},
36+
description: sheetDescription,
3937
};
38+
const method = sheetId ? "patch" : "post";
39+
const url = sheetId ? `/api/sheets/${sheetId}` : "/api/sheets";
40+
4041
axios()
41-
.post(`/api/sheets`, payload)
42+
[method](url, payload)
4243
.then((response) => {
4344
setSheetId(response.data.uuid);
45+
setSheet(response.data);
4446
setOpen(false);
45-
navigate(`/sheets/${response.data.uuid}`);
47+
if (!sheetId) {
48+
navigate(`/sheets/${response.data.uuid}`);
49+
}
4650
});
4751
};
4852

@@ -75,8 +79,8 @@ export function SheetFromTemplateDialog({
7579
</DialogContent>
7680
<DialogActions>
7781
<Button onClick={handleClose}>Cancel</Button>
78-
<Button onClick={createSheet} variant="contained">
79-
Create Sheet
82+
<Button onClick={handleSave} variant="contained">
83+
{sheetId ? "Save Changes" : "Create Sheet"}
8084
</Button>
8185
</DialogActions>
8286
</Dialog>

llmstack/client/src/components/sheets/SheetsList.jsx

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import { axios } from "../../data/axios";
1919
import SheetDeleteDialog from "./SheetDeleteDialog";
2020
import { useEffect } from "react";
2121

22-
function SheetListItem({ sheet, onDelete }) {
22+
function SheetListItem({ sheet, onDelete, onEdit }) {
2323
const navigate = useNavigate();
2424
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
25+
const [editDialogOpen, setEditDialogOpen] = useState(false);
2526

2627
const handleDelete = () => {
2728
setDeleteDialogOpen(true);
@@ -32,48 +33,63 @@ function SheetListItem({ sheet, onDelete }) {
3233
setDeleteDialogOpen(false);
3334
};
3435

36+
const handleEdit = (e) => {
37+
e.stopPropagation();
38+
setEditDialogOpen(true);
39+
};
40+
3541
return (
36-
<TableRow
37-
key={sheet.uuid}
38-
onClick={() => navigate(`/sheets/${sheet.uuid}`)}
39-
sx={{
40-
cursor: "pointer",
41-
"&:hover": {
42-
backgroundColor: "rgba(0, 0, 0, 0.04)",
43-
},
44-
}}
45-
>
46-
<TableCell>
47-
<Typography variant="subtitle2" sx={{ fontWeight: "normal" }}>
48-
{sheet.name}
49-
</Typography>
50-
</TableCell>
51-
<TableCell>
52-
<Typography variant="body2" sx={{ color: "text.secondary" }}>
53-
{sheet.data?.description || "No description available"}
54-
</Typography>
55-
</TableCell>
56-
<TableCell>
57-
<IconButton aria-label="edit" onClick={(e) => e.stopPropagation()}>
58-
<EditOutlined />
59-
</IconButton>
60-
<IconButton
61-
aria-label="delete"
62-
onClick={(e) => {
63-
e.stopPropagation();
64-
handleDelete();
65-
}}
66-
>
67-
<DeleteOutlineOutlined />
68-
</IconButton>
69-
</TableCell>
42+
<>
43+
<TableRow
44+
key={sheet.uuid}
45+
onClick={() => navigate(`/sheets/${sheet.uuid}`)}
46+
sx={{
47+
cursor: "pointer",
48+
"&:hover": {
49+
backgroundColor: "rgba(0, 0, 0, 0.04)",
50+
},
51+
}}
52+
>
53+
<TableCell>
54+
<Typography variant="subtitle2" sx={{ fontWeight: "normal" }}>
55+
{sheet.name}
56+
</Typography>
57+
</TableCell>
58+
<TableCell>
59+
<Typography variant="body2" sx={{ color: "text.secondary" }}>
60+
{sheet.description || "No description available"}
61+
</Typography>
62+
</TableCell>
63+
<TableCell>
64+
<IconButton aria-label="edit" onClick={handleEdit}>
65+
<EditOutlined />
66+
</IconButton>
67+
<IconButton
68+
aria-label="delete"
69+
onClick={(e) => {
70+
e.stopPropagation();
71+
handleDelete();
72+
}}
73+
>
74+
<DeleteOutlineOutlined />
75+
</IconButton>
76+
</TableCell>
77+
</TableRow>
7078
<SheetDeleteDialog
7179
open={deleteDialogOpen}
7280
onClose={() => setDeleteDialogOpen(false)}
7381
onConfirm={confirmDelete}
7482
sheetName={sheet.name}
7583
/>
76-
</TableRow>
84+
<SheetFromTemplateDialog
85+
open={editDialogOpen}
86+
setOpen={setEditDialogOpen}
87+
sheet={sheet}
88+
setSheet={onEdit}
89+
sheetId={sheet.uuid}
90+
setSheetId={() => {}}
91+
/>
92+
</>
7793
);
7894
}
7995

@@ -102,6 +118,15 @@ function SheetsList() {
102118
});
103119
};
104120

121+
const handleEditSheet = (updatedSheet) => {
122+
setSheets((prevSheets) =>
123+
prevSheets.map((sheet) =>
124+
sheet.uuid === updatedSheet.uuid ? updatedSheet : sheet,
125+
),
126+
);
127+
enqueueSnackbar("Sheet updated successfully", { variant: "success" });
128+
};
129+
105130
return (
106131
<Stack>
107132
<Typography variant="h5" className="section-header">
@@ -139,6 +164,7 @@ function SheetsList() {
139164
key={sheet.uuid}
140165
sheet={sheet}
141166
onDelete={handleDeleteSheet}
167+
onEdit={handleEditSheet}
142168
/>
143169
))
144170
) : (

llmstack/sheets/apis.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def create(self, request):
8787
sheet = PromptlySheet.objects.create(
8888
name=request.data.get("name"),
8989
profile_uuid=profile.uuid,
90-
data=request.data.get("data", {}),
90+
data={
91+
"description": request.data.get("description", ""),
92+
},
9193
extra_data=request.data.get("extra_data", {"has_header": True}),
9294
)
9395

0 commit comments

Comments
 (0)