Skip to content

Commit

Permalink
Merge branch 'main' into feat/generator-custom
Browse files Browse the repository at this point in the history
  • Loading branch information
cregourd committed Nov 8, 2024
2 parents 30b3421 + ae432ac commit e9094a5
Show file tree
Hide file tree
Showing 15 changed files with 16,074 additions and 52 deletions.
18 changes: 18 additions & 0 deletions apps/docs/pages/changelog/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @premieroctet/next-admin

## 6.1.8

### Patch Changes

- [fa0b2af](https://github.com/premieroctet/next-admin/commit/fa0b2af118ba7ec5922ba42904385e9fa7adc2f3): Support Next 15

## 6.1.8-beta.0

### Patch Changes

- [ba36b45](https://github.com/premieroctet/next-admin/commit/ba36b456e4530ae52b96bd1087e21e732e743cc2): Support Next 15

## 6.1.7

### Patch Changes

- [cb7987d](https://github.com/premieroctet/next-admin/commit/cb7987d): Fix advanced filter on nullable field

## 6.1.6

### Patch Changes
Expand Down
4 changes: 0 additions & 4 deletions apps/example/.babelrc

This file was deleted.

15 changes: 8 additions & 7 deletions apps/example/app/[locale]/admin/[[...nextadmin]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Dashboard from "@/components/Dashboard";
import { options } from "@/options";
import { prisma } from "@/prisma";
import { NextAdmin, PageProps } from "@premieroctet/next-admin";
import schema from "@/prisma/json-schema/json-schema.json";
import { NextAdmin, PromisePageProps } from "@premieroctet/next-admin";
import { getNextAdminProps } from "@premieroctet/next-admin/appRouter";
import { Metadata, Viewport } from "next";
import { getMessages } from "next-intl/server";
Expand All @@ -15,11 +16,11 @@ export const metadata: Metadata = {
icons: "/assets/logo.svg",
};

export default async function AdminPage({
params,
searchParams,
}: Readonly<PageProps>) {
const props = await getNextAdminProps({
export default async function AdminPage(props: PromisePageProps) {
const params = await props.params;
const searchParams = await props.searchParams;

const nextAdminProps = await getNextAdminProps({
params: params.nextadmin,
searchParams,
basePath: "/admin",
Expand All @@ -42,7 +43,7 @@ export default async function AdminPage({

return (
<NextAdmin
{...props}
{...nextAdminProps}
dashboard={<Dashboard />}
user={{
data: {
Expand Down
16 changes: 7 additions & 9 deletions apps/example/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { notFound } from "next/navigation";
import { PropsWithChildren } from "react";
import { PropsWithChildren, use } from "react";
import "../../styles.css";

type Props = {
params: {
locale: "en" | "fr";
};
};

type ParamsProps = Promise<{
locale: "en" | "fr";
}>;
const locales = ["en", "fr"];

export default function Layout({
children,
params: { locale },
}: PropsWithChildren<Props>) {
params,
}: PropsWithChildren<{ params: ParamsProps }>) {
const locale = use(params)?.locale;
if (!locales.includes(locale)) {
notFound();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/example/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
19 changes: 16 additions & 3 deletions apps/example/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
const withNextIntl = require("next-intl/plugin")("./i18n.ts");
const { withSuperjson } = require("next-superjson");

/** @type {import('next').NextConfig} */
module.exports = withNextIntl({
reactStrictMode: true,
});
module.exports = withNextIntl(
withSuperjson({
reactStrictMode: true,
experimental: {
swcPlugins: [
[
"next-superjson-plugin",
{
excluded: [],
},
],
],
}
})
);
8 changes: 5 additions & 3 deletions apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
"@picocss/pico": "^1.5.7",
"@premieroctet/next-admin": "workspace:*",
"@premieroctet/next-admin-generator-prisma": "workspace:*",
"next-intl": "^3.3.2",
"@prisma/client": "5.14.0",
"@tremor/react": "^3.2.2",
"next": "14.0.3",
"next-intl": "^3.3.2",
"next": "^15.0.2",
"next-superjson": "^1.0.1",
"next-superjson-plugin": "^0.6.3",
"react": "^18.2.0",
"react-datepicker": "^4.24.0",
"react-dom": "^18.2.0",
"superjson": "^1.12.2"
"superjson": "^2.2.1"
},
"devDependencies": {
"@playwright/test": "^1.37.0",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
},
"dependencies": {
"@changesets/cli": "^2.26.1",
"@radix-ui/react-slot": "^1.0.2",
"prettier-plugin-tailwindcss": "^0.6.6"
},
"packageManager": "[email protected]",
Expand Down
18 changes: 18 additions & 0 deletions packages/next-admin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@

- [1fa56bc](https://github.com/premieroctet/next-admin/commit/1fa56bc): feat: add custom generator ([#414](https://github.com/premieroctet/next-admin/issues/414))

## 6.1.8

### Patch Changes

- [fa0b2af](https://github.com/premieroctet/next-admin/commit/fa0b2af118ba7ec5922ba42904385e9fa7adc2f3): Support Next 15

## 6.1.8-beta.0

### Patch Changes

- [ba36b45](https://github.com/premieroctet/next-admin/commit/ba36b456e4530ae52b96bd1087e21e732e743cc2): Support Next 15

## 6.1.7

### Patch Changes

- [cb7987d](https://github.com/premieroctet/next-admin/commit/cb7987d): Fix advanced filter on nullable field

## 6.1.6

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/next-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@rjsf/core": "^5.19.3",
Expand Down
31 changes: 17 additions & 14 deletions packages/next-admin/src/appHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const createHandler = <P extends string = "nextadmin">({
const resources = getResources(options);

if (onRequest) {
router.use(async (req, ctx, next) => {
router.use(async (req, ctxPromise, next) => {
const ctx = await ctxPromise;
const response = await onRequest(req, ctx);

if (response) {
Expand All @@ -44,7 +45,8 @@ export const createHandler = <P extends string = "nextadmin">({

router
.get(`${apiBasePath}/:model/raw`, async (req, ctx) => {
const resource = getResourceFromParams(ctx.params[paramKey], resources);
const params = await ctx.params;
const resource = getResourceFromParams(params[paramKey], resources);

if (!resource) {
return NextResponse.json(
Expand Down Expand Up @@ -81,13 +83,11 @@ export const createHandler = <P extends string = "nextadmin">({
return NextResponse.json(data);
})
.post(`${apiBasePath}/:model/actions/:id`, async (req, ctx) => {
const id = ctx.params[paramKey].at(-1)!;
const params = await ctx.params;
const id = params[paramKey].at(-1)!;

// Make sure we don't have a false positive with a model that could be named actions
const resource = getResourceFromParams(
[ctx.params[paramKey][0]],
resources
);
const resource = getResourceFromParams([params[paramKey][0]], resources);

if (!resource) {
return NextResponse.json(
Expand Down Expand Up @@ -129,14 +129,15 @@ export const createHandler = <P extends string = "nextadmin">({
);
}
})
.post(`${apiBasePath}/options`, async (req, ctx) => {
.post(`${apiBasePath}/options`, async (req, _ctx) => {
const body = await req.json();
const data = await handleOptionsSearch(body, prisma, options);

return NextResponse.json(data);
})
.post(`${apiBasePath}/:model/:id?`, async (req, ctx) => {
const resource = getResourceFromParams(ctx.params[paramKey], resources);
const params = await ctx.params;
const resource = getResourceFromParams(params[paramKey], resources);

if (!resource) {
return NextResponse.json(
Expand All @@ -147,8 +148,8 @@ export const createHandler = <P extends string = "nextadmin">({

const body = await getFormValuesFromFormData(await req.formData());
const id =
ctx.params[paramKey].length === 2
? formatId(resource, ctx.params[paramKey].at(-1)!)
params[paramKey].length === 2
? formatId(resource, params[paramKey].at(-1)!)
: undefined;

const editOptions = options?.model?.[resource]?.edit;
Expand Down Expand Up @@ -195,7 +196,8 @@ export const createHandler = <P extends string = "nextadmin">({
}
})
.delete(`${apiBasePath}/:model/:id`, async (req, ctx) => {
const resource = getResourceFromParams(ctx.params[paramKey], resources);
const params = await ctx.params;
const resource = getResourceFromParams(params[paramKey], resources);

if (!resource) {
return NextResponse.json(
Expand All @@ -212,15 +214,16 @@ export const createHandler = <P extends string = "nextadmin">({
}

await deleteResource({
body: [ctx.params[paramKey][1]],
body: [params[paramKey][1]],
prisma,
resource,
});

return NextResponse.json({ ok: true });
})
.delete(`${apiBasePath}/:model`, async (req, ctx) => {
const resource = getResourceFromParams(ctx.params[paramKey], resources);
const params = await ctx.params;
const resource = getResourceFromParams(params[paramKey], resources);

if (!resource) {
return NextResponse.json(
Expand Down
2 changes: 0 additions & 2 deletions packages/next-admin/src/components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,9 @@ function List({
}}
>
<SelectTrigger className="bg-nextadmin-background-default dark:bg-dark-nextadmin-background-subtle max-h-[36px] max-w-[100px]">
<SelectValue asChild>
<span className="text-nextadmin-content-inverted dark:text-dark-nextadmin-content-inverted pointer-events-none">
{pageSize}
</span>
</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectItem value={"10"}>10</SelectItem>
Expand Down
10 changes: 7 additions & 3 deletions packages/next-admin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,14 @@ export const colorSchemes = ["light", "dark", "system"];
export type ColorScheme = (typeof colorSchemes)[number];
export type BasicColorScheme = Exclude<ColorScheme, "system">;

export type PageProps = Readonly<{
export type PageProps = {
params: { [key: string]: string[] | string };
searchParams: { [key: string]: string | string[] | undefined } | undefined;
}>;
};

export type PromisePageProps = {
[key in keyof PageProps]: Promise<PageProps[key]>;
}

export type GetNextAdminPropsParams = {
/**
Expand Down Expand Up @@ -1035,7 +1039,7 @@ export type GetMainLayoutPropsParams = Omit<
>;

export type RequestContext<P extends string> = {
params: Record<P, string[]>;
params: Promise<Record<P, string[]>>;
};

export type CreateAppHandlerParams<P extends string = "nextadmin"> = {
Expand Down
15 changes: 11 additions & 4 deletions packages/next-admin/src/utils/advancedSearch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JSONSchema7 } from "json-schema";
import get from "lodash.get";
import set from "lodash.set";
import z from "zod";
Expand Down Expand Up @@ -330,8 +331,8 @@ export const buildUIBlocks = <M extends ModelName>(

const childResourceName = (
isArrayConditionKey
? schemaProperty.items?.$ref
: schemaProperty.$ref
? schemaProperty.items?.$ref || (schemaProperty?.anyOf?.[0] as JSONSchema7)?.$ref
: schemaProperty.$ref || (schemaProperty?.anyOf?.[0] as JSONSchema7)?.$ref
)
?.split("/")
?.at(-1)! as keyof typeof schema.definitions;
Expand Down Expand Up @@ -497,8 +498,14 @@ export const buildQueryBlocks = <M extends ModelName>(
[path, basePath, "some"].filter(Boolean).join(".")
);
}
} else if (schemaProperty?.$ref) {
const childResource = schemaProperty.$ref.split("/").at(-1)!;
} else if (
schemaProperty &&
(schemaProperty?.$ref || (schemaProperty?.anyOf?.[0] as JSONSchema7)?.$ref)
) {
const ref =
schemaProperty.$ref ||
(schemaProperty.anyOf?.[0] as JSONSchema7)?.$ref;
const childResource = ref!.split("/").at(-1)!;

if (!get(acc, [path, basePath].filter(Boolean))) {
set(acc, [path, basePath].filter(Boolean).join("."), {});
Expand Down
Loading

0 comments on commit e9094a5

Please sign in to comment.