-
-
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 #4494 from marmelab/reference-array-input-selected…
…-value Fix ReferenceArrayInput list when filter is changed
- Loading branch information
Showing
6 changed files
with
139 additions
and
20 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
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,46 @@ | ||
import React, { useState } from 'react'; | ||
import { useForm } from 'react-final-form'; | ||
import { AutocompleteArrayInput, ReferenceArrayInput } from 'react-admin'; | ||
import Button from '@material-ui/core/Button'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
const useStyles = makeStyles({ | ||
button: { | ||
margin: '0 24px', | ||
position: 'relative', | ||
}, | ||
input: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
width: '50%', | ||
}, | ||
}); | ||
|
||
const TagReferenceInput = ({ ...props }) => { | ||
const classes = useStyles(); | ||
const { change } = useForm(); | ||
const [filter, setFilter] = useState(true); | ||
|
||
const handleAddFilter = () => { | ||
setFilter(!filter); | ||
change('tags', []); | ||
}; | ||
|
||
return ( | ||
<div className={classes.input}> | ||
<ReferenceArrayInput {...props} filter={{ published: filter }}> | ||
<AutocompleteArrayInput /> | ||
</ReferenceArrayInput> | ||
<Button | ||
name="change-filter" | ||
className={classes.button} | ||
onClick={handleAddFilter} | ||
> | ||
Filter {filter ? 'Unpublished' : 'Published'} Tags | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TagReferenceInput; |
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