Skip to content

Commit

Permalink
fix(explorer): editable checkbox display (#3392)
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis authored Dec 10, 2024
1 parent b819749 commit 1cea106
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useChain } from "../../../../hooks/useChain";

type Props = {
name: string;
value: string | undefined;
value: unknown;
table: Table;
keyTuple: readonly Hex[];
};
Expand Down Expand Up @@ -89,26 +89,20 @@ export function EditableTableCell({ name, table, keyTuple, value: defaultValue }
if (!account.isConnected) {
return openConnectModal?.();
}

if (newValue !== defaultValue) {
mutate(newValue);
}
mutate(newValue);
};

if (fieldType === "bool") {
return (
<>
<div className="flex items-center gap-1">
<Checkbox
id={`checkbox-${name}`}
checked={value === "1"}
onCheckedChange={(checked) => {
const newValue = checked ? "1" : "0";
handleSubmit(newValue);
}}
checked={Boolean(value)}
onCheckedChange={handleSubmit}
disabled={isPending}
/>
{isPending && <Loader className="h-4 w-4 animate-spin" />}
</>
</div>
);
}

Expand All @@ -127,9 +121,7 @@ export function EditableTableCell({ name, table, keyTuple, value: defaultValue }
>
<input
className="w-full bg-transparent"
onChange={(evt: ChangeEvent<HTMLInputElement>) => {
setValue(evt.target.value);
}}
onChange={(evt: ChangeEvent<HTMLInputElement>) => setValue(evt.target.value)}
onBlur={(evt) => handleSubmit(evt.target.value)}
value={String(value)}
disabled={isPending}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export function TablesViewer({ table, query }: { table?: TableType; query?: stri
cell: ({ row }) => {
const namespace = table?.namespace;
const keySchema = getKeySchema(table);
const value = row.getValue(name)?.toString();

const value = row.getValue(name);
if (!table || Object.keys(keySchema).includes(name) || internalNamespaces.includes(namespace)) {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function useTableDataQuery({ table, query }: Props) {
select: (data: DozerResponse): TData | undefined => {
if (!table || !data?.result?.[0]) return undefined;

const indexer = indexerForChainId(chainId);
const result = data.result[0];
// if columns are undefined, the result is empty
if (!result[0]) return undefined;
Expand All @@ -61,7 +62,18 @@ export function useTableDataQuery({ table, query }: Props) {
})
.filter((key) => schema.includes(key));

const rows = result.slice(1).map((row) => Object.fromEntries(columns.map((key, index) => [key, row[index]])));
const rows = result.slice(1).map((row) =>
Object.fromEntries(
columns.map((key, index) => {
const value = row[index];
const type = table?.schema[key];
if (type?.type === "bool") {
return [key, indexer.type === "sqlite" ? value === "1" : value];
}
return [key, value];
}),
),
);
return {
columns,
rows,
Expand Down

0 comments on commit 1cea106

Please sign in to comment.