Skip to content

Commit

Permalink
urql: convert remaining schedule files to urql (#3822)
Browse files Browse the repository at this point in the history
* convert to use urql

* remove unused file

* remove extra check and typename

* add suspense false

* add engine trigger in test
  • Loading branch information
KatieMSB committed Apr 26, 2024
1 parent 23fe852 commit c657a15
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 77 deletions.
16 changes: 9 additions & 7 deletions web/src/app/schedules/ScheduleRuleDeleteDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { useMutation } from '@apollo/client'
import { gql, useQuery } from 'urql'
import { gql, useQuery, useMutation } from 'urql'
import FormDialog from '../dialogs/FormDialog'
import { startCase } from 'lodash'
import { GenericError } from '../error-pages'
Expand Down Expand Up @@ -46,9 +45,7 @@ export default function ScheduleRuleDeleteDialog(
variables: { id: props.scheduleID, tgt: props.target },
})

const [deleteRule] = useMutation(mutation, {
onCompleted: props.onClose,
})
const [deleteRuleStatus, deleteRule] = useMutation(mutation)

if (error) {
return <GenericError error={error.message} />
Expand All @@ -64,16 +61,21 @@ export default function ScheduleRuleDeleteDialog(
title={`Remove ${startCase(props.target.type)} From Schedule?`}
subTitle={`This will remove all rules, as well as end any active or future on-call shifts on this schedule for ${props.target.type}: ${data.schedule.target.target.name}.`}
caption='Overrides will not be affected.'
loading={deleteRuleStatus.fetching}
errors={deleteRuleStatus.error ? [deleteRuleStatus.error] : []}
confirm
onSubmit={() => {
deleteRule({
variables: {
deleteRule(
{
input: {
target: props.target,
scheduleID: props.scheduleID,
rules: [],
},
},
{ additionalTypenames: ['Schedule'] },
).then((result) => {
if (!result.error) props.onClose()
})
}}
/>
Expand Down
8 changes: 6 additions & 2 deletions web/src/app/schedules/ScheduleShiftList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql, useQuery } from '@apollo/client'
import { gql, useQuery } from 'urql'
import { GroupAdd } from '@mui/icons-material'
import {
Button,
Expand Down Expand Up @@ -71,6 +71,8 @@ interface ScheduleShiftListProps {
scheduleID: string
}

const context = { suspense: false }

function ScheduleShiftList({
scheduleID,
}: ScheduleShiftListProps): JSX.Element {
Expand Down Expand Up @@ -124,7 +126,9 @@ function ScheduleShiftList({
'duration',
)

const { data } = useQuery(query, {
const [{ data }] = useQuery({
query,
context,
variables: {
id: scheduleID,
start,
Expand Down
61 changes: 0 additions & 61 deletions web/src/app/schedules/ScheduleTZFilter.jsx

This file was deleted.

10 changes: 4 additions & 6 deletions web/src/app/schedules/useOverrideNotices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Notice, TemporarySchedule } from '../../schema'
import { parseInterval, SpanISO } from '../util/shifts'
import { useQuery, gql } from '@apollo/client'
import { useQuery, gql } from 'urql'

const scheduleQuery = gql`
query ($id: ID!) {
Expand All @@ -19,15 +19,13 @@ export default function useOverrideNotices(
scheduleID: string,
value: SpanISO,
): Notice[] {
const { data, loading } = useQuery(scheduleQuery, {
const [{ data }] = useQuery({
query: scheduleQuery,
variables: {
id: scheduleID,
},
pollInterval: 0,
})
if (loading) {
return []
}

const tempSchedules = data?.schedule?.temporarySchedules
const zone = data?.schedule?.timeZone
const valueInterval = parseInterval(value, zone)
Expand Down
2 changes: 1 addition & 1 deletion web/src/cypress/e2e/schedules.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ function testSchedules(screen: ScreenFormat): void {
},
],
}).then(() => {
cy.engineTrigger()
cy.get('[data-cy="route-links"] li').contains('Shifts').click()
cy.reload()
cy.get('[data-cy=flat-list-item-subheader]').should('contain', 'Today')
cy.get('[data-cy=flat-list-item-subheader]').should(
'contain',
Expand Down

0 comments on commit c657a15

Please sign in to comment.