// Copyright (c) 2022 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import React, { Component, MouseEventHandler, TouchEventHandler, CSSProperties, ChangeEventHandler } from 'react'; import styled from 'styled-components'; import LayerConfiguratorFactory from './layer-configurator'; import LayerPanelHeaderFactory from './layer-panel-header'; import {Datasets, NestedPartial} from 'reducers'; import {Layer, LayerBaseConfig, LayerVisConfig} from 'layers'; import {toggleModal} from 'actions/ui-state-actions'; import * as VisStateActions from 'actions/vis-state-actions'; import {ColorUI} from 'layers/layer-factory'; import {ActionHandler} from 'actions'; type LayerPanelProps = { className?: string; disabled?: boolean; style?: CSSProperties; onMouseDown?: MouseEventHandler; onTouchStart?: TouchEventHandler; layer: Layer; datasets: Datasets; idx: number; layerTypeOptions: { id: string; label: string; icon: any; // requireData: any; // }[]; isDraggable?: boolean; openModal: ActionHandler; layerColorUIChange: ActionHandler; layerConfigChange: ActionHandler; layerVisualChannelConfigChange: ActionHandler< typeof VisStateActions.layerVisualChannelConfigChange >; layerTypeChange: ActionHandler; layerVisConfigChange: ActionHandler; layerTextLabelChange: ActionHandler; removeLayer: ActionHandler; duplicateLayer: ActionHandler; updateLayerVisualChannelConfigCallback?: Function; }; const PanelWrapper = styled.div<{active: boolean}>` font-size: 12px; border-radius: 1px; margin-bottom: 8px; z-index: 1000; &.dragging { cursor: move; } `; LayerPanelFactory.deps = [LayerConfiguratorFactory, LayerPanelHeaderFactory]; function LayerPanelFactory( LayerConfigurator: ReturnType, LayerPanelHeader: ReturnType ): React.ComponentType { class LayerPanel extends Component { updateLayerConfig = (newProp: Partial) => { this.props.layerConfigChange(this.props.layer, newProp); }; updateLayerType = (newType: string) => { this.props.layerTypeChange(this.props.layer, newType); }; updateLayerVisConfig = (newVisConfig: Partial) => { this.props.layerVisConfigChange(this.props.layer, newVisConfig); }; updateLayerColorUI = (...args: [string, NestedPartial]) => { this.props.layerColorUIChange(this.props.layer, ...args); }; updateLayerTextLabel = (...args: [number | 'all', string, any]) => { this.props.layerTextLabelChange(this.props.layer, ...args); }; updateLayerVisualChannelConfig = (newConfig: Partial, channel: string) => { this.props.layerVisualChannelConfigChange(this.props.layer, newConfig, channel); this.props.updateLayerVisualChannelConfigCallback && this.props.updateLayerVisualChannelConfigCallback( newConfig, channel, this.updateLayerConfig ); }; _updateLayerLabel: ChangeEventHandler = ({target: {value}}) => { this.updateLayerConfig({label: value}); }; _toggleVisibility: MouseEventHandler = e => { e.stopPropagation(); const isVisible = !this.props.layer.config.isVisible; this.updateLayerConfig({isVisible}); }; _toggleEnableConfig: MouseEventHandler = e => { e.stopPropagation(); const { layer: { config: {isConfigActive} } } = this.props; this.updateLayerConfig({isConfigActive: !isConfigActive}); }; _removeLayer: MouseEventHandler = e => { e.stopPropagation(); this.props.removeLayer(this.props.idx); }; _duplicateLayer: MouseEventHandler = e => { e.stopPropagation(); this.props.duplicateLayer(this.props.idx); }; render() { const {layer, datasets, isDraggable, layerTypeOptions, disabled} = this.props; const {config} = layer; const {isConfigActive} = config; return ( {isConfigActive && ( )} ); } } return LayerPanel; } export default LayerPanelFactory;