mirror of
https://github.com/apache/superset.git
synced 2026-05-11 19:05:24 +00:00
fix(map-box): make opacity, lon, lat, and zoom controls functional (#38374)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: codeant-ai-for-open-source[bot] <244253245+codeant-ai-for-open-source[bot]@users.noreply.github.com>
(cherry picked from commit 96705c156a)
This commit is contained in:
committed by
Michael S. Molina
parent
e855fbf71d
commit
cffca7367c
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 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 type {
|
||||
ControlPanelConfig,
|
||||
CustomControlItem,
|
||||
} from '@superset-ui/chart-controls';
|
||||
import controlPanel from '../src/controlPanel';
|
||||
|
||||
type ControlConfig = Required<CustomControlItem['config']>;
|
||||
|
||||
function isCustomControlItem(
|
||||
controlItem: unknown,
|
||||
): controlItem is CustomControlItem & { config: ControlConfig } {
|
||||
return (
|
||||
typeof controlItem === 'object' &&
|
||||
controlItem !== null &&
|
||||
'name' in controlItem &&
|
||||
'config' in controlItem
|
||||
);
|
||||
}
|
||||
|
||||
function getControl(
|
||||
panel: ControlPanelConfig,
|
||||
controlName: string,
|
||||
): CustomControlItem & { config: ControlConfig } {
|
||||
const item = (panel.controlPanelSections || [])
|
||||
.flatMap(section => section?.controlSetRows || [])
|
||||
.flat()
|
||||
.find(
|
||||
controlItem =>
|
||||
isCustomControlItem(controlItem) && controlItem.name === controlName,
|
||||
);
|
||||
|
||||
if (!isCustomControlItem(item)) {
|
||||
throw new Error(`Control "${controlName}" not found`);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
test('viewport controls default to empty values and rerender without query refresh', () => {
|
||||
const longitudeControl = getControl(controlPanel, 'viewport_longitude');
|
||||
const latitudeControl = getControl(controlPanel, 'viewport_latitude');
|
||||
const zoomControl = getControl(controlPanel, 'viewport_zoom');
|
||||
|
||||
expect(longitudeControl.config.default).toBe('');
|
||||
expect(latitudeControl.config.default).toBe('');
|
||||
expect(zoomControl.config.default).toBe('');
|
||||
|
||||
expect(longitudeControl.config.renderTrigger).toBe(true);
|
||||
expect(latitudeControl.config.renderTrigger).toBe(true);
|
||||
expect(zoomControl.config.renderTrigger).toBe(true);
|
||||
|
||||
expect(longitudeControl.config.dontRefreshOnChange).toBe(true);
|
||||
expect(latitudeControl.config.dontRefreshOnChange).toBe(true);
|
||||
expect(zoomControl.config.dontRefreshOnChange).toBe(true);
|
||||
});
|
||||
|
||||
test('opacity control rerenders immediately when changed', () => {
|
||||
const opacityControl = getControl(controlPanel, 'global_opacity');
|
||||
|
||||
expect(opacityControl.config.default).toBe(1);
|
||||
expect(opacityControl.config.renderTrigger).toBe(true);
|
||||
expect(opacityControl.config.isFloat).toBe(true);
|
||||
});
|
||||
Reference in New Issue
Block a user