diff --git a/packages/ra-core/src/actions/uiActions.ts b/packages/ra-core/src/actions/uiActions.ts index d52166d20b9..3868f19ecc5 100644 --- a/packages/ra-core/src/actions/uiActions.ts +++ b/packages/ra-core/src/actions/uiActions.ts @@ -22,26 +22,16 @@ export const setSidebarVisibility = ( payload: isOpen, }); -// refresh increases version (i.e. forces refetch) and empties the cache export const REFRESH_VIEW = 'RA/REFRESH_VIEW'; export interface RefreshViewAction { readonly type: typeof REFRESH_VIEW; + readonly payload: { hard: boolean }; } -export const refreshView = (): RefreshViewAction => ({ +export const refreshView = (hard?: boolean): RefreshViewAction => ({ type: REFRESH_VIEW, -}); - -// soft refresh only increases version (i.e. forces refetch) -export const SOFT_REFRESH_VIEW = 'RA/SOFT_REFRESH_VIEW'; - -export interface SoftRefreshViewAction { - readonly type: typeof SOFT_REFRESH_VIEW; -} - -export const softRefreshView = (): SoftRefreshViewAction => ({ - type: SOFT_REFRESH_VIEW, + payload: { hard }, }); export const SET_AUTOMATIC_REFRESH = 'RA/SET_AUTOMATIC_REFRESH'; diff --git a/packages/ra-core/src/dataProvider/Mutation.spec.tsx b/packages/ra-core/src/dataProvider/Mutation.spec.tsx index 3524eb7d9a5..62506a591cb 100644 --- a/packages/ra-core/src/dataProvider/Mutation.spec.tsx +++ b/packages/ra-core/src/dataProvider/Mutation.spec.tsx @@ -3,11 +3,7 @@ import { fireEvent, waitFor, act, render } from '@testing-library/react'; import expect from 'expect'; import Mutation from './Mutation'; -import { - showNotification, - softRefreshView, - setListSelectedIds, -} from '../actions'; +import { showNotification, refreshView, setListSelectedIds } from '../actions'; import DataProviderContext from './DataProviderContext'; import { renderWithRedux, TestContext } from 'ra-test'; import { useNotify } from '../sideEffect'; @@ -104,7 +100,7 @@ describe('Mutation', () => { }) ); expect(historyForAssertions.location.pathname).toEqual('/a_path'); - expect(dispatchSpy).toHaveBeenCalledWith(softRefreshView()); + expect(dispatchSpy).toHaveBeenCalledWith(refreshView()); expect(dispatchSpy).toHaveBeenCalledWith( setListSelectedIds('foo', []) ); @@ -226,7 +222,7 @@ describe('Mutation', () => { }) ); expect(historyForAssertions.location.pathname).toEqual('/a_path'); - expect(dispatchSpy).toHaveBeenCalledWith(softRefreshView()); + expect(dispatchSpy).toHaveBeenCalledWith(refreshView()); expect(dispatchSpy).toHaveBeenCalledWith( setListSelectedIds('foo', []) ); diff --git a/packages/ra-core/src/dataProvider/Query.spec.tsx b/packages/ra-core/src/dataProvider/Query.spec.tsx index 1acc223f525..4f3b198b18e 100644 --- a/packages/ra-core/src/dataProvider/Query.spec.tsx +++ b/packages/ra-core/src/dataProvider/Query.spec.tsx @@ -6,11 +6,7 @@ import Query from './Query'; import { CoreAdmin, Resource } from '../core'; import { renderWithRedux, TestContext } from 'ra-test'; import DataProviderContext from './DataProviderContext'; -import { - showNotification, - softRefreshView, - setListSelectedIds, -} from '../actions'; +import { showNotification, refreshView, setListSelectedIds } from '../actions'; import { useNotify, useRefresh } from '../sideEffect'; import { History } from 'history'; @@ -315,7 +311,7 @@ describe('Query', () => { }) ); expect(historyForAssertions.location.pathname).toEqual('/a_path'); - expect(dispatchSpy).toHaveBeenCalledWith(softRefreshView()); + expect(dispatchSpy).toHaveBeenCalledWith(refreshView()); expect(dispatchSpy).toHaveBeenCalledWith( setListSelectedIds('foo', []) ); @@ -436,7 +432,7 @@ describe('Query', () => { }) ); expect(historyForAssertions.location.pathname).toEqual('/a_path'); - expect(dispatchSpy).toHaveBeenCalledWith(softRefreshView()); + expect(dispatchSpy).toHaveBeenCalledWith(refreshView()); expect(dispatchSpy).toHaveBeenCalledWith( setListSelectedIds('foo', []) ); diff --git a/packages/ra-core/src/reducer/admin/resource/index.ts b/packages/ra-core/src/reducer/admin/resource/index.ts index 216bfe89bcf..3cb7045f15d 100644 --- a/packages/ra-core/src/reducer/admin/resource/index.ts +++ b/packages/ra-core/src/reducer/admin/resource/index.ts @@ -5,8 +5,6 @@ import { UnregisterResourceAction, REFRESH_VIEW, RefreshViewAction, - SOFT_REFRESH_VIEW, - SoftRefreshViewAction, } from '../../../actions'; import data from './data'; @@ -19,7 +17,6 @@ type ActionTypes = | RegisterResourceAction | UnregisterResourceAction | RefreshViewAction - | SoftRefreshViewAction | { type: 'OTHER_ACTION'; payload?: any; meta?: { resource?: string } }; export default (previousState = initialState, action: ActionTypes) => { @@ -48,7 +45,6 @@ export default (previousState = initialState, action: ActionTypes) => { if ( action.type !== REFRESH_VIEW && - action.type !== SOFT_REFRESH_VIEW && (!action.meta || !action.meta.resource) ) { return previousState; @@ -60,7 +56,6 @@ export default (previousState = initialState, action: ActionTypes) => { ...acc, [resource]: action.type === REFRESH_VIEW || - action.type === SOFT_REFRESH_VIEW || action.meta.resource === resource ? { props: previousState[resource].props, diff --git a/packages/ra-core/src/reducer/admin/resource/list/cachedRequests.ts b/packages/ra-core/src/reducer/admin/resource/list/cachedRequests.ts index b375b6d7a5f..151d64b6072 100644 --- a/packages/ra-core/src/reducer/admin/resource/list/cachedRequests.ts +++ b/packages/ra-core/src/reducer/admin/resource/list/cachedRequests.ts @@ -1,11 +1,7 @@ import { Reducer } from 'redux'; import { Identifier } from '../../../../types'; -import { - FETCH_END, - REFRESH_VIEW, - SOFT_REFRESH_VIEW, -} from '../../../../actions'; +import { FETCH_END, REFRESH_VIEW } from '../../../../actions'; import { GET_LIST, CREATE, @@ -36,19 +32,20 @@ const cachedRequestsReducer: Reducer = ( action ) => { if (action.type === REFRESH_VIEW) { - // force refresh - return initialState; - } - if (action.type === SOFT_REFRESH_VIEW) { - // remove validity only - const newState = {}; - Object.keys(previousState).forEach(key => { - newState[key] = { - ...previousState[key], - validity: undefined, - }; - }); - return newState; + if (action.payload?.hard) { + // force refresh + return initialState; + } else { + // remove validity only + const newState = {}; + Object.keys(previousState).forEach(key => { + newState[key] = { + ...previousState[key], + validity: undefined, + }; + }); + return newState; + } } if (action.meta && action.meta.optimistic) { if ( diff --git a/packages/ra-core/src/reducer/admin/resource/list/validity.ts b/packages/ra-core/src/reducer/admin/resource/list/validity.ts index 04706c25e08..c1dc85284c8 100644 --- a/packages/ra-core/src/reducer/admin/resource/list/validity.ts +++ b/packages/ra-core/src/reducer/admin/resource/list/validity.ts @@ -1,9 +1,5 @@ import { Reducer } from 'redux'; -import { - FETCH_END, - REFRESH_VIEW, - SOFT_REFRESH_VIEW, -} from '../../../../actions'; +import { FETCH_END, REFRESH_VIEW } from '../../../../actions'; import { GET_LIST, CREATE } from '../../../../core'; interface ValidityRegistry { @@ -16,7 +12,7 @@ const validityReducer: Reducer = ( previousState = initialState, { type, payload, requestPayload, meta } ) => { - if (type === REFRESH_VIEW || type === SOFT_REFRESH_VIEW) { + if (type === REFRESH_VIEW) { return initialState; } if ( diff --git a/packages/ra-core/src/reducer/admin/resource/validity.ts b/packages/ra-core/src/reducer/admin/resource/validity.ts index 0d9a988be5e..b6559965e5d 100644 --- a/packages/ra-core/src/reducer/admin/resource/validity.ts +++ b/packages/ra-core/src/reducer/admin/resource/validity.ts @@ -1,5 +1,5 @@ import { Reducer } from 'redux'; -import { FETCH_END, REFRESH_VIEW, SOFT_REFRESH_VIEW } from '../../../actions'; +import { FETCH_END, REFRESH_VIEW } from '../../../actions'; import { CREATE, DELETE, @@ -25,7 +25,7 @@ const validityReducer: Reducer = ( previousState = initialState, { type, payload, requestPayload, meta } ) => { - if (type === REFRESH_VIEW || type === SOFT_REFRESH_VIEW) { + if (type === REFRESH_VIEW) { return initialState; } if ( diff --git a/packages/ra-core/src/reducer/admin/ui.ts b/packages/ra-core/src/reducer/admin/ui.ts index a2ee66b13f6..420dceea818 100644 --- a/packages/ra-core/src/reducer/admin/ui.ts +++ b/packages/ra-core/src/reducer/admin/ui.ts @@ -6,8 +6,6 @@ import { SetSidebarVisibilityAction, REFRESH_VIEW, RefreshViewAction, - SOFT_REFRESH_VIEW, - SoftRefreshViewAction, START_OPTIMISTIC_MODE, StartOptimisticModeAction, STOP_OPTIMISTIC_MODE, @@ -22,7 +20,6 @@ type ActionTypes = | ToggleSidebarAction | SetSidebarVisibilityAction | RefreshViewAction - | SoftRefreshViewAction | StartOptimisticModeAction | StopOptimisticModeAction | SetAutomaticRefreshAction @@ -70,7 +67,6 @@ const uiReducer: Reducer = ( automaticRefreshEnabled: action.payload, }; case REFRESH_VIEW: - case SOFT_REFRESH_VIEW: return { ...previousState, viewVersion: previousState.viewVersion + 1, diff --git a/packages/ra-core/src/sideEffect/useRefresh.ts b/packages/ra-core/src/sideEffect/useRefresh.ts index c9bca611421..b35499efbd7 100644 --- a/packages/ra-core/src/sideEffect/useRefresh.ts +++ b/packages/ra-core/src/sideEffect/useRefresh.ts @@ -1,6 +1,6 @@ import { useCallback } from 'react'; import { useDispatch } from 'react-redux'; -import { refreshView, softRefreshView } from '../actions/uiActions'; +import { refreshView } from '../actions/uiActions'; /** * Hook for Refresh Side Effect @@ -24,7 +24,7 @@ const useRefresh = () => { const dispatch = useDispatch(); return useCallback( (hard?: boolean) => { - dispatch(hard ? refreshView() : softRefreshView()); + dispatch(refreshView(hard)); }, [dispatch] ); diff --git a/packages/ra-ui-materialui/src/button/RefreshButton.tsx b/packages/ra-ui-materialui/src/button/RefreshButton.tsx index f9786cf2f10..b7779cde9e2 100644 --- a/packages/ra-ui-materialui/src/button/RefreshButton.tsx +++ b/packages/ra-ui-materialui/src/button/RefreshButton.tsx @@ -3,7 +3,7 @@ import { FC, ReactElement, MouseEvent, useCallback } from 'react'; import PropTypes from 'prop-types'; import { useDispatch } from 'react-redux'; import NavigationRefresh from '@material-ui/icons/Refresh'; -import { softRefreshView } from 'ra-core'; +import { refreshView } from 'ra-core'; import Button, { ButtonProps } from './Button'; @@ -17,7 +17,7 @@ const RefreshButton: FC = ({ const handleClick = useCallback( event => { event.preventDefault(); - dispatch(softRefreshView()); + dispatch(refreshView()); if (typeof onClick === 'function') { onClick(event); } diff --git a/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx b/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx index f62a2685bb5..04d694c50c7 100644 --- a/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx +++ b/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx @@ -5,7 +5,7 @@ import { useDispatch } from 'react-redux'; import Tooltip from '@material-ui/core/Tooltip'; import IconButton, { IconButtonProps } from '@material-ui/core/IconButton'; import NavigationRefresh from '@material-ui/icons/Refresh'; -import { softRefreshView, useTranslate } from 'ra-core'; +import { refreshView, useTranslate } from 'ra-core'; const RefreshIconButton: FC = ({ label = 'ra.action.refresh', @@ -19,7 +19,7 @@ const RefreshIconButton: FC = ({ const handleClick = useCallback( event => { event.preventDefault(); - dispatch(softRefreshView()); + dispatch(refreshView()); if (typeof onClick === 'function') { onClick(event); }