import * as React from 'react';
import { onlineManager, QueryClient } from '@tanstack/react-query';
import fakeRestDataProvider from 'ra-data-fakerest';
import { CoreAdmin } from '../../core/CoreAdmin';
import { Resource } from '../../core/Resource';
import { ShowBase } from '../../controller/show/ShowBase';
import { TestMemoryRouter } from '../../routing';
import { ReferenceFieldBase } from './ReferenceFieldBase';
import { useFieldValue } from '../../util/useFieldValue';
import { useReferenceFieldContext } from './ReferenceFieldContext';
import { DataProvider } from '../../types';
import { useIsOffline } from '../../core/useIsOffline';
import { IsOffline } from '../..';
export default {
title: 'ra-core/controller/field/ReferenceFieldBase',
excludeStories: ['dataProviderWithAuthors'],
};
const authors = [
{ id: 1, first_name: 'Leo', last_name: 'Tolstoy', language: 'Russian' },
{ id: 2, first_name: 'Victor', last_name: 'Hugo', language: 'French' },
{
id: 3,
first_name: 'William',
last_name: 'Shakespeare',
language: 'English',
},
{
id: 4,
first_name: 'Charles',
last_name: 'Baudelaire',
language: 'French',
},
{ id: 5, first_name: 'Marcel', last_name: 'Proust', language: 'French' },
];
export const dataProviderWithAuthors = {
getOne: () =>
Promise.resolve({
data: {
id: 1,
title: 'War and Peace',
author: 1,
summary:
"War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society.",
year: 1869,
},
}),
getMany: (_resource, params) =>
Promise.resolve({
data: authors.filter(author => params.ids.includes(author.id)),
}),
} as any;
export const Basic = ({ dataProvider = dataProviderWithAuthors }) => (
}
/>
);
const dataProviderWithAuthorsError = {
getOne: () =>
Promise.resolve({
data: {
id: 1,
title: 'War and Peace',
author: 1,
summary:
"War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society.",
year: 1869,
},
}),
getMany: _resource => Promise.reject(new Error('Error')),
} as any;
export const Errored = ({ dataProvider = dataProviderWithAuthorsError }) => (
}
/>
);
const dataProviderWithAuthorsLoading = {
getOne: () =>
Promise.resolve({
data: {
id: 1,
title: 'War and Peace',
author: 1,
summary:
"War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society.",
year: 1869,
},
}),
getMany: _resource => new Promise(() => {}),
} as any;
export const Loading = ({ dataProvider = dataProviderWithAuthorsLoading }) => (
}
/>
);
const BookShowQueryOptions = () => {
const [enabled, setEnabled] = React.useState(false);
return (
<>
>
);
};
export const QueryOptions = () => (
);
const BookShowMeta = () => {
return (
);
};
export const Meta = ({
dataProvider = fakeRestDataProvider(
{
books: [
{
id: 1,
title: 'War and Peace',
author: 1,
summary:
"War and Peace broadly focuses on Napoleon's invasion of Russia, and the impact it had on Tsarist society. The book explores themes such as revolution, revolution and empire, the growth and decline of various states and the impact it had on their economies, culture, and society.",
year: 1869,
},
],
authors: [
{
id: 1,
first_name: 'Leo',
last_name: 'Tolstoy',
language: 'Russian',
},
{
id: 2,
first_name: 'Victor',
last_name: 'Hugo',
language: 'French',
},
{
id: 3,
first_name: 'William',
last_name: 'Shakespeare',
language: 'English',
},
{
id: 4,
first_name: 'Charles',
last_name: 'Baudelaire',
language: 'French',
},
{
id: 5,
first_name: 'Marcel',
last_name: 'Proust',
language: 'French',
},
],
},
process.env.NODE_ENV === 'development'
),
}: {
dataProvider: DataProvider;
}) => (
);
export const WithRenderProp = ({ dataProvider = dataProviderWithAuthors }) => (
{
if (isPending) {
return