From 5bbd0efbcba5f870105fb627cfce82b4dad2f16d Mon Sep 17 00:00:00 2001 From: 42Atomys Date: Tue, 5 Jul 2022 23:29:45 +0200 Subject: [PATCH] feat: add the helsinki campus map (#170) * feat: add the helsinki campus map * chore: run make-pretty --- internal/models/utils.go | 5 +- web/ui/src/components/ClusterMap/types.d.ts | 15 ++- web/ui/src/components/Sidebar/SidebarMenu.tsx | 2 +- .../containers/clusters/ClusterSidebar.tsx | 29 ++++ .../src/pages/clusters/helsinki/[cluster].tsx | 127 ++++++++++++++++++ 5 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 web/ui/src/pages/clusters/helsinki/[cluster].tsx diff --git a/internal/models/utils.go b/internal/models/utils.go index 0d1acca8..aa81043a 100644 --- a/internal/models/utils.go +++ b/internal/models/utils.go @@ -24,7 +24,10 @@ func WithTx(ctx context.Context, client *modelgen.Client, fn func(tx *modelgen.T } defer func() { if v := recover(); v != nil { - tx.Rollback() + if err := tx.Rollback(); err != nil { + log.Error().Err(err).Msg("failed to rollback transaction") + sentry.CaptureException(err) + } sentry.CaptureException(v.(error)) } }() diff --git a/web/ui/src/components/ClusterMap/types.d.ts b/web/ui/src/components/ClusterMap/types.d.ts index 5475ecb6..82d5c3c4 100644 --- a/web/ui/src/components/ClusterMap/types.d.ts +++ b/web/ui/src/components/ClusterMap/types.d.ts @@ -28,10 +28,17 @@ type ClusterContainerChildrenProps = { hidePopup: () => void; }; -type ClusterContainerProps = { - campus: 'Paris'; - cluster: 'e1' | 'e2' | 'e3'; - children: (props: ClusterContainerChildrenProps) => JSX.Element; +type CampusClusterMap = { + Paris: 'e1' | 'e2' | 'e3'; + Helsinki: 'c1' | 'c2' | 'c3'; }; +export type ClusterContainerProps = { + [Key in keyof CampusClusterMap]: { + campus: Key; + cluster: CampusClusterMap[Key]; + children: (props: ClusterContainerChildrenProps) => JSX.Element; + }; +}[keyof CampusClusterMap]; + type ClusterContainerComponent = (props: ClusterContainerProps) => JSX.Element; diff --git a/web/ui/src/components/Sidebar/SidebarMenu.tsx b/web/ui/src/components/Sidebar/SidebarMenu.tsx index f286e345..e20241cc 100644 --- a/web/ui/src/components/Sidebar/SidebarMenu.tsx +++ b/web/ui/src/components/Sidebar/SidebarMenu.tsx @@ -110,7 +110,7 @@ export const MenuItem = ({ )} - {name} + {name || text} {text && ( + + + + + + + + + + + + + + + + + You don't see your campus ? Go on github and add it ! diff --git a/web/ui/src/pages/clusters/helsinki/[cluster].tsx b/web/ui/src/pages/clusters/helsinki/[cluster].tsx new file mode 100644 index 00000000..c092716f --- /dev/null +++ b/web/ui/src/pages/clusters/helsinki/[cluster].tsx @@ -0,0 +1,127 @@ +import React from 'react'; +import { GetStaticProps, NextPage } from 'next'; +import { + ClusterEmpty, + ClusterMap, + ClusterPillar, + ClusterRow, + ClusterWorkspace, + ClusterWorkspaceWithUser, + extractNode, +} from '@components/ClusterMap'; +import { ClusterContainer } from '@components/ClusterMap/ClusterContainer'; + +type PageProps = { + cluster: 'c1' | 'c2' | 'c3'; +}; + +type Campus = { + [key: string]: { + [key: string]: (number | 'pillar' | null)[]; + }; +}; + +// prettier-ignore +const clusters: Campus = { + c1: { + r6: [1, 2, 3, 4, 5, 6, 7, 8, 9, null, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], + r5: [1, 2, 3, 4, 5, 6, 7, 8, 9, null, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], + r4: [null, null, null, null, null, 1, 2, 3, 4, 5, 6, 7, 8, null, 9, 10, 11, null, null, null, null, null, null, null], + r3: [null, null, null, null, null, 1, 2, 3, null, 4, null, 5, null, 6, 7, 8, 9, null, null, null, null, null, null, null], + r2: [null, null, null, null, null, 1, 2, null, null, null, null, null, null, 3, 4, 5, 6, null, null, null, null, null, null, null], + r1: [null, null, null, null, null, 1, 2, 3, 4, 5, 6, 7, 8, null, 9, 10, 11, null, null, null, null, null, null, null], + }, + c2: { + r6: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], + r5: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], + r4: [1, 2, 3, 4, 5, 6, 7, 8, null, 9, 10, 11, 12], + r3: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], + r2: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], + r1: [1, 2, 3, 4, 5, 6, 7, 8, null, 9, 10, 11, 12], + }, + c3: { + r5: [1, 2, 3, 4, 5, 6], + r4: [1, 2, 3, 4, 5, 6], + r3: [1, 2, 3, 4, 5, 6], + r2: [1, 2, 3, 4, 5, 6, 7], + r1: [1, 2, 3, 4, 5, 6, 7], + }, +} + +export const IndexPage: NextPage = ({ cluster }) => { + const clusterRows = clusters[cluster]; + + return ( + + {({ locations, showPopup }) => ( + + {Object.keys(clusterRows).map((row) => ( + + {clusterRows[row].map((workspace) => { + if (workspace === null) return ; + if (workspace === 'pillar') return ; + + const identifier = `${cluster}${row}p${workspace}`; + const key = `cluster-workspace-${row}-${workspace}`; + const loc = extractNode(locations, identifier); + + if (loc) { + return ( + { + showPopup({ + location: location, + user: location.user, + position: currentTarget.getBoundingClientRect(), + }); + }} + /> + ); + } + + return ( + + ); + })} + + ))} + + )} + + ); +}; + +export const getStaticPaths = async () => { + return { + paths: [ + { params: { cluster: 'c1' } }, + { params: { cluster: 'c2' } }, + { params: { cluster: 'c3' } }, + ], + fallback: false, + }; +}; + +export const getStaticProps: GetStaticProps = ({ params = {} }) => { + const { cluster } = params; + + if (!cluster || ['c1', 'c2', 'c3'].includes(cluster as string) === false) { + return { notFound: true }; + } + + return { + props: { + cluster, + }, + }; +}; + +export default IndexPage;