Skip to content

Commit

Permalink
Merge pull request #282 from premieroctet/changeset-release/main
Browse files Browse the repository at this point in the history
Version Packages
  • Loading branch information
cregourd authored May 17, 2024
2 parents 23786c5 + f2551a3 commit 6b14540
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/next-admin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @premieroctet/next-admin

## 4.2.2

### Patch Changes

- 6cd3362: Add slug inside breadcrumb (#263)

## 4.2.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/next-admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@premieroctet/next-admin",
"version": "4.2.1",
"version": "4.2.2",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion packages/next-admin/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export type FormProps = {
schema: any;
dmmfSchema: readonly Prisma.DMMF.Field[];
resource: ModelName;
slug?: string;
validation?: PropertyValidationError[];
action?: (formData: FormData) => Promise<SubmitFormResult | undefined>;
title: string;
Expand Down Expand Up @@ -107,6 +108,7 @@ const Form = ({
schema,
dmmfSchema,
resource,
slug,
validation: validationProp,
action,
title,
Expand Down Expand Up @@ -479,7 +481,7 @@ const Form = ({

if (edit && id) {
breadcrumItems.push({
label: id.toString(),
label: slug ?? id.toString(),
href: `${basePath}/${slugify(resource)}/${id}`,
current: true,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/next-admin/src/components/NextAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function NextAdmin({
resource,
schema,
resources,
slug,
message,
error,
total,
Expand Down Expand Up @@ -79,6 +80,7 @@ export function NextAdmin({
return (
<Form
data={data}
slug={slug}
schema={modelSchema}
dmmfSchema={dmmfSchema!}
resource={resource!}
Expand Down
1 change: 1 addition & 0 deletions packages/next-admin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export type AdminComponentProps = {
schema?: Schema;
data?: ListData<ModelName>;
resource?: ModelName;
slug?: string;
/**
* Page router only
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/next-admin/src/utils/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getResourceFromParams,
getResourceIdFromParam,
getResources,
getToStringForModel,
transformData,
transformSchema,
} from "./server";
Expand Down Expand Up @@ -273,11 +274,18 @@ export async function getPropsFromParams({
}
});

const toStringFunction = getToStringForModel(
options?.model?.[resource]
);
const slug = toStringFunction
? toStringFunction(data)
: resourceId.toString();
data = transformData(data, resource, edit, options);
return {
...defaultProps,
resource,
data,
slug,
schema: deepCopySchema,
dmmfSchema: dmmfSchema?.fields,
customInputs,
Expand Down
12 changes: 12 additions & 0 deletions packages/next-admin/src/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EditOptions,
Enumeration,
Field,
Model,
ModelName,
ModelWithoutRelationships,
NextAdminOptions,
Expand Down Expand Up @@ -78,6 +79,17 @@ export const getToStringForRelations = <M extends ModelName>(
return toStringForRelations;
};

export const getToStringForModel = <M extends ModelName>(
options: Required<NextAdminOptions>["model"][M]
): ((item: Model<M>) => string) | undefined => {
const nonCheckedToString = options?.toString;
const toStringForRelations =
nonCheckedToString && !isNativeFunction(nonCheckedToString)
? nonCheckedToString
: undefined;
return toStringForRelations;
};

/**
* Order the fields in the schema according to the display option
*
Expand Down

0 comments on commit 6b14540

Please sign in to comment.