Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 4.x][Fixes #1051] Total number of resources and list of resources should be updated after deleting a resource from the list #1103

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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