mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 16:01:15 +01:00
Prevent same prefix from being collapsed
This commit is contained in:
parent
abceb457c9
commit
df94d9c842
2 changed files with 50 additions and 16 deletions
|
@ -11,8 +11,6 @@ import AddModal from '../modals/AddModal'
|
||||||
import style from '../../libs/style.js'
|
import style from '../../libs/style.js'
|
||||||
import {SortableContainer, SortableHandle, arrayMove} from 'react-sortable-hoc';
|
import {SortableContainer, SortableHandle, arrayMove} from 'react-sortable-hoc';
|
||||||
|
|
||||||
const layerPrefix = name => name.replace(' ', '-').replace('_', '-').split('-')[0]
|
|
||||||
|
|
||||||
const layerListPropTypes = {
|
const layerListPropTypes = {
|
||||||
layers: React.PropTypes.array.isRequired,
|
layers: React.PropTypes.array.isRequired,
|
||||||
selectedLayerIndex: React.PropTypes.number.isRequired,
|
selectedLayerIndex: React.PropTypes.number.isRequired,
|
||||||
|
@ -21,6 +19,25 @@ const layerListPropTypes = {
|
||||||
sources: React.PropTypes.object.isRequired,
|
sources: React.PropTypes.object.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function layerPrefix(name) {
|
||||||
|
return name.replace(' ', '-').replace('_', '-').split('-')[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
function findClosestCommonPrefix(layers, idx) {
|
||||||
|
console.log('find prefix', idx, layers)
|
||||||
|
const currentLayerPrefix = layerPrefix(layers[idx].id)
|
||||||
|
let closestIdx = idx
|
||||||
|
for (let i = idx; i > 0; i--) {
|
||||||
|
const previousLayerPrefix = layerPrefix(layers[i-1].id)
|
||||||
|
if(previousLayerPrefix === currentLayerPrefix) {
|
||||||
|
closestIdx = i - 1
|
||||||
|
} else {
|
||||||
|
return closestIdx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return closestIdx
|
||||||
|
}
|
||||||
|
|
||||||
// List of collapsible layer editors
|
// List of collapsible layer editors
|
||||||
@SortableContainer
|
@SortableContainer
|
||||||
class LayerListContainer extends React.Component {
|
class LayerListContainer extends React.Component {
|
||||||
|
@ -93,42 +110,48 @@ class LayerListContainer extends React.Component {
|
||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleLayerGroup(groupPrefix) {
|
toggleLayerGroup(groupPrefix, idx) {
|
||||||
|
const lookupKey = [groupPrefix, idx].join('-')
|
||||||
const newGroups = { ...this.state.collapsedGroups }
|
const newGroups = { ...this.state.collapsedGroups }
|
||||||
if(groupPrefix in this.state.collapsedGroups) {
|
if(lookupKey in this.state.collapsedGroups) {
|
||||||
newGroups[groupPrefix] = !this.state.collapsedGroups[groupPrefix]
|
newGroups[lookupKey] = !this.state.collapsedGroups[lookupKey]
|
||||||
} else {
|
} else {
|
||||||
newGroups[groupPrefix] = true
|
newGroups[lookupKey] = true
|
||||||
}
|
}
|
||||||
|
console.log(newGroups)
|
||||||
this.setState({
|
this.setState({
|
||||||
collapsedGroups: newGroups
|
collapsedGroups: newGroups
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
isCollapsed(groupPrefix, idx) {
|
||||||
const isCollapsed = groupPrefix => {
|
console.log('is collapsed', groupPrefix, idx)
|
||||||
const collapsed = this.state.collapsedGroups[groupPrefix]
|
const collapsed = this.state.collapsedGroups[[groupPrefix, idx].join('-')]
|
||||||
return collapsed === undefined ? false : collapsed
|
return collapsed === undefined ? false : collapsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
|
||||||
const listItems = []
|
const listItems = []
|
||||||
let idx = 0
|
let idx = 0
|
||||||
this.groupedLayers().forEach(layers => {
|
this.groupedLayers().forEach(layers => {
|
||||||
const groupPrefix = layerPrefix(layers[0].id)
|
const groupPrefix = layerPrefix(layers[0].id)
|
||||||
if(layers.length > 1) {
|
if(layers.length > 1) {
|
||||||
const grp = <LayerListGroup
|
const grp = <LayerListGroup
|
||||||
key={'group-' + groupPrefix + '-' + idx}
|
key={[groupPrefix, idx].join('-')}
|
||||||
title={groupPrefix}
|
title={groupPrefix}
|
||||||
isActive={!isCollapsed(groupPrefix)}
|
isActive={!this.isCollapsed(groupPrefix, idx)}
|
||||||
onActiveToggle={this.toggleLayerGroup.bind(this, groupPrefix)}
|
onActiveToggle={this.toggleLayerGroup.bind(this, groupPrefix, idx)}
|
||||||
/>
|
/>
|
||||||
listItems.push(grp)
|
listItems.push(grp)
|
||||||
}
|
}
|
||||||
|
|
||||||
layers.forEach(layer => {
|
layers.forEach((layer, idxInGroup) => {
|
||||||
|
const groupIdx = findClosestCommonPrefix(this.props.layers, idx)
|
||||||
const listItem = <LayerListItem
|
const listItem = <LayerListItem
|
||||||
className={classnames({
|
className={classnames({
|
||||||
'maputnik-layer-list-item-collapsed': isCollapsed(groupPrefix)
|
'maputnik-layer-list-item-collapsed': this.isCollapsed(groupPrefix, groupIdx),
|
||||||
|
'maputnik-layer-list-item-collapsed-last': idxInGroup == layers.length - 1 && layers.length > 1
|
||||||
})}
|
})}
|
||||||
index={idx}
|
index={idx}
|
||||||
key={layer.id}
|
key={layer.id}
|
||||||
|
|
|
@ -38,9 +38,13 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
line-height: 1.3;
|
line-height: 1.3;
|
||||||
|
max-height: 50px;
|
||||||
display: flex;
|
display: flex;
|
||||||
display: -ms-flexbox;
|
display: -ms-flexbox;
|
||||||
@include vendor-prefix(flex-direction, row)
|
@include vendor-prefix(flex-direction, row)
|
||||||
|
|
||||||
|
transition: max-height 0.1s ease-in;
|
||||||
|
transition: padding 0.05s ease-in;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-icon-action svg {
|
&-icon-action svg {
|
||||||
|
@ -63,9 +67,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&-item-collapsed {
|
&-item-collapsed {
|
||||||
height: 0;
|
max-height: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
|
transition: max-height 0.1s ease-out;
|
||||||
|
transition: padding 0.1s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-item-collapsed-last {
|
||||||
|
border-bottom: 2px solid $color-gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-item-id {
|
&-item-id {
|
||||||
|
|
Loading…
Reference in a new issue