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

feat(dashboard): add basic drag & drop functionality to homescreen #301

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions client/src/pages/home/AppGrid.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {React, useEffect} from 'react';
import { Box, Stack } from '@mui/material';
import Grid2 from '@mui/material/Unstable_Grid2/Grid2';
import { Link } from 'react-router-dom';
import { getFullOrigin } from '../../utils/routes';
import { ServAppIcon } from '../../utils/servapp-icon';
import { useDragAndDrop } from '@formkit/drag-and-drop/react';

const AppGrid = ({ config, servApps, routes, coStatus, appColor, appBorder, blockStyle }) => {
const savedOrder = JSON.parse(localStorage.getItem('appOrder')) || [];
const initialRoutes = routes ? routes.filter(route => !route.HideFromDashboard) : [];
const initialApps = savedOrder.length ? savedOrder : initialRoutes;
const [parentRef, apps, setApps] = useDragAndDrop(initialApps);

useEffect(() => {
localStorage.setItem('appOrder', JSON.stringify(apps));
}, [apps]);

return (
<Grid2 container spacing={2} ref={parentRef}>
{config && servApps && apps.map((route) => {
let skip = route.Mode === 'REDIRECT';
let containerName;
let container;
if (route.Mode === 'SERVAPP') {
containerName = route.Target.split(':')[1].slice(2);
container = servApps.find((c) => c.Names.includes('/' + containerName));
// TOOD: rework, as it prevents users from seeing the apps
// if (!container || container.State != "running") {
// skip = true
// }
}

if (route.HideFromDashboard) skip = true;

return (
!skip && coStatus && (coStatus.homepage.Expanded ? (
<Grid2 xs={12} sm={6} md={4} lg={3} xl={3} xxl={3} key={route.Name}>
<Box className='app app-hover' style={{ padding: 25, borderRadius: 5, ...appColor, ...appBorder }}>
<Link to={getFullOrigin(route)} target="_blank" style={{ textDecoration: 'none', ...appColor }}>
<Stack direction='row' spacing={2} alignItems='center'>
<ServAppIcon container={container} route={route} className='loading-image' width='70px' />
<div style={{ minWidth: 0 }}>
<h3 style={blockStyle}>{route.Name}</h3>
<p style={blockStyle}>{route.Description}</p>
<p style={{ ...blockStyle, fontSize: '90%', paddingTop: '3px', opacity: '0.45' }}>{route.Target}</p>
</div>
</Stack>
</Link>
</Box>
</Grid2>
) : (
<Grid2 xs={6} sm={4} md={3} lg={2} xl={2} xxl={2} key={route.Name}>
<Box className='app app-hover' style={{ padding: 25, borderRadius: 5, ...appColor, ...appBorder }}>
<Link to={getFullOrigin(route)} target='_blank' style={{ textDecoration: 'none', ...appColor }}>
<Stack direction='column' spacing={2} alignItems='center'>
<ServAppIcon container={container} route={route} className='loading-image' width='70px' />
<div style={{ minWidth: 0 }}>
<h3 style={blockStyle}>{route.Name}</h3>
</div>
</Stack>
</Link>
</Box>
</Grid2>
))
);
})}
</Grid2>
);
};

export default AppGrid;
60 changes: 9 additions & 51 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useClientInfos } from "../../utils/hooks";
import { FormaterForMetric, formatDate } from "../dashboard/components/utils";
import MiniPlotComponent from "../dashboard/components/mini-plot";
import Migrate014 from "./migrate014";

import AppGrid from "./AppGrid";

export const HomeBackground = () => {
const theme = useTheme();
Expand Down Expand Up @@ -465,56 +465,13 @@ const HomePage = () => {

</>)}
</>)}

{config && servApps && routes.map((route) => {
let skip = route.Mode == "REDIRECT";
let containerName;
let container;
if (route.Mode == "SERVAPP") {
containerName = route.Target.split(':')[1].slice(2);
container = servApps.find((c) => c.Names.includes('/' + containerName));
// TOOD: rework, as it prevents users from seeing the apps
// if (!container || container.State != "running") {
// skip = true
// }
}

if (route.HideFromDashboard)
skip = true;

return !skip && coStatus && (coStatus.homepage.Expanded ?

<Grid2 item xs={12} sm={6} md={4} lg={3} xl={3} xxl={3} key={route.Name}>
<Box className='app app-hover' style={{ padding: 25, borderRadius: 5, ...appColor, ...appBorder }}>
<Link to={getFullOrigin(route)} target="_blank" style={{ textDecoration: 'none', ...appColor }}>
<Stack direction="row" spacing={2} alignItems="center">
<ServAppIcon container={container} route={route} className="loading-image" width="70px" />
<div style={{ minWidth: 0 }}>
<h3 style={blockStyle}>{route.Name}</h3>
<p style={blockStyle}>{route.Description}</p>
<p style={{ ...blockStyle, fontSize: '90%', paddingTop: '3px', opacity: '0.45' }}>{route.Target}</p>
</div>
</Stack>
</Link>
</Box>
</Grid2>
:
<Grid2 item xs={6} sm={4} md={3} lg={2} xl={2} xxl={2} key={route.Name}>
<Box className='app app-hover' style={{ padding: 25, borderRadius: 5, ...appColor, ...appBorder }}>
<Link to={getFullOrigin(route)} target="_blank" style={{ textDecoration: 'none', ...appColor }}>
<Stack direction="column" spacing={2} alignItems="center">
<ServAppIcon container={container} route={route} className="loading-image" width="70px" />
<div style={{ minWidth: 0 }}>
<h3 style={blockStyle}>{route.Name}</h3>
</div>
</Stack>
</Link>
</Box>
</Grid2>)
})}

{config && routes.length === 0 && (
<Grid2 item xs={12} sm={12} md={12} lg={12} xl={12}>
<Grid2 container spacing={2} style={{ zIndex: 2 }}>
{config && routes.length > 0 && (
<AppGrid config={config} servApps={servApps} routes={routes} coStatus={coStatus} appColor={appColor} appBorder={appBorder} blockStyle={blockStyle} />
)}
{config && routes.length === 0 && (
<Grid2 xs={12} sm={12} md={12} lg={12} xl={12}>
<Box style={{ padding: 10, borderRadius: 5, ...appColor }}>
<Stack direction="row" spacing={2} alignItems="center">
<div style={{ minWidth: 0 }}>
Expand All @@ -524,7 +481,8 @@ const HomePage = () => {
</Stack>
</Box>
</Grid2>
)}
)}
</Grid2>
</Grid2>
</Stack>
}
Expand Down
10 changes: 8 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@emotion/cache": "^11.10.3",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@formkit/drag-and-drop": "^0.1.6",
"@jamesives/github-sponsors-readme-action": "^1.2.2",
"@mui/lab": "^5.0.0-alpha.100",
"@mui/material": "^5.10.6",
Expand Down