diff --git a/geonode_mapstore_client/client/js/actions/gnsearch.js b/geonode_mapstore_client/client/js/actions/gnsearch.js index dd80cf9f3c..384422f905 100644 --- a/geonode_mapstore_client/client/js/actions/gnsearch.js +++ b/geonode_mapstore_client/client/js/actions/gnsearch.js @@ -14,6 +14,7 @@ export const REQUEST_RESOURCE = 'GEONODE_SEARCH:REQUEST_RESOURCE'; export const UPDATE_RESOURCES_METADATA = 'GEONODE_SEARCH:UPDATE_RESOURCES_METADATA'; export const SET_FEATURED_RESOURCES = 'GEONODE:SET_FEATURED_RESOURCES'; export const UPDATE_FEATURED_RESOURCES = 'GEONODE_SEARCH:UPDATE_FEATURED_RESOURCES'; +export const REDUCE_TOTAL_COUNT = 'GEONODE_REDUCE_TOTAL_COUNT'; /** * Actions for GeoNode resource featured items @@ -80,6 +81,16 @@ export function loadFeaturedResources(action, pageSize = 4) { }; } +/** + * Reduce total count of resouces after deletion + */ +export function reduceTotalCount() { + return { + type: REDUCE_TOTAL_COUNT + }; +} + + export default { SEARCH_RESOURCES, searchResources, diff --git a/geonode_mapstore_client/client/js/epics/resourceservice.js b/geonode_mapstore_client/client/js/epics/resourceservice.js index 6594bcd59e..0525ae51a0 100644 --- a/geonode_mapstore_client/client/js/epics/resourceservice.js +++ b/geonode_mapstore_client/client/js/epics/resourceservice.js @@ -28,6 +28,7 @@ import { downloadResource } from '@js/api/geonode/v2'; import { PROCESS_RESOURCES, DOWNLOAD_RESOURCE, downloadComplete } from '@js/actions/gnresource'; +import { reduceTotalCount } from '@js/actions/gnsearch'; import { setControlProperty } from '@mapstore/framework/actions/controls'; import { push } from 'connected-react-router'; import { @@ -53,7 +54,14 @@ export const gnMonitorAsyncProcesses = (action$, store) => { ) .switchMap((output) => { if (output.error || output.status === ProcessStatus.FINISHED || output.status === ProcessStatus.FAILED) { - return Observable.of(stopAsyncProcess({ ...action.payload, output, completed: true })); + return Observable.of( + stopAsyncProcess({ ...action.payload, output, completed: true }), + // reduce total count of resource if an original resource is deleted + // when cloned resources are removed, the getTotalResources selector already adjusts total count + ...(action?.payload?.processType === ProcessTypes.DELETE_RESOURCE && !action?.payload?.resource['@temporary'] + ? [reduceTotalCount()] + : []) + ); } return Observable.of(updateAsyncProcess({ ...action.payload, output })); }) : Observable.empty() diff --git a/geonode_mapstore_client/client/js/reducers/gnsearch.js b/geonode_mapstore_client/client/js/reducers/gnsearch.js index 2c726ba5a5..7ac2901a6e 100644 --- a/geonode_mapstore_client/client/js/reducers/gnsearch.js +++ b/geonode_mapstore_client/client/js/reducers/gnsearch.js @@ -13,7 +13,8 @@ import { UPDATE_RESOURCES, LOADING_RESOURCES, UPDATE_RESOURCES_METADATA, - SET_FEATURED_RESOURCES + SET_FEATURED_RESOURCES, + REDUCE_TOTAL_COUNT } from '@js/actions/gnsearch'; const defaultState = { @@ -81,6 +82,12 @@ function gnsearch(state = defaultState, action) { ...action.data } }; + case REDUCE_TOTAL_COUNT: { + return { + ...state, + total: state.total - 1 + }; + } default: return state; }