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

#9583 Fix SaveAs plugin showing persisted data #9984

Merged
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
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();
});
});

});
Loading