Skip to content

Commit

Permalink
fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash committed Dec 11, 2024
1 parent 78e6128 commit cba1d26
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/example/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const options: NextAdminOptions = {
birthDate: {
formatter: (date, context) => {
return new Date(date as unknown as string)
?.toLocaleString(context?.locale)
?.toLocaleString(context?.locale ?? "en")
.split(/[\s,]+/)[0];
},
},
Expand Down
3 changes: 2 additions & 1 deletion apps/example/pageRouterOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export const options: NextAdminOptions = {
},
birthDate: {
formatter: (date, context) => {
console.log("context", context);
return new Date(date as unknown as string)
?.toLocaleString(context?.locale)
?.toLocaleString(context?.locale ?? "fr")
.split(" ")[0];
},
},
Expand Down
8 changes: 4 additions & 4 deletions packages/next-admin/src/components/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import React, { ReactNode } from "react";
import clsx from "clsx";
import Link from "next/link";
import { useConfig } from "../context/ConfigContext";
import { ListDataFieldValue } from "../types";
import { ListDataFieldValue, NextAdminContext } from "../types";
import { getDisplayedValue } from "../utils/tools";
import Clipboard from "./common/Clipboard";

type Props = {
cell: ListDataFieldValue;
formatter?: (cell: any) => ReactNode;
formatter?: (cell: any, context?: NextAdminContext) => ReactNode;
copyable?: boolean;
};

export default function Cell({ cell, formatter, copyable }: Props) {
const { basePath } = useConfig();
const { basePath, nextAdminContext } = useConfig();

let cellValue = cell?.__nextadmin_formatted;

Expand All @@ -34,7 +34,7 @@ export default function Cell({ cell, formatter, copyable }: Props) {
);
} else if (typeof cell === "object" && !isReactNode(cellValue)) {
if (formatter) {
cellValue = formatter(cell?.value);
cellValue = formatter(cell?.value, nextAdminContext);
}

if (cell.type === "link") {
Expand Down
1 change: 1 addition & 0 deletions packages/next-admin/src/components/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const MainLayout = ({
resource={resource}
resourcesIdProperty={resourcesIdProperty!}
schema={schema}
nextAdminContext={{ locale }}
>
<I18nProvider translations={mergedTranslations}>
<ThemeProvider
Expand Down
9 changes: 8 additions & 1 deletion packages/next-admin/src/context/ConfigContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"use client";
import React, { useContext, useMemo } from "react";
import { ModelName, NextAdminOptions, Schema } from "../types";
import {
ModelName,
NextAdminContext,
NextAdminOptions,
Schema,
} from "../types";

export type ConfigContextType = {
options?: NextAdminOptions;
Expand All @@ -10,6 +15,7 @@ export type ConfigContextType = {
resource?: ModelName;
resourcesIdProperty: Record<ModelName, string> | null;
schema: Schema;
nextAdminContext?: NextAdminContext;
};

const ConfigContext = React.createContext<ConfigContextType>(
Expand All @@ -25,6 +31,7 @@ type ProviderProps = {
resource?: ModelName;
resourcesIdProperty: Record<ModelName, string> | null;
schema: Schema;
nextAdminContext?: NextAdminContext;
};

export const ConfigProvider = ({ children, ...props }: ProviderProps) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-admin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ export type SubmitFormResult = {
};

export type NextAdminContext = {
locale?: string;
locale?: string | null;
row?: any;
};

Expand Down

0 comments on commit cba1d26

Please sign in to comment.