-
Notifications
You must be signed in to change notification settings - Fork 0
Priority Button #105
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
Open
RJ0907
wants to merge
43
commits into
master
Choose a base branch
from
reorganizing-priorities
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Priority Button #105
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
dd0d3d4
Ran - added a component
RJ0907 4dba5c3
Ran - removed match-id
RJ0907 bf7b24c
Ran - making it smaller
RJ0907 3525fd3
Ran - more informative name
RJ0907 5f05e18
Ran - added the router but it is buggy
RJ0907 5c1c6ef
Ran - not red now
RJ0907 183529f
Linting
RJ0907 e2d5fda
Ran - added to index
RJ0907 7d91d13
Ran - fixed adding to index
RJ0907 a7c659c
Ran - started implementing this router
RJ0907 bc9461d
Ran - added the post request
RJ0907 fee3b44
Ran - error handling in the frontend
RJ0907 f0d0059
Ran - fixes to the frontend
RJ0907 9c5f28a
Ran - returned it to App
RJ0907 febc6d3
Ran - created a folder
RJ0907 4e98e41
Ran - PresentPriority component
RJ0907 f88d02f
Ran - added the components
RJ0907 4651f83
Ran - changed handle submit's url
RJ0907 f779647
Ran - worksssssss
RJ0907 2f3edbd
styling the priority components
RJ0907 6c87068
Ran - moving to correct location
RJ0907 e498984
Ran - moved the edirPriority
RJ0907 ff64fb6
Ran - Priority in table
RJ0907 d3c9a6d
Ran - now also apllies to the table
RJ0907 4efa076
Ran - now in grid instead of flex
RJ0907 d47797c
Ran - works!!
RJ0907 c578d61
Ran - now added not interseting option. almost ready for PR
RJ0907 0514a01
Ran - added priority zero
RJ0907 4b6cdd5
Ran - changed null to undefined after Yoni's notes
RJ0907 e02fffa
Ran - useTeamPriority hool
RJ0907 6947054
Ran - null to undefined in edit priority component
RJ0907 281b186
Ran - removed unnecessary import statements
RJ0907 3da79fc
Ran - changed from null to undefined
RJ0907 4d2597e
Ran - cleaner version of the display
RJ0907 4c977db
Ran - merged master
RJ0907 68fd0bb
Ran - try chatch #!
RJ0907 164fdfa
Ran - try catch #2
RJ0907 a59fd4d
Ran - try chatch #3
RJ0907 5ff3a7b
Ran - foldResponse
RJ0907 ecfc2c0
Ran - foldResponse #!
RJ0907 4de0b26
Ran - foldResponse #2
RJ0907 13bf2cc
Removed a redaundent variable
RJ0907 761e599
Ran - now using the useLocalStorage hook
RJ0907 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { Router } from "express"; | ||
| import { StatusCodes } from "http-status-codes"; | ||
| import { flow, pipe } from "fp-ts/lib/function"; | ||
| import { flatMap, fold, map, tryCatch, fromEither } from "fp-ts/lib/TaskEither"; | ||
| import { right as rightEither } from "fp-ts/lib/Either"; | ||
| import { map as mapTask } from "fp-ts/lib/Task"; | ||
| import * as t from "io-ts"; | ||
|
|
||
| import { | ||
| createBodyVerificationPipe, | ||
| createTypeCheckingEndpointFlow, | ||
| } from "../middleware/verification"; | ||
| import type { EndpointError } from "../middleware/verification"; | ||
| import type { TaskEither } from "fp-ts/lib/TaskEither"; | ||
| import { getDb } from "../middleware/db"; | ||
| import { left } from "fp-ts/lib/TaskEither"; | ||
| import { flatTryCatch, foldResponse } from "../../../../../packages/flow-utils"; | ||
|
|
||
| export const teamPriorityCodec = t.type({ | ||
| teamNumber: t.number, | ||
| priority: t.number, | ||
| }); | ||
|
|
||
| export const teamPriorityArrayCodec = t.array(teamPriorityCodec); | ||
|
|
||
| export type TeamPriority = t.TypeOf<typeof teamPriorityCodec>; | ||
|
|
||
| export const priorityRouter = Router(); | ||
|
|
||
| const getPriorityCollection = flow( | ||
| getDb, | ||
| map((db) => db.collection<TeamPriority>("teamPriorities")), | ||
| ); | ||
|
|
||
| export const readAllPriorities = (): TaskEither< | ||
| EndpointError, | ||
| TeamPriority[] | ||
| > => | ||
| pipe( | ||
| getPriorityCollection(), | ||
| flatTryCatch( | ||
| (collection) => collection.find({}).toArray(), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error reading priorities: ${error}`, | ||
| }), | ||
| ), | ||
| mapTask( | ||
| createTypeCheckingEndpointFlow(teamPriorityArrayCodec, (errors) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Invalid priorities data format. error: ${errors}`, | ||
| })), | ||
| ), | ||
| ); | ||
|
|
||
| export const readPriorityByTeamNumber = ( | ||
| teamNumber: number, | ||
| ): TaskEither<EndpointError, TeamPriority> => | ||
| pipe( | ||
| getPriorityCollection(), | ||
| flatTryCatch( | ||
| (collection) => collection.findOne({ teamNumber }), | ||
| (error): EndpointError => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error reading priority for team ${teamNumber}: ${String(error)}`, | ||
| }), | ||
| ), | ||
| flatMap((result) => | ||
| result | ||
| ? pipe( | ||
| rightEither(result), | ||
| createTypeCheckingEndpointFlow(teamPriorityCodec, (errors) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Invalid team priority format. error: ${errors}`, | ||
| })), | ||
| fromEither, | ||
| ) | ||
| : left({ | ||
| status: StatusCodes.NOT_FOUND, | ||
| reason: `Priority for team ${teamNumber} not found`, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| export const upsertPriority = ( | ||
| teamPriority: TeamPriority, | ||
| ): TaskEither<EndpointError, void> => | ||
| pipe( | ||
| getPriorityCollection(), | ||
| flatTryCatch( | ||
| (collection) => | ||
| collection.updateOne( | ||
| { teamNumber: teamPriority.teamNumber }, | ||
| { $set: { priority: teamPriority.priority } }, | ||
| { upsert: true }, | ||
| ), | ||
| (error) => ({ | ||
| status: StatusCodes.INTERNAL_SERVER_ERROR, | ||
| reason: `Error writing priority: ${error}`, | ||
| }), | ||
| ), | ||
| map(() => undefined), | ||
|
RJ0907 marked this conversation as resolved.
|
||
| ); | ||
|
|
||
| priorityRouter.get("/", async (_req, res) => { | ||
| await pipe( | ||
| readAllPriorities(), | ||
| map((priorities) => ({ priorities })), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
|
|
||
| priorityRouter.get("/:teamNumber", async (req, res) => { | ||
| const teamNumber = Number(req.params.teamNumber); | ||
|
|
||
| if (Number.isNaN(teamNumber)) { | ||
| res | ||
| .status(StatusCodes.BAD_REQUEST) | ||
| .send("teamNumber must be a valid number"); | ||
| return; | ||
| } | ||
|
Comment on lines
+114
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider putting this neatly in the pipe by using a |
||
|
|
||
| await pipe( | ||
| readPriorityByTeamNumber(teamNumber), | ||
| map((teamPriority) => ({ teamPriority })), | ||
| foldResponse(res), | ||
| )(); | ||
| }); | ||
|
|
||
| priorityRouter.post("/", async (req, res) => { | ||
| await pipe( | ||
| rightEither(req), | ||
| createBodyVerificationPipe(teamPriorityCodec), | ||
| fromEither, | ||
| flatMap((teamPriority) => upsertPriority(teamPriority)), | ||
| fold( | ||
| (error) => () => | ||
| Promise.resolve(res.status(error.status).send(error.reason)), | ||
| () => () => | ||
| Promise.resolve( | ||
| res | ||
| .status(StatusCodes.OK) | ||
| .json({ message: "Priority written successfully" }), | ||
| ), | ||
| ), | ||
|
RJ0907 marked this conversation as resolved.
|
||
| )(); | ||
| }); | ||
53 changes: 53 additions & 0 deletions
53
apps/scouting/frontend/src/strategy/components/priority/DisplayPriority.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
| import { fetchATeamPriority, type TeamPriority } from "./EditPriority"; | ||
| import { useTeamPriority } from "../../hooks/useTeamPriority"; | ||
|
|
||
| interface DisplayPriorityProps { | ||
| teamNumber: number; | ||
| } | ||
|
|
||
| export const DisplayPriority: React.FC<DisplayPriorityProps> = ({ | ||
| teamNumber, | ||
| }) => { | ||
| const { teamPriority, isLoading, feedbackMessage } = | ||
| useTeamPriority(teamNumber); | ||
|
|
||
| return ( | ||
| <div | ||
| className=" | ||
| w-52 p-4 | ||
| flex flex-col gap-3 | ||
| items-center | ||
| bg-slate-900/40 backdrop-blur-md | ||
| border border-white/10 | ||
| rounded-3xl shadow-2xl | ||
| " | ||
| > | ||
| <span className="text-xs font-black tracking-[0.2em] uppercase text-slate-400"> | ||
| Team Priority | ||
| </span> | ||
|
|
||
| <div | ||
| className=" | ||
| w-full min-h-[72px] | ||
| flex items-center justify-center | ||
| rounded-2xl | ||
| border border-white/10 | ||
| bg-slate-950/70 | ||
| text-3xl font-black text-white | ||
| shadow-inner | ||
| " | ||
| > | ||
| {isLoading ? "..." : teamPriority ? teamPriority.priority : "--"} | ||
| </div> | ||
|
|
||
| {feedbackMessage ? ( | ||
| <p className="text-xs text-red-300 text-center">{feedbackMessage}</p> | ||
| ) : ( | ||
| <p className="text-[11px] text-slate-500 text-center"> | ||
| Current saved value | ||
| </p> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; |
27 changes: 27 additions & 0 deletions
27
apps/scouting/frontend/src/strategy/components/priority/DisplayPriorityCell.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
| import { fetchATeamPriority, type TeamPriority } from "./EditPriority"; | ||
| import { useTeamPriority } from "../../hooks/useTeamPriority"; | ||
|
|
||
| interface DisplayPriorityCellProps { | ||
| teamNumber: number; | ||
| } | ||
|
|
||
| export const DisplayPriorityCell: React.FC<DisplayPriorityCellProps> = ({ | ||
| teamNumber, | ||
| }) => { | ||
| const { teamPriority, isLoading } = | ||
| useTeamPriority(teamNumber); | ||
|
|
||
| return ( | ||
| <span | ||
| className=" | ||
| inline-flex min-w-[3rem] items-center justify-center | ||
| rounded-lg border border-emerald-500/20 | ||
| bg-slate-800/70 px-2.5 py-1 | ||
| text-xs font-black text-emerald-400 | ||
| " | ||
| > | ||
| {isLoading ? "..." : teamPriority ? teamPriority.priority : "--"} | ||
| </span> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.