Skip to content

Commit

Permalink
[Fixes GeoNode#1051] Total number of resources and list of resources …
Browse files Browse the repository at this point in the history
…should be updated after deleting a resource from the list (GeoNode#1057)
  • Loading branch information
DavidQuartz committed Jul 14, 2022
1 parent 1578b55 commit 4164f7b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion geonode_mapstore_client/client/js/epics/resourceservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion geonode_mapstore_client/client/js/reducers/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -81,6 +82,12 @@ function gnsearch(state = defaultState, action) {
...action.data
}
};
case REDUCE_TOTAL_COUNT: {
return {
...state,
total: state.total - 1
};
}
default:
return state;
}
Expand Down

0 comments on commit 4164f7b

Please sign in to comment.