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

Put container, E&A style, etc. #33

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
19 changes: 9 additions & 10 deletions app/(datasets)/data-catalog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React from 'react';
import { getDatasets } from 'app/content/utils/mdx';
import { getTransformedDatasetMetadata } from 'app/content/utils/mdx';
import { Suspense } from 'react';
import Catalog from './catalog';
import { transformData } from '@helpers/data';

export default function Page() {
const posts: any[] = getDatasets(); // @TODO: Revist type here, should use data types from veda-ui
const transformed = transformData(posts);
const transformed = getTransformedDatasetMetadata();

return (
<section>
<h1 className='font-semibold text-2xl mb-8 tracking-tighter'>Datasets</h1>
<Suspense fallback={<>Loading...</>}>
<Catalog datasets={transformed} />
</Suspense>
</section>
<div className='grid-container'>
Copy link
Contributor

Choose a reason for hiding this comment

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

We might need to override the default max width configuration for the grid-container, if we want to match what we have in the Earthdata instance / designs (full width container)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the template instance goal is more to provide the structure that any other instance can override those values - like grid-container can be whichever width that people want but the template instance's job is to offer a structure that the defined width will be applied.

<section>
<Suspense fallback={<>Loading...</>}>
<Catalog datasets={transformed} />
</Suspense>
</section>
</div>
);
}
54 changes: 22 additions & 32 deletions app/(datasets)/exploration/exploration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,40 @@ import {
useTimelineDatasetAtom,
externalDatasetsAtom,
} from 'app/lib';

import { useSetAtom } from 'jotai';
import useElemengHeight from '@utils/hooks/use-element-height';

export default function ExplorationAnalysis({ datasets }: { datasets: any }) {
const transformData = () => {
const data = datasets?.map((post) => ({
...post.metadata,
}));

const result = data?.map((d) => {
const updatedTax = d.taxonomy.map((t) => {
const updatedVals = t.values.map((v) => {
return {
id: v.replace(/ /g, '_').toLowerCase(),
name: v,
};
});
return { ...t, values: updatedVals };
});
return { ...d, taxonomy: updatedTax };
});

return result;
};

const transformed = transformData();

const setExternalDatasets = useSetAtom(externalDatasetsAtom);

setExternalDatasets(transformed);
setExternalDatasets(datasets);

const [timelineDatasets, setTimelineDatasets] = useTimelineDatasetAtom();
const [datasetModalRevealed, setDatasetModalRevealed] = useState(
!timelineDatasets.length,
);

const openModal = () => {
setDatasetModalRevealed(true);
};
const closeModal = () => {
setDatasetModalRevealed(false);
};

const [timelineDatasets, setTimelineDatasets] = useTimelineDatasetAtom();
const [datasetModalRevealed, setDatasetModalRevealed] = useState(
!timelineDatasets.length,
);
// On landing, measure the height of Header and fill up the rest of the space with E&A
const offsetHeight = useElemengHeight({ queryToSelect: 'header' });

return (
<>
<div
id='ea-wrapper'
// The below styles adjust the E&A page to match what we have on earthdata.nasa.gov
// E&A is supposed to fill up whichever space given
// Adjusting the container's height so the page with E&A doesn't overflow.
style={{
width: '100%',
height: `calc(100vh - ${offsetHeight}px)`,
}}
>
<DatasetSelectorModal
revealed={datasetModalRevealed}
close={closeModal}
Expand All @@ -61,14 +51,14 @@ export default function ExplorationAnalysis({ datasets }: { datasets: any }) {
timelineDatasets={timelineDatasets}
setTimelineDatasets={setTimelineDatasets}
datasetPathName={'data-catalog'}
datasets={transformed}
datasets={datasets}
/>

<ExplorationAndAnalysis
datasets={timelineDatasets}
setDatasets={setTimelineDatasets}
openDatasetsSelectionModal={openModal}
/>
</>
</div>
);
}
24 changes: 6 additions & 18 deletions app/(datasets)/exploration/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import React, { Suspense } from 'react';
import { getDatasets } from 'app/content/utils/mdx';
import { getTransformedDatasetMetadata } from 'app/content/utils/mdx';
import ExplorationAnalysis from './exploration';
import { PageHero } from 'app/lib';

export default function Page() {
const datasets: any[] = getDatasets();
const datasets: any[] = getTransformedDatasetMetadata();
return (
<section>
<div
// The below styles adjust the E&A page to match what we have on earthdata.nasa.gov
// Ideally, we would replace some of the custom styles with the USWDS grid and util classes
// but since we do not have USWDS yet in the template instance, this is a quick workaround
// to make the page look closer to the current E&A page.
style={{
height: 'calc(100vh - 64px)',
position: 'absolute',
width: '100%',
}}
>
<Suspense fallback={<>Loading...</>}>
<PageHero title='Exploration' isHidden />
<ExplorationAnalysis datasets={datasets} />
</Suspense>
</div>
<Suspense fallback={<>Loading...</>}>
<PageHero title='Exploration' isHidden />
<ExplorationAnalysis datasets={datasets} />
</Suspense>
</section>
);
}
10 changes: 7 additions & 3 deletions app/(datasets)/stories/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { getStoriesMetadata } from 'app/content/utils/mdx';
import Hub from './hub';

export default function Page() {
const stories = getStoriesMetadata().map(d => ({...d.metadata, path: `stories/${d.slug}`}));
const stories = getStoriesMetadata().map((d) => ({
...d.metadata,
path: `stories/${d.slug}`,
}));

return (
<section>
<h1 className='font-semibold text-2xl mb-8 tracking-tighter'>Stories</h1>
<Hub stories={stories} />
<div className='grid-container'>
<Hub stories={stories} />
</div>
</section>
);
}
63 changes: 29 additions & 34 deletions app/content/utils/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,6 @@ import { DatasetLayer, StoryData } from 'app/types/veda';

const md = markdownit();

export function resolveConfigFunctions<T>(datum, bag);
export function resolveConfigFunctions<T extends any[]>(datum, bag);
export function resolveConfigFunctions(datum, bag): any {
if (Array.isArray(datum)) {
return datum.map((v) => resolveConfigFunctions(v, bag));
}

if (datum != null && typeof datum === 'object') {
// Use for loop instead of reduce as it faster.
const ready = {};
for (const [k, v] of Object.entries(datum as object)) {
ready[k] = resolveConfigFunctions(v, bag);
}
return ready;
}

if (typeof datum === 'function') {
try {
return datum(bag);
} catch (error) {
/* eslint-disable-next-line no-console */
console.error(
'Failed to resolve function %s(%o) with error %s',
datum.name,
bag,
error.message,
);
return null;
}
}

return datum;
}

function parseAttributes(obj) {
const convert = (obj) => {
return Object.keys(obj).reduce(
Expand Down Expand Up @@ -115,6 +81,27 @@ function getMDXMetaData(dir) {
});
}

const transformData = (content: any) => {
const data = content?.map((post) => ({
...post.metadata,
}));

const result = data?.map((d) => {
const updatedTax = d.taxonomy.map((t) => {
const updatedVals = t.values.map((v) => {
return {
id: v.replace(/ /g, '_').toLowerCase(),
name: v,
};
});
return { ...t, values: updatedVals };
});
return { ...d, taxonomy: updatedTax };
});

return result;
};

export function getStoriesMetadata() {
return getMDXMetaData(path.join(process.cwd(), 'app', 'content', 'stories'));
}
Expand All @@ -127,6 +114,14 @@ export function getDatasets() {
return getMDXData(path.join(process.cwd(), 'app', 'content', 'datasets'));
}

export function getTransformedDatasetMetadata() {
return transformData(getDatasetsMetadata());
}

export function getTransformedDatasets() {
return transformData(getDatasets());
}

export function getStories() {
return getMDXData(path.join(process.cwd(), 'app', 'content', 'stories'));
}
Expand Down
1 change: 0 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default function RootLayout({
>
<Navbar />
{children}
<Footer />
</EnvConfigProvider>
</DevSeedUIThemeProvider>
</main>
Expand Down
16 changes: 9 additions & 7 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import React from 'react';
export default function Page() {
return (
<section>
<h1 className='mb-8 text-2xl font-semibold tracking-tighter'>
Next.js VEDA Template Instance
</h1>
<div className='grid-container'>
<h1 className='mb-8 text-2xl font-semibold tracking-tighter'>
Next.js VEDA Template Instance
</h1>

<p className='mb-4'>
This is a test Next JS instance to figure out how to use VEDA specific
MDX files with NEXT JS Instance.
</p>
<p className='mb-4'>
This is a test Next JS instance to figure out how to use VEDA specific
MDX files with NEXT JS Instance.
</p>
</div>
</section>
);
}
8 changes: 6 additions & 2 deletions app/store/providers/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import React, { ReactNode } from 'react';
import { createUITheme } from '@devseed-ui/theme-provider';
import { DevseedUiThemeProvider, PageMainContent } from '@lib';

// Values here should be manually synced until we consolidate all the styles to USWDS
// Be mindful that these values are used more for VEDA UI component, not for instance
// Use this page to look up the value: https://designsystem.digital.gov/design-tokens/color/system-tokens/
const VEDA_OVERRIDE_THEME = {
zIndices: {
hide: -1,
Expand All @@ -16,10 +19,11 @@ const VEDA_OVERRIDE_THEME = {
toast: 1700,
tooltip: 1800,
},

color: {
base: '#2c3e50',
primary: '#2276ac',
link: '#FFFFFF',
primary: '#d83933',
link: '#6f3331',
danger: '#FC3D21',
infographicA: '#fcab10',
infographicB: '#f4442e',
Expand Down
4 changes: 4 additions & 0 deletions app/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
@forward 'uswds';

@use 'uswds-core' as *;

.veda__hug-reset-container {
grid-column: 1 / -1;
}
21 changes: 0 additions & 21 deletions app/utilities/helpers/data.tsx

This file was deleted.

38 changes: 38 additions & 0 deletions app/utilities/hooks/use-element-height.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useState, useEffect } from 'react';

const DEFAULT_HEIGHT = 100;

export default function useElementHeight({
queryToSelect,
}: {
queryToSelect: string;
}): number | null {
const [headerHeight, setHeaderHeight] = useState<number | null>(
DEFAULT_HEIGHT,
);

useEffect(() => {
const matchingElement = document.querySelector<HTMLElement>(queryToSelect);
if (matchingElement) {
const updateHeaderHeight = () => {
setHeaderHeight(matchingElement.offsetHeight);
};
// Initial height check
updateHeaderHeight();
// Add a resize observer to update height on resize
const resizeObserver = new ResizeObserver(() => {
updateHeaderHeight();
});
resizeObserver.observe(matchingElement);

return () => {
resizeObserver.disconnect();
};
} else {
console.warn(`No matching element for ${queryToSelect} found.`);
}
// Runs once on mount
}, []);

return headerHeight;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"paths": {
"@lib": ["app/lib"],
"@lib/*": ["app/lib/*"],
"@helpers/*": ["app/utilities/helpers/*"]
"@utils/*": ["app/utilities/*"]
},
"plugins": [
{
Expand Down
Loading