Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explorer): editable checkbox display #3392

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading