score:6
There is no way to refresh a route via react router, and that's a known problem. Admin-on-rest's List
component has its own refresh mechanism, but offers no API for it.
My advice would be to use a custom <List>
component based on admin-on-rest's one. And if you find a way to expose the refresh
action, feel free to open a PR on the aor repository!
score:0
Pim Schaaf's solution worked like a charm for me, Mine looks a bit different
yield put(push('/comments/-1')); // This refreshes the data
yield put(showNotification('')); // Hide error
score:1
I've solve this task with small hack via Actions panel. I'm sure it is not correct solution, but in some situations it can help:
class RefreshButton extends FlatButton {
componentDidMount() {
if (this.props.refreshInterval) {
this.interval = setInterval(() => {
this.props.refresh(new Event('refresh'))
}, this.props.refreshInterval)
}
}
componentWillUnmount() {
clearInterval(this.interval)
}
}
const StreamActions = ({ resource, filters, displayedFilters, filterValues, basePath, showFilter, refresh }) => (
<CardActions>
{filters && React.cloneElement(filters, { resource, showFilter, displayedFilters, filterValues, context: 'button' }) }
<RefreshButton primary label="Refresh streams" onClick={refresh} refreshInterval={15000} refresh={refresh} icon={<NavigationRefresh />} />
</CardActions>
);
export default class StreamsListPage extends Component {
render() {
return (
<List
{...this.props}
perPage={20}
actions={<StreamActions />}
filter={{ active: true }}
title='Active Streams'>
<StreamsList />
</List>
)
}
}
score:1
The push
is just a redirect for AOR which did not seem to work for me either. What guleryuz posted was on the right track for me.. Here's what I did building on his example:
// Import Statement
import { refreshView as refreshViewAction } from 'admin-on-rest';
class RemoveButton extends Component {
handleClick = () => {
const { refreshView, record, showNotification } = this.props;
fetch(`http://localhost:33333/api/v1/batch/stage/${record.id}`, { method: 'DELETE' })
.then(() => {
showNotification('Removed domain from current stage');
refreshView();
})
.catch((e) => {
console.error(e);
showNotification('Error: could not find domain');
});
}
render() {
return <FlatButton secondary label="Delete" icon={<DeleteIcon />}onClick={this.handleClick} />;
}
}
These bits are important as well:
RemoveButton.propTypes = {
record: PropTypes.object,
showNotification: PropTypes.func,
refreshView: PropTypes.func,
};
export default connect(null, {
showNotification: showNotificationAction,
refreshView: refreshViewAction,
})(RemoveButton);
So the way this works is it uses AOR's refreshViewAction
as a prop function. This uses the underlying call to populate the data grid for me which is GET_LIST
. This may not apply to your specific use case. Let me know if you have any questions.
score:2
using refreshView action via redux works well.
see example....
import { refreshView as refreshViewAction } from 'admin-on-rest';
import { connect } from 'react-redux';
class MyReactComponent extends Component {
//... etc etc standard react stuff...
doSomething() {
// etc etc do smt then trigger refreshView like below
this.props.refreshView();
}
render() {
return <div>etc etc your stuff</div>
}
}
export default connect(undefined, { refreshView: refreshViewAction })(
MyReactComponent
);
score:3
Definitely hacky, but a work-around could be:
push('/comments/1') //any path to change the current route
push('/comments') //the path to refresh, which is now a new route
score:4
@Danila Smirnov's answer above shows this message when I use it now:
Deprecation warning: The preferred way to refresh the List view is to connect your custom button with redux and dispatch the refreshView action.
Clicking the refresh button itself wasn't working either nowadays.
Here's the tweaked version that I got working in mine.
Edit: Modified it a bit more to make it reusable.
RefreshListActions.js
import React, { Component } from 'react'
import FlatButton from 'material-ui/FlatButton'
import { CardActions } from 'material-ui/Card'
import NavigationRefresh from 'material-ui/svg-icons/navigation/refresh'
import { connect } from 'react-redux'
import { REFRESH_VIEW } from 'admin-on-rest/src/actions/uiActions'
import { refreshView as refreshViewAction } from 'admin-on-rest/src/actions/uiActions'
class MyRefresh extends Component {
componentDidMount() {
const { refreshInterval, refreshView } = this.props
if (refreshInterval) {
this.interval = setInterval(() => {
refreshView()
}, refreshInterval)
}
}
componentWillUnmount() {
clearInterval(this.interval)
}
render() {
const { label, refreshView, icon } = this.props;
return (
<FlatButton
primary
label={label}
onClick={refreshView}
icon={icon}
/>
);
}
}
const RefreshButton = connect(null, { refreshView: refreshViewAction })(MyRefresh)
const RefreshListActions = ({ resource, filters, displayedFilters, filterValues, basePath, showFilter, refreshInterval }) => (
<CardActions>
{filters && React.cloneElement(filters, { resource, showFilter, displayedFilters, filterValues, context: 'button' }) }
<RefreshButton primary label="Refresh" refreshInterval={refreshInterval} icon={<NavigationRefresh />} />
</CardActions>
);
export default RefreshListActions
In my list that I want to refresh so often:
import RefreshListActions from './RefreshListActions'
export default (props) => (
<List {...props}
actions={<RefreshListActions refreshInterval="10000" />}
>
<Datagrid>
...
</Datagrid>
</List>
)
Source: stackoverflow.com
Related Query
- How to refresh a List View in admin on rest
- How to get the marquee effect with list view in react native?
- How to limit column width on react-admin List View
- How to refresh the React-Admin list data every X seconds?
- how to display large list of data using reactJS as frontend and django rest framework as backend
- How to add a permanent filter function to a List view in react-admin?
- How to make the first item of the list always be at the top and the rest of the list will scroll independently of it
- How to deselect list items in react admin custom bulk action buttons
- Admin on rest - How to display a Datagrid withtout a ReferenceField?
- How to scroll a list item into view using scrollintoview method using reactjs?
- How to create list and detail view using React Router DOM?
- How to insert a new Item in List view in ReactJS
- How can I refresh a list in one component after form submit in another component that shares same parent?
- How to refresh list after successfully created post in react redux form
- How to refresh a nested Component view that shows the result for a search being done in React
- ReactJs - List view with vertical lines. How to draw this?
- How can I add a button to each list view item with Reactjs?
- How can I make my admin page (for removing users from DB) not display other users in the list if they have an admin role?
- How to filter the retrieved items using a pnp.sp.web REST call to a SharePoint list
- How to display object properties dynamically in reactjs list view
- How to prevent refresh of list over API after drag & drop with beautiful DND?
- How do I toggle between List and Grid view (the image must change together)?
- How to show single hidden element of list and hide the rest
- How to Refresh entire app after rest call / how to to refresh app after an event
- How to make a rest post call from ReactJS code?
- How to refresh a Page using react-route Link
- How to maintain state after a page refresh in React.js?
- React: How to navigate through list by arrow keys
- How to add a link to a List in material-ui 1.0?
- How to use Redux to refresh JWT token?
More Query from same tag
- Adding property to URL config
- How can I dynamically load an image from my assets folder based on props in ReactJS?
- Bootstrap Form.Control select populated with date string options in format 'MONTH YYYY'
- How to map data from two nested arrays in react js?
- More values in Ternary operator?
- Create-react-app css modules with typescript: Cant resolve .module.css
- How to have a separator between arabic numbers in javascript?
- Proper use of useEffect with useState called within async function
- Axios post entering catch block even after successful Rest API call completion
- IE array.flat() Object doesn't support property or method 'flat'
- Set all categories in firebase & react
- React state array gives null error in rendor
- I have created a home page using reactstrap and hashrouter. But the router views are not working
- React hooks boolean in state not properly being set
- getting errors in retrieving information through inputs
- useEffect not setting data to state in functional component
- React Router v4.2 style
- ReactDOM.render(Array, DivContext) only works once
- value is always empty inside ternary operator statement
- Route exact path="/" not working for react github
- how to show bootstrap Modal in another component react js
- callback function after dispatch function in react-redux
- React Private Route is redirecting before logging in on refresh
- Page-layout -> getPrintArea() in office-JS is returning blank Object
- Switch class on tabs with React.js
- Trigger a function at particular time everyday in javascript
- Is their a way to disable interaction on few polygons based on the property of a polygon?
- npm start suddenly stops working on react app
- Using iFrame Resizer with a React JS Page As Content
- Tailwind select element not displaying correctly