Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dataset layer visibility toggle button to explore page #619

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/scripts/components/common/mapbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ function MapboxMapComponent(
aoi,
onAoiChange,
projection,
onProjectionChange
onProjectionChange,
isDatasetLayerHidden
} = props;
/* eslint-enable react/prop-types */

Expand Down Expand Up @@ -425,6 +426,7 @@ function MapboxMapComponent(
zoomExtent={baseLayerResolvedData.zoomExtent}
bounds={baseLayerResolvedData.bounds}
onStatusChange={onBaseLayerStatusChange}
isHidden={isDatasetLayerHidden}
/>
)}
<SimpleMap
Expand Down Expand Up @@ -531,6 +533,7 @@ export interface MapboxMapProps {
onAoiChange?: AoiChangeListenerOverload;
projection?: ProjectionOptions;
onProjectionChange?: (projection: ProjectionOptions) => void;
isDatasetLayerHidden?: boolean;
}

export interface MapboxMapRef {
Expand Down
26 changes: 19 additions & 7 deletions app/scripts/components/datasets/s-explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { ProjectionOptions } from 'veda';
import { FormSwitch } from '@devseed-ui/form';

import LayerVisibilityToggleButton from './layer-visibility-toggle';
import DatasetLayers from './dataset-layers';
import { PanelDateWidget } from './panel-date-widget';
import { resourceNotFound } from '$components/uhoh';
Expand Down Expand Up @@ -76,13 +77,16 @@ const Carto = styled.div`
margin-top: calc(2rem + ${variableGlsp(0.5)});
}
}
`;

${NotebookConnectButton} {
position: absolute;
z-index: 1;
right: ${variableGlsp()};
top: ${variableGlsp()};
}
const CustomControlWrapper = styled.div`
position: absolute;
right: ${variableGlsp()};
top: ${variableGlsp()};
z-index: 1;
display: flex;
flex-direction: column;
gap: ${variableGlsp(0.5)};
`;

const DatesWrapper = styled.div`
Expand Down Expand Up @@ -311,6 +315,7 @@ function DatasetsExplore() {
});

const [isComparing, setIsComparing] = useState(!!selectedCompareDatetime);
const [isDatasetLayerHidden, setIsDatasetLayerHidden] = useState(false);

// END QsState setup
/** *********************************************************************** */
Expand Down Expand Up @@ -559,7 +564,13 @@ function DatasetsExplore() {
</PanelInner>
</Panel>
<Carto>
<NotebookConnectButton dataset={dataset.data} />
<CustomControlWrapper>
<NotebookConnectButton dataset={dataset.data} />
<LayerVisibilityToggleButton
isDatasetLayerHidden={isDatasetLayerHidden}
onLayerVisibilityClick={setIsDatasetLayerHidden}
/>
</CustomControlWrapper>
<MapboxMap
ref={mapboxRef}
withGeocoder
Expand All @@ -578,6 +589,7 @@ function DatasetsExplore() {
}}
projection={mapProjection ?? projectionDefault}
onProjectionChange={setMapProjection}
isDatasetLayerHidden={isDatasetLayerHidden}
/>
</Carto>
</Explorer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import styled from 'styled-components';
import { Button } from '@devseed-ui/button';
import {
CollecticonEye,
CollecticonEyeDisabled
} from '@devseed-ui/collecticons';

interface LayerVisibilityToggleButtonProps {
isDatasetLayerHidden: boolean;
onLayerVisibilityClick: (a: boolean) => void;
className?: string;
}

function LayerVisibilityToggleButtonSelf(
props: LayerVisibilityToggleButtonProps
) {
const { className, isDatasetLayerHidden, onLayerVisibilityClick } = props;

return (
<Button
type='button'
className={className}
variation={isDatasetLayerHidden ? 'danger-fill' : 'primary-fill'}
fitting='skinny'
onClick={() => onLayerVisibilityClick(!isDatasetLayerHidden)}
>
{!isDatasetLayerHidden && (
<CollecticonEye meaningful title='Turn off data layer visibility' />
)}
{isDatasetLayerHidden && (
<CollecticonEyeDisabled
meaningful
title='Turn on data layer visibility'
/>
)}
</Button>
);
}

const LayerVisibilityToggleButton = styled(LayerVisibilityToggleButtonSelf)`
/* Convert to styled-component: https://styled-components.com/docs/advanced#caveat */
`;

export default LayerVisibilityToggleButton;
Loading