Skip to content

Commit 6415d92

Browse files
committed
Update sheet on data
1 parent dc4c047 commit 6415d92

File tree

2 files changed

+72
-38
lines changed

2 files changed

+72
-38
lines changed

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

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,24 @@ function Sheet(props) {
104104
}/ws`;
105105

106106
const getCellContent = useCallback(
107-
([row, column]) => {
108-
const cell = cells[row]?.[column];
107+
([column, row]) => {
108+
// Find the column in cells
109+
const col = columns[column].col;
110+
const cell = cells[row]?.[col];
111+
109112
return {
110-
kind: cell?.kind || GridCellKind.Text,
113+
kind:
114+
(cell?.kind === "app_run" ? GridCellKind.Text : cell?.kind) ||
115+
columns[column].kind,
111116
displayData: cell?.displayData || cell?.data || "",
112117
data: cell?.data || "",
113118
allowOverlay: true,
119+
allowWrapping: true,
120+
skeletonWidth: 80,
121+
skeletonWidthVariability: 25,
114122
};
115123
},
116-
[cells],
124+
[cells, columns],
117125
);
118126

119127
const parseSheetColumnsIntoGridColumns = (columns) => {
@@ -129,6 +137,7 @@ function Sheet(props) {
129137
data: column.data,
130138
hasMenu: true,
131139
icon: GridColumnIcon.HeaderString,
140+
width: column.width || 200,
132141
};
133142
});
134143
};
@@ -194,26 +203,53 @@ function Sheet(props) {
194203
if (event.type === "cell.update") {
195204
const cell = event.cell;
196205
const [row, col] = cell.id.split("-");
206+
const column = columns.find((c) => c.col === col);
197207

198208
setCells((cells) => ({
199209
...cells,
200210
[row]: {
201211
...cells[row],
202212
[col]: {
203213
...cells[row]?.[col],
204-
...cell,
214+
...{
215+
kind: column?.kind || GridCellKind.Text,
216+
data: cell.data,
217+
displayData: cell.data,
218+
},
205219
},
206220
},
207221
}));
208222

209-
sheetRef.current?.updateCells([{ cell: [row, col] }]);
223+
sheetRef.current?.updateCells([
224+
{ cell: [columns.findIndex((c) => c.col === col), row] },
225+
]);
226+
} else if (event.type === "cell.updating") {
227+
const cell = event.cell;
228+
const [row, col] = cell.id.split("-");
229+
230+
setCells((cells) => ({
231+
...cells,
232+
[row]: {
233+
...cells[row],
234+
[col]: {
235+
...cells[row]?.[col],
236+
...{
237+
kind: GridCellKind.Loading,
238+
},
239+
},
240+
},
241+
}));
242+
243+
sheetRef.current?.updateCells([
244+
{ cell: [columns.findIndex((c) => c.col === col), row] },
245+
]);
210246
}
211247
});
212248

213249
ws.send(JSON.stringify({ event: "run" }));
214250
}
215251
}
216-
}, [runId, sheet?.uuid, wsUrlPrefix]);
252+
}, [runId, sheet?.uuid, wsUrlPrefix, columns]);
217253

218254
return sheet ? (
219255
<Stack>
@@ -261,11 +297,13 @@ function Sheet(props) {
261297
onCellEdited={(cell, value) => {
262298
setCells((cells) => ({
263299
...cells,
264-
[cell[0]]: {
265-
...cells[cell[0]],
266-
[cell[1]]: {
267-
...(cells[cell[0]]?.[cell[1]] || {}),
300+
[cell[1]]: {
301+
...cells[cell[1]],
302+
[cell[0]]: {
303+
...(cells[cell[1]]?.[cell[0]] || {}),
268304
...value,
305+
kind: columns[cell[0]].kind,
306+
data: value.data,
269307
displayData: value.displayData || value.data,
270308
},
271309
},
@@ -279,6 +317,16 @@ function Sheet(props) {
279317
};
280318
setShowEditColumnMenu(true);
281319
}}
320+
onColumnResize={(column, width) => {
321+
setColumns((columns) => {
322+
const newColumns = [...columns];
323+
const columnIndex = newColumns.findIndex(
324+
(c) => c.col === column.col,
325+
);
326+
newColumns[columnIndex].width = width;
327+
return newColumns;
328+
});
329+
}}
282330
rows={numRows}
283331
/>
284332
</Box>

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,13 @@ import ThemedJsonForm from "../ThemedJsonForm";
2121
import TextFieldWithVars from "../apps/TextFieldWithVars";
2222
import "@glideapps/glide-data-grid/dist/index.css";
2323

24-
export const columnTypeToDatagridMapping = {
25-
text: {
26-
kind: GridCellKind.Text,
27-
},
28-
number: {
29-
kind: GridCellKind.Number,
30-
},
31-
image: {
32-
kind: GridCellKind.Image,
33-
},
34-
file: {
35-
kind: GridCellKind.Image,
36-
},
37-
app_run: {
38-
kind: GridCellKind.Custom,
39-
},
24+
const numberToLetters = (num) => {
25+
let letters = "";
26+
while (num >= 0) {
27+
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[num % 26] + letters;
28+
num = Math.floor(num / 26) - 1;
29+
}
30+
return letters;
4031
};
4132

4233
// Allow the user to pick an app, and then show the form for that app input
@@ -54,9 +45,9 @@ const AppRunForm = ({ columns, data, setData }) => {
5445
{...props}
5546
introText={"Available columns"}
5647
schemas={columns.map((c, index) => ({
57-
id: `${index}`,
58-
pillPrefix: `${index}:${c.title}`,
59-
label: `${index}: ${c.title}`,
48+
id: `${numberToLetters(index)}`,
49+
pillPrefix: `${numberToLetters(index)}:${c.title}`,
50+
label: `${numberToLetters(index)}: ${c.title}`,
6051
}))}
6152
/>
6253
);
@@ -147,12 +138,7 @@ export function SheetColumnMenu({
147138
const columnAppRunData = useRef(column?.data || {});
148139

149140
useEffect(() => {
150-
if (column?.kind === GridCellKind.Custom) {
151-
setColumnType(column?.data?.kind || GridCellKind.Text);
152-
} else {
153-
setColumnType(column?.kind || GridCellKind.Text);
154-
}
155-
141+
setColumnType(column?.kind || GridCellKind.Text);
156142
setColumnName(column?.title || "");
157143
columnAppRunData.current = column?.data || {};
158144
}, [column]);
@@ -161,10 +147,10 @@ export function SheetColumnMenu({
161147
const newColumn = {
162148
col: columns.length,
163149
title: columnName || "New Column",
164-
kind: columnTypeToDatagridMapping[columnType].kind,
150+
kind: columnType,
165151
data:
166152
columnType === "app_run" && columnAppRunData.current
167-
? { ...columnAppRunData.current, kind: columnType }
153+
? columnAppRunData.current
168154
: {},
169155
};
170156

0 commit comments

Comments
 (0)