From ef72a0351e8a29970a2e4fb4344ff98ada549e65 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Fri, 22 Dec 2023 14:19:59 +0530 Subject: [PATCH] Refactor routes with layout and show search bar in project details page (#23) * Refactor routes with layout and show search bar in project details page * Set common search layout for child routes --- packages/frontend/src/App.tsx | 35 +++++++++++++++-- .../src/components/projects/ProjectCard.tsx | 2 +- ...ProjectSearch.tsx => ProjectSearchBar.tsx} | 4 +- .../create/template/deploy/DeployStep.tsx | 2 +- .../project/settings/DeleteProjectDialog.tsx | 4 +- packages/frontend/src/layouts/Dashboard.tsx | 21 ++++++++++ .../frontend/src/layouts/ProjectSearch.tsx | 31 +++++++++++++++ packages/frontend/src/pages/Settings.tsx | 2 +- packages/frontend/src/pages/index.tsx | 39 ++++++++++++++----- .../frontend/src/pages/projects/Create.tsx | 14 ++++--- .../frontend/src/pages/projects/Project.tsx | 2 +- .../{Projects.tsx => projects/index.tsx} | 25 ++---------- .../frontend/src/pages/projects/routes.tsx | 13 ++++--- packages/frontend/src/pages/routes.tsx | 20 ---------- 14 files changed, 141 insertions(+), 73 deletions(-) rename packages/frontend/src/components/projects/{ProjectSearch.tsx => ProjectSearchBar.tsx} (96%) create mode 100644 packages/frontend/src/layouts/Dashboard.tsx create mode 100644 packages/frontend/src/layouts/ProjectSearch.tsx rename packages/frontend/src/pages/{Projects.tsx => projects/index.tsx} (50%) delete mode 100644 packages/frontend/src/pages/routes.tsx diff --git a/packages/frontend/src/App.tsx b/packages/frontend/src/App.tsx index 0efb68b0..78908393 100644 --- a/packages/frontend/src/App.tsx +++ b/packages/frontend/src/App.tsx @@ -1,14 +1,41 @@ import React from 'react'; import { createBrowserRouter, RouterProvider } from 'react-router-dom'; +import DashboardLayout from './layouts/Dashboard'; import Home from './pages/index'; -import { homeRoutes } from './pages/routes'; +import Settings from './pages/Settings'; +import { + projectsRoutesWithSearch, + projectsRoutesWithoutSearch, +} from './pages/projects/routes'; +import ProjectSearchLayout from './layouts/ProjectSearch'; const router = createBrowserRouter([ { - path: '/', - element: , - children: homeRoutes, + element: , + children: [ + { + element: , + children: [ + { + path: '/', + element: , + }, + { + path: 'projects', + children: projectsRoutesWithSearch, + }, + ], + }, + { + path: 'settings', + element: , + }, + { + path: 'projects', + children: projectsRoutesWithoutSearch, + }, + ], }, ]); diff --git a/packages/frontend/src/components/projects/ProjectCard.tsx b/packages/frontend/src/components/projects/ProjectCard.tsx index afa24369..338fa764 100644 --- a/packages/frontend/src/components/projects/ProjectCard.tsx +++ b/packages/frontend/src/components/projects/ProjectCard.tsx @@ -39,7 +39,7 @@ const ProjectCard: React.FC = ({ project }) => { -
+
{project.latestCommit.message} diff --git a/packages/frontend/src/components/projects/ProjectSearch.tsx b/packages/frontend/src/components/projects/ProjectSearchBar.tsx similarity index 96% rename from packages/frontend/src/components/projects/ProjectSearch.tsx rename to packages/frontend/src/components/projects/ProjectSearchBar.tsx index e5037431..b958eaa3 100644 --- a/packages/frontend/src/components/projects/ProjectSearch.tsx +++ b/packages/frontend/src/components/projects/ProjectSearchBar.tsx @@ -17,7 +17,7 @@ interface ProjectsSearchProps { onChange?: (data: ProjectDetails) => void; } -const ProjectSearch = ({ onChange }: ProjectsSearchProps) => { +const ProjectSearchBar = ({ onChange }: ProjectsSearchProps) => { const [items, setItems] = useState([]); const [selectedItem, setSelectedItem] = useState(null); @@ -105,4 +105,4 @@ const ProjectSearch = ({ onChange }: ProjectsSearchProps) => { ); }; -export default ProjectSearch; +export default ProjectSearchBar; diff --git a/packages/frontend/src/components/projects/create/template/deploy/DeployStep.tsx b/packages/frontend/src/components/projects/create/template/deploy/DeployStep.tsx index b2e18961..e064757e 100644 --- a/packages/frontend/src/components/projects/create/template/deploy/DeployStep.tsx +++ b/packages/frontend/src/components/projects/create/template/deploy/DeployStep.tsx @@ -31,7 +31,7 @@ const DeployStep = ({ const [collapse, setCollapse] = useState(false); return ( -
+
{status === DeployStatus.NOT_STARTED &&
{step}
} {status === DeployStatus.PROCESSING &&
O
} diff --git a/packages/frontend/src/components/projects/project/settings/DeleteProjectDialog.tsx b/packages/frontend/src/components/projects/project/settings/DeleteProjectDialog.tsx index 3463c2e0..4fdf6e34 100644 --- a/packages/frontend/src/components/projects/project/settings/DeleteProjectDialog.tsx +++ b/packages/frontend/src/components/projects/project/settings/DeleteProjectDialog.tsx @@ -57,8 +57,8 @@ const DeleteProjectDialog = ({ > - Deleting your project is irreversible. Enter your project’s name -   + Deleting your project is irreversible. Enter your project’s + name  ({project.name})  below to confirm you want to permanently delete it: diff --git a/packages/frontend/src/layouts/Dashboard.tsx b/packages/frontend/src/layouts/Dashboard.tsx new file mode 100644 index 00000000..056f5dcb --- /dev/null +++ b/packages/frontend/src/layouts/Dashboard.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { Outlet } from 'react-router-dom'; + +import Sidebar from '../components/Sidebar'; + +const Dashboard = () => { + return ( +
+
+ +
+
+
+ +
+
+
+ ); +}; + +export default Dashboard; diff --git a/packages/frontend/src/layouts/ProjectSearch.tsx b/packages/frontend/src/layouts/ProjectSearch.tsx new file mode 100644 index 00000000..90772a8a --- /dev/null +++ b/packages/frontend/src/layouts/ProjectSearch.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { Outlet } from 'react-router-dom'; + +import HorizontalLine from '../components/HorizontalLine'; +import { IconButton, Typography } from '@material-tailwind/react'; +import ProjectSearchBar from '../components/projects/ProjectSearchBar'; + +const ProjectSearch = () => { + return ( +
+
+
+ {}} /> +
+ + + + +
+ ^ +
+
+ SY +
+
+ + +
+ ); +}; + +export default ProjectSearch; diff --git a/packages/frontend/src/pages/Settings.tsx b/packages/frontend/src/pages/Settings.tsx index cf834b75..dccab0ce 100644 --- a/packages/frontend/src/pages/Settings.tsx +++ b/packages/frontend/src/pages/Settings.tsx @@ -1,7 +1,7 @@ import React from 'react'; const Settings = () => { - return
Settings page
; + return
Settings page
; }; export default Settings; diff --git a/packages/frontend/src/pages/index.tsx b/packages/frontend/src/pages/index.tsx index 82d10bda..204b7a84 100644 --- a/packages/frontend/src/pages/index.tsx +++ b/packages/frontend/src/pages/index.tsx @@ -1,19 +1,40 @@ import React from 'react'; -import { Outlet } from 'react-router-dom'; +import { Link } from 'react-router-dom'; -import Sidebar from '../components/Sidebar'; +import { Button, Typography, Chip } from '@material-tailwind/react'; -const Home = () => { +import ProjectCard from '../components/projects/ProjectCard'; +import projectsDetail from '../assets/projects.json'; + +const Projects = () => { return ( -
-
- +
+
+
+
+ Projects + +
+
+
+ + + +
-
- +
+ {projectsDetail.map((project, key) => { + return ; + })}
); }; -export default Home; +export default Projects; diff --git a/packages/frontend/src/pages/projects/Create.tsx b/packages/frontend/src/pages/projects/Create.tsx index 52de4851..1f383105 100644 --- a/packages/frontend/src/pages/projects/Create.tsx +++ b/packages/frontend/src/pages/projects/Create.tsx @@ -1,20 +1,22 @@ import React from 'react'; import { Outlet, Link } from 'react-router-dom'; +import { IconButton } from '@material-tailwind/react'; + import HorizontalLine from '../../components/HorizontalLine'; const CreateProject = () => { return ( -
-
-
+
+
+

Create new project

-
+
- +
diff --git a/packages/frontend/src/pages/projects/Project.tsx b/packages/frontend/src/pages/projects/Project.tsx index 2ec96d15..8536622f 100644 --- a/packages/frontend/src/pages/projects/Project.tsx +++ b/packages/frontend/src/pages/projects/Project.tsx @@ -19,7 +19,7 @@ const Project = () => { const project = useMemo(() => getProject(Number(id)), [id]); return ( -
+
{project ? ( <>
diff --git a/packages/frontend/src/pages/Projects.tsx b/packages/frontend/src/pages/projects/index.tsx similarity index 50% rename from packages/frontend/src/pages/Projects.tsx rename to packages/frontend/src/pages/projects/index.tsx index daafcd5e..3f181baf 100644 --- a/packages/frontend/src/pages/Projects.tsx +++ b/packages/frontend/src/pages/projects/index.tsx @@ -1,31 +1,14 @@ import React from 'react'; import { Link } from 'react-router-dom'; -import { Button, IconButton, Typography, Chip } from '@material-tailwind/react'; +import { Button, Typography, Chip } from '@material-tailwind/react'; -import ProjectCard from '../components/projects/ProjectCard'; -import HorizontalLine from '../components/HorizontalLine'; -import projectsDetail from '../assets/projects.json'; -import ProjectSearch from '../components/projects/ProjectSearch'; +import ProjectCard from '../../components/projects/ProjectCard'; +import projectsDetail from '../../assets/projects.json'; const Projects = () => { return ( -
-
-
- {}} /> -
- - + - -
- ^ -
-
- SY -
-
- +
diff --git a/packages/frontend/src/pages/projects/routes.tsx b/packages/frontend/src/pages/projects/routes.tsx index 9d450f10..e31eeef2 100644 --- a/packages/frontend/src/pages/projects/routes.tsx +++ b/packages/frontend/src/pages/projects/routes.tsx @@ -4,14 +4,17 @@ import CreateProject from './Create'; import Project from './Project'; import { createProjectRoutes } from './create/routes'; -export const projectsRoutes = [ - { - path: ':id', - element: , - }, +export const projectsRoutesWithoutSearch = [ { path: 'create', element: , children: createProjectRoutes, }, ]; + +export const projectsRoutesWithSearch = [ + { + path: ':id', + element: , + }, +]; diff --git a/packages/frontend/src/pages/routes.tsx b/packages/frontend/src/pages/routes.tsx deleted file mode 100644 index 756b362e..00000000 --- a/packages/frontend/src/pages/routes.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react'; - -import Projects from './Projects'; -import Settings from './Settings'; -import { projectsRoutes } from './projects/routes'; - -export const homeRoutes = [ - { - index: true, - element: , - }, - { - path: 'settings', - element: , - }, - { - path: 'projects', - children: projectsRoutes, - }, -];