Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dev] Add story for ReferenceArrayInput #9710

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 30 additions & 15 deletions packages/ra-ui-materialui/src/input/ReferenceArrayInput.stories.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import { createMemoryHistory } from 'history';
import { DataProvider, Form, testDataProvider } from 'ra-core';

Check warning on line 3 in packages/ra-ui-materialui/src/input/ReferenceArrayInput.stories.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'testDataProvider' is defined but never used. Allowed unused vars must match /^_/u
import polyglotI18nProvider from 'ra-i18n-polyglot';
import englishMessages from 'ra-language-english';
import { Admin, Resource } from 'react-admin';
Expand All @@ -26,21 +26,10 @@
{ id: 4, name: 'Photography' },
];

const dataProvider = testDataProvider({
// @ts-ignore
getList: () =>
Promise.resolve({
data: tags,
total: tags.length,
}),
// @ts-ignore
getMany: (resource, params) => {
console.log('getMany', resource, params);
return Promise.resolve({
data: params.ids.map(id => tags.find(tag => tag.id === id)),
});
},
});
const dataProvider = fakeRestProvider(
{ tags },
process.env.NODE_ENV === 'development'
);

const i18nProvider = polyglotI18nProvider(() => englishMessages);

Expand Down Expand Up @@ -84,6 +73,32 @@
</AdminContext>
);

export const SmallPageSize = ({ perPage = 2 }) => (
<Admin dataProvider={dataProvider} history={history}>
<Resource name="tags" recordRepresentation={'name'} />
<Resource
name="posts"
create={() => (
<Create
resource="posts"
record={{ tags_ids: [1, 3] }}
sx={{ width: 600 }}
>
<SimpleForm>
<ReferenceArrayInput
reference="tags"
resource="posts"
source="tags_ids"
perPage={perPage}
/>
</SimpleForm>
</Create>
)}
/>
</Admin>
);
SmallPageSize.args = { perPage: 2 };

export const ErrorAutocomplete = () => (
<AdminContext
dataProvider={
Expand Down