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 api route #324

Merged
merged 100 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
aee2b13
feat: add api route
foyarash May 29, 2024
af8d39c
Merge branch 'main' into feature/migrate-api-route
foyarash May 29, 2024
f2c6c14
handle page router
foyarash May 30, 2024
d49107e
wip docs
foyarash Jun 3, 2024
2abf67d
Merge branch 'main' into feature/migrate-api-route
cregourd Jun 3, 2024
423d931
Merge branch 'main' into feature/migrate-api-route
cregourd Jun 13, 2024
10f8513
Merge branch 'main' into feature/migrate-api-route
cregourd Jun 14, 2024
779b5ca
Add get route
cregourd Jun 14, 2024
82ae6d7
Merge branch 'main' into feature/migrate-api-route
cregourd Jun 17, 2024
c682adb
Format and remove actions
cregourd Jun 17, 2024
d02b4fc
Pursue
cregourd Jun 18, 2024
0808f12
Merge branch 'main' into feature/migrate-api-route
cregourd Jun 19, 2024
19062db
Forward locale value
cregourd Jun 19, 2024
13b8a7a
Pass test
cregourd Jun 20, 2024
3617012
Update turbo
cregourd Jun 20, 2024
a85f001
Refacto code
cregourd Jun 20, 2024
c59a062
Fix build
cregourd Jun 21, 2024
6ad85b4
Fix test e2e
cregourd Jun 21, 2024
a005fdf
Change Documentation
cregourd Jun 21, 2024
76719f2
Fix build
cregourd Jun 21, 2024
cf134d6
Fix unit test
cregourd Jun 21, 2024
2aa9b34
Add redirect on save anyway
cregourd Jun 21, 2024
8f72ecc
Remove unused code
cregourd Jun 24, 2024
bc0adf1
Fix unit test
cregourd Jun 24, 2024
38a505a
Change README and changeset
cregourd Jun 24, 2024
c61762b
Add previous doc to nextra
cregourd Jun 24, 2024
ce36dbb
Add superjson doc for page router
cregourd Jun 25, 2024
4249814
Format and fix doc
cregourd Jun 25, 2024
1cb7219
Fix getMainLayout function
cregourd Jun 25, 2024
9d197dc
Enter prerelease mode and version packages (v5.0.0)
cregourd Jun 26, 2024
44a8a8d
Fix install monorepo
cregourd Jun 26, 2024
ee3ac66
Merge branch 'fix/file-handler-serveless' into feature/migrate-api-route
cregourd Jun 26, 2024
a38014f
Patch pre-release
cregourd Jun 26, 2024
866e223
Merge branch 'fix/prefetch-export-link' into feature/migrate-api-route
cregourd Jun 26, 2024
7d60e88
Patch pre-release
cregourd Jun 26, 2024
06092ee
Merge branch 'main' into feature/migrate-api-route
cregourd Jul 1, 2024
135db87
Merge no fast forward main
cregourd Jul 1, 2024
818f1e4
Merge main
cregourd Jul 1, 2024
3a861d2
Fix params is not an array
cregourd Jul 2, 2024
b2ff79c
Fix date set input
cregourd Jul 2, 2024
f120d10
Add `next-themes` to handle color scheme
cregourd Jul 3, 2024
b5f3395
Add to handle color scheme
cregourd Jul 3, 2024
ed78f46
Dependency `next-themes`
cregourd Jul 3, 2024
60afe2f
Add history on Save
cregourd Jul 3, 2024
81d7369
Add history on Save
cregourd Jul 3, 2024
119a053
Redirect useEffect
cregourd Jul 3, 2024
f3636ad
Small fixes
cregourd Jul 4, 2024
12de962
Change logout and fix select/input
cregourd Jul 9, 2024
e2cb61c
Change example
cregourd Jul 9, 2024
cd02217
Fix undefined, and cell
cregourd Jul 9, 2024
c644bcc
Add return date from post reponse
cregourd Jul 10, 2024
76c0816
Remove form context
cregourd Jul 11, 2024
198c48d
Remove console.log
cregourd Jul 11, 2024
3405095
Fix is Dirty and select
cregourd Jul 11, 2024
e13910f
Submit only dirty
cregourd Jul 11, 2024
4e0e774
Add `isDirty` for form to submit only fields touched
cregourd Jul 12, 2024
0221476
Fix date input and add time-second format
cregourd Jul 12, 2024
d52443f
update doc
quentingrchr Jul 25, 2024
518f9cf
remove old v4 documentation
quentingrchr Aug 1, 2024
e414b4d
remove old v4 documentation
quentingrchr Aug 1, 2024
d13210c
update link
quentingrchr Aug 1, 2024
0392151
update v5 glossary docs
quentingrchr Aug 1, 2024
7026ad4
add OptionsTable in v5 docs
quentingrchr Aug 1, 2024
80141c6
replace > Note with Callout
quentingrchr Aug 1, 2024
59f1156
update docs/api structure
quentingrchr Aug 1, 2024
de40ecd
fix typo
quentingrchr Aug 1, 2024
5225b02
update title
quentingrchr Aug 1, 2024
5e53179
update route docs
quentingrchr Aug 1, 2024
0d8531d
update route.mdx
quentingrchr Aug 1, 2024
50938c9
fix typo
quentingrchr Aug 1, 2024
dc69aac
fix typo
quentingrchr Aug 1, 2024
01399e6
fix english typos
quentingrchr Aug 2, 2024
d11ccca
Merge pull request #375 from premieroctet/feature/update-v4-docs
quentingrchr Aug 2, 2024
aae2abf
fix various typos
quentingrchr Aug 2, 2024
169b642
add migration guide
quentingrchr Aug 2, 2024
07360a5
update migration guide
quentingrchr Aug 6, 2024
55b285c
fix some typos
quentingrchr Aug 6, 2024
a9dcafb
fix: add error message in appHandler delete
quentingrchr Aug 6, 2024
b45e538
fix schema, delete on cascade post and categories
quentingrchr Aug 6, 2024
e63655a
fix: file widget cors error
quentingrchr Aug 6, 2024
851fd1b
fix: render condition
quentingrchr Aug 6, 2024
510ab0c
update var name
quentingrchr Aug 6, 2024
63d9723
update readme
quentingrchr Aug 6, 2024
df809c2
add check docker compose command
quentingrchr Aug 6, 2024
cc6c33c
revert check docker compose command
quentingrchr Aug 7, 2024
9e1cf9c
fix: fix function import
quentingrchr Aug 7, 2024
1412aa1
fix: update options example
quentingrchr Aug 7, 2024
259bd2d
fix utils functions
quentingrchr Aug 7, 2024
c5c736b
test gh actions update
quentingrchr Aug 7, 2024
18eabec
add tests
quentingrchr Aug 7, 2024
170a48b
add changeset
quentingrchr Aug 7, 2024
728a381
prerelease 5.0.0-rc.12
quentingrchr Aug 7, 2024
2aa7acd
fix docs
quentingrchr Aug 8, 2024
debdffe
Merge pull request #377 from premieroctet/fix/file-widget
quentingrchr Aug 8, 2024
badd0c7
update logout property to handle string
quentingrchr Aug 8, 2024
b5322db
pre release 5.0.0-rc.13
quentingrchr Aug 8, 2024
2c29a7c
remove log
quentingrchr Aug 8, 2024
07b514f
fix: make user.logout property optional
quentingrchr Aug 8, 2024
5b295bb
update next admin to rc.14
quentingrchr Aug 8, 2024
6137d60
exit prerelease
quentingrchr Aug 9, 2024
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
5 changes: 5 additions & 0 deletions .changeset/big-bobcats-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Add `next-themes` to handle color scheme
5 changes: 5 additions & 0 deletions .changeset/chilled-llamas-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Redirect useEffect
5 changes: 5 additions & 0 deletions .changeset/flat-pandas-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

