-
Notifications
You must be signed in to change notification settings - Fork 4
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
Ryder PCA Sorting #540
base: master
Are you sure you want to change the base?
Ryder PCA Sorting #540
Changes from 1 commit
f623bcb
98fb57e
2634219
ba20fc9
729ec90
d4d2f23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import { | ||
GridItem, | ||
GridCourseTitle, | ||
} from "pcx-shared-components/src/common/layout"; | ||
import { P } from "../common/common"; | ||
import ToggleSwitch from "../common/ToggleSwitch"; | ||
import { AlertAction, SectionStatus } from "../../types"; | ||
import { Img } from "../common/common"; | ||
import { configureScope } from "@sentry/browser"; | ||
import { Flex } from "pcx-shared-components/src/common/layout"; | ||
|
||
const GridTitle = styled.div` | ||
color: #282828; | ||
font-size: 1rem; | ||
font-family: "Inter", sans-serif; | ||
font-weight: bold; | ||
padding-top: 0.5rem; | ||
`; | ||
|
||
const GridSubtitle = styled.div` | ||
color: #282828; | ||
font-size: 0.9rem; | ||
padding-top: 0.4rem; | ||
font-family: "Inter", sans-serif; | ||
font-weight: bold; | ||
`; | ||
|
||
const TrashImg = styled(Img)` | ||
cursor: pointer; | ||
opacity: 75%; | ||
|
||
&:hover { | ||
opacity: 100%; | ||
} | ||
&:active { | ||
transform: translateY(0.1rem); | ||
} | ||
`; | ||
|
||
// Component for an alert entry (renders as a row in CSS grid) | ||
interface AlertHeaderProps { | ||
course: string; | ||
rownum: number; | ||
} | ||
export const AlertHeader = ({ course, rownum }: AlertHeaderProps) => { | ||
return ( | ||
<> | ||
<GridCourseTitle column={1} valign border> | ||
<GridSubtitle>{course.toUpperCase()}</GridSubtitle> | ||
</GridCourseTitle> | ||
|
||
{/* used to make sure grid line goes to end */} | ||
<GridItem | ||
column={2} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
<GridItem | ||
column={3} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
<GridItem | ||
column={4} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
<GridItem | ||
column={5} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
<GridItem | ||
column={6} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
<GridItem | ||
column={7} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
<GridItem | ||
column={8} | ||
row={rownum} | ||
border | ||
halign | ||
valign | ||
talign | ||
></GridItem> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ import Header from "./Header"; | |
import { AlertSearch } from "./AlertSearch"; | ||
import { AlertItem } from "./AlertItem"; | ||
import { maxWidth, PHONE } from "../../constants"; | ||
import { Alert, AlertAction, TAlertSel } from "../../types"; | ||
import { Alert, AlertAction, SectionStatus, TAlertSel } from "../../types"; | ||
import { AlertHeader } from "./AlertHeader"; | ||
|
||
const Container = styled.div` | ||
background: #ffffff; | ||
|
@@ -90,6 +91,91 @@ export const ManageAlert = ({ | |
const [searchTimeout, setSearchTimeout] = useState<number>(); | ||
const [numSelected, setNumSelected] = useState(0); | ||
|
||
//Alerts for testing | ||
var alert1: Alert = { | ||
id: 1, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "cis-1100-001", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert2: Alert = { | ||
id: 2, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "cis-1100-002", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert3: Alert = { | ||
id: 3, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "cis-1200-001", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert4: Alert = { | ||
id: 4, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "stat-4300-002", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert5: Alert = { | ||
id: 5, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "stat-4300-001", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert6: Alert = { | ||
id: 6, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "math-1400-001", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert7: Alert = { | ||
id: 7, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "math-1410-002", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var alert8: Alert = { | ||
id: 8, | ||
originalCreatedAt: "2023-09-11T12:00:00Z", | ||
section: "stat-4100-001", | ||
alertLastSent: "2023-09-11T12:00:00Z", | ||
status: SectionStatus.OPEN, | ||
actions: AlertAction.ONALERT, | ||
closedNotif: AlertAction.ONCLOSED, | ||
}; | ||
var testAlerts: Alert[]; | ||
testAlerts = [ | ||
alert1, | ||
alert2, | ||
alert3, | ||
alert4, | ||
alert5, | ||
alert6, | ||
alert7, | ||
alert8, | ||
]; | ||
|
||
useEffect(() => { | ||
setNumSelected( | ||
Object.values(alertSel).reduce((acc, x) => acc + (x ? 1 : 0), 0) | ||
|
@@ -109,6 +195,25 @@ export const ManageAlert = ({ | |
); | ||
}; | ||
|
||
let rowNum = 0; | ||
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. nit: lets move this to under useStates |
||
|
||
/** | ||
* Returns alerts grouped by course | ||
* @return grouped alerts | ||
*/ | ||
const groupedAlerts = testAlerts | ||
.sort((a, b) => a.section.localeCompare(b.section)) | ||
.reduce((res, obj) => { | ||
const [courseName, midNum, endNum] = obj.section.split("-"); | ||
if (res[`${courseName}-${midNum}`]) { | ||
res[`${courseName}-${midNum}`].push(obj); | ||
} else { | ||
res[`${courseName}-${midNum}`] = [obj]; | ||
} | ||
|
||
return res; | ||
}, {}); | ||
|
||
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. can we generalize this with the other grouping and put it in a shared util file? |
||
return ( | ||
<Container> | ||
<Flex margin="0.2rem 2rem 0.1rem 2rem" center valign spaceBetween> | ||
|
@@ -123,28 +228,49 @@ export const ManageAlert = ({ | |
batchSelectHandler={batchSelectHandler} | ||
/> | ||
<AlertGrid> | ||
{alerts?.map?.((alert, i) => ( | ||
<AlertItem | ||
key={alert.id} | ||
checked={alertSel[alert.id]} | ||
rownum={i + 1} | ||
alertLastSent={alert.alertLastSent} | ||
course={alert.section} | ||
status={alert.status} | ||
actions={alert.actions} | ||
closed={alert.closedNotif} | ||
toggleAlert={toggleAlert(alert.id)} | ||
alertHandler={() => | ||
actionHandler(alert.id, alert.actions) | ||
} | ||
closedHandler={() => | ||
actionHandler(alert.id, alert.closedNotif) | ||
} | ||
deleteHandler={() => | ||
actionHandler(alert.id, AlertAction.DELETE) | ||
} | ||
/> | ||
))} | ||
{Object.keys(groupedAlerts).map((key) => { | ||
rowNum++; | ||
return ( | ||
<> | ||
<AlertHeader course={key} rownum={rowNum} /> | ||
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.
|
||
{groupedAlerts[key]?.map?.((alert) => { | ||
console.log(alert); | ||
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. remove console log |
||
rowNum++; | ||
return ( | ||
<AlertItem | ||
key={alert.id} | ||
checked={alertSel[alert.id]} | ||
rownum={rowNum} | ||
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.
nit: |
||
alertLastSent={alert.alertLastSent} | ||
course={alert.section} | ||
status={alert.status} | ||
actions={alert.actions} | ||
closed={alert.closedNotif} | ||
toggleAlert={toggleAlert(alert.id)} | ||
alertHandler={() => | ||
actionHandler( | ||
alert.id, | ||
alert.actions | ||
) | ||
} | ||
closedHandler={() => | ||
actionHandler( | ||
alert.id, | ||
alert.closedNotif | ||
) | ||
} | ||
deleteHandler={() => | ||
actionHandler( | ||
alert.id, | ||
AlertAction.DELETE | ||
) | ||
} | ||
/> | ||
); | ||
})} | ||
</> | ||
); | ||
})} | ||
</AlertGrid> | ||
</Container> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
courseCode
androwNum
?