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

ui: add user shifts calendar to profile #3229

Merged
merged 40 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e176558
add UserShifts query to gql schema
Forfold Aug 4, 2023
5c9affc
update schema
Forfold Aug 9, 2023
ed1e2af
add UserShifts gql query
Forfold Aug 9, 2023
f741693
render calendar on users route
Forfold Aug 11, 2023
2ce3667
show user data shifts
Forfold Aug 11, 2023
08b1b9a
organize calendar files
Forfold Aug 11, 2023
39727b5
render users name on each shift
Forfold Aug 11, 2023
bf67c50
add target to shifts
Forfold Aug 15, 2023
969d077
add err return
Forfold Aug 15, 2023
87b8290
cleanup fn call
Forfold Aug 15, 2023
dbe8b35
fix profile quick link toolbar titles
Forfold Aug 15, 2023
7a18509
fix shifts not returning
Forfold Aug 16, 2023
a6cc655
update calendar shift buttons ux
Forfold Aug 16, 2023
8d046c5
move popover to above shift cell, add name to top
Forfold Aug 17, 2023
18ccc51
Merge branch 'master' into user-shifts
Forfold Oct 27, 2023
aea59d9
revert backend changes
Forfold Oct 27, 2023
c3f18cc
make check
Forfold Oct 27, 2023
ea936af
revert state.go
Forfold Oct 27, 2023
230fe84
update ui types to show data
Forfold Oct 27, 2023
0c8a4b5
dont show quick link if mobile
Forfold Oct 27, 2023
2cf80dd
add test, update setScheduleTarget return type
Forfold Oct 27, 2023
8cd9e15
move calendar to profile
Forfold Oct 27, 2023
177a7b4
Merge branch 'master' into user-shifts
Forfold Nov 7, 2023
00b33bf
use urql and suspense for userdetails
Forfold Nov 7, 2023
40effcf
use urql and suspense for user calendar
Forfold Nov 7, 2023
37b7fc9
Merge remote-tracking branch 'origin/master' into user-shifts
Forfold Nov 8, 2023
6651f9b
remove null checks
Forfold Nov 8, 2023
eccc703
Merge branch 'master' into user-shifts
Forfold Nov 17, 2023
f97cc7d
show visit schedule btns without scheduleid prop
Forfold Nov 17, 2023
2a29555
remove spin container
Forfold Nov 17, 2023
8d4158f
dont reload whole page on calendar interval change
Forfold Nov 17, 2023
e9e1b84
update url so toolbar title matches
Forfold Nov 21, 2023
7d19e2b
Merge branch 'master' of github.com:target/goalert into user-shifts
KatieMSB Nov 22, 2023
3cd7a5d
revert url changes
Forfold Nov 22, 2023
5a1d873
update tests
Forfold Nov 22, 2023
29b08a8
pr comments.
Forfold Nov 22, 2023
3e808e6
revert
Forfold Nov 22, 2023
b08257b
fix temp sched tests
Forfold Nov 28, 2023
08817af
use wrapper for schedule link instead of determining within component
Forfold Nov 28, 2023
83eb81f
skip on mobile
Forfold Nov 28, 2023
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
95 changes: 0 additions & 95 deletions web/src/app/loading/components/SpinContainer.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion web/src/app/loading/components/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export default function Spinner(props: SpinnerProps): JSX.Element | null {

return (
<div style={style}>
<CircularProgress size={props.text ? '1em' : '40px'} />
<CircularProgress
data-cy='loading-spinner'
size={props.text ? '1em' : '40px'}
/>
&nbsp;<Typography variant='body2'>{props.text}</Typography>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import { gql, useQuery } from 'urql'
import ScheduleCalendar from './ScheduleCalendar'
import { getStartOfWeek, getEndOfWeek } from '../../util/luxon-helpers'
import { getStartOfWeek, getEndOfWeek } from '../util/luxon-helpers'
import { DateTime } from 'luxon'
import { useIsWidthDown } from '../../util/useWidth'
import { GenericError, ObjectNotFound } from '../../error-pages'
import { useCalendarNavigation } from './hooks'
import { useIsWidthDown } from '../util/useWidth'
import { GenericError, ObjectNotFound } from '../error-pages'
import { useCalendarNavigation } from '../util/calendar/hooks'
import Calendar from '../util/calendar/Calendar'

const query = gql`
query scheduleCalendarShifts(
Expand Down Expand Up @@ -104,7 +104,7 @@ function ScheduleCalendarQuery({
return <ObjectNotFound type='schedule' />

return (
<ScheduleCalendar
<Calendar
scheduleID={scheduleID}
loading={fetching}
shifts={data?.schedule?.shifts ?? []}
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/schedules/ScheduleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Edit, Delete } from '@mui/icons-material'
import DetailsPage from '../details/DetailsPage'
import ScheduleEditDialog from './ScheduleEditDialog'
import ScheduleDeleteDialog from './ScheduleDeleteDialog'
import ScheduleCalendarQuery from './calendar/ScheduleCalendarQuery'
import ScheduleCalendarQuery from './ScheduleCalendarQuery'
import { QuerySetFavoriteButton } from '../util/QuerySetFavoriteButton'
import CalendarSubscribeButton from './calendar-subscribe/CalendarSubscribeButton'
import { ObjectNotFound, GenericError } from '../error-pages'
Expand Down
8 changes: 8 additions & 0 deletions web/src/app/users/UserDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import UserDeleteDialog from './UserDeleteDialog'
import { QuerySetFavoriteButton } from '../util/QuerySetFavoriteButton'
import { EscalationPolicyStep } from '../../schema'
import { useIsWidthDown } from '../util/useWidth'
import UserShiftsCalendar from './UserShiftsCalendar'

const userQuery = gql`
query userInfo($id: ID!) {
Expand Down Expand Up @@ -240,6 +241,13 @@ export default function UserDetails(props: {
userID={userID}
readOnly={props.readOnly}
/>
{!mobile && (
<Suspense>
<Grid item xs={12}>
<UserShiftsCalendar userID={userID} />
</Grid>
</Suspense>
)}
</Grid>
}
secondaryActions={options}
Expand Down
30 changes: 16 additions & 14 deletions web/src/app/users/UserNotificationRuleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import UserNotificationRuleDeleteDialog from './UserNotificationRuleDeleteDialog
import { styles as globalStyles } from '../styles/materialStyles'
import UserNotificationRuleCreateDialog from './UserNotificationRuleCreateDialog'
import { useIsWidthDown } from '../util/useWidth'
import { User } from '../../schema'
import { ObjectNotFound, GenericError } from '../error-pages'
import { User } from '../../schema'

const query = gql`
query nrList($id: ID!) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export default function UserNotificationRuleList(props: {
variant='contained'
onClick={() => setShowAddDialog(true)}
startIcon={<Add />}
disabled={user.contactMethods.length === 0}
disabled={user?.contactMethods.length === 0}
>
Add Rule
</Button>
Expand All @@ -91,18 +91,20 @@ export default function UserNotificationRuleList(props: {
/>
<FlatList
data-cy='notification-rules'
items={sortNotificationRules(user.notificationRules).map((nr) => ({
title: formatNotificationRule(nr.delayMinutes, nr.contactMethod),
secondaryAction: props.readOnly ? null : (
<IconButton
aria-label='Delete notification rule'
onClick={() => setDeleteID(nr.id)}
color='secondary'
>
<Delete />
</IconButton>
),
}))}
items={sortNotificationRules(user?.notificationRules ?? []).map(
(nr) => ({
title: formatNotificationRule(nr.delayMinutes, nr.contactMethod),
secondaryAction: props.readOnly ? null : (
<IconButton
aria-label='Delete notification rule'
onClick={() => setDeleteID(nr.id)}
color='secondary'
>
<Delete />
</IconButton>
),
}),
)}
emptyMessage='No notification rules'
/>
</Card>
Expand Down
77 changes: 77 additions & 0 deletions web/src/app/users/UserShiftsCalendar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react'
import { gql, useQuery } from 'urql'
import { getStartOfWeek, getEndOfWeek } from '../util/luxon-helpers'
import { DateTime } from 'luxon'
import { GenericError } from '../error-pages'
import { useCalendarNavigation } from '../util/calendar/hooks'
import Calendar, { Shift } from '../util/calendar/Calendar'
import { OnCallShift, Schedule } from '../../schema'

const query = gql`
query user($id: ID!, $start: ISOTimestamp!, $end: ISOTimestamp!) {
user(id: $id) {
id
assignedSchedules {
id
name
shifts(start: $start, end: $end, userIDs: [$id]) {
start
end
}
}
}
}
`

interface UserShiftsCalendarProps {
userID: string
}

export default function UserShiftsCalendar({
userID,
}: UserShiftsCalendarProps): JSX.Element | null {
const { weekly, start } = useCalendarNavigation()

const queryStart = weekly
? getStartOfWeek(DateTime.fromISO(start)).toISO()
: getStartOfWeek(DateTime.fromISO(start).startOf('month')).toISO()

const queryEnd = weekly
? getEndOfWeek(DateTime.fromISO(start)).toISO()
: getEndOfWeek(DateTime.fromISO(start).endOf('month')).toISO()

const [{ data, error }] = useQuery({
query,
variables: {
id: userID,
start: queryStart,
end: queryEnd,
},
})

if (error) return <GenericError error={error.message} />

function makeCalendarShifts(): OnCallShift[] {
const assignedSchedules: Schedule[] = data?.user?.assignedSchedules ?? []

const s: Shift[] = []
assignedSchedules.forEach((a) => {
a.shifts.forEach((shift) => {
s.push({
userID: shift.userID,
start: shift.start,
end: shift.end,
truncated: shift.truncated,
targetName: a.name,
targetID: a.id,
})
})
})

return s
}

return (
<Calendar loading={false} shifts={makeCalendarShifts()} showScheduleLink />
)
}
Loading