add dist
5 changes: 5 additions & 0 deletions .changeset/gentle-cooks-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Change logout system (Request or server action)
5 changes: 5 additions & 0 deletions .changeset/great-bees-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Fix images CORS issues
26 changes: 26 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"mode": "exit",
"tag": "rc",
"initialVersions": {
"docs": "0.0.0",
"example": "0.0.0",
"eslint-config-custom": "0.0.0",
"@premieroctet/next-admin": "4.4.5",
"tsconfig": "0.0.0"
},
"changesets": [
"big-bobcats-occur",
"chilled-llamas-grab",
"flat-pandas-dance",
"gentle-cooks-tickle",
"great-bees-pump",
"quiet-otters-study",
"spotty-forks-greet",
"stale-cycles-peel",
"strong-cobras-look",
"tricky-brooms-appear",
"weak-olives-call",
"young-maps-study",
"young-ties-care"
]
}
5 changes: 5 additions & 0 deletions .changeset/quiet-otters-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Small fixes (select, dark mode, dashboard, layout, doc)
5 changes: 5 additions & 0 deletions .changeset/spotty-forks-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Add history on redirect `Save`
5 changes: 5 additions & 0 deletions .changeset/stale-cycles-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Fix date input and add time-second format
128 changes: 128 additions & 0 deletions .changeset/strong-cobras-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
"@premieroctet/next-admin": major
---

