-
-
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 #3771 from marmelab/ra-tree-v2
[RFR] New ra-tree for react-admin v2
- Loading branch information
Showing
71 changed files
with
3,546 additions
and
1,866 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint react/jsx-key: off */ | ||
import React from 'react'; | ||
import { | ||
Create, | ||
SimpleForm, | ||
TextField, | ||
TextInput, | ||
required, | ||
} from 'react-admin'; | ||
|
||
const TagCreate = props => ( | ||
<Create {...props}> | ||
<SimpleForm redirect="list"> | ||
<TextField source="id" /> | ||
<TextInput source="name" validate={[required()]} /> | ||
</SimpleForm> | ||
</Create> | ||
); | ||
|
||
export default TagCreate; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,41 @@ | ||
import React from 'react'; | ||
import { TextField } from 'react-admin'; | ||
import { | ||
DeleteButton, | ||
EditButton, | ||
List, | ||
SaveButton, | ||
ShowButton, | ||
TextInput, | ||
} from 'react-admin'; | ||
import { | ||
DragPreview, | ||
IgnoreFormProps, | ||
NodeForm, | ||
AddChildNodeMenuItem, | ||
AddNodeAfterMenuItem, | ||
AddNodeBeforeMenuItem, | ||
DeleteMenuItem, | ||
EditMenuItem, | ||
Tree, | ||
NodeActions, | ||
TreeNode, | ||
TreeList, | ||
TreeNodeActions, | ||
TreeNodeActionsMenu, | ||
} from 'ra-tree-ui-materialui'; | ||
|
||
const TagDragPreview = props => ( | ||
<DragPreview {...props}>{({ node }) => node.record.name}</DragPreview> | ||
const TagNodeActions = props => ( | ||
<TreeNodeActions {...props}> | ||
<TreeNodeActionsMenu {...props}> | ||
<AddChildNodeMenuItem /> | ||
<AddNodeBeforeMenuItem /> | ||
<AddNodeAfterMenuItem /> | ||
<EditMenuItem /> | ||
<DeleteMenuItem /> | ||
</TreeNodeActionsMenu> | ||
</TreeNodeActions> | ||
); | ||
|
||
const CustomNodeActions = props => ( | ||
<NodeActions {...props}> | ||
<SaveButton variant="flat" /> | ||
<IgnoreFormProps> | ||
<EditButton /> | ||
<ShowButton /> | ||
<DeleteButton /> | ||
</IgnoreFormProps> | ||
</NodeActions> | ||
); | ||
// Disallow dragging of items without parent (top level items) | ||
const canDrag = record => !!record.parent_id; | ||
|
||
const TagList = props => ( | ||
<List {...props} perPage={1000}> | ||
<Tree | ||
allowDropOnRoot | ||
enableDragAndDrop | ||
parentSource="parent_id" | ||
dragPreviewComponent={TagDragPreview} | ||
> | ||
<NodeForm actions={<CustomNodeActions />}> | ||
<TextInput source="name" /> | ||
</NodeForm> | ||
</Tree> | ||
</List> | ||
<Tree positionSource="position" {...props}> | ||
<TreeList> | ||
<TreeNode actions={<TagNodeActions />} canDrag={canDrag}> | ||
<TextField source="name" /> | ||
</TreeNode> | ||
</TreeList> | ||
</Tree> | ||
); | ||
|
||
export default TagList; |
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.