Skip to content

Commit

Permalink
#937: Pending copy exectutions are not updated correctly on page relo…
Browse files Browse the repository at this point in the history
…ad (#936)
  • Loading branch information
allyoucanmap committed Apr 15, 2022
1 parent 4acf476 commit b989d57
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 9 deletions.
20 changes: 11 additions & 9 deletions geonode_mapstore_client/client/js/epics/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import {
import {
resourceLoading,
setResource,
resourceError,
processResources
resourceError
} from '@js/actions/gnresource';
import {
LOCATION_CHANGE,
Expand All @@ -41,10 +40,15 @@ import {
} from '@js/utils/SearchUtils';
import url from 'url';
import { getCustomMenuFilters } from '@js/selectors/config';
import { STOP_ASYNC_PROCESS, stopAsyncProcess } from '@js/actions/resourceservice';
import {
STOP_ASYNC_PROCESS,
stopAsyncProcess,
startAsyncProcess
} from '@js/actions/resourceservice';
import {
ProcessTypes,
ProcessStatus
ProcessStatus,
extractExecutionsFromResources
} from '@js/utils/ResourceServiceUtils';
import { getCurrentProcesses } from '@js/selectors/resourceservice';
import { userSelector } from '@mapstore/framework/selectors/security';
Expand Down Expand Up @@ -143,12 +147,10 @@ const requestResourcesObservable = ({
isNextPageAvailable
}) => {
const currentUser = userSelector(state);
const processingResources = resources.filter((resource) => (resource.executions?.length > 0 && resource.executions[0].status_url && resource.executions[0].user === currentUser?.info?.preferred_username) && { ...resource, executions: resource.executions[0] });
const preferredUsername = currentUser?.info?.preferred_username;
const pendingExecutions = extractExecutionsFromResources(resources, preferredUsername);
return Observable.of(
...processingResources.map((resource) => {
const process = `${resource?.executions[0].func_name}Resource`;
return processResources(process, [resource], false);
}),
...pendingExecutions.map((payload) => startAsyncProcess(payload)),
updateResources(resources, reset),
updateResourcesMetadata({
isNextPageAvailable,
Expand Down
29 changes: 29 additions & 0 deletions geonode_mapstore_client/client/js/utils/ResourceServiceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/

import flatten from 'lodash/flatten';

export const ProcessTypes = {
DELETE_RESOURCE: 'deleteResource',
COPY_RESOURCE: 'copyResource',
Expand Down Expand Up @@ -35,3 +37,30 @@ export const actionButtons = {
isControlled: true
}
};

export const extractExecutionsFromResources = (resources, username) => {
const processingResources = resources
.filter((resource) => (
resource.executions?.length > 0
&& resource.executions.find(({ status_url: statusUrl, user }) =>
statusUrl && user && user === username
)
));
return flatten(processingResources.map((resource) => {
return resource.executions
.filter(({
func_name: funcName,
status_url: statusUrl,
user
}) =>
funcName === 'copy'
&& statusUrl && user && user === username
).map((output) => {
return {
resource,
output,
processType: ProcessTypes.COPY_RESOURCE
};
});
}));
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

/*
* Copyright 2021, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import expect from 'expect';
import {
ProcessTypes,
extractExecutionsFromResources
} from '../ResourceServiceUtils';

describe('Test Resource Service Utils', () => {
it('should extract executions from resources', () => {
const executions = extractExecutionsFromResources([
{
pk: 1,
executions: [
{
status_url: 'status_url',
user: 'admin',
func_name: 'copy'
},
{
status_url: 'status_url',
user: 'user',
func_name: 'copy'
},
{
status_url: 'status_url',
user: 'user'
}
]
},
{
pk: 2,
executions: []
}
], 'admin');
expect(executions).toEqual([{
resource: {
pk: 1,
executions: [
{
status_url: 'status_url',
user: 'admin',
func_name: 'copy'
},
{
status_url: 'status_url',
user: 'user',
func_name: 'copy'
},
{
status_url: 'status_url',
user: 'user'
}
]
},
output: {
status_url: 'status_url',
user: 'admin',
func_name: 'copy'
},
processType: ProcessTypes.COPY_RESOURCE
}]);
});
});

0 comments on commit b989d57

Please sign in to comment.