Skip to content

Commit

Permalink
Add RoutesConfig interface to VedaUI provider and hook up layer info …
Browse files Browse the repository at this point in the history
…modal to use context for route
  • Loading branch information
sandrahoang686 committed Jan 2, 2025
1 parent f0fb0e1 commit c71dc4f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
35 changes: 20 additions & 15 deletions app/scripts/components/exploration/components/layer-info-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {
ModalHeadline
} from '@devseed-ui/modal';
import { glsp, themeVal } from '@devseed-ui/theme-provider';
import { Button } from '@devseed-ui/button';
import { LayerInfo } from 'veda';
import { getDatasetPath } from '$utils/routes';
import { CollecticonDatasetLayers } from '$components/common/icons/dataset-layers';
import { ParentDatasetTitle } from '$components/common/catalog/catalog-content';
import { useVedaUI } from '$context/veda-ui-provider';
import { USWDSButton } from '$components/common/uswds/button';

const DatasetModal = styled(Modal)`
const StyledModal = styled(Modal)`
z-index: ${themeVal('zIndices.modal')};
/* Override ModalContents */
> div {
Expand Down Expand Up @@ -94,19 +94,15 @@ const LayerInfoLinerModal = styled.div`

export default function LayerInfoModal(props: LayerInfoModalProps) {
const { revealed, close, layerData, onNavigation } = props;
const {
navigation: { LinkComponent },
routes: { dataCatalogPath }
} = useVedaUI();

const { parentData } = layerData;
const dataCatalogPage = getDatasetPath(parentData.id);

const handleButtonClick = () => {
close();
if (onNavigation) {
onNavigation(dataCatalogPage);
}
};

return (
<DatasetModal
<StyledModal
id='modal'
size='xlarge'
revealed={revealed}
Expand Down Expand Up @@ -134,9 +130,18 @@ export default function LayerInfoModal(props: LayerInfoModalProps) {
<div dangerouslySetInnerHTML={{__html: parentData.infoDescription?? 'Currently, we are unable to display the layer information, but you can find it in the data catalog.' }} />
}
footerContent={
<Button onClick={handleButtonClick} variation='primary-fill' size='medium'>
Open in Data Catalog
</Button>
<LinkComponent to={dataCatalogPath}>
<USWDSButton
onClick={close}
type='button'
size='small'
inverse={true}
outline={false}
tabindex="-1"

Check failure on line 140 in app/scripts/components/exploration/components/layer-info-modal.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected usage of doublequote
>
Open in Data Catalog
</USWDSButton>
</LinkComponent>
}
/>
);
Expand Down
27 changes: 23 additions & 4 deletions app/scripts/context/veda-ui-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { createContext, ReactNode, useContext } from 'react';
import { DATASETS_PATH, STORIES_PATH } from '$utils/routes';

interface EnvironmentConfig {
envMapboxToken: string;
Expand All @@ -17,23 +18,35 @@ interface NavigationConfig {
linkPropName: string;
}

const defaultNavigation: NavigationConfig = {
LinkComponent: 'a',
linkPropName: 'href'
};
interface RoutesConfig {
dataCatalogPath?: string;
storiesCatalogPath?: string;
}

interface VedaUIConfig extends EnvironmentConfig {
navigation: NavigationConfig;
routes: RoutesConfig;
Link: React.FC<LinkProps>;
}

interface VedaUIProviderProps {
config: EnvironmentConfig & {
navigation?: Partial<NavigationConfig>;
routes?: RoutesConfig;
};
children: ReactNode;
}

const defaultNavigation: NavigationConfig = {
LinkComponent: 'a',
linkPropName: 'href'
};

const defaultRoutes: RoutesConfig = {
dataCatalogPath: DATASETS_PATH,
storiesCatalogPath: STORIES_PATH
};

const VedaUIContext = createContext<VedaUIConfig | null>(null);
VedaUIContext.displayName = 'VedaUIContext';

Expand Down Expand Up @@ -67,6 +80,11 @@ export function VedaUIProvider({ config, children }: VedaUIProviderProps) {
...config.navigation
};

const routes = {
...defaultRoutes,
...config.routes
}

Check failure on line 86 in app/scripts/context/veda-ui-provider.tsx

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

const Link: React.FC<LinkProps> = ({ to, children, ...props }) => {
const { LinkComponent, linkPropName } = navigation;
return (
Expand All @@ -79,6 +97,7 @@ export function VedaUIProvider({ config, children }: VedaUIProviderProps) {
const fullConfig: VedaUIConfig = {
...config,
navigation,
routes,
Link
};

Expand Down

0 comments on commit c71dc4f

Please sign in to comment.