Skip to content

Commit

Permalink
feat(deckgl-map): use an arbitraty Mabpox style URL (#26027) (#26031)
Browse files Browse the repository at this point in the history
Signed-off-by: François Travais <francois.travais@solinum.org>
  • Loading branch information
francois-travais authored Nov 28, 2023
1 parent 7223633 commit af58784
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export { default as legacyValidateNumber } from './legacyValidateNumber';
export { default as validateInteger } from './validateInteger';
export { default as validateNumber } from './validateNumber';
export { default as validateNonEmpty } from './validateNonEmpty';
export { default as validateMapboxStylesUrl } from './validateMapboxStylesUrl';
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { t } from '../translation';

/**
* Validate a [Mapbox styles URL](https://docs.mapbox.com/help/glossary/style-url/)
* @param v
*/
export default function validateMapboxStylesUrl(v: unknown) {
if (
typeof v === 'string' &&
v.trim().length > 0 &&
v.trim().startsWith('mapbox://styles/')
) {
return false;
}

return t('is expected to be a Mapbox URL');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { validateMapboxStylesUrl } from '@superset-ui/core';
import './setup';

describe('validateMapboxStylesUrl', () => {
it('should validate mapbox style URLs', () => {
expect(
validateMapboxStylesUrl('mapbox://styles/mapbox/streets-v9'),
).toEqual(false);
expect(
validateMapboxStylesUrl(
'mapbox://styles/foobar/clp2dr5r4008a01pcg4ad45m8',
),
).toEqual(false);
});

[
123,
['mapbox://styles/mapbox/streets-v9'],
{ url: 'mapbox://styles/mapbox/streets-v9' },
'https://superset.apache.org/',
'mapbox://tileset/mapbox/streets-v9',
].forEach(value => {
it(`should not validate ${value}`, () => {
expect(validateMapboxStylesUrl(value)).toEqual(
'is expected to be a Mapbox URL',
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core';
import {
FeatureFlag,
isFeatureEnabled,
t,
validateMapboxStylesUrl,
} from '@superset-ui/core';
import {
columnChoices,
ControlPanelConfig,
Expand Down Expand Up @@ -224,6 +229,8 @@ const config: ControlPanelConfig = {
label: t('Map Style'),
clearable: false,
renderTrigger: true,
freeForm: true,
validators: [validateMapboxStylesUrl],
choices: [
['mapbox://styles/mapbox/streets-v9', t('Streets')],
['mapbox://styles/mapbox/dark-v9', t('Dark')],
Expand All @@ -236,7 +243,10 @@ const config: ControlPanelConfig = {
['mapbox://styles/mapbox/outdoors-v9', t('Outdoors')],
],
default: 'mapbox://styles/mapbox/light-v9',
description: t('Base layer map style'),
description: t(
'Base layer map style. See Mapbox documentation: %s',
'https://docs.mapbox.com/help/glossary/style-url/',
),
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default {
label: t('Map'),
expanded: true,
controlSetRows: [
[mapboxStyle, viewport],
[mapboxStyle],
[viewport],
[
{
name: 'deck_slices',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ const config: ControlPanelConfig = {
},
{
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
[autozoom, null],
],
controlSetRows: [[mapboxStyle], [autozoom, viewport]],
},
{
label: t('Arc'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ const config: ControlPanelConfig = {
label: t('Map'),
expanded: true,
controlSetRows: [
[mapboxStyle, viewport],
[autozoom],
[mapboxStyle],
[autozoom, viewport],
[
{
name: 'cellSize',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const config: ControlPanelConfig = {
{
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
[mapboxStyle],
[viewport],
['color_scheme'],
[autozoom],
[gridSize],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ const config: ControlPanelConfig = {
{
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
[mapboxStyle],
[viewport],
['linear_color_scheme'],
[autozoom],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const config: ControlPanelConfig = {
{
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
['color_scheme'],
[mapboxStyle],
['color_scheme', viewport],
[autozoom],
[gridSize],
[extruded],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const config: ControlPanelConfig = {
label: t('Map'),
expanded: true,
controlSetRows: [
[mapboxStyle, viewport],
[mapboxStyle],
[viewport],
['color_picker'],
[lineWidth],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ const config: ControlPanelConfig = {
{
label: t('Map'),
expanded: true,
controlSetRows: [
[mapboxStyle, viewport],
[autozoom, null],
],
controlSetRows: [[mapboxStyle], [autozoom, viewport]],
},
{
label: t('Point Size'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ const config: ControlPanelConfig = {
},
{
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
[autozoom, null],
],
controlSetRows: [[mapboxStyle], [autozoom, viewport]],
},
{
label: t('Grid'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
isFeatureEnabled,
t,
validateNonEmpty,
validateMapboxStylesUrl,
} from '@superset-ui/core';
import { D3_FORMAT_OPTIONS, sharedControls } from '@superset-ui/chart-controls';
import { columnChoices, PRIMARY_COLOR } from './controls';
Expand Down Expand Up @@ -370,6 +371,8 @@ export const mapboxStyle = {
label: t('Map Style'),
clearable: false,
renderTrigger: true,
freeForm: true,
validators: [validateMapboxStylesUrl],
choices: [
['mapbox://styles/mapbox/streets-v9', t('Streets')],
['mapbox://styles/mapbox/dark-v9', t('Dark')],
Expand All @@ -379,7 +382,10 @@ export const mapboxStyle = {
['mapbox://styles/mapbox/outdoors-v9', t('Outdoors')],
],
default: 'mapbox://styles/mapbox/light-v9',
description: t('Base layer map style'),
description: t(
'Base layer map style. See Mapbox documentation: %s',
'https://docs.mapbox.com/help/glossary/style-url/',
),
},
};

Expand Down

0 comments on commit af58784

Please sign in to comment.