Skip to content

Commit

Permalink
feat(dashboard): "Under Development" message
Browse files Browse the repository at this point in the history
 - shows "Under Development" message when "Devices" and "Labs" labels
   are clicked
 - labels change when clicked

Closes #223
  • Loading branch information
Lucas Bracher committed Sep 10, 2024
1 parent 543ecc7 commit 5ed781f
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 24 deletions.
65 changes: 42 additions & 23 deletions dashboard/src/components/SideMenu/SideMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { useMemo } from 'react';

import { MdOutlineMonitorHeart } from 'react-icons/md';

import { ImTree, ImImages } from 'react-icons/im';
import { HiOutlineDocumentSearch } from 'react-icons/hi';

import { useRouter, useSearch } from '@tanstack/react-router';

import { useMemo } from 'react';
import {
Link,

Check failure on line 9 in dashboard/src/components/SideMenu/SideMenu.tsx

View workflow job for this annotation

GitHub Actions / lint-js

'Link' is defined but never used. Allowed unused vars must match /^_/u
useRouter,
useSearch,
useLocation,
} from '@tanstack/react-router';

import { MessagesKey } from '@/locales/messages';

Expand All @@ -26,7 +31,7 @@ import SendFeedback from './SendFeedback';
import NavLink from './NavLink';

type RouteMenuItems = {
onClick: () => void;
navigateTo: string;
idIntl: MessagesKey;
icon: JSX.Element;
selected: boolean;
Expand All @@ -46,14 +51,20 @@ const linkItems: LinkMenuItems[] = [
},
];

const emptyFunc = (): void => {};
type SideMenuItemProps = {
item: RouteMenuItems;
};

