Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Add li placeholder to give accurate index when dnd-ing #1326

Benjamin King1d4607768381
diff --git a/web/css/sidebar.css b/web/css/sidebar.css
index 42998bb13..21e106518 100644
--- a/web/css/sidebar.css
+++ b/web/css/sidebar.css
@@ -58,7 +58,9 @@
opacity: 0.5;
cursor: default;
}
-
+#productsHolder .layer-list-placeholder {
+ height: 0;
+}
.tab-content .nav-tabs {
border-bottom: 3px solid #dee2e6;
}
diff --git a/web/js/components/sidebar/products/layer-list.js b/web/js/components/sidebar/products/layer-list.js
index b897750a9..bc5b4d4fd 100644
--- a/web/js/components/sidebar/products/layer-list.js
+++ b/web/js/components/sidebar/products/layer-list.js
@@ -9,7 +9,6 @@ const reorder = (list, startIndex, endIndex) => {
const result = Array.from(list);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);
-
return result;
};
class LayerList extends React.Component {
@@ -58,15 +57,12 @@ class LayerList extends React.Component {
if (result.source.index === result.destination.index) {
return;
}
-
const newLayerArray = reorder(
layers,
result.source.index,
result.destination.index
);
-
replaceSubGroup(newLayerArray, layerGroupName, groupId);
- this.setState({ layers: newLayerArray });
}
render() {
const { groupId, title, layerGroupName } = this.props;
@@ -91,48 +87,47 @@ class LayerList extends React.Component {
className="category"
ref={provided.innerRef}
>
- {layers.map((object, i) => {
- return object.projections[context.projection] ? (
- <Layer
- layer={object}
- groupId={groupId}
- layerGroupName={layerGroupName}
- getLegend={context.getLegend}
- key={i}
- index={i}
- layerClasses="item productsitem"
- zot={
- context.zotsObject[object.id]
- ? context.zotsObject[object.id].value
- : null
- }
- isMobile={context.isMobile}
- names={context.getNames(object.id)}
- checkerBoardPattern={context.checkerBoardPattern}
- palette={this.getPalette(
- object,
- context.palettePromise
- )}
- isDisabled={
- !context.getAvailability(
- object.id,
- undefined,
- layerGroupName
- )
- }
- isVisible={object.visible}
- updateLayer={context.updateLayer}
- runningObject={
- context.runningLayers &&
- context.runningLayers[object.id]
- ? context.runningLayers[object.id]
- : null
- }
- />
- ) : (
- ''
- );
- })}
+ {layers.map((object, i) => (
+ <Layer
+ layer={object}
+ groupId={groupId}
+ layerGroupName={layerGroupName}
+ isInProjection={
+ !!object.projections[context.projection]
+ }
+ getLegend={context.getLegend}
+ key={i}
+ index={i}
+ layerClasses="item productsitem"
+ zot={
+ context.zotsObject[object.id]
+ ? context.zotsObject[object.id].value
+ : null
+ }
+ isMobile={context.isMobile}
+ names={context.getNames(object.id)}
+ checkerBoardPattern={context.checkerBoardPattern}
+ palette={this.getPalette(
+ object,
+ context.palettePromise
+ )}
+ isDisabled={
+ !context.getAvailability(
+ object.id,
+ undefined,
+ layerGroupName
+ )
+ }
+ isVisible={object.visible}
+ updateLayer={context.updateLayer}
+ runningObject={
+ context.runningLayers &&
+ context.runningLayers[object.id]
+ ? context.runningLayers[object.id]
+ : null
+ }
+ />
+ ))}
{provided.placeholder}
</ul>
);
diff --git a/web/js/components/sidebar/products/layer.js b/web/js/components/sidebar/products/layer.js
index dc4398ff4..0f932fcb7 100644
--- a/web/js/components/sidebar/products/layer.js
+++ b/web/js/components/sidebar/products/layer.js
@@ -17,13 +17,17 @@ class Layer extends React.Component {
super(props);
this.state = {
zot: props.zot,
- index: props.index
+ index: props.index,
+ isInProjection: props.isInProjection
};
}
componentWillReceiveProps(props) {
if (props.zot !== this.state.zot) {
this.setState({ zot: props.zot });
}
+ if (props.isInProjection !== this.state.isInProjection) {
+ this.setState({ isInProjection: props.isInProjection });
+ }
}
hover(value) {
const { updateLayer, layer } = this.props;
@@ -73,7 +77,7 @@ class Layer extends React.Component {
onLayerHover() {}
getPalette() {}
render() {
- const { zot } = this.state;
+ const { zot, isInProjection } = this.state;
const {
layerGroupName,
layer,
@@ -91,7 +95,7 @@ class Layer extends React.Component {
direction="vertical"
>
{(provided, snapshot) => {
- return (
+ return isInProjection ? (
<li
ref={provided.innerRef}
{...provided.draggableProps}
@@ -186,6 +190,13 @@ class Layer extends React.Component {
{this.getLegend()}
</div>
</li>
+ ) : (
+ <li
+ className="layer-list-placeholder"
+ ref={provided.innerRef}
+ {...provided.draggableProps}
+ {...provided.dragHandleProps}
+ />
);
}}
</Draggable>
@@ -213,6 +224,8 @@ Layer.propTypes = {
runningObject: PropTypes.object,
getLegend: PropTypes.func,
index: PropTypes.number,
- checkerBoardPattern: PropTypes.object
+ checkerBoardPattern: PropTypes.object,
+ isInProjection: PropTypes.bool,
+ zot: PropTypes.number
};
export default Layer;