Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Enhancement] Move layer panel visible toggle to end (#1017)
Shan He1d85d37d35e8
diff --git a/examples/demo-app/src/app.js b/examples/demo-app/src/app.jsindex b9da3a01b..0715fb0db 100644--- a/examples/demo-app/src/app.js+++ b/examples/demo-app/src/app.js@@ -177,11 +177,11 @@ class App extends Component {_loadSampleData() {this._loadPointData();- this._loadGeojsonData();+ // this._loadGeojsonData();// this._loadTripGeoJson();- this._loadIconData();- this._loadH3HexagonData();- this._loadS2Data();+ // this._loadIconData();+ // this._loadH3HexagonData();+ // this._loadS2Data();// this._loadScenegraphLayer();}diff --git a/src/components/index.js b/src/components/index.jsindex db41026f6..68792ac2b 100644--- a/src/components/index.js+++ b/src/components/index.js@@ -42,6 +42,7 @@ export {default as PanelToggleFactory} from './side-panel/panel-toggle';export {AddDataButtonFactory, default as LayerManagerFactory} from './side-panel/layer-manager';export {default as LayerPanelFactory} from './side-panel/layer-panel/layer-panel';+export {default as LayerPanelHeaderFactory} from './side-panel/layer-panel/layer-panel-header';export {default as LayerConfiguratorFactory} from './side-panel/layer-panel/layer-configurator';export {default as SourceDataCatalogFactory} from './side-panel/common/source-data-catalog';diff --git a/src/components/side-panel/layer-panel/layer-panel-header.js b/src/components/side-panel/layer-panel/layer-panel-header.jsindex a1b38ff57..1032cfd5e 100644--- a/src/components/side-panel/layer-panel/layer-panel-header.js+++ b/src/components/side-panel/layer-panel/layer-panel-header.js@@ -30,22 +30,23 @@ import {InlineInput, StyledPanelHeader} from 'components/common/styled-componentconst propTypes = {// required- id: PropTypes.string.isRequired,- isDragNDropEnabled: PropTypes.bool,+ layerId: PropTypes.string.isRequired,isVisible: PropTypes.bool.isRequired,- label: PropTypes.string.isRequired,onToggleVisibility: PropTypes.func.isRequired,+ onUpdateLayerLabel: PropTypes.func.isRequired,+ onToggleEnableConfig: PropTypes.func.isRequired,+ onRemoveLayer: PropTypes.func.isRequired,+ isConfigActive: PropTypes.bool.isRequired,// optional- className: PropTypes.string,- idx: PropTypes.number,- isConfigActive: PropTypes.bool,- labelRCGColorValues: PropTypes.arrayOf(PropTypes.number),- onUpdateLayerLabel: PropTypes.func,- onRemoveLayer: PropTypes.func+ showRemoveLayer: PropTypes.bool,+ label: PropTypes.string,+ layerType: PropTypes.string,+ isDragNDropEnabled: PropTypes.bool,+ labelRCGColorValues: PropTypes.arrayOf(PropTypes.number)};-const defaultProps = {+export const defaultProps = {isDragNDropEnabled: true,showRemoveLayer: true};@@ -65,10 +66,6 @@ const StyledLayerPanelHeader = styled(StyledPanelHeader)`.layer__remove-layer {opacity: 1;}-- .layer__enable-config {- color: ${props => props.theme.textColorHl};- }}`;@@ -82,7 +79,7 @@ const HeaderActionSection = styled.div``;const LayerTitleSection = styled.div`- margin-left: 12px;+ margin-left: 4px;.layer__title__type {color: ${props => props.theme.subtextColor};@@ -106,79 +103,11 @@ const StyledDragHandle = styled.div`}`;-const DragHandle = sortableHandle(({className, children}) => (+export const DragHandle = sortableHandle(({className, children}) => (<StyledDragHandle className={className}>{children}</StyledDragHandle>));-const LayerPanelHeader = ({- className,- idx,- isConfigActive,- isDragNDropEnabled,- isVisible,- label,- layerId,- layerType,- labelRCGColorValues,- onToggleVisibility,- onUpdateLayerLabel,- onToggleEnableConfig,- onRemoveLayer,- showRemoveLayer-}) => (- <StyledLayerPanelHeader- className={classnames('layer-panel__header', {- 'sort--handle': !isConfigActive- })}- active={isConfigActive}- labelRCGColorValues={labelRCGColorValues}- onClick={onToggleEnableConfig}- >- <HeaderLabelSection className="layer-panel__header__content">- {isDragNDropEnabled && (- <DragHandle className="layer__drag-handle">- <VertDots height="20px" />- </DragHandle>- )}- <PanelHeaderAction- className="layer__visibility-toggle"- id={layerId}- tooltip={isVisible ? 'hide layer' : 'show layer'}- onClick={onToggleVisibility}- IconComponent={isVisible ? EyeSeen : EyeUnseen}- active={isVisible}- flush- />- <LayerTitleSection className="layer__title">- <div>- <LayerLabelEditor label={label} onEdit={onUpdateLayerLabel} />- <div className="layer__title__type">{layerType}</div>- </div>- </LayerTitleSection>- </HeaderLabelSection>- <HeaderActionSection className="layer-panel__header__actions">- {showRemoveLayer ? (- <PanelHeaderAction- className="layer__remove-layer"- id={layerId}- tooltip={'Remove layer'}- onClick={onRemoveLayer}- tooltipType="error"- IconComponent={Trash}- />- ) : null}- <PanelHeaderAction- className="layer__enable-config"- id={layerId}- tooltip={'Layer settings'}- onClick={onToggleEnableConfig}- IconComponent={ArrowDown}- />- </HeaderActionSection>- </StyledLayerPanelHeader>-);--const LayerLabelEditor = ({label, onEdit}) => (+const LayerLabelEditor = ({layerId, label, onEdit}) => (<InlineInputtype="text"className="layer__title__editor"@@ -187,11 +116,79 @@ const LayerLabelEditor = ({label, onEdit}) => (e.stopPropagation();}}onChange={onEdit}- id="input-layer-label"+ id={`${layerId}:input-layer-label`}/>);-LayerPanelHeader.propTypes = propTypes;-LayerPanelHeader.defaultProps = defaultProps;+function LayerPanelHeaderFactory() {+ const LayerPanelHeader = ({+ isConfigActive,+ isDragNDropEnabled,+ isVisible,+ label,+ layerId,+ layerType,+ labelRCGColorValues,+ onToggleVisibility,+ onUpdateLayerLabel,+ onToggleEnableConfig,+ onRemoveLayer,+ showRemoveLayer+ }) => (+ <StyledLayerPanelHeader+ className={classnames('layer-panel__header', {+ 'sort--handle': !isConfigActive+ })}+ active={isConfigActive}+ labelRCGColorValues={labelRCGColorValues}+ onClick={onToggleEnableConfig}+ >+ <HeaderLabelSection className="layer-panel__header__content">+ {isDragNDropEnabled && (+ <DragHandle className="layer__drag-handle">+ <VertDots height="20px" />+ </DragHandle>+ )}+ <LayerTitleSection className="layer__title">+ <div>+ <LayerLabelEditor layerId={layerId} label={label} onEdit={onUpdateLayerLabel} />+ <div className="layer__title__type">{layerType}</div>+ </div>+ </LayerTitleSection>+ </HeaderLabelSection>+ <HeaderActionSection className="layer-panel__header__actions">+ {showRemoveLayer ? (+ <PanelHeaderAction+ className="layer__remove-layer"+ id={layerId}+ tooltip={'Remove layer'}+ onClick={onRemoveLayer}+ tooltipType="error"+ IconComponent={Trash}+ />+ ) : null}+ <PanelHeaderAction+ className="layer__visibility-toggle"+ id={layerId}+ tooltip={isVisible ? 'hide layer' : 'show layer'}+ onClick={onToggleVisibility}+ IconComponent={isVisible ? EyeSeen : EyeUnseen}+ />+ <PanelHeaderAction+ className="layer__enable-config"+ id={layerId}+ tooltip={'Layer settings'}+ onClick={onToggleEnableConfig}+ IconComponent={ArrowDown}+ />+ </HeaderActionSection>+ </StyledLayerPanelHeader>+ );++ LayerPanelHeader.propTypes = propTypes;+ LayerPanelHeader.defaultProps = defaultProps;++ return LayerPanelHeader;+}-export default LayerPanelHeader;+export default LayerPanelHeaderFactory;diff --git a/src/components/side-panel/layer-panel/layer-panel.js b/src/components/side-panel/layer-panel/layer-panel.jsindex 4b8b93190..e859b5c3f 100644--- a/src/components/side-panel/layer-panel/layer-panel.js+++ b/src/components/side-panel/layer-panel/layer-panel.js@@ -23,7 +23,7 @@ import styled from 'styled-components';import PropTypes from 'prop-types';import LayerConfiguratorFactory from './layer-configurator';-import LayerPanelHeader from './layer-panel-header';+import LayerPanelHeaderFactory from './layer-panel-header';const PanelWrapper = styled.div`font-size: 12px;@@ -36,9 +36,9 @@ const PanelWrapper = styled.div`}`;-LayerPanelFactory.deps = [LayerConfiguratorFactory];+LayerPanelFactory.deps = [LayerConfiguratorFactory, LayerPanelHeaderFactory];-function LayerPanelFactory(LayerConfigurator) {+function LayerPanelFactory(LayerConfigurator, LayerPanelHeader) {class LayerPanel extends Component {static propTypes = {layer: PropTypes.object.isRequired,@@ -107,7 +107,7 @@ function LayerPanelFactory(LayerConfigurator) {};render() {- const {layer, idx, datasets, layerTypeOptions} = this.props;+ const {layer, datasets, layerTypeOptions} = this.props;const {config} = layer;const {isConfigActive} = config;@@ -121,12 +121,11 @@ function LayerPanelFactory(LayerConfigurator) {><LayerPanelHeaderisConfigActive={isConfigActive}- id={layer.id}- idx={idx}+ layerId={layer.id}isVisible={config.isVisible}label={config.label}labelRCGColorValues={datasets[config.dataId].color}- layerType={layer.name}+ layerType={layer.type}onToggleEnableConfig={this._toggleEnableConfig}onToggleVisibility={this._toggleVisibility}onUpdateLayerLabel={this._updateLayerLabel}diff --git a/src/components/side-panel/panel-header-action.js b/src/components/side-panel/panel-header-action.jsindex 1ca6cd8e5..a3d791f71 100644--- a/src/components/side-panel/panel-header-action.js+++ b/src/components/side-panel/panel-header-action.js@@ -84,7 +84,7 @@ export default class PanelHeaderAction extends Component {<this.props.IconComponentdata-tipdata-for={`${tooltip}_${id}`}- height="18px"+ height="16px"onClick={onClick}/>{tooltip ? (diff --git a/test/browser/components/side-panel/index.js b/test/browser/components/side-panel/index.jsindex 62b65af6e..1c923c6b7 100644--- a/test/browser/components/side-panel/index.js+++ b/test/browser/components/side-panel/index.js@@ -21,3 +21,4 @@import './color-selector-test';import './save-export-dropdown-test';import './side-panel-test';+import './layer-panel-header-test';diff --git a/test/browser/components/side-panel/layer-panel-header-test.js b/test/browser/components/side-panel/layer-panel-header-test.jsnew file mode 100644index 000000000..09e775ed7--- /dev/null+++ b/test/browser/components/side-panel/layer-panel-header-test.js@@ -0,0 +1,59 @@+// Copyright (c) 2020 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.++/* eslint-disable max-statements */++import React from 'react';+import test from 'tape';++import {LayerPanelHeaderFactory} from 'components';+import {DragHandle} from 'components/side-panel/layer-panel/layer-panel-header';+import {appInjector} from 'components/container';+import {mountWithTheme} from 'test/helpers/component-utils';++// components+const nop = () => {};+const defaultProps = {+ layerId: 'taro',+ isVisible: true,+ isConfigActive: false,+ onToggleVisibility: nop,+ onUpdateLayerLabel: nop,+ onToggleEnableConfig: nop,+ onRemoveLayer: nop+};++test('Components -> LayerPanelHeader.mount -> no prop', t => {+ const LayerPanelHeader = appInjector.get(LayerPanelHeaderFactory);++ // mount+ let wrapper;+ t.doesNotThrow(() => {+ wrapper = mountWithTheme(<LayerPanelHeader {...defaultProps} />);+ }, 'LayerPanelHeader should not fail without props');++ t.ok(wrapper.find('.layer-panel__header').length, 'should render layer-panel__header');+ t.ok(wrapper.find(DragHandle).length, 'should render drag handle');+ t.ok(wrapper.find('.layer__title__editor').length, 'should render title eidtor');+ t.ok(wrapper.find('.layer__visibility-toggle').length, 'should render visibility toggle');+ t.ok(wrapper.find('.layer__enable-config').length, 'should render enable config toggle');++ t.end();+});