const SideMenu = (): JSX.Element => {
const SideMenuItem = ({ item }: SideMenuItemProps): JSX.Element => {
const selectedItemClassName =
'w-full flex pl-5 py-4 cursor-pointer text-sky-500 bg-black border-l-4 border-sky-500';
const notSelectedItemClassName =
'w-full flex pl-5 py-4 cursor-pointer text-white';

const { pathname } = useLocation();

const isCurrentPath = pathname === item.navigateTo;

const useNavigateTo = (path: string): (() => void) => {

Check failure on line 68 in dashboard/src/components/SideMenu/SideMenu.tsx

View workflow job for this annotation

GitHub Actions / lint-js

'useNavigateTo' is assigned a value but never used. Allowed unused vars must match /^_/u
const router = useRouter();
const { origin: unsafeOrigin } = useSearch({ strict: false });
Expand All @@ -72,25 +83,41 @@ const SideMenu = (): JSX.Element => {
};
};

return (
<NavigationMenuItem
className={
isCurrentPath ? selectedItemClassName : notSelectedItemClassName
}
key={item.idIntl}
>
<NavLink icon={item.icon} idIntl={item.idIntl} />
</NavigationMenuItem>
);
};

const SideMenu = (): JSX.Element => {
const notSelectedItemClassName =
'w-full flex pl-5 py-4 cursor-pointer text-white';

const routeItems: RouteMenuItems[] = [
{
onClick: useNavigateTo('/'),
idIntl: 'routes.treeMonitor',
icon: <ImTree className="size-5" />,
selected: true,
},
{
onClick: emptyFunc,
navigateTo: '/devices',
idIntl: 'routes.deviceMonitor',
icon: <MdOutlineMonitorHeart className="size-5" />,
selected: false,
},
{
onClick: emptyFunc,
navigateTo: '/labs',
idIntl: 'routes.labsMonitor',
icon: <ImImages className="size-5" />,
selected: false,
},
{
navigateTo: '/',
idIntl: 'routes.treeMonitor',
icon: <ImTree className="size-5" />,
selected: true,
},
];

const linksItemElements = useMemo(
Expand Down Expand Up @@ -124,15 +151,7 @@ const SideMenu = (): JSX.Element => {

<NavigationMenuList className="w-52 flex-col space-x-0 space-y-4">
{routeItems.map(item => (
<NavigationMenuItem
className={
item.selected ? selectedItemClassName : notSelectedItemClassName
}
key={item.idIntl}
onClick={item.onClick}
>
<NavLink icon={item.icon} idIntl={item.idIntl} />
</NavigationMenuItem>
<SideMenuItem item={item}></SideMenuItem>

Check failure on line 154 in dashboard/src/components/SideMenu/SideMenu.tsx

View workflow job for this annotation

GitHub Actions / lint-js

Missing "key" prop for element in iterator
))}
<Separator className="my-4 bg-onSecondary-10" />
{linksItemElements}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { FormattedMessage } from 'react-intl';

export const UnderDevelopment = (): JSX.Element => {
return (
<div className="grid h-[400px] place-items-center rounded-md bg-slate-100 dark:bg-slate-800">
<FormattedMessage id="global.underDevelopment" />
</div>
);
};
3 changes: 3 additions & 0 deletions dashboard/src/components/UnderDevelopment/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { UnderDevelopment } from './UnderDevelopment';

export { UnderDevelopment };
1 change: 1 addition & 0 deletions dashboard/src/locales/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const messages = {
'global.timing': 'Timing',
'global.total': 'Total',
'global.tree': 'Tree',
'global.underDevelopment': 'Under Development',
'global.unknown': 'Unknown',
'global.url': 'URL',
'global.valid': 'Valid',
Expand Down
38 changes: 37 additions & 1 deletion dashboard/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// Import Routes

import { Route as rootRoute } from './routes/__root'
import { Route as LabsImport } from './routes/labs'
import { Route as DevicesImport } from './routes/devices'
import { Route as TreeRouteImport } from './routes/tree/route'
import { Route as IndexImport } from './routes/index'
import { Route as TreeIndexImport } from './routes/tree/index'
Expand All @@ -23,6 +25,16 @@ import { Route as TreeTreeIdBuildBuildIdIndexImport } from './routes/tree/$treeI

// Create/Update Routes

const LabsRoute = LabsImport.update({
path: '/labs',
getParentRoute: () => rootRoute,
} as any)

const DevicesRoute = DevicesImport.update({
path: '/devices',
getParentRoute: () => rootRoute,
} as any)

const TreeRouteRoute = TreeRouteImport.update({
path: '/tree',
getParentRoute: () => rootRoute,
Expand Down Expand Up @@ -87,6 +99,20 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof TreeRouteImport
parentRoute: typeof rootRoute
}
'/devices': {
id: '/devices'
path: '/devices'
fullPath: '/devices'
preLoaderRoute: typeof DevicesImport
parentRoute: typeof rootRoute
}
'/labs': {
id: '/labs'
path: '/labs'
fullPath: '/labs'
preLoaderRoute: typeof LabsImport
parentRoute: typeof rootRoute
}
'/tree/$treeId': {
id: '/tree/$treeId'
path: '/$treeId'
Expand Down Expand Up @@ -156,6 +182,8 @@ export const routeTree = rootRoute.addChildren({
}),
TreeIndexRoute,
}),
DevicesRoute,
LabsRoute,
})

/* prettier-ignore-end */
Expand All @@ -167,7 +195,9 @@ export const routeTree = rootRoute.addChildren({
"filePath": "__root.tsx",
"children": [
"/",
"/tree"
"/tree",
"/devices",
"/labs"
]
},
"/": {
Expand All @@ -180,6 +210,12 @@ export const routeTree = rootRoute.addChildren({
"/tree/"
]
},
"/devices": {
"filePath": "devices.tsx"
},
"/labs": {
"filePath": "labs.tsx"
},
"/tree/$treeId": {
"filePath": "tree/$treeId/route.tsx",
"parent": "/tree",
Expand Down
7 changes: 7 additions & 0 deletions dashboard/src/routes/devices.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';

import { UnderDevelopment } from '@/components/UnderDevelopment';

export const Route = createFileRoute('/devices')({
component: () => <UnderDevelopment />,
});
7 changes: 7 additions & 0 deletions dashboard/src/routes/labs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';

import { UnderDevelopment } from '@/components/UnderDevelopment';

export const Route = createFileRoute('/labs')({
component: () => <UnderDevelopment />,
});

0 comments on commit 5ed781f

Please sign in to comment.