import { useGetList, ListBase, Datagrid, BooleanField, DateField, EmailField, FileField, FunctionField, NumberField, ReferenceArrayField, TextField, ReferenceField, ReferenceManyCount, } from "react-admin"; import { AdminStoryContext } from "../../../utils"; import { MemoryRouter } from "react-router"; import { useArgs } from "@storybook/preview-api"; import { StoryContext } from "@storybook/react"; import React from "react"; const FIELD_STORIES_MAP: Record JSX.Element> = { BooleanField: () => { return ; }, DateField: () => { return ; }, EmailField: () => { return ; }, FileField: () => { return ; }, FunctionField: () => { const createFunctionRender = (record: any) => { return
Custom render: {record.name}
; }; return ( ); }, NumberField: () => { return ; }, ReferenceArrayField: () => { return ( ); }, ReferenceField: () => { return ( ); }, ReferenceManyCount: () => { return ( ); }, TextField: () => { return ; }, }; export const adminContextDecorator = (Story: () => React.JSX.Element) => { return ( ); }; export const listDecorator = ( Story: () => React.JSX.Element, context: StoryContext ) => { const { data } = useGetList("users", { sort: { field: "id", order: "ASC" }, }); const activeStoryId = context.title.split("/").pop(); const activeIndex = activeStoryId ? Object.keys(FIELD_STORIES_MAP).findIndex( (story) => story === activeStoryId ) : undefined; return ( {Object.entries(FIELD_STORIES_MAP).map(([id, Component]) => { if (context.title.match(id)) { return Story(); } return Component(); })} ); }; export const shadowArgsDecorator = (Story: () => React.JSX.Element) => { const [args, updateArgs, resetArgs] = useArgs(); if (!("sortable" in args)) { updateArgs({ ...args, sortable: false }); } return ; }; export const fieldDecorators = [ (Story: () => React.JSX.Element, context: StoryContext) => listDecorator(Story, context), (Story: () => React.JSX.Element) => adminContextDecorator(Story), (Story: () => React.JSX.Element) => shadowArgsDecorator(Story), ];