Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
20 changes: 0 additions & 20 deletions app/scripts/components/exploration/atoms/embed.ts

This file was deleted.

20 changes: 20 additions & 0 deletions app/scripts/components/exploration/atoms/viewMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { atomWithUrlValueStability } from '$utils/params-location-atom/atom-with-url-value-stability';

const initialParams = new URLSearchParams(window.location.search);

const hydrateViewMode = (serialized: string | null) => {
if (serialized === 'simple') return serialized;
return 'default';
};

const dehydrateViewMode = (value: 'simple' | 'default') => {
return value ?? 'default';
};

export const viewModeAtom = atomWithUrlValueStability<'simple' | 'default'>({
initialValue: hydrateViewMode(initialParams.get('viewMode')),
urlParam: 'viewMode',
hydrate: hydrateViewMode,
dehydrate: dehydrateViewMode,
areEqual: (prev, next) => prev === next
});
Comment on lines +6 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is largely the same as the embed atom, however, we're now managing a view mode (simple or default) vs a boolean. This allows for more view modes in the future

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useAtom } from 'jotai';
import {
convertProjectionToMapbox,
projectionDefault
} from '../common/map/controls/map-options/projections';
import { BasemapId } from '../common/map/controls/map-options/basemap';
import { selectedCompareDateAtom, selectedDateAtom } from './atoms/dates';
import { zoomAtom } from './atoms/zoom';
import { centerAtom } from './atoms/center';
import EmbedTimeline from './components/embed-exploration/embed-timeline';
} from '../../../common/map/controls/map-options/projections';
import { BasemapId } from '../../../common/map/controls/map-options/basemap';
import { selectedCompareDateAtom, selectedDateAtom } from '../../atoms/dates';
import { zoomAtom } from '../../atoms/zoom';
import { centerAtom } from '../../atoms/center';
import TimelineSimpleView from './timeline-simple-view';
import MapBlock from '$components/common/blocks/block-map';
import {
VizDataset,
Expand All @@ -21,31 +21,33 @@ import { useReconcileWithStacMetadata } from '$components/exploration/hooks/use-
import { ProjectionOptions, TimeDensity } from '$types/veda';
import { useVedaUI } from '$context/veda-ui-provider';

const Carto = styled.div`
const StyledDiv = styled.div`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use a more descriptive name as Container and remove StyledDiv from StyledDivTimelineContainer and StyledDivCompareTimelineContainer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do! I do like to prefix Styled on components that are simply styles this way it's obvious this component contains to no functionality. It makes debugging simpler in component inspect view.

position: relative;
flex-grow: 1;
height: 100vh;
display: flex;
`;
const BaseTimelineContainer = styled.div<{ isCompareMode?: boolean }>`
const StyledDivTimelineContainer = styled.div<{ isCompareMode?: boolean }>`
position: absolute;
bottom: 2rem;
left: ${({ isCompareMode }) => (isCompareMode ? '25%' : '50%')};
transform: translateX(-50%);
z-index: 10;
`;
const CompareTimelineContainer = styled.div`
const StyledDivCompareTimelineContainer = styled.div`
position: absolute;
bottom: 2rem;
left: 75%;
transform: translateX(-50%);
z-index: 10;
`;

interface EmbeddedExplorationProps {
interface ExplorationSimpleViewProps {
datasets: TimelineDataset[];
}
export default function EmbeddedExploration(props: EmbeddedExplorationProps) {
export default function ExplorationSimpleView(
props: ExplorationSimpleViewProps
) {
const { datasets } = props;
const [selectedDay, setSelectedDay] = useAtom(selectedDateAtom);
const [selectedCompareDay, setSelectedComparedDay] = useAtom(
Expand All @@ -54,21 +56,20 @@ export default function EmbeddedExploration(props: EmbeddedExplorationProps) {
const [zoom] = useAtom(zoomAtom);
const [center] = useAtom(centerAtom);
return (
<>
<EmbeddedLayersExploration
datasets={datasets}
selectedDay={selectedDay}
setSelectedDay={setSelectedDay}
setSelectedComparedDay={setSelectedComparedDay}
selectedCompareDay={selectedCompareDay}
center={center}
zoom={zoom}
/>
</>
// eslint-disable-next-line react/jsx-pascal-case
<ExplorationSimpleView_
datasets={datasets}
selectedDay={selectedDay}
setSelectedDay={setSelectedDay}
setSelectedComparedDay={setSelectedComparedDay}
selectedCompareDay={selectedCompareDay}
center={center}
zoom={zoom}
/>
);
}

interface EmbeddedLayersExplorationProps {
interface ExplorationSimpleViewProps_ {
datasets: TimelineDataset[];
setSelectedDay: (x: Date) => void;
setSelectedComparedDay: (x: Date) => void;
Expand Down Expand Up @@ -99,7 +100,7 @@ const getDataLayer = (
};
};

function EmbeddedLayersExploration(props: EmbeddedLayersExplorationProps) {
function ExplorationSimpleView_(props: ExplorationSimpleViewProps_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use a more descript name here, maybe ExplorationSimpleviewContent?

const {
datasets,
selectedDay,
Expand Down Expand Up @@ -164,7 +165,7 @@ function EmbeddedLayersExploration(props: EmbeddedLayersExplorationProps) {
}, [basemapId]);

return (
<Carto>
<StyledDiv>
<MapBlock
baseDataLayer={baseDataLayer}
compareDataLayer={compareDataLayer}
Expand All @@ -181,28 +182,34 @@ function EmbeddedLayersExploration(props: EmbeddedLayersExplorationProps) {
navigationControlPosition='top-right'
height='100%'
/>
<BaseTimelineContainer isCompareMode={!!selectedCompareDay}>
<StyledDivTimelineContainer isCompareMode={!!selectedCompareDay}>
{selectedDay && (
<EmbedTimeline
<TimelineSimpleView
label=''
date={selectedDay}
setDate={setSelectedDay}
datasets={layers as TimelineDataset[]}
timeDensity={baseTimeDensity}
tipContent={
selectedCompareDay
? 'Date shown on left map'
: 'Date shown on map'
}
/>
)}
</BaseTimelineContainer>
<CompareTimelineContainer>
</StyledDivTimelineContainer>
<StyledDivCompareTimelineContainer>
{selectedCompareDay && (
<EmbedTimeline
<TimelineSimpleView
label=''
date={selectedCompareDay}
setDate={setSelectedComparedDay}
datasets={layers as TimelineDataset[]}
timeDensity={compareTimeDensity}
tipContent='Date shown on right map'
/>
)}
</CompareTimelineContainer>
</Carto>
</StyledDivCompareTimelineContainer>
</StyledDiv>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ const TimelineWrapper = styled.div`
background-color: white;
border-radius: 2px;
`;
interface EmbedTimelineProps {
interface TimelineSimpleViewProps {
date: Date | null;
setDate: (date: Date | null) => void;
timeDensity: TimeDensity;
datasets: TimelineDataset[];
label: string;
tipContent?: string;
}

function EmbedTimeline(props: EmbedTimelineProps) {
const { date, setDate, timeDensity, datasets, label } = props;
function TimelineSimpleView(props: TimelineSimpleViewProps) {
const { date, setDate, timeDensity, datasets, label, tipContent } = props;

const lowestCommonTimeDensity = useMemo(
() =>
Expand Down Expand Up @@ -85,6 +86,7 @@ function EmbedTimeline(props: EmbedTimelineProps) {
minDate={minMaxTemporalExtent[0]}
maxDate={minMaxTemporalExtent[1]}
selectedDay={date}
tipContent={tipContent}
onConfirm={(d) => {
if (!d) return;
setDate(new Date(d));
Expand All @@ -98,4 +100,4 @@ function EmbedTimeline(props: EmbedTimelineProps) {
);
}

export default EmbedTimeline;
export default TimelineSimpleView;
64 changes: 35 additions & 29 deletions app/scripts/components/exploration/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useAtom, useSetAtom } from 'jotai';
import { DatasetSelectorModal } from './components/dataset-selector-modal';
import useTimelineDatasetAtom from './hooks/use-timeline-dataset-atom';
import { externalDatasetsAtom } from './atoms/datasetLayers';
import { isEmbeddedAtom } from './atoms/embed';
import EmbeddedExploration from './embed-exploration';
import { viewModeAtom } from './atoms/viewMode';
import ExplorationSimpleView from './components/exploration-simple-view/exploration-simple-view';
import ExplorationAndAnalysis from '.';
import { allExploreDatasets } from '$data-layer/datasets';
import { urlAtom } from '$utils/params-location-atom/url';
Expand All @@ -34,13 +34,10 @@ export default function ExplorationAndAnalysisContainer() {
// atomWithLocation gets initialized outside of Exploration page and returns the previous page's value
// We check if url Atom actually returns the values for exploration page here.
const [currentUrl] = useAtom(urlAtom);
const [isEmbedded] = useAtom(isEmbeddedAtom);
const [viewMode] = useAtom(viewModeAtom);

if (!currentUrl.pathname?.includes(EXPLORATION_PATH)) return null;

if (isEmbedded) {
return <EmbeddedExploration datasets={timelineDatasets} />;
}
const openModal = () => setDatasetModalRevealed(true);
const closeModal = () => setDatasetModalRevealed(false);

Expand All @@ -51,32 +48,41 @@ export default function ExplorationAndAnalysisContainer() {
title='Exploration'
description='Explore and analyze datasets'
hideFooter
{...(viewMode === 'simple' && { hideNav: true, hideHeader: true })}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the intended way to hide the header and footer, such that the simpleView can be exported independently, and not need to manage the header and footer / or interfere with SPA behavior.

/>
<PageMainContent>
<PageHero title='Exploration' isHidden />
<ExplorationAndAnalysis
datasets={timelineDatasets}
setDatasets={setTimelineDatasets}
openDatasetsSelectionModal={openModal}
/>
<DatasetSelectorModal
revealed={datasetModalRevealed}
close={closeModal}
datasets={allExploreDatasets}
timelineDatasets={timelineDatasets}
setTimelineDatasets={setTimelineDatasets}
emptyStateContent={
<>
<p>There are no datasets to show with the selected filters.</p>
<p>
This tool allows the exploration and analysis of time-series
datasets in raster format. For a comprehensive list of available
datasets, please visit the{' '}
<Link to={DATASETS_PATH}>Data Catalog</Link>.
</p>
</>
}
/>
{viewMode === 'simple' ? (
<ExplorationSimpleView datasets={timelineDatasets} />
) : (
<>
<ExplorationAndAnalysis
datasets={timelineDatasets}
setDatasets={setTimelineDatasets}
openDatasetsSelectionModal={openModal}
/>
<DatasetSelectorModal
revealed={datasetModalRevealed}
close={closeModal}
datasets={allExploreDatasets}
timelineDatasets={timelineDatasets}
setTimelineDatasets={setTimelineDatasets}
emptyStateContent={
<>
<p>
There are no datasets to show with the selected filters.
</p>
<p>
This tool allows the exploration and analysis of time-series
datasets in raster format. For a comprehensive list of
available datasets, please visit the{' '}
<Link to={DATASETS_PATH}>Data Catalog</Link>.
</p>
</>
}
/>
</>
)}
</PageMainContent>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/libs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export {

export {
CatalogContent,
EmbeddedExploration,
ExplorationSimpleView,
ExplorationAndAnalysis,
StoriesHubContent,
DatasetSelectorModal
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/libs/page-components.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { default as CatalogContent } from '$components/common/catalog/catalog-content';
export { default as ExplorationAndAnalysis } from '$components/exploration';
export { default as EmbeddedExploration } from '$components/exploration/embed-exploration';
export { default as ExplorationSimpleView } from '$components/exploration/components/exploration-simple-view/exploration-simple-view';
// DataSelectorModal needs to be paried with E&A, so putting this for now.
export { DatasetSelectorModal } from '$components/exploration/components/dataset-selector-modal';
export { default as StoriesHubContent } from '$components/stories/hub/hub-content';
Loading