## Major Changes

- **Breaking Change**:

- New implementation of `NextAdmin`. Usage of `API route` instead of `server actions`.
- Configuration of `page.tsx` and `route.ts` files in the `app/admin/[[...nextadmin]]` and `app/api/[[...nextadmin]]` folders respectively.
- `createHandler` function now available in `appHandler` and `pageHandler` modules to configure the API route.
- `getNextAdminProps` function now available in `appRouter` and `pageRouter` modules to configure the page route.

## Migration

### API Route `[[...nextadmin]]`

Create a dynamic route `[[...nextadmin]]` to handle all the API routes.

<details>
<summary>App router</summary>

```tsx
// app/api/admin/[[...nextadmin]]/route.ts
import { prisma } from "@/prisma";
import { createHandler } from "@premieroctet/next-admin/dist/appHandler";

const { run } = createHandler({
apiBasePath: "/api/admin",
prisma,
/*options*/
});

export { run as DELETE, run as GET, run as POST };
```

</details>

<details>
<summary>Page router</summary>

```ts copy
// pages/api/admin/[[...nextadmin]].ts
import { prisma } from "@/prisma";
import { createApiRouter } from "@premieroctet/next-admin/dist/pageHandler";
import schema from "@/prisma/json-schema/json-schema.json";

export const config = {
api: {
bodyParser: false,
},
};

const { run } = createHandler({
apiBasePath: "/api/admin",
prisma,
schema: schema,
/*options*/,
});

export default run;
```

</details>

### Change `getPropsFromParams` to `getNextAdminProps`

<details>
<summary>App router</summary>

Replace the `getPropsFromParams` function with the `getNextAdminProps` function in the `page.tsx` file.

```tsx
// app/admin/[[...nextadmin]]/page.tsx
import { NextAdmin, PageProps } from "@premieroctet/next-admin";
import { getNextAdminProps } from "@premieroctet/next-admin/dist/appRouter";
import { prisma } from "@/prisma";

export default async function AdminPage({ params, searchParams }: PageProps) {
const props = await getNextAdminProps({
params: params.nextadmin,
searchParams,
basePath: "/admin",
apiBasePath: "/api/admin",
prisma,
/*options*/
});

return <NextAdmin {...props} />;
}
```

</details>

<details>
<summary>Page router</summary>

Do not use `nextAdminRouter` anymore. Replace it with the `getNextAdminProps` function in the `[[...nextadmin]].ts` file for `getServerSideProps`.

```tsx copy
// pages/admin/[[...nextadmin]].tsx
import { AdminComponentProps, NextAdmin } from "@premieroctet/next-admin";

import { getNextAdminProps } from "@premieroctet/next-admin/dist/pageRouter";
import { GetServerSideProps } from "next";
import { prisma } from " @/prisma";
import schema from "@/prisma/json-schema/json-schema.json";
import "@/styles.css";

export default function Admin(props: AdminComponentProps) {
return (
<NextAdmin
{...props}
/*options*/
/>
);
}

export const getServerSideProps: GetServerSideProps = async ({ req }) =>
await getNextAdminProps({
basePath: "/pagerouter/admin",
apiBasePath: "/api/pagerouter/admin",
prisma,
schema,
/*options*/
req,
});
```
5 changes: 5 additions & 0 deletions .changeset/tricky-brooms-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Add `isDirty` for form to submit only fields touched
5 changes: 5 additions & 0 deletions .changeset/weak-olives-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Dependency `next-themes`
5 changes: 5 additions & 0 deletions .changeset/young-maps-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

