Skip to content

Commit af58784

Browse files
feat(deckgl-map): use an arbitraty Mabpox style URL (#26027) (#26031)
Signed-off-by: François Travais <[email protected]>
1 parent 7223633 commit af58784

File tree

14 files changed

+118
-23
lines changed

14 files changed

+118
-23
lines changed

superset-frontend/packages/superset-ui-core/src/validator/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export { default as legacyValidateNumber } from './legacyValidateNumber';
2222
export { default as validateInteger } from './validateInteger';
2323
export { default as validateNumber } from './validateNumber';
2424
export { default as validateNonEmpty } from './validateNonEmpty';
25+
export { default as validateMapboxStylesUrl } from './validateMapboxStylesUrl';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { t } from '../translation';
21+
22+
/**
23+
* Validate a [Mapbox styles URL](https://docs.mapbox.com/help/glossary/style-url/)
24+
* @param v
25+
*/
26+
export default function validateMapboxStylesUrl(v: unknown) {
27+
if (
28+
typeof v === 'string' &&
29+
v.trim().length > 0 &&
30+
v.trim().startsWith('mapbox://styles/')
31+
) {
32+
return false;
33+
}
34+
35+
return t('is expected to be a Mapbox URL');
36+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { validateMapboxStylesUrl } from '@superset-ui/core';
20+
import './setup';
21+
22+
describe('validateMapboxStylesUrl', () => {
23+
it('should validate mapbox style URLs', () => {
24+
expect(
25+
validateMapboxStylesUrl('mapbox://styles/mapbox/streets-v9'),
26+
).toEqual(false);
27+
expect(
28+
validateMapboxStylesUrl(
29+
'mapbox://styles/foobar/clp2dr5r4008a01pcg4ad45m8',
30+
),
31+
).toEqual(false);
32+
});
33+
34+
[
35+
123,
36+
['mapbox://styles/mapbox/streets-v9'],
37+
{ url: 'mapbox://styles/mapbox/streets-v9' },
38+
'https://superset.apache.org/',
39+
'mapbox://tileset/mapbox/streets-v9',
40+
].forEach(value => {
41+
it(`should not validate ${value}`, () => {
42+
expect(validateMapboxStylesUrl(value)).toEqual(
43+
'is expected to be a Mapbox URL',
44+
);
45+
});
46+
});
47+
});

superset-frontend/plugins/legacy-plugin-chart-map-box/src/controlPanel.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core';
19+
import {
20+
FeatureFlag,
21+
isFeatureEnabled,
22+
t,
23+
validateMapboxStylesUrl,
24+
} from '@superset-ui/core';
2025
import {
2126
columnChoices,
2227
ControlPanelConfig,
@@ -224,6 +229,8 @@ const config: ControlPanelConfig = {
224229
label: t('Map Style'),
225230
clearable: false,
226231
renderTrigger: true,
232+
freeForm: true,
233+
validators: [validateMapboxStylesUrl],
227234
choices: [
228235
['mapbox://styles/mapbox/streets-v9', t('Streets')],
229236
['mapbox://styles/mapbox/dark-v9', t('Dark')],
@@ -236,7 +243,10 @@ const config: ControlPanelConfig = {
236243
['mapbox://styles/mapbox/outdoors-v9', t('Outdoors')],
237244
],
238245
default: 'mapbox://styles/mapbox/light-v9',
239-
description: t('Base layer map style'),
246+
description: t(
247+
'Base layer map style. See Mapbox documentation: %s',
248+
'https://docs.mapbox.com/help/glossary/style-url/',
249+
),
240250
},
241251
},
242252
],

superset-frontend/plugins/legacy-preset-chart-deckgl/src/Multi/controlPanel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default {
2727
label: t('Map'),
2828
expanded: true,
2929
controlSetRows: [
30-
[mapboxStyle, viewport],
30+
[mapboxStyle],
31+
[viewport],
3132
[
3233
{
3334
name: 'deck_slices',

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Arc/controlPanel.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ const config: ControlPanelConfig = {
7676
},
7777
{
7878
label: t('Map'),
79-
controlSetRows: [
80-
[mapboxStyle, viewport],
81-
[autozoom, null],
82-
],
79+
controlSetRows: [[mapboxStyle], [autozoom, viewport]],
8380
},
8481
{
8582
label: t('Arc'),

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Contour/controlPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const config: ControlPanelConfig = {
5252
label: t('Map'),
5353
expanded: true,
5454
controlSetRows: [
55-
[mapboxStyle, viewport],
56-
[autozoom],
55+
[mapboxStyle],
56+
[autozoom, viewport],
5757
[
5858
{
5959
name: 'cellSize',

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Grid/controlPanel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const config: ControlPanelConfig = {
5353
{
5454
label: t('Map'),
5555
controlSetRows: [
56-
[mapboxStyle, viewport],
56+
[mapboxStyle],
57+
[viewport],
5758
['color_scheme'],
5859
[autozoom],
5960
[gridSize],

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Heatmap/controlPanel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ const config: ControlPanelConfig = {
9999
{
100100
label: t('Map'),
101101
controlSetRows: [
102-
[mapboxStyle, viewport],
102+
[mapboxStyle],
103+
[viewport],
103104
['linear_color_scheme'],
104105
[autozoom],
105106
[

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Hex/controlPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ const config: ControlPanelConfig = {
5353
{
5454
label: t('Map'),
5555
controlSetRows: [
56-
[mapboxStyle, viewport],
57-
['color_scheme'],
56+
[mapboxStyle],
57+
['color_scheme', viewport],
5858
[autozoom],
5959
[gridSize],
6060
[extruded],

0 commit comments

Comments
 (0)