Skip to content

Commit 137c384

Browse files
committed
Fix rendering of custom cells
1 parent 0cf083d commit 137c384

File tree

2 files changed

+4
-48
lines changed

2 files changed

+4
-48
lines changed

src/spicedb-common/components/relationshipeditor/RelationshipEditor.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ export function RelationshipEditor({
470470

471471
const getCellData = useCallback(
472472
([col, row]: readonly [number, number]): GridCell => {
473-
console.log("getting cell data")
474473
if (row >= data.length) {
475474
return {
476475
kind: GridCellKind.Text,
@@ -935,9 +934,7 @@ export function RelationshipEditor({
935934
});
936935
};
937936

938-
console.log("data dump")
939-
console.log(data)
940-
const { drawCell, provideEditor } = useCustomCells(
937+
const { customRenderers } = useCustomCells(
941938
relationshipsService,
942939
data,
943940
gridSelection,
@@ -1009,8 +1006,6 @@ export function RelationshipEditor({
10091006
label="Highlight same types, objects and relations"
10101007
/>
10111008
</div>
1012-
{console.log("this is how long we think data is")}
1013-
{console.log(data.length)}
10141009
<DataEditor
10151010
theme={dataEditorTheme}
10161011
keybindings={{ search: true }}
@@ -1020,8 +1015,7 @@ export function RelationshipEditor({
10201015
columns={columnsWithWidths}
10211016
rows={data.length}
10221017
onPaste={handlePaste}
1023-
drawCell={drawCell}
1024-
provideEditor={provideEditor}
1018+
customRenderers={customRenderers}
10251019
getCellsForSelection={getCellsForSelection}
10261020
onCellEdited={isReadOnly ? undefined : handleCellEdited}
10271021
onRowAppended={isReadOnly ? undefined : handleRowAppended}

src/spicedb-common/components/relationshipeditor/customcells.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ export function useCustomCells(
5454
columnsWithWidths: Column[],
5555
isReadOnly: boolean,
5656
): {
57-
drawCell: DrawCallback;
58-
provideEditor: ProvideEditorCallback<GridCell>;
57+
customRenderers: readonly any[];
5958
} {
6059
const selectedType = useMemo(() => {
6160
if (!gridSelection?.current?.cell) {
@@ -253,42 +252,5 @@ export function useCustomCells(
253252
];
254253
}, []);
255254

256-
// TODO: come up with a way to express this that doesn't require looping.
257-
const drawCell = useCallback<DrawCallback>(
258-
(args) => {
259-
console.log("calling drawCell");
260-
console.log(args);
261-
const { cell } = args;
262-
console.log("cell.kind:", cell.kind);
263-
console.log(cell);
264-
if (cell.kind !== GridCellKind.Custom) return false;
265-
console.log("looping over renderers");
266-
for (const r of renderers) {
267-
if (r.isMatch(cell)) {
268-
// @ts-expect-error typescript can't see that we're looping over something static
269-
return r.draw(args, cell);
270-
}
271-
}
272-
return false;
273-
},
274-
[renderers],
275-
);
276-
277-
const provideEditor = useCallback<ProvideEditorCallback<GridCell>>(
278-
// @ts-expect-error typescript can't see that we're looping over something static.
279-
(cell) => {
280-
if (cell.kind !== GridCellKind.Custom || isReadOnly) return undefined;
281-
282-
for (const r of renderers) {
283-
if (r.isMatch(cell)) {
284-
return r.provideEditor();
285-
}
286-
}
287-
288-
return undefined;
289-
},
290-
[renderers, isReadOnly],
291-
);
292-
293-
return { drawCell, provideEditor };
255+
return { customRenderers: renderers };
294256
}

0 commit comments

Comments
 (0)