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

[Maps] enable auto fit to bounds by default #79296

Merged
merged 5 commits into from
Oct 5, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { setDefaultAutoFitToBounds } from './set_default_auto_fit_to_bounds';

describe('setDefaultAutoFitToBounds', () => {
test('Should handle missing mapStateJSON attribute', () => {
const attributes = {
title: 'my map',
};
expect(setDefaultAutoFitToBounds({ attributes })).toEqual({
title: 'my map',
});
});

test('Should set default auto fit to bounds when map settings exist in map state', () => {
const attributes = {
title: 'my map',
mapStateJSON: JSON.stringify({
settings: { showSpatialFilters: false },
}),
};
expect(JSON.parse(setDefaultAutoFitToBounds({ attributes }).mapStateJSON!)).toEqual({
settings: { autoFitToDataBounds: false, showSpatialFilters: false },
});
});

test('Should set default auto fit to bounds when map settings does not exist in map state', () => {
const attributes = {
title: 'my map',
mapStateJSON: JSON.stringify({}),
};
expect(JSON.parse(setDefaultAutoFitToBounds({ attributes }).mapStateJSON!)).toEqual({
settings: { autoFitToDataBounds: false },
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { MapSavedObjectAttributes } from '../map_saved_object_type';

export function setDefaultAutoFitToBounds({
attributes,
}: {
attributes: MapSavedObjectAttributes;
}): MapSavedObjectAttributes {
if (!attributes || !attributes.mapStateJSON) {
return attributes;
}

// MapState type is defined in public, no need to bring all of that to common for this migration
const mapState: { settings?: { autoFitToDataBounds: boolean } } = JSON.parse(
attributes.mapStateJSON
);
if ('settings' in mapState) {
mapState.settings!.autoFitToDataBounds = false;
} else {
mapState.settings = {
autoFitToDataBounds: false,
};
}

return {
...attributes,
mapStateJSON: JSON.stringify(mapState),
};
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MapSettings } from './map';

export function getDefaultMapSettings(): MapSettings {
return {
autoFitToDataBounds: false,
autoFitToDataBounds: true,
initialLocation: INITIAL_LOCATION.LAST_SAVED_LOCATION,
fixedLocation: { lat: 0, lon: 0, zoom: 2 },
browserLocation: { zoom: 2 },
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/maps/server/saved_objects/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { migrateSymbolStyleDescriptor } from '../../common/migrations/migrate_sy
import { migrateUseTopHitsToScalingType } from '../../common/migrations/scaling_type';
import { migrateJoinAggKey } from '../../common/migrations/join_agg_key';
import { removeBoundsFromSavedObject } from '../../common/migrations/remove_bounds';
import { setDefaultAutoFitToBounds } from '../../common/migrations/set_default_auto_fit_to_bounds';

export const migrations = {
map: {
Expand Down Expand Up @@ -70,6 +71,14 @@ export const migrations = {
'7.9.0': (doc) => {
const attributes = removeBoundsFromSavedObject(doc);

return {
...doc,
attributes,
};
},
'7.10.0': (doc) => {
const attributes = setDefaultAutoFitToBounds(doc);

return {
...doc,
attributes,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/maps/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function ({ getService }) {
type: 'index-pattern',
},
]);
expect(resp.body.migrationVersion).to.eql({ map: '7.9.0' });
expect(resp.body.migrationVersion).to.eql({ map: '7.10.0' });
expect(resp.body.attributes.layerListJSON.includes('indexPatternRefName')).to.be(true);
});
});
Expand Down