import * as React from 'react';
import {
QueryClientProvider,
QueryClient,
onlineManager,
} from '@tanstack/react-query';
import { RecordContextProvider } from '../record';
import { DataProviderContext } from '../../dataProvider';
import { ResourceContextProvider, useIsOffline } from '../../core';
import { TestMemoryRouter } from '../../routing';
import { ReferenceManyCountBase } from './ReferenceManyCountBase';
export default {
title: 'ra-core/controller/field/ReferenceManyCountBase',
excludeStories: ['Wrapper'],
};
const post = {
id: 1,
title: 'Lorem Ipsum',
};
const comments = [
{ id: 1, post_id: 1, is_published: true },
{ id: 2, post_id: 1, is_published: true },
{ id: 3, post_id: 1, is_published: false },
{ id: 4, post_id: 2, is_published: true },
{ id: 5, post_id: 2, is_published: false },
];
export const Wrapper = ({ dataProvider, children }) => (
{children}
);
export const Basic = () => (
Promise.resolve({
data: [comments.filter(c => c.post_id === 1)[0]],
total: comments.filter(c => c.post_id === 1).length,
}),
}}
>
);
export const WithRender = () => (
Promise.resolve({
data: [comments.filter(c => c.post_id === 1)[0]],
total: comments.filter(c => c.post_id === 1).length,
}),
}}
>
{total} comments}
/>
);
export const LoadingState = () => (
new Promise(() => {}) }}>
);
export const ErrorState = () => (
Promise.reject(new Error('problem')),
}}
>
);
export const Filter = () => (
Promise.resolve({
data: comments
.filter(c => c.post_id === 1)
.filter(post =>
Object.keys(params.filter).every(
key => post[key] === params.filter[key]
)
),
total: comments
.filter(c => c.post_id === 1)
.filter(post =>
Object.keys(params.filter).every(
key => post[key] === params.filter[key]
)
).length,
}),
}}
>
);
export const Slow = () => (
new Promise(resolve =>
setTimeout(
() =>
resolve({
data: [
comments.filter(c => c.post_id === 1)[0],
],
total: comments.filter(c => c.post_id === 1)
.length,
}),
2000
)
),
}}
>
);
export const Offline = () => {
return (
Promise.resolve({
data: [comments.filter(c => c.post_id === 1)[0]],
total: comments.filter(c => c.post_id === 1).length,
}),
}}
>
You are offline, cannot load data
}
/>
);
};
const SimulateOfflineButton = () => {
const isOffline = useIsOffline();
return (
);
};
const RenderChildOnDemand = ({ children }) => {
const [showChild, setShowChild] = React.useState(false);
return (
<>
{showChild &&
{children}
}
>
);
};