add URL redirect support for logout
5 changes: 5 additions & 0 deletions .changeset/young-ties-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Merge main branch
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/yarn.lock') }}
- name: Start docker-compose
run: docker-compose up -d
run: docker compose up -d
- name: Install dependencies
run: yarn install
- name: Run linter
Expand Down
75 changes: 75 additions & 0 deletions apps/docs/components/OptionsTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
interface Option {
name: string;
type?: string;
description: string | React.ReactNode;
defaultValue?: string;
}

interface HeadersLabel {
name: string;
type: string;
description: string;
defaultValue: string;
}

interface OptionsTableProps {
options: Option[];
labels?: HeadersLabel;
}

export function OptionsTable({ options, labels }: OptionsTableProps) {
const hasTypeColumn = options.some((option) => Boolean(option.type));
const hasDefaultValueColumn = options.some((option) =>
Boolean(option.defaultValue)
);

return (
<div className="-mx-6 mb-4 mt-6 overflow-x-auto overscroll-x-contain px-6 pb-4">
<table className="w-full border-collapse text-sm">
<thead>
<tr className="border-b py-4 text-left dark:border-neutral-700">
<th className="py-2 font-semibold">{labels?.name || "Name"}</th>
{hasTypeColumn && (
<th className="py-2 pl-6 font-semibold">
{labels?.type || "Type"}
</th>
)}
<th className="px-6 py-2 font-semibold">
{labels?.description || "Description"}
</th>
{hasDefaultValueColumn && (
<th className="px-6 py-2 font-semibold">
{labels?.defaultValue || "Default Value"}
</th>
)}
</tr>
</thead>
<tbody className="align-baseline text-gray-900 dark:text-gray-100">
{options.map(({ name, type, description, defaultValue }) => (
<tr
key={name}
className="border-b border-gray-100 dark:border-neutral-700/50"
>
<td className="whitespace-pre py-2 font-mono text-xs font-semibold leading-6 text-violet-600 dark:text-violet-500">
{name}
</td>
{hasTypeColumn && (
<td className="whitespace-pre py-2 pl-6 font-mono text-xs font-semibold leading-6 text-slate-500 dark:text-slate-400">
{Boolean(type) ? type : "-"}
</td>
)}
<td className="py-2 pl-6">{description}</td>
{hasDefaultValueColumn && (
<td className="py-2 pl-6 font-mono text-xs text-slate-500 dark:text-slate-400">
{Boolean(defaultValue) ? defaultValue : "-"}
</td>
)}
</tr>
))}
</tbody>
</table>
</div>
);
}

export default OptionsTable;
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@heroicons/react": "^2.1.1",
"@premieroctet/next-admin": "*",
"@premieroctet/next-admin": "5.0.0-rc.14",
"clsx": "^2.1.0",
"framer-motion": "^11.0.8",
"mini-svg-data-uri": "^1.4.4",
Expand Down
5 changes: 5 additions & 0 deletions apps/docs/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"type": "page",
"display": "hidden"
},
"v4": {
"title": "v4",
"type": "page",
"display": "hidden"
},
"changelog": {
"title": "Changelog",
"type": "page"
Expand Down
11 changes: 10 additions & 1 deletion apps/docs/pages/docs/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
{
"index": "Introduction",
"getting-started": "Getting Started",
"api-docs": "API",
"api": {
"title": "API",
"theme": {
"breadcrumb": true,
"footer": true,
"sidebar": true,
"toc": true,
"pagination": true
}
},
"i18n": "I18n",
"theming": "Theming",
"glossary": "Glossary",
Expand Down
Loading
Loading