Skip to content

Commit

Permalink
Make the client check if a resource is clonable and manage clone requ…
Browse files Browse the repository at this point in the history
…est error response (#836)
  • Loading branch information
DavidQuartz authored Feb 21, 2022
1 parent c00e6d3 commit 68bee7d
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 20 deletions.
2 changes: 2 additions & 0 deletions geonode_mapstore_client/client/js/apps/gn-catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import gnsearch from '@js/reducers/gnsearch';
import gnresource from '@js/reducers/gnresource';
import resourceservice from '@js/reducers/resourceservice';
import gnsettings from '@js/reducers/gnsettings';
import notifications from '@mapstore/framework/reducers/notifications';

import {
getConfiguration,
Expand Down Expand Up @@ -301,6 +302,7 @@ Promise.all([
geostory,
gnsearch,
annotations,
notifications,
...pluginsDefinition.reducers
},
appEpics,
Expand Down
6 changes: 4 additions & 2 deletions geonode_mapstore_client/client/js/apps/gn-home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { connect } from 'react-redux';

import security from '@mapstore/framework/reducers/security';
import controls from '@mapstore/framework/reducers/controls';
import notifications from '@mapstore/framework/reducers/notifications';
import Home from '@js/routes/Home';

import gnsearch from '@js/reducers/gnsearch';
Expand Down Expand Up @@ -94,12 +95,13 @@ Promise.all([
resourceservice,
security,
controls,
gnsettings
gnsettings,
notifications
},
appEpics,
geoNodeConfiguration,
initialActions: [
updateGeoNodeSettings.bind(null, settings),
updateGeoNodeSettings.bind(null, settings)
]
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function ActionButtons({
<div className="gn-resource-action-buttons">
<Dropdown className="gn-card-options" pullRight>
<Dropdown.Toggle
id={`gn-card-options-${resource.pk}`}
id={`gn-card-options-${resource.pk2 || resource.pk}`}
variant="default"
size="sm"
noCaret
Expand All @@ -33,7 +33,7 @@ function ActionButtons({
{options.map((opt) => {
if (opt.type === 'button' && actions[opt.action]) {
return (
<Dropdown.Item
(opt.action !== 'copy' || resource?.is_copyable) && <Dropdown.Item
key={opt.action}
onClick={() =>
onAction(actions[opt.action], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
startAsyncProcess
} from '@js/actions/resourceservice';
import { gnMonitorAsyncProcesses } from '../resourceservice';
import {
SHOW_NOTIFICATION
} from '@mapstore/framework/actions/notifications';

let mockAxios;

Expand Down Expand Up @@ -54,4 +57,30 @@ describe('resourceservice epics', () => {
testState
);
});

it('shows error notification on error gnMonitorAsyncProcesses', (done) => {
const testState = {
resourceservice: {}
};
const actionsCount = 2;
mockAxios.onGet().reply(() => [400, { error: 'failed' }]);
testEpic(
gnMonitorAsyncProcesses,
actionsCount,
startAsyncProcess({ error: 'failed' }),
(actions) => {
try {
expect(actions.map(({ type }) => type))
.toEqual([
STOP_ASYNC_PROCESS,
SHOW_NOTIFICATION
]);
} catch (e) {
done(e);
}
done();
},
testState
);
});
});
5 changes: 1 addition & 4 deletions geonode_mapstore_client/client/js/epics/gnsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ export const gnWatchStopCopyProcessOnSave = (action$, store) =>
}
const isError = action?.payload?.error || action?.payload?.output?.status === ProcessStatus.FAILED;
if (isError) {
return Observable.of(errorNotification({
title: "map.mapError.errorTitle",
message: "map.mapError.errorDefault"
}));
return Observable.empty();
}
const newResourceUuid = action?.payload?.output?.output_params?.output?.uuid;
if (newResourceUuid === undefined) {
Expand Down
6 changes: 5 additions & 1 deletion geonode_mapstore_client/client/js/epics/resourceservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ import {
import { PROCESS_RESOURCES } from '@js/actions/gnresource';
import { setControlProperty } from '@mapstore/framework/actions/controls';
import { push } from 'connected-react-router';
import {
error as errorNotification
} from '@mapstore/framework/actions/notifications';

export const gnMonitorAsyncProcesses = (action$, store) => {
return action$.ofType(START_ASYNC_PROCESS)
.flatMap((action) => {
const { status_url: statusUrl } = action?.payload?.output || {};
if (!statusUrl || action?.payload?.error) {
return Observable.of(stopAsyncProcess({ ...action.payload, completed: true }));
return action?.payload?.error ? Observable.of(stopAsyncProcess({ ...action.payload, completed: true }), errorNotification({ title: 'gnviewer.invalidUploadMessageError', message: 'gnviewer.cannotCloneResource' }))
: Observable.of(stopAsyncProcess({ ...action.payload, completed: true }));
}
return Observable
.interval(ProcessInterval[action?.payload?.processType] || 1000)
Expand Down
5 changes: 4 additions & 1 deletion geonode_mapstore_client/client/js/routes/Detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import {
import { getTotalResources } from '@js/selectors/search';
import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import DeleteResource from '@js/plugins/DeleteResource';
import Notifications from '@mapstore/framework/plugins/Notifications';
import SaveAs from '@js/plugins/SaveAs';
const { DeleteResourcePlugin } = DeleteResource;
const { SaveAsPlugin } = SaveAs;
const { NotificationsPlugin } = Notifications;

const ConnectedDetailsPanel = connect(
createSelector([
Expand Down Expand Up @@ -176,7 +178,8 @@ function Detail({
pathname: '/search/'
}).replace('#', '')}
/>
<SaveAsPlugin closeOnSave labelId="gnviewer.clone"/>
<SaveAsPlugin closeOnSave labelId="gnviewer.clone" />
<NotificationsPlugin />
</>
);
}
Expand Down
5 changes: 4 additions & 1 deletion geonode_mapstore_client/client/js/routes/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import { getFeaturedResults, getTotalResources } from '@js/selectors/search';
import DeleteResource from '@js/plugins/DeleteResource';
import SaveAs from '@js/plugins/SaveAs';
import Notifications from '@mapstore/framework/plugins/Notifications';
import { processResources } from '@js/actions/gnresource';
import { setControlProperty } from '@mapstore/framework/actions/controls';
const { DeleteResourcePlugin } = DeleteResource;
const { SaveAsPlugin } = SaveAs;
const { NotificationsPlugin } = Notifications;

const ConnectedFeatureList = connect(
createSelector([
Expand Down Expand Up @@ -155,7 +157,8 @@ function Home({
</div>
</div>
<DeleteResourcePlugin redirectTo={false} />
<SaveAsPlugin closeOnSave labelId="gnviewer.clone"/>
<SaveAsPlugin closeOnSave labelId="gnviewer.clone" />
<NotificationsPlugin />
</div>
);
}
Expand Down
5 changes: 4 additions & 1 deletion geonode_mapstore_client/client/js/routes/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import {
import { getTotalResources } from '@js/selectors/search';
import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import DeleteResource from '@js/plugins/DeleteResource';
import Notifications from '@mapstore/framework/plugins/Notifications';
import SaveAs from '@js/plugins/SaveAs';
const { DeleteResourcePlugin } = DeleteResource;
const { SaveAsPlugin } = SaveAs;
const { NotificationsPlugin } = Notifications;

const suggestionsRequestTypes = {
categories: {
Expand Down Expand Up @@ -223,7 +225,8 @@ function Search({
</div>
</div>
<DeleteResourcePlugin redirectTo={false} />
<SaveAsPlugin closeOnSave labelId="gnviewer.clone"/>
<SaveAsPlugin closeOnSave labelId="gnviewer.clone" />
<NotificationsPlugin />
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const getResourcePermissions = (options) => {
let selectOptions = [];
for (let indx = 0; indx < permissions.length; indx++) {
const permission = permissions[indx].name || permissions[indx];
const label = permissions[indx].label
const label = permissions[indx].label;
if (permission !== 'owner') {
selectOptions.push({
value: permission,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@
},
{
"type": "plugin",
"name": "SaveAs"
"name": "SaveAs",
"disableIf": "{state('gnResourceData') && state('gnResourceData').is_copyable ? false : true}"
}
]
},
Expand Down Expand Up @@ -2210,7 +2211,8 @@
},
{
"type": "plugin",
"name": "SaveAs"
"name": "SaveAs",
"disableIf": "{state('gnResourceData') && state('gnResourceData').is_copyable ? false : true}"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
"uploadDocument": "Ein Dokument hochladen",
"transferInProgress": "Übertragung läuft",
"fileExceeds": "Die Dateigröße überschreitet {limit} MB. Bitte versuchen Sie es erneut mit einer kleineren Datei.",
"exceedingFileMsg": "Algunos de sus archivos exceden el límite de carga de {limit} MB. Por favor, elimínelos de la lista."
"exceedingFileMsg": "Algunos de sus archivos exceden el límite de carga de {limit} MB. Por favor, elimínelos de la lista.",
"cannotCloneResource": "Ressource kann nicht geklont werden."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
"uploadDocument": "Upload a document",
"transferInProgress": "Transfer in progress",
"fileExceeds": "File size size exceeds {limit} MB. Please try again with a smaller file.",
"exceedingFileMsg": "Some of your files exceed the upload limit of {limit} MB. Please remove them from the list."
"exceedingFileMsg": "Some of your files exceed the upload limit of {limit} MB. Please remove them from the list.",
"cannotCloneResource": "Resource cannot be cloned"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@
"uploadDocument": "Subir un documento",
"transferInProgress": "Transferencia en progreso",
"fileExceeds": "El tamaño del archivo supera los {limit} MB. Vuelva a intentarlo con un archivo más pequeño.",
"exceedingFileMsg": "Algunos de sus archivos exceden el límite de carga de {limit} MB. Por favor, elimínelos de la lista."
"exceedingFileMsg": "Algunos de sus archivos exceden el límite de carga de {limit} MB. Por favor, elimínelos de la lista.",
"cannotCloneResource": "El recurso no se puede clonar."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
"uploadDocument": "Télécharger un document",
"transferInProgress": "Transfert en cours",
"fileExceeds": "La taille du fichier dépasse {Limit} Mo. Veuillez réessayer avec un fichier plus petit.",
"exceedingFileMsg": "Certains de vos fichiers dépassent la limite de téléchargement de {limit} Mo. Veuillez les supprimer de la liste."
"exceedingFileMsg": "Certains de vos fichiers dépassent la limite de téléchargement de {limit} Mo. Veuillez les supprimer de la liste.",
"cannotCloneResource": "La ressource ne peut pas être clonée."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@
"uploadDocument": "Carica un documento",
"transferInProgress": "Trasferimento in corso",
"fileExceeds": "La dimensione del file supera i {limit} MB. Riprova con un file più piccolo.",
"exceedingFileMsg": "Alcuni dei tuoi file superano il limite di caricamento di {limit} MB. Si prega di rimuoverli dall'elenco."
"exceedingFileMsg": "Alcuni dei tuoi file superano il limite di caricamento di {limit} MB. Si prega di rimuoverli dall'elenco.",
"cannotCloneResource": "La risorsa non può essere clonata."
}
}
}

0 comments on commit 68bee7d

Please sign in to comment.