Skip to content

Commit 3ffa127

Browse files
karooolisfrolic
andauthored
fix(explorer): update only changed table values (#3733)
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
1 parent 81f051c commit 3ffa127

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

.changeset/twenty-mangos-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
Table cell edits are now saved only when the value has changed.

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/EditableTableCell.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.j
1717
import { useConnectModal } from "@rainbow-me/rainbowkit";
1818
import { useMutation, useQueryClient } from "@tanstack/react-query";
1919
import { Checkbox } from "../../../../../../components/ui/Checkbox";
20-
import { cn } from "../../../../../../utils";
2120
import { useChain } from "../../../../hooks/useChain";
2221

2322
type Props = {
@@ -105,11 +104,7 @@ export function EditableTableCell({ name, table, keyTuple, value: defaultValue }
105104
}
106105

107106
return (
108-
<div
109-
className={cn("w-full", {
110-
"flex cursor-wait items-center gap-1": isPending,
111-
})}
112-
>
107+
<div className="w-full">
113108
{!isPending && (
114109
<form
115110
onSubmit={(evt) => {
@@ -118,20 +113,25 @@ export function EditableTableCell({ name, table, keyTuple, value: defaultValue }
118113
}}
119114
>
120115
<input
121-
className="w-full bg-transparent"
116+
className="w-full bg-transparent px-2 py-4"
122117
onChange={(evt: ChangeEvent<HTMLInputElement>) => setValue(evt.target.value)}
123-
onBlur={(evt) => handleSubmit(evt.target.value)}
118+
onBlur={(evt) => {
119+
const newValue = evt.target.value;
120+
if (newValue !== String(defaultValue)) {
121+
handleSubmit(newValue);
122+
}
123+
}}
124124
value={String(value)}
125125
disabled={isPending}
126126
/>
127127
</form>
128128
)}
129129

130130
{isPending && (
131-
<>
131+
<div className="flex items-center gap-1 px-2">
132132
{String(value)}
133133
<LoaderIcon className="h-4 w-4 animate-spin" />
134-
</>
134+
</div>
135135
)}
136136
</div>
137137
);

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/explore/TablesViewer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
189189
<TableRow key={headerGroup.id}>
190190
{headerGroup.headers.map((header) => {
191191
return (
192-
<TableHead key={header.id}>
192+
<TableHead key={header.id} className="px-4">
193193
{header.isPlaceholder
194194
? null
195195
: flexRender(header.column.columnDef.header, header.getContext())}
@@ -211,7 +211,9 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
211211
<TableRow key={row.id}>
212212
{row.getVisibleCells().map((cell) => {
213213
return (
214-
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
214+
<TableCell key={cell.id} className="px-2 py-0">
215+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
216+
</TableCell>
215217
);
216218
})}
217219
</TableRow>

0 commit comments

Comments
 (0)