Skip to content

Commit

Permalink
feat: add the helsinki campus map (#170)
Browse files Browse the repository at this point in the history
* feat: add the helsinki campus map

* chore: run make-pretty
  • Loading branch information
42atomys authored Jul 5, 2022
1 parent 94cc9ec commit 5bbd0ef
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 6 deletions.
5 changes: 4 additions & 1 deletion internal/models/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}()
Expand Down
15 changes: 11 additions & 4 deletions web/ui/src/components/ClusterMap/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion web/ui/src/components/Sidebar/SidebarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const MenuItem = ({
<Emoji emoji={emoji} size={24} containerClassName="contents" />
)}
<span className="ml-2 flex items-baseline">
<span className="">{name}</span>
<span className="">{name || text}</span>
{text && (
<span
className={classNames(
Expand Down
29 changes: 29 additions & 0 deletions web/ui/src/containers/clusters/ClusterSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ export const ClusterSidebar = ({
</a>
</Link>
</MenuCategory>
<MenuCategory emoji="🇫🇮" name="Helsinki">
<Link href="/clusters/helsinki/c1" passHref={true}>
<a>
<MenuItem
active={campus == 'helsinki' && cluster == 'c1'}
name=""
text="C1"
/>
</a>
</Link>
<Link href="/clusters/helsinki/c2" passHref={true}>
<a>
<MenuItem
active={campus == 'helsinki' && cluster == 'c2'}
name=""
text="C2"
/>
</a>
</Link>
<Link href="/clusters/helsinki/c3" passHref={true}>
<a>
<MenuItem
active={campus == 'helsinki' && cluster == 'c3'}
name=""
text="C3"
/>
</a>
</Link>
</MenuCategory>
</Menu>
<span className="flex p-2 text-xs text-slate-400 dark:text-slate-600 italic">
You don&apos;t see your campus ? Go on github and add it !
Expand Down
127 changes: 127 additions & 0 deletions web/ui/src/pages/clusters/helsinki/[cluster].tsx
Original file line number Diff line number Diff line change
@@ -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<PageProps> = ({ cluster }) => {
const clusterRows = clusters[cluster];

return (
<ClusterContainer campus="Helsinki" cluster={cluster}>
{({ locations, showPopup }) => (
<ClusterMap>
{Object.keys(clusterRows).map((row) => (
<ClusterRow key={`cluster-row-${row}`} displayText={row}>
{clusterRows[row].map((workspace) => {
if (workspace === null) return <ClusterEmpty />;
if (workspace === 'pillar') return <ClusterPillar />;

const identifier = `${cluster}${row}p${workspace}`;
const key = `cluster-workspace-${row}-${workspace}`;
const loc = extractNode(locations, identifier);

if (loc) {
return (
<ClusterWorkspaceWithUser
key={key}
identifier={identifier}
displayText={workspace.toString()}
location={loc}
onClick={({ currentTarget }, location) => {
showPopup({
location: location,
user: location.user,
position: currentTarget.getBoundingClientRect(),
});
}}
/>
);
}

return (
<ClusterWorkspace
key={key}
identifier={identifier}
displayText={workspace.toString()}
/>
);
})}
</ClusterRow>
))}
</ClusterMap>
)}
</ClusterContainer>
);
};

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;

0 comments on commit 5bbd0ef

Please sign in to comment.