-
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.
[Maps] add attribution to layer editor (#98328)
* [Maps] add attribution to layer editor * update sources to getAttributionProvider * remove attribution UI from EMS_XYZ source * remove attribution UI from WMS source editor * clean up * tslint * AttributionFormRow jest test * add migration * tslint * i18n fixes * attribution * [Maps] Improving design and a11y for attribution layer settings (#38) * Design and a11y improvements * Buttons aria labels * Addressing PR review * tslint and i18n fixes * update jest snapshots * remove placeholder for url Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Elizabet Oliveira <[email protected]>
- Loading branch information
1 parent
24fd3a1
commit 85b7871
Showing
36 changed files
with
712 additions
and
443 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
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/maps/common/migrations/move_attribution.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,67 @@ | ||
/* | ||
* 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 { moveAttribution } from './move_attribution'; | ||
import { LayerDescriptor } from '../descriptor_types'; | ||
|
||
test('Should handle missing layerListJSON attribute', () => { | ||
const attributes = { | ||
title: 'my map', | ||
}; | ||
expect(moveAttribution({ attributes })).toEqual({ | ||
title: 'my map', | ||
}); | ||
}); | ||
|
||
test('Should migrate source attribution to layer attribution', () => { | ||
const layerListJSON = JSON.stringify(([ | ||
{ | ||
sourceDescriptor: { | ||
attributionText: 'myLabel', | ||
attributionUrl: 'myUrl', | ||
id: 'mySourceId', | ||
}, | ||
}, | ||
] as unknown) as LayerDescriptor[]); | ||
|
||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
|
||
const { layerListJSON: migratedLayerListJSON } = moveAttribution({ attributes }); | ||
const migratedLayerList = JSON.parse(migratedLayerListJSON!); | ||
expect(migratedLayerList).toEqual([ | ||
{ | ||
attribution: { label: 'myLabel', url: 'myUrl' }, | ||
sourceDescriptor: { id: 'mySourceId' }, | ||
}, | ||
]); | ||
}); | ||
|
||
test('Should not add attribution to layer when source does not provide attribution', () => { | ||
const layerListJSON = JSON.stringify(([ | ||
{ | ||
sourceDescriptor: { | ||
id: 'mySourceId', | ||
}, | ||
}, | ||
] as unknown) as LayerDescriptor[]); | ||
|
||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
|
||
const { layerListJSON: migratedLayerListJSON } = moveAttribution({ attributes }); | ||
const migratedLayerList = JSON.parse(migratedLayerListJSON!); | ||
expect(migratedLayerList).toEqual([ | ||
{ | ||
sourceDescriptor: { id: 'mySourceId' }, | ||
}, | ||
]); | ||
}); |
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,42 @@ | ||
/* | ||
* 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 { MapSavedObjectAttributes } from '../map_saved_object_type'; | ||
import { LayerDescriptor } from '../descriptor_types'; | ||
|
||
// In 7.14, attribution added to the layer_descriptor. Prior to 7.14, 2 sources, WMS and TMS, had attribution on source descriptor. | ||
export function moveAttribution({ | ||
attributes, | ||
}: { | ||
attributes: MapSavedObjectAttributes; | ||
}): MapSavedObjectAttributes { | ||
if (!attributes || !attributes.layerListJSON) { | ||
return attributes; | ||
} | ||
|
||
const layerList: LayerDescriptor[] = JSON.parse(attributes.layerListJSON); | ||
|
||
layerList.forEach((layer: LayerDescriptor) => { | ||
const sourceDescriptor = layer.sourceDescriptor as { | ||
attributionText?: string; | ||
attributionUrl?: string; | ||
}; | ||
if (sourceDescriptor.attributionText && sourceDescriptor.attributionUrl) { | ||
layer.attribution = { | ||
label: sourceDescriptor.attributionText, | ||
url: sourceDescriptor.attributionUrl, | ||
}; | ||
delete sourceDescriptor.attributionText; | ||
delete sourceDescriptor.attributionUrl; | ||
} | ||
}); | ||
|
||
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
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
Oops, something went wrong.