-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ml-forecast-functional-test
- Loading branch information
Showing
27 changed files
with
204 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/maps/common/migrations/set_ems_tms_default_modes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { setEmsTmsDefaultModes } from './set_ems_tms_default_modes'; | ||
|
||
describe('setEmsTmsDefaultModes', () => { | ||
test('Should handle missing layerListJSON attribute', () => { | ||
const attributes = { | ||
title: 'my map', | ||
}; | ||
expect(setEmsTmsDefaultModes({ attributes })).toEqual({ | ||
title: 'my map', | ||
}); | ||
}); | ||
|
||
test('Should add lightModeDefault to existing EMS_TMS source descriptors', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
sourceDescriptor: { | ||
type: 'EMS_TMS', | ||
}, | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(setEmsTmsDefaultModes({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"sourceDescriptor":{"type":"EMS_TMS","lightModeDefault":"road_map"}}]', | ||
}); | ||
}); | ||
|
||
// test edge case where sample data maps set lightModeDefault but still run migration | ||
test('Should not change lightModeDefault if provided', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
sourceDescriptor: { | ||
type: 'EMS_TMS', | ||
lightModeDefault: 'road_map_desaturated', | ||
}, | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(setEmsTmsDefaultModes({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: | ||
'[{"sourceDescriptor":{"type":"EMS_TMS","lightModeDefault":"road_map_desaturated"}}]', | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/maps/common/migrations/set_ems_tms_default_modes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { SOURCE_TYPES } from '../constants'; | ||
import { LayerDescriptor, EMSTMSSourceDescriptor } from '../descriptor_types'; | ||
import { MapSavedObjectAttributes } from '../map_saved_object_type'; | ||
|
||
// LightModeDefault added to EMSTMSSourceDescriptor in 8.0.0 | ||
// to avoid changing auto selected light mode tiles for maps created < 8.0.0 | ||
// < 8.0.0 did not specify defaults and used bright for light mode | ||
// > 8.0.0 changed default light mode from bright to desaturated | ||
export function setEmsTmsDefaultModes({ | ||
attributes, | ||
}: { | ||
attributes: MapSavedObjectAttributes; | ||
}): MapSavedObjectAttributes { | ||
if (!attributes || !attributes.layerListJSON) { | ||
return attributes; | ||
} | ||
|
||
const layerList: LayerDescriptor[] = JSON.parse(attributes.layerListJSON); | ||
layerList.forEach((layerDescriptor: LayerDescriptor) => { | ||
if (layerDescriptor.sourceDescriptor?.type === SOURCE_TYPES.EMS_TMS) { | ||
const sourceDescriptor = layerDescriptor.sourceDescriptor as EMSTMSSourceDescriptor; | ||
// auto select bright tiles for EMS_TMS layers created before 8.0.0 | ||
if (!sourceDescriptor.lightModeDefault) { | ||
sourceDescriptor.lightModeDefault = 'road_map'; | ||
} | ||
} | ||
}); | ||
|
||
return { | ||
...attributes, | ||
layerListJSON: JSON.stringify(layerList), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.