-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10367 from marmelab/feat/next/select_all
Add a “SELECT ALL” button in the `<BulkActionsToolbar>`
- Loading branch information
Showing
47 changed files
with
2,585 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/ra-core/src/controller/field/useReferenceArrayFieldController.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import * as React from 'react'; | ||
import { | ||
CoreAdminContext, | ||
type GetManyResult, | ||
type ListControllerResult, | ||
testDataProvider, | ||
useReferenceArrayFieldController, | ||
} from '../..'; | ||
|
||
const dataProvider = testDataProvider({ | ||
getMany: (_resource, _params): Promise<GetManyResult> => | ||
Promise.resolve({ | ||
data: [ | ||
{ id: 1, title: 'bar1' }, | ||
{ id: 2, title: 'bar2' }, | ||
], | ||
}), | ||
}); | ||
|
||
/** | ||
* Render prop version of the controller hook | ||
*/ | ||
const ReferenceArrayFieldController = props => { | ||
const { children, ...rest } = props; | ||
const controllerProps = useReferenceArrayFieldController({ | ||
sort: { | ||
field: 'id', | ||
order: 'ASC', | ||
}, | ||
...rest, | ||
}); | ||
return children(controllerProps); | ||
}; | ||
|
||
const defaultRenderProp = (props: ListControllerResult) => ( | ||
<div> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '10px', | ||
}} | ||
> | ||
<button | ||
onClick={() => props.onSelectAll()} | ||
disabled={props.total === props.selectedIds.length} | ||
> | ||
Select All | ||
</button> | ||
<button | ||
onClick={props.onUnselectItems} | ||
disabled={props.selectedIds.length === 0} | ||
> | ||
Unselect All | ||
</button> | ||
<p data-testid="selected_ids"> | ||
Selected ids: {JSON.stringify(props.selectedIds)} | ||
</p> | ||
</div> | ||
<ul | ||
style={{ | ||
listStyleType: 'none', | ||
}} | ||
> | ||
{props.data?.map(record => ( | ||
<li key={record.id}> | ||
<input | ||
type="checkbox" | ||
checked={props.selectedIds.includes(record.id)} | ||
onChange={() => props.onToggleItem(record.id)} | ||
style={{ | ||
cursor: 'pointer', | ||
marginRight: '10px', | ||
}} | ||
data-testid={`checkbox-${record.id}`} | ||
/> | ||
{record.id} - {record.title} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
|
||
export const Basic = ({ children = defaultRenderProp }) => ( | ||
<CoreAdminContext dataProvider={dataProvider}> | ||
<ReferenceArrayFieldController | ||
resource="foo" | ||
reference="bar" | ||
record={{ id: 1, barIds: [1, 2] }} | ||
source="barIds" | ||
> | ||
{children} | ||
</ReferenceArrayFieldController> | ||
</CoreAdminContext> | ||
); | ||
|
||
export default { | ||
title: 'ra-core/controller/useReferenceArrayFieldController', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.