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

Version Packages #282

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading