Skip to content

Commit

Permalink
change file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mauberti-bc committed Feb 5, 2025
1 parent 2f1bd3c commit 56572ff
Show file tree
Hide file tree
Showing 27 changed files with 503 additions and 247 deletions.
213 changes: 49 additions & 164 deletions app/src/features/support/SupportPage.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
import {
mdiAccountSupervisor,
mdiAutoFix,
mdiCardAccountMailOutline,
mdiCheckDecagram,
mdiChevronLeft,
mdiChevronRight,
mdiDatabaseCog,
mdiEye,
mdiFileOutline,
mdiFolder,
mdiHome,
mdiInformationOutline,
mdiListBoxOutline,
mdiPaw,
mdiPineTreeVariant,
mdiWifiMarker
} from '@mdi/js';
import { mdiChevronLeft, mdiChevronRight } from '@mdi/js';
import Icon from '@mdi/react';
import { Box, Button, Container, Divider, Paper, Stack, Typography } from '@mui/material';
import AutocompleteSearchField from 'components/fields/AutocompleteSearch/AutocompleteSearchField';
import PageHeader from 'components/layout/PageHeader';
import CustomToggleButtonGroup from 'components/toolbar/CustomToggleButtonGroup';
import { useSearchParams } from 'hooks/useSearchParams';
import { ReactNode, SetStateAction } from 'react';
import { ISupportPageView, SupportPageParams, SupportPageView } from '../support/constants/SupportPageView';
import { SupportOverview } from './content/overview/SupportOverview';
import { SupportProjects } from './content/projects/SupportProjects';
import { SupportObservations } from './content/projects/surveys/data/observations/SupportObservations';
import { SupportData } from './content/projects/surveys/data/SupportData';
import { SupportTelemetry } from './content/projects/surveys/data/telemetry/SupportTelemetry';
import { SupportSampling } from './content/projects/surveys/sampling/SupportSampling';
import { SupportSurveys } from './content/projects/surveys/SupportSurveys';
import { SupportTeam } from './content/projects/team/SupportTeam';
import { useMemo, useState } from 'react';
import {
ISupportPageView,
SupportPageParams,
SupportPageView,
SupportPageViewMap,
SupportPageViews
} from './SupportPageView';

const VIEW_KEY = 'v';

Check warning on line 16 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L16

Added line #L16 was not covered by tests

/**
* Returns information about how to use the app, definitions, and other resources for users.
Expand All @@ -41,153 +23,52 @@ import { SupportTeam } from './content/projects/team/SupportTeam';
export const SupportPage = () => {
const { searchParams, setSearchParams } = useSearchParams<SupportPageParams>();

Check warning on line 24 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L23-L24

Added lines #L23 - L24 were not covered by tests

const currentViewParam = searchParams.get('support_view');
const currentView = (currentViewParam as SupportPageView) || SupportPageView.GENERAL;
// Initialize activeView based on the URL params
const [activeView, setActiveView] = useState(

Check warning on line 27 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L27

Added line #L27 was not covered by tests
(searchParams.get(VIEW_KEY) as SupportPageView) ?? SupportPageView.overview
);

// Add nested structure
const views: ISupportPageView[] = [
{
label: 'Overview',
value: SupportPageView.GENERAL,
icon: mdiHome,
children: []
},
{
label: 'Projects',
value: SupportPageView.PROJECTS,
icon: mdiFolder,
children: [
{
label: 'Team',
value: SupportPageView.PROJECT_TEAM,
icon: mdiAccountSupervisor,
children: []
},
{
label: 'Surveys',
value: SupportPageView.SURVEYS,
icon: mdiListBoxOutline,
children: [
{
label: 'Sampling',
value: SupportPageView.SAMPLING,
icon: mdiAutoFix,
children: []
},
{
label: 'Data',
value: SupportPageView.DATA,
icon: mdiDatabaseCog,
children: [
{
label: 'Observations',
value: SupportPageView.OBSERVATIONS,
icon: mdiEye,
children: []
},
{
label: 'Telemetry',
value: SupportPageView.TELEMETRY,
icon: mdiWifiMarker,
children: []
},
{
label: 'Animals',
value: SupportPageView.ANIMALS,
icon: mdiPaw,
children: []
},
{
label: 'Habitat Features',
value: SupportPageView.HABITAT,
icon: mdiPineTreeVariant,
children: []
}
]
},
{
label: 'Attachments',
value: SupportPageView.FILES,
icon: mdiFileOutline,
children: []
},
{
label: 'Metadata',
value: SupportPageView.METADATA,
icon: mdiInformationOutline,
children: []
}
]
}
]
},
{
label: 'Standards',
value: SupportPageView.DATA_STANDARDS,
icon: mdiCheckDecagram,
children: []
},
{
label: 'Contact',
value: SupportPageView.CONTACT,
icon: mdiCardAccountMailOutline,
children: []
const handleViewChange = (view: SupportPageView) => {

Check warning on line 31 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L31

Added line #L31 was not covered by tests
if (view) {
setActiveView(view);
setSearchParams(searchParams.set(VIEW_KEY, view));

Check warning on line 34 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L33-L34

Added lines #L33 - L34 were not covered by tests
}
];
};

// Finding the current view and navigating to the correct parent/child
const findView = (value: SupportPageView, views: ISupportPageView[]): ISupportPageView | null => {
for (const view of views) {
if (view.value === value) {
return view;
}
if (view.children.length > 0) {
const foundChild = findView(value, view.children);
if (foundChild) return foundChild;
}
}
return null;
// Recursively flattens child views
const flattenViews = (views: ISupportPageView[]): ISupportPageView[] => {

Check warning on line 39 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L39

Added line #L39 was not covered by tests
return views.flatMap((view) => [view, ...flattenViews(view.children ?? [])]);
};

const currentViewData = findView(currentView, views);
const currentIndex = views.findIndex((view) => view.value === currentView);
const nextView = views[(currentIndex + 1) % views.length];
const prevView = views[(currentIndex - 1 + views.length) % views.length];
// Find the current view object for its label, icon, children
const currentView = useMemo(
() => flattenViews(SupportPageViews).find((view) => view.value === activeView),

Check warning on line 45 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L44-L45

Added lines #L44 - L45 were not covered by tests
[activeView]

Check warning on line 46 in app/src/features/support/SupportPage.tsx

View workflow job for this annotation

GitHub Actions / Running Linter and Formatter

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

const handleViewChange: React.Dispatch<SetStateAction<SupportPageView>> = (value) => {
const newView = typeof value === 'function' ? value(currentView) : value;
setSearchParams(searchParams.set('support_view', newView));
window.scrollTo(0, 0);
};
// Sort views based on the order field
const orderedViews = useMemo(
() => SupportPageViews.flatMap((view) => [view, ...view.children]).sort((a, b) => a.order - b.order),

Check warning on line 51 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L50-L51

Added lines #L50 - L51 were not covered by tests
[]
);

const dataMap: Partial<Record<SupportPageView, ReactNode>> = {
[SupportPageView.GENERAL]: <SupportOverview />,
[SupportPageView.PROJECTS]: <SupportProjects />,
[SupportPageView.PROJECT_TEAM]: <SupportTeam />,
[SupportPageView.SURVEYS]: <SupportSurveys />,
[SupportPageView.SAMPLING]: <SupportSampling />,
[SupportPageView.OBSERVATIONS]: <SupportObservations />,
[SupportPageView.TELEMETRY]: <SupportTelemetry />,
[SupportPageView.DATA]: <SupportData />
};
const currentIndex = currentView ? orderedViews.findIndex((v) => v.value === currentView.value) : 0;
const prevView = orderedViews[currentIndex - 1] || null;
const nextView = orderedViews[currentIndex + 1] || null;

// Get the JSX content to display for the activeView
const children = SupportPageViewMap[activeView];

Check warning on line 60 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L60

Added line #L60 was not covered by tests

return (

Check warning on line 62 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L62

Added line #L62 was not covered by tests
<>
<PageHeader title="Support" />
<Container maxWidth="xl" sx={{ py: 3 }}>
<AutocompleteSearchField
onSelect={() => {}}
onSearch={() => new Promise(() => 'a')}
fieldName=""
getOptionLabel={() => ''}
label="Search"
/>
<Stack direction="row" gap={3} component={Paper} sx={{ p: 3, mt: 3, height: '100%' }}>
{/* Navigation Pane */}
<Box width="300px" flexShrink={0}>
<CustomToggleButtonGroup
views={views}
activeView={currentView}
views={SupportPageViews}
activeView={activeView}
onViewChange={handleViewChange}
orientation={'vertical'}
/>
Expand All @@ -200,18 +81,22 @@ export const SupportPage = () => {
{/* Content */}
<Box flex="1 1 auto">
<Typography variant="h2" gutterBottom mb={3}>
{currentViewData?.label}
{currentView?.label}
</Typography>

<Stack gap={2}>{dataMap[currentView]}</Stack>
<Stack gap={2}>{children}</Stack>
</Box>

{/* Chevron Arrows */}
<Stack
direction="row"
alignItems="center"
justifyContent={
currentIndex === 0 ? 'flex-end' : currentIndex === views.length - 1 ? 'flex-start' : 'space-between'
currentIndex === 0
? 'flex-end'
: currentIndex === SupportPageViews.length - 1
? 'flex-start'
: 'space-between'
}
sx={{ width: '100%', '& .MuiButton-root': { fontWeight: 700 } }}>
{currentIndex > 0 && (
Expand All @@ -221,7 +106,7 @@ export const SupportPage = () => {
Previous
</Button>
)}
{currentIndex < views.length - 1 && (
{currentIndex < SupportPageViews.length - 1 && (
<Button
onClick={() => handleViewChange(nextView.value)}

Check warning on line 111 in app/src/features/support/SupportPage.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/support/SupportPage.tsx#L111

Added line #L111 was not covered by tests
endIcon={<Icon path={mdiChevronRight} size={1} />}>
Expand Down
Loading

0 comments on commit 56572ff

Please sign in to comment.