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

refactor: enable routing config via provider, remove linkProps from DatasetSelectorModal #1338

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions app/scripts/components/common/blocks/block-map.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState, useEffect, useContext } from 'react';
import React, { useMemo, useState, useEffect } from 'react';
import styled from 'styled-components';
import { MapboxOptions } from 'mapbox-gl';
import * as dateFns from 'date-fns';
Expand Down Expand Up @@ -37,7 +37,7 @@
} from '$components/exploration/data-utils-no-faux-module';
import { useReconcileWithStacMetadata } from '$components/exploration/hooks/use-stac-metadata-datasets';
import { ProjectionOptions, VedaDatum, DatasetData } from '$types/veda';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

export const mapHeight = '32rem';
const Carto = styled.div`
Expand Down Expand Up @@ -181,11 +181,11 @@
totalLayers = [...totalLayers, compareMapStaticData];
}
return totalLayers;
}, [layerId]);

Check warning on line 184 in app/scripts/components/common/blocks/block-map.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has a missing dependency: 'datasetLayers'. Either include it or remove the dependency array

const [layers, setLayers] = useState<VizDataset[]>(layersToFetch);

const { envApiStacEndpoint } = useContext(EnvConfigContext);
const { envApiStacEndpoint } = useVedaUI();

useReconcileWithStacMetadata(layers, setLayers, envApiStacEndpoint);

Expand Down
5 changes: 2 additions & 3 deletions app/scripts/components/common/blocks/scrollytelling/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {
Children,
ReactElement,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
Expand Down Expand Up @@ -52,7 +51,7 @@ import {
formatSingleDate,
reconcileVizDataset
} from '$components/common/map/utils';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

type ResolvedScrollyMapLayer = {
vizDataset: VizDatasetSuccess;
Expand Down Expand Up @@ -260,7 +259,7 @@ const MAP_OPTIONS = {
function Scrollytelling(props) {
const { children } = props;

const { envApiStacEndpoint } = useContext(EnvConfigContext);
const { envApiStacEndpoint } = useVedaUI();

const { isHeaderHidden, headerHeight, wrapperHeight } =
useSlidingStickyHeaderProps();
Expand Down
12 changes: 3 additions & 9 deletions app/scripts/components/common/map/map-component.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import React, {
useCallback,
ReactElement,
useMemo,
Ref,
useContext
} from 'react';
import React, { useCallback, ReactElement, useMemo, Ref } from 'react';
import ReactMapGlMap, { LngLatBoundsLike, MapRef } from 'react-map-gl';
import { debounce } from 'lodash';
import useMapStyle from './hooks/use-map-style';
Expand All @@ -13,7 +7,7 @@ import { convertProjectionToMapbox } from './controls/map-options/projections';
import { ProjectionOptions } from '$types/veda';
import 'mapbox-gl/dist/mapbox-gl.css';
import 'mapbox-gl-compare/dist/mapbox-gl-compare.css';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

const maxMapBounds: LngLatBoundsLike = [
[-540, -90], // SW
Expand All @@ -35,7 +29,7 @@ export default function MapComponent({
onMapLoad?: () => void;
interactive?: boolean;
}) {
const { envMapboxToken } = useContext(EnvConfigContext);
const { envMapboxToken } = useVedaUI();

const { initialViewState, setInitialViewState, mainId, comparedId } =
useMapsContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { AnySourceImpl, Layer, Style } from 'mapbox-gl';
import { useContext, useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import {
BasemapId,
getStyleUrl,
Expand All @@ -9,7 +9,7 @@ import {
} from '../controls/map-options/basemap';
import { ExtendedLayer } from '../types';
import useMapStyle from '../hooks/use-map-style';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

interface BasemapProps {
basemapStyleId?: BasemapId;
Expand All @@ -33,7 +33,7 @@ export function Basemap({
labelsOption = true,
boundariesOption = true
}: BasemapProps) {
const { envMapboxToken } = useContext(EnvConfigContext);
const { envMapboxToken } = useVedaUI();
const { updateStyle } = useMapStyle();
const [baseStyle, setBaseStyle] = useState<Style | undefined>(undefined);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React, { useCallback, useEffect, useState } from 'react';
import styled from 'styled-components';
import {
Modal,
ModalBody,
ModalFooter,
ModalHeader
} from '@devseed-ui/modal';
import { Modal, ModalBody, ModalFooter, ModalHeader } from '@devseed-ui/modal';
import { glsp, themeVal } from '@devseed-ui/theme-provider';

import {
reconcileDatasets,
getLayersFromDataset
Expand All @@ -15,11 +11,13 @@ import { TimelineDataset } from '../../types.d.ts';

import RenderModalHeader from './header';
import ModalFooterRender from './footer';
import { DATASETS_PATH } from '$utils/routes';
import CatalogContent from '$components/common/catalog/catalog-content';
import { useFiltersWithURLAtom } from '$components/common/catalog/controls/hooks/use-filters-with-query';
import { FilterActions } from '$components/common/catalog/utils';

import { DatasetData, LinkProperties, DatasetLayer } from '$types/veda';
import { DatasetData, DatasetLayer } from '$types/veda';
import { useVedaUI } from '$context/veda-ui-provider';

const DatasetModal = styled(Modal)`
z-index: ${themeVal('zIndices.modal')};
Expand Down Expand Up @@ -66,33 +64,35 @@ const DatasetModal = styled(Modal)`
interface DatasetSelectorModalProps {
revealed: boolean;
close: () => void;
linkProperties?: LinkProperties;
datasets: DatasetData[];
datasetPathName: string;
timelineDatasets: TimelineDataset[];
setTimelineDatasets: (datasets: TimelineDataset[]) => void;
}

export function DatasetSelectorModal(props: DatasetSelectorModalProps) {
const { revealed, linkProperties, datasets, datasetPathName, timelineDatasets, setTimelineDatasets, close } = props;
const { LinkElement , pathAttributeKeyName } = linkProperties as { LinkElement: React.ElementType, pathAttributeKeyName: string };
const { revealed, datasets, timelineDatasets, setTimelineDatasets, close } =
props;

const {
navigation: { LinkComponent }
} = useVedaUI();

const datasetLayers = getLayersFromDataset(datasets);

const [selectedIds, setSelectedIds] = useState<string[]>(
timelineDatasets.map((dataset) => dataset.data.id)
);
const enhancedDatasetLayers = datasetLayers.flatMap(e => e);
const enhancedDatasetLayers = datasetLayers.flatMap((e) => e);

// Use Jotai controlled atoms for query parameter manipulation on new E&A page
const {search: searchTerm, taxonomies, onAction } = useFiltersWithURLAtom();
const { search: searchTerm, taxonomies, onAction } = useFiltersWithURLAtom();

useEffect(() => {
// Reset filter when modal is hidden
if(!revealed) {
if (!revealed) {
onAction(FilterActions.CLEAR);
}
},[revealed, onAction]);
}, [revealed, onAction]);

useEffect(() => {
setSelectedIds(timelineDatasets.map((dataset) => dataset.data.id));
Expand All @@ -104,19 +104,23 @@ export function DatasetSelectorModal(props: DatasetSelectorModalProps) {
);
onAction(FilterActions.CLEAR);
close();
}, [close, selectedIds, timelineDatasets, enhancedDatasetLayers, setTimelineDatasets, onAction]);
}, [
close,
selectedIds,
timelineDatasets,
enhancedDatasetLayers,
setTimelineDatasets,
onAction
]);

const linkElementProps = {[pathAttributeKeyName]: datasetPathName};
return (
<DatasetModal
id='modal'
size='xlarge'
title='Select data layers'
revealed={revealed}
onCloseClick={close}
renderHeadline={() => (
<RenderModalHeader />
)}
renderHeadline={() => <RenderModalHeader />}
content={
<CatalogContent
datasets={datasets}
Expand All @@ -129,7 +133,15 @@ export function DatasetSelectorModal(props: DatasetSelectorModalProps) {
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 <LinkElement {...linkElementProps} target='_blank'>Data Catalog</LinkElement>.</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{' '}
<LinkComponent to={DATASETS_PATH} target='_blank'>
Data Catalog
</LinkComponent>
.
</p>
</>
}
/>
Expand All @@ -150,4 +162,4 @@ export interface DatasetLayerCardProps {
searchTerm: string;
selected: boolean;
onDatasetClick: () => void;
}
}
7 changes: 3 additions & 4 deletions app/scripts/components/exploration/components/map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useContext, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import { ProjectionOptions } from 'veda';
import { useReconcileWithStacMetadata } from '../../hooks/use-stac-metadata-datasets';
Expand Down Expand Up @@ -26,7 +26,7 @@ import { usePreviousValue } from '$utils/use-effect-previous';
import { ExtendedStyle } from '$components/common/map/styles';
import DrawControl from '$components/common/map/controls/aoi';
import CustomAoIControl from '$components/common/map/controls/aoi/custom-aoi-control';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

interface ExplorationMapProps {
datasets: TimelineDataset[];
Expand All @@ -36,8 +36,7 @@ interface ExplorationMapProps {
}

export function ExplorationMap(props: ExplorationMapProps) {
const { envApiStacEndpoint, envMapboxToken } =
useContext(EnvConfigContext);
const { envApiStacEndpoint, envMapboxToken } = useVedaUI();

const { datasets, setDatasets, selectedDay, selectedCompareDay } = props;

Expand Down
7 changes: 3 additions & 4 deletions app/scripts/components/exploration/components/map/layer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react';
import React, { useMemo } from 'react';
// Avoid error: node_modules/date-fns/esm/index.js does not export 'default'
import * as dateFns from 'date-fns';

Expand All @@ -11,7 +11,7 @@ import { VectorTimeseries } from '$components/common/map/style-generators/vector
import { ZarrTimeseries } from '$components/common/map/style-generators/zarr-timeseries';
import { CMRTimeseries } from '$components/common/map/style-generators/cmr-timeseries';
import { ActionStatus } from '$utils/status';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

interface LayerProps {
id: string;
Expand All @@ -22,8 +22,7 @@ interface LayerProps {
}

export function Layer(props: LayerProps) {
const { envApiStacEndpoint, envApiRasterEndpoint } =
useContext(EnvConfigContext);
const { envApiStacEndpoint, envApiRasterEndpoint } = useVedaUI();

const { id: layerId, dataset, order, selectedDay, onStatusChange } = props;
const { isVisible, opacity, colorMap, scale } = dataset.settings;
Expand Down
12 changes: 2 additions & 10 deletions app/scripts/components/exploration/container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { TourProvider } from '@reactour/tour';
import { useNavigate } from "react-router-dom";
import { useNavigate } from 'react-router-dom';
import { DevTools } from 'jotai-devtools';
import { useAtom, useSetAtom } from 'jotai';
import { PopoverTourComponent, TourManager } from './tour-manager';
Expand All @@ -11,12 +11,11 @@ import useTimelineDatasetAtom from './hooks/use-timeline-dataset-atom';
import { externalDatasetsAtom } from './atoms/datasetLayers';
import ExplorationAndAnalysis from '.';
import { urlAtom } from '$utils/params-location-atom/url';
import { DATASETS_PATH, EXPLORATION_PATH } from '$utils/routes';
import { EXPLORATION_PATH } from '$utils/routes';
import { PageMainContent } from '$styles/page';

import { LayoutProps } from '$components/common/layout-root';
import PageHero from '$components/common/page-hero';
import SmartLink from '$components/common/smart-link';

/**
* @VEDA2-REFACTOR-WORK
Expand Down Expand Up @@ -55,11 +54,6 @@ export default function ExplorationAndAnalysisContainer() {
navigate(path);
};

const linkProps = {
LinkElement: SmartLink,
pathAttributeKeyName: 'to'
};

return (
<TourProvider
steps={[]}
Expand Down Expand Up @@ -87,8 +81,6 @@ export default function ExplorationAndAnalysisContainer() {
datasets={allExploreDatasets}
timelineDatasets={timelineDatasets}
setTimelineDatasets={setTimelineDatasets}
datasetPathName={DATASETS_PATH}
linkProperties={linkProps} // @TODO: To be removed and replaced with handleNavigation callback
/>
</PageMainContent>
</TourProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useCallback, useEffect, useContext } from 'react';
import { useState, useCallback, useEffect } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { FeatureCollection, Polygon } from 'geojson';
import { PrimitiveAtom, useAtom, useAtomValue } from 'jotai';
Expand All @@ -15,7 +15,7 @@ import {
} from '../types.d.ts';
import { MAX_QUERY_NUM } from '../constants';
import useAois from '$components/common/map/controls/hooks/use-aois';
import { EnvConfigContext } from '$context/env-config';
import { useVedaUI } from '$context/veda-ui-provider';

export function useAnalysisController() {
const [controller, setController] = useAtom(analysisControllerAtom);
Expand Down Expand Up @@ -72,8 +72,7 @@ export function useAnalysisDataRequest({
}) {
const queryClient = useQueryClient();

const { envApiRasterEndpoint, envApiStacEndpoint } =
useContext(EnvConfigContext);
const { envApiRasterEndpoint, envApiStacEndpoint } = useVedaUI();

const selectedInterval = useAtomValue(selectedIntervalAtom);
const { features } = useAois();
Expand Down
27 changes: 0 additions & 27 deletions app/scripts/context/env-config.tsx

This file was deleted.

Loading
Loading