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: Remove statistics from front page #45

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM node:current-alpine as build
WORKDIR /app

ENV PATH /app/node_modules/.bin:$PATH
ENV PATH=/app/node_modules/.bin:$PATH

COPY package.json /app/package.json
COPY yarn.lock /app/yarn.lock

RUN yarn --silent
COPY . /app

ENV NODE_OPTIONS=--openssl-legacy-provider
RUN yarn build

# Running the app
ENV NODE_ENV production
ENV NODE_ENV=production
CMD ["node", "server"]
34 changes: 0 additions & 34 deletions pages/api/stats.js

This file was deleted.

98 changes: 13 additions & 85 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,106 +25,38 @@ import React from "react";
import Container from "@material-ui/core/Container";
import Box from "@material-ui/core/Box";
import Button from "@material-ui/core/Button";
import { makeStyles } from "@material-ui/core/styles";
import Logo from "../src/Logo";
import Link from "next/link";
import Footer from "../src/Footer";
import PropTypes from "prop-types";
import Typography from "@material-ui/core/Typography";
import { makeStyles } from "@material-ui/core/styles";

import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableContainer from "@material-ui/core/TableContainer";
import Skeleton from "@material-ui/lab/Skeleton";
import Alert from "@material-ui/lab/Alert";
import AlertTitle from "@material-ui/lab/AlertTitle";
import TableRow from "@material-ui/core/TableRow";
import Paper from "@material-ui/core/Paper";
import useSWR from "swr";
import { state } from "../server/state";
import { serializeStats } from "../server/serialization";

