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

Add templates for Data table and columns #148

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

afogel
Copy link
Contributor

@afogel afogel commented Feb 23, 2024

This PR is the first of a few to incorporate a data table for the index page when generating a new resource using kirimase.

It incorporates the Eta templating package in order to generate views and components.
Additionally, it incorporates the tanstack react-table library, as per Shadcn's recommendations. I purposefully kept the table relatively barebones in this first attempt. It includes pagination and column hiding, alone.

I have a few outstanding questions re: incremental improvements, but I figure that smaller PRs that are easier to review are better than mammoth new PRs.

To test, generate a new next project:
bun run reinstall && bun run createTesterApp

cd into the tester dir.
then, generate a new resource using kirimase:
kirimase g

follow the instructions. When you hit the index page for the newly created resource, you should see a table under the list of actions.

This should work when you generate a new project both with server actions as well as trpc.

Screenshots

Screenshot 2024-02-27 at 18 18 57 Screenshot 2024-02-27 at 18 18 48

Copy link
Contributor Author

@afogel afogel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial PR pass, it should work e2e, but happy to update further based on feedback.

@@ -9,7 +9,7 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npx tsc",
"build": "npx tsc && rm -rf dist/templates && cp -r src/templates dist/templates",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if there is a better way to do this, but I figured this is at least a quick and dirty way to pull templates into the dist folder.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally used a npm package called typescript-cp for it and then just using the watch flag in dev and without it when building it.

Edit: I'm also using npm-run-all to run the dev scripts in parallel. I dont like concurrently so I used npm-run-all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@@ -540,7 +540,7 @@ export const addScriptsToPackageJson = (
"db:migrate": `tsx ${libPath}/db/migrate.ts`,
"db:drop": "drizzle-kit drop",
"db:pull": `drizzle-kit introspect:${driver}`,
...(driver !== "pg" ? { "db:push": `drizzle-kit push:${driver}` } : {}),
"db:push": `drizzle-kit push:${driver}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the guardrails around db:push for pg, now that it's supported.

@@ -20,6 +20,7 @@ addCommonOptions(program.command("init"))

program
.command("generate")
.alias("g")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias 😎

import { Button } from "@/components/ui/button"

export const columns: ColumnDef<TData, TValue>[] = [
<% it.fields.map(function (field) { %>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templating in action

@afogel afogel marked this pull request as ready for review February 23, 2024 15:47
@@ -469,19 +481,6 @@ export default function ${tableNameSingularCapitalised}List({
+
</Button>
</div>
{optimistic${tableNamePluralCapitalised}.length === 0 ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this list since it's taken care of by the table

PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the imports also so it works with a different alias.
I got that part working if u want some code. I'll push it later onto my fork in a new branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants