-
Notifications
You must be signed in to change notification settings - Fork 1
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
Editable table data #295
Editable table data #295
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
59fd016
to
db68e44
Compare
150c596
to
76c628d
Compare
|
||
const table = useReactTable({ | ||
data, | ||
data: tab.results, | ||
columns: tab.columns, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The react table lib needs the data as some sort of reactive state (prop, state, memo, etc). If you give it another object derived from some reactive state, like we were, you get that freeze up. I'm not sure what's it's doing internally that results in this behavior, but I was able to verify it using a simplified version of the console code I wrote and then made sure that fix worked here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't a problem previously because previous to my branch here, the data was passed as a prop to the DataTable
component which internally passed that data prop to useReactTable
. We now must call useReactTable
outside DataTable
and pass the resulting table
into DataTable
as a prop.
usersForAddresses: publicProcedure | ||
.input(z.object({ addresses: z.array(z.string().trim()).min(1) })) | ||
.query(async ({ input }) => { | ||
const users = await store.users.usersForAddresses(input.addresses); | ||
const res = users.reduce<Map<string, (typeof users)[number]>>( | ||
(acc, item) => { | ||
acc.set(item.user.address, item); | ||
return acc; | ||
}, | ||
new Map<string, (typeof users)[number]>(), | ||
); | ||
return res; | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this new users router with this function that, given a list of addresses, returns a map of Studio accounts (keyed by address). If an address in the input doesn't correspond to a Studio user, there will be no entry in the map for it. You'll see the store
package implementaiton as well.
registryRecord = await cache(getRegistryRecord)( | ||
deployment.chainId, | ||
deployment.tableId, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a card to show the table owner to the table page. This required a new validator query that reads information about the registry. This data is also used deeper into the view hierarchy for ACL related stuff.
export function LatestTables({ | ||
initialData, | ||
}: { | ||
initialData: RegistryRecord[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just updated the Table
type name to RegistryRecord
to better represent what it is and avoid using our already-overloaded word "table".
const session = await cache(getSession)({ | ||
headers: headers(), | ||
cookies: cookies(), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated update, just noticed we should be caching this call so the results are reused during a single server side rendering pass.
@@ -80,6 +84,7 @@ export default async function TablePage({ | |||
schema={schema} | |||
tableName={params.name} | |||
tableId={tableId} | |||
owner={registryRecord.controller} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just querying and passing the new prop for the table owner here in the page for a Tableland table out of the context of a project.
export async function getTablePermissionsForAddress( | ||
chainId: number, | ||
tableId: string, | ||
address: string, | ||
) { | ||
const baseUrl = baseUrlForChain(chainId); | ||
const validator = new Validator({ baseUrl }); | ||
const [res] = await validator.queryByStatement<{ | ||
chain_id: number; | ||
controller: string; | ||
created_at: number; | ||
privileges: number; | ||
table_id: number; | ||
updated_at: number | null; | ||
}>({ | ||
statement: `select * from system_acl | ||
where chain_id = ${chainId} | ||
and table_id = ${tableId} | ||
and controller = '${address}' | ||
limit 1`, | ||
}); | ||
const permission: TablePermission = { | ||
insert: (res.privileges & 1) > 0, | ||
update: (res.privileges & 2) > 0, | ||
delete: (res.privileges & 4) > 0, | ||
}; | ||
return permission; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New function to get the ACL for a single address and table. I don't think we actually use this in the end, but left it anyway.
packages/web/lib/wagmi-ethers.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved these here for shared use.
@@ -51,6 +51,7 @@ | |||
"class-variance-authority": "^0.7.0", | |||
"clsx": "^2.0.0", | |||
"cmdk": "^0.2.0", | |||
"deep-object-diff": "^1.1.9", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the package I use for JSON object diffing.
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
"include": [ | ||
"next-env.d.ts", | ||
"types.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to add this line to pick up our type extensions for tanstack table (file below).
declare module "@tanstack/table-core" { | ||
interface TableMeta<TData extends RowData> { | ||
getRowClassName: (row: Row<TData>) => string; | ||
pkName?: string; | ||
accountPermissions?: ACLItem; | ||
pendingTxn?: boolean; | ||
editRow: (row: Row<TData>) => void; | ||
updateRowColumn: ( | ||
row: Row<TData>, | ||
columnName: string, | ||
value: string | number, | ||
) => void; | ||
addRow: () => void; | ||
deleteRow: (row: Row<TData>) => void; | ||
revertRow: (row: Row<TData>) => void; | ||
revertAll: () => void; | ||
} | ||
interface ColumnMeta { | ||
columnName: string; | ||
type: "number" | "string"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how tanstack table allows you to add custom metadata types to your table and column metadata when you use typescript.
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
13bb75d
to
7ee03a7
Compare
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Title says it all. This also leverages and displays new data related to table owner and ACL.