const useStyles = makeStyles((theme) => ({
tableContainer: {
marginTop: theme.spacing(2),
export const useStyles = makeStyles((theme) => ({
description: {
paddingBottom: theme.spacing(1),
},
}));

function Statistics({ initialData }) {
export default function Index() {
const classes = useStyles();
const fetcher = (url) => fetch(url).then((r) => r.json());
const { data, error } = useSWR("/api/stats", fetcher, { initialData, revalidateOnMount: true });

return (
<>
{error && (
<Box my={2}>
<Alert variant="filled" severity="error">
<AlertTitle>Could not load statistics!</AlertTitle>
It&apos;s your fault probably.
</Alert>
</Box>
)}
{!error && (
<TableContainer component={Paper} variant="outlined" className={classes.tableContainer}>
{!data && (
<Box my={2} mx={2}>
<Skeleton />
<Skeleton />
<Skeleton />
</Box>
)}
{data && (
<Table aria-label="simple table">
<TableBody>
<TableRow>
<TableCell component="th" scope="row">
Number of active sessions
</TableCell>
<TableCell align="right">{data.numSessions}</TableCell>
</TableRow>
<TableRow>
<TableCell component="th" scope="row">
Total number of players
</TableCell>
<TableCell align="right">{data.numPlayers}</TableCell>
</TableRow>
<TableRow>
<TableCell component="th" scope="row">
Number of voters
</TableCell>
<TableCell align="right">{data.numVoters}</TableCell>
</TableRow>
<TableRow>
<TableCell component="th" scope="row">
Number of observers
</TableCell>
<TableCell align="right">{data.numObservers}</TableCell>
</TableRow>
</TableBody>
</Table>
)}
</TableContainer>
)}
</>
);
}

Statistics.propTypes = {
initialData: PropTypes.object,
};

export default function Index({ initialData }) {
return (
<Container maxWidth="sm">
<Logo />
<Box my={2}>
<Typography className={classes.description} variant="body1">
This is a a Planning Poker app, useful for Scrum grooming sessions to avoid anchoring in
point estimates.
</Typography>
<Typography className={classes.description} variant="body1">
To start a new session, click the button below.
</Typography>
<Link href="/new" passHref>
<Button color="secondary" fullWidth size="large" variant="contained">
New session
</Button>
</Link>
<Statistics initialData={initialData} />
</Box>
<Footer />
</Container>
Expand All @@ -134,7 +66,3 @@ export default function Index({ initialData }) {
Index.propTypes = {
initialData: PropTypes.object,
};

Index.getInitialProps = async () => {
return { initialData: serializeStats(state) };
};
19 changes: 0 additions & 19 deletions server/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,6 @@ function serializeSession(sessionState, me) {
};
}

function serializeStats(state) {
const sessions = Object.values(state).filter(({ finished }) => !finished);
const numVoters = sessions.reduce(
(a, b) => a + Object.values(b.clients).filter(({ name }) => name).length,
0
);
const numObservers = sessions.reduce(
(a, b) => a + Object.values(b.clients).filter(({ name }) => !name).length,
0
);
return {
numSessions: sessions.length,
numVoters,
numObservers,
numPlayers: numVoters + numObservers,
};
}

function exportSession(sessionState) {
const { pagination, settings, finished } = sessionState;

Expand All @@ -161,5 +143,4 @@ function exportSession(sessionState) {
exports.serializeClient = serializeClient;
exports.serializeClients = serializeClients;
exports.serializeSession = serializeSession;
exports.serializeStats = serializeStats;
exports.exportSession = exportSession;
2 changes: 1 addition & 1 deletion src/PaginationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function PaginationPanel({
container
direction="row"
alignItems="center"
justify={
justifyContent={
matches &&
(permissions.canPaginate || permissions.canAddDeletePages || permissions.canEditSettings)
? "space-between"
Expand Down
2 changes: 1 addition & 1 deletion src/VotePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function VotePanel({
className={classes.container}
container
direction="row"
justify="space-between"
justifyContent="space-between"
alignItems="center"
>
<Grid item sm={controlEnabled ? 9 : 12} xs={12} className={classes.scoresContainer}>
Expand Down
4 changes: 2 additions & 2 deletions src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { createMuiTheme } from "@material-ui/core/styles";
import { createTheme } from "@material-ui/core/styles";

const theme = createMuiTheme({
const theme = createTheme({
palette: {
primary: {
main: "#556cd6",
Expand Down
6 changes: 3 additions & 3 deletions tests/client/__snapshots__/Footer.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Array [
className="MuiDivider-root"
/>,
<div
className="MuiGrid-root makeStyles-footer-2 MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-footer-2 MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root makeStyles-timer-3 MuiGrid-item"
Expand Down Expand Up @@ -195,7 +195,7 @@ Array [
className="MuiDivider-root"
/>,
<div
className="MuiGrid-root makeStyles-footer-2 MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-footer-2 MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root makeStyles-timer-3 MuiGrid-item"
Expand Down Expand Up @@ -258,7 +258,7 @@ Array [
className="MuiDivider-root"
/>,
<div
className="MuiGrid-root makeStyles-footer-2 MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-footer-2 MuiGrid-container MuiGrid-spacing-xs-2 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down
24 changes: 12 additions & 12 deletions tests/client/__snapshots__/Session.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`renders Session unchanged {"clients": [Array], "description": "### Markdown", "disconnectedClients": [Object], "epoch": 0, "host": "5cdf4eb9-4c88-47ee-85da-5a2e970ed79f", "me": [Object], "pagination": [Object], "privatePreview": 0, "settings": [Object], "timerState": [Object], "votesVisible": false} 1`] = `
Array [
<div
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down Expand Up @@ -386,7 +386,7 @@ Array [
</div>
</div>,
<div
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-between"
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-between"
>
<div
className="MuiGrid-root makeStyles-scoresContainer-15 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-12"
Expand Down Expand Up @@ -824,7 +824,7 @@ Array [
exports[`renders Session unchanged {"clients": [Array], "description": "### Markdown", "disconnectedClients": [Object], "epoch": 0, "host": "5cdf4eb9-4c88-47ee-85da-5a2e970ed79f", "me": [Object], "pagination": [Object], "privatePreview": null, "settings": [Object], "timerState": [Object], "votesVisible": false} 1`] = `
Array [
<div
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down Expand Up @@ -1133,7 +1133,7 @@ Array [
</div>
</div>,
<div
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-between"
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-between"
>
<div
className="MuiGrid-root makeStyles-scoresContainer-15 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9"
Expand Down Expand Up @@ -1659,7 +1659,7 @@ Array [
exports[`renders Session unchanged {"clients": [Array], "description": "### Markdown", "disconnectedClients": [Object], "epoch": 0, "host": "5cdf4eb9-4c88-47ee-85da-5a2e970ed79f", "me": [Object], "pagination": [Object], "privatePreview": null, "settings": [Object], "timerState": [Object], "votesVisible": false} 2`] = `
Array [
<div
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down Expand Up @@ -1881,7 +1881,7 @@ Array [
</div>
</div>,
<div
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-between"
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-between"
>
<div
className="MuiGrid-root makeStyles-scoresContainer-15 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9"
Expand Down Expand Up @@ -2413,7 +2413,7 @@ Array [
exports[`renders Session unchanged {"clients": [Array], "description": "### Markdown", "disconnectedClients": [Object], "epoch": 0, "host": "5cdf4eb9-4c88-47ee-85da-5a2e970ed79f", "me": [Object], "pagination": [Object], "privatePreview": null, "settings": [Object], "timerState": [Object], "votesVisible": false} 3`] = `
Array [
<div
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down Expand Up @@ -2635,7 +2635,7 @@ Array [
</div>
</div>,
<div
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-between"
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-between"
>
<div
className="MuiGrid-root makeStyles-scoresContainer-15 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9"
Expand Down Expand Up @@ -3161,7 +3161,7 @@ Array [
exports[`renders Session unchanged {"clients": [Array], "description": "### Markdown", "disconnectedClients": [Object], "epoch": 0, "host": "5cdf4eb9-4c88-47ee-85da-5a2e970ed79f", "me": [Object], "pagination": [Object], "privatePreview": null, "settings": [Object], "timerState": [Object], "votesVisible": false} 4`] = `
Array [
<div
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down Expand Up @@ -3383,7 +3383,7 @@ Array [
</div>
</div>,
<div
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-between"
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-between"
>
<div
className="MuiGrid-root makeStyles-scoresContainer-15 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-12"
Expand Down Expand Up @@ -3851,7 +3851,7 @@ Array [
exports[`renders Session unchanged {"clients": [Array], "description": "### Markdown", "disconnectedClients": [Object], "epoch": 0, "host": "5cdf4eb9-4c88-47ee-85da-5a2e970ed79f", "me": [Object], "pagination": [Object], "privatePreview": null, "settings": [Object], "timerState": [Object], "votesVisible": true} 1`] = `
Array [
<div
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-around"
className="MuiGrid-root makeStyles-sessionPaper-2 MuiGrid-container MuiGrid-spacing-xs-1 MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-around"
>
<div
className="MuiGrid-root MuiGrid-item"
Expand Down Expand Up @@ -4160,7 +4160,7 @@ Array [
</div>
</div>,
<div
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-xs-space-between"
className="MuiGrid-root makeStyles-container-16 MuiGrid-container MuiGrid-align-items-xs-center MuiGrid-justify-content-xs-space-between"
>
<div
className="MuiGrid-root makeStyles-scoresContainer-15 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9"
Expand Down
Loading