import * as React from 'react';
import { onlineManager, QueryClient } from '@tanstack/react-query';
import { RecordsIterator } from 'ra-core';
import { CoreAdmin } from '../../core/CoreAdmin';
import { Resource } from '../../core/Resource';
import { ShowBase } from '../../controller/show/ShowBase';
import { TestMemoryRouter } from '../../routing';
import { ReferenceManyFieldBase } from './ReferenceManyFieldBase';
import { ListBase, useListContext } from '../list';
import fakeRestDataProvider from 'ra-data-fakerest';
import { useIsOffline } from '../../core';
export default {
title: 'ra-core/controller/field/ReferenceManyFieldBase',
excludeStories: ['dataProviderWithAuthors'],
};
const author = {
id: 1,
first_name: 'Leo',
last_name: 'Tolstoy',
language: 'Russian',
};
const books = [
{
id: 1,
title: 'War and Peace',
author: 1,
},
{
id: 2,
title: 'Anna Karenina',
author: 1,
},
{
id: 3,
title: 'The Kreutzer Sonata',
author: 1,
},
{
id: 4,
author: 2,
title: 'Hamlet',
},
];
export const dataProviderWithAuthors = {
getOne: async () => ({ data: author }),
getMany: async (_resource, params) => ({
data: books.filter(book => params.ids.includes(book.author)),
}),
getManyReference: async (_resource, params) => {
const result = books.filter(book => book.author === params.id);
return {
data: result.slice(
(params.pagination.page - 1) * params.pagination.perPage,
(params.pagination.page - 1) * params.pagination.perPage +
params.pagination.perPage
),
total: result.length,
};
},
} as any;
export const Basic = ({ dataProvider = dataProviderWithAuthors }) => (
Loading...
{error.message}
{data?.map((datum, index) => (
{author.last_name} Books
You are offline, cannot load data
), }, }, }; const SimulateOfflineButton = () => { const isOffline = useIsOffline(); return ( ); }; const RenderChildOnDemand = ({ children }) => { const [showChild, setShowChild] = React.useState(false); return ( <> {showChild &&Loading...
; } if (isPaused) { returnAuthorList: Offline. Could not load data
; } if (error) { return{error.toString()}
; } return ({data?.map((datum, index) =>