Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { CreateBase } from '../../controller/create/CreateBase';
import { testDataProvider } from '../../dataProvider/testDataProvider';
import { DataProvider } from '../../types';
import { Form } from '../../form/Form';
import { useInput } from '../../form/useInput';
import { InputProps } from '../../form/types';
import { InputProps, useInput } from '../../form/useInput';
import { TestMemoryRouter } from '../../routing/TestMemoryRouter';
import {
ReferenceArrayInputBase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { InputProps } from '../../form/types';
import { InputProps } from '../../form/useInput';
import {
useReferenceArrayInputController,
type UseReferenceArrayInputParams,
Expand Down
6 changes: 0 additions & 6 deletions packages/ra-core/src/form/types.ts

This file was deleted.

13 changes: 12 additions & 1 deletion packages/ra-ui-materialui/src/input/ReferenceArrayInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { DatagridInput } from './DatagridInput';
import { TextField } from '../field';
import { ReferenceArrayInput } from './ReferenceArrayInput';
import { SelectArrayInput } from './SelectArrayInput';
import { DifferentIdTypes } from './ReferenceArrayInput.stories';
import { AsFilters, DifferentIdTypes } from './ReferenceArrayInput.stories';

describe('<ReferenceArrayInput />', () => {
const defaultProps = {
Expand Down Expand Up @@ -292,4 +292,15 @@ describe('<ReferenceArrayInput />', () => {
})
).toBeNull();
});

it('can be used as a list filter', async () => {
render(<AsFilters />);
await screen.findByText('band_2');
fireEvent.click(screen.getByText('Members'));
fireEvent.click(screen.getByText('artist_2'));
await waitFor(() => {
expect(screen.queryByText('band_2')).toBeNull();
});
await screen.findByText('band_1');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ReferenceArrayInput } from './ReferenceArrayInput';
import { AutocompleteArrayInput } from './AutocompleteArrayInput';
import { SelectArrayInput } from './SelectArrayInput';
import { CheckboxGroupInput } from './CheckboxGroupInput';
import { List, Datagrid } from '../list';

export default { title: 'ra-ui-materialui/input/ReferenceArrayInput' };

Expand Down Expand Up @@ -77,6 +78,51 @@ export const Basic = () => (
</TestMemoryRouter>
);

export const AsFilters = () => {
const fakeData = {
bands: [
{ id: 1, name: 'band_1', members: [2] },
{ id: 2, name: 'band_2', members: [3] },
],
artists: [
{ id: 1, name: 'artist_1' },
{ id: 2, name: 'artist_2' },
{ id: 3, name: 'artist_3' },
],
};
return (
<TestMemoryRouter initialEntries={['/bands']}>
<AdminContext
dataProvider={fakeRestProvider(fakeData, false)}
i18nProvider={i18nProvider}
>
<AdminUI>
<Resource name="tags" recordRepresentation={'name'} />
<Resource
name="bands"
list={() => (
<List
filters={[
<ReferenceArrayInput
alwaysOn
key="test"
reference="artists"
source="members"
/>,
]}
>
<Datagrid>
<TextField source="name" />
</Datagrid>
</List>
)}
/>
</AdminUI>
</AdminContext>
</TestMemoryRouter>
);
};

export const WithAutocompleteInput = () => (
<AdminContext
dataProvider={dataProvider}
Expand Down
Loading