Skip to content

Commit

Permalink
#9583 Fix SaveAs plugin showing persisted data (#9984)
Browse files Browse the repository at this point in the history
  • Loading branch information
Igi-ID committed Feb 21, 2024
1 parent c485410 commit f154a58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 5 additions & 4 deletions web/client/plugins/SaveAs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {resetMapSaveError} from '../actions/config';
import SaveBaseDialog from './maps/MapSave';

const showMapSaveAsSelector = state => state.controls && state.controls.mapSaveAs && state.controls.mapSaveAs.enabled;
export const omitResourceProperties = (show, resource) => {
const {id, attributes, name, description, detailsSettings, creator, editor, advertised, creation, lastUpdate, ...others} = resource || {};
return { show, resource: others };
};

/**
* Plugin for Create/Clone a Map. Saves the map as a new Resource (using the persistence API).
Expand All @@ -33,10 +37,7 @@ export default createPlugin('SaveAs', {
connect(createSelector(
showMapSaveAsSelector,
mapInfoSelector,
(show, resource) => {
const {id, attributes, name, description, detailsSettings, ...others} = resource || {};
return {show, resource: others};
}),
omitResourceProperties),
{
onClose: toggleControl.bind(null, 'mapSaveAs', false),
onResetMapSaveError: resetMapSaveError
Expand Down
21 changes: 20 additions & 1 deletion web/client/plugins/__tests__/SaveAs-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';

import MapSaveAs from '../SaveAs';
import MapSaveAs, { omitResourceProperties } from '../SaveAs';
import { getPluginForTest } from './pluginsTestUtils';
import { createStateMocker } from '../../reducers/__tests__/reducersTestUtils';

Expand Down Expand Up @@ -83,6 +83,25 @@ describe('MapSave Plugins (MapSave, MapSaveAs)', () => {
TestUtils.Simulate.change(inputEl);
expect(inputEl.value).toBe('f');
});
it('does not show creator, editor, created and lastUpdate fields. Advertised field is unchecked.', () => {
const _resources = {
creator: 'creator',
editor: 'editor',
advertised: 'advertised',
creation: 'creation',
lastUpdate: 'lastUpdate',
shownProperty: 'shownProperty'
};

const filtered = omitResourceProperties(true, _resources);
expect(filtered.resource.creator).toBeFalsy();
expect(filtered.resource.editor).toBeFalsy();
expect(filtered.resource.advertised).toBeFalsy();
expect(filtered.resource.creation).toBeFalsy();
expect(filtered.resource.lastUpdate).toBeFalsy();

expect(filtered.resource.shownProperty).toBeTruthy();
});
});

});

0 comments on commit f154a58

Please sign in to comment.