Skip to content

Commit

Permalink
Merge branch 'master' into normalize-public-url
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercactapus committed Jan 25, 2024
2 parents dae2229 + ba9df2d commit ed35796
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 58 deletions.
3 changes: 3 additions & 0 deletions app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ func getConfig(ctx context.Context) (Config, error) {
if err != nil {
return cfg, errors.Wrap(err, "parse public url")
}
if u.Scheme == "" {
return cfg, errors.New("public-url must be an absolute URL (missing scheme)")
}
u.Path = strings.TrimSuffix(u.Path, "/")
cfg.PublicURL = u.String()
if cfg.HTTPPrefix != "" {
Expand Down
4 changes: 3 additions & 1 deletion test/integration/schedules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ test('local time hover', async ({ page, isMobile }) => {

// should display schedule tz on hover
await page.hover(`span:has-text("CST")`) // local TZ is configured to CST
await expect(page.locator('div[role=tooltip]')).toContainText('GMT')
await expect(page.locator('[data-testid="shift-tooltip"]')).toContainText(
'GMT',
)
})
27 changes: 12 additions & 15 deletions web/src/app/schedules/ScheduleCreateDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState } from 'react'
import { useMutation } from '@apollo/client'
import { gql } from 'urql'
import { gql, useMutation } from 'urql'
import FormDialog from '../dialogs/FormDialog'
import ScheduleForm, { Value } from './ScheduleForm'
import { nonFieldErrors, fieldErrors } from '../util/errutil'
Expand All @@ -27,7 +26,7 @@ export default function ScheduleCreateDialog(props: {
favorite: true,
})

const [createSchedule, { loading, data, error }] = useMutation(mutation)
const [{ fetching, data, error }, commit] = useMutation(mutation)

if (data && data.createSchedule) {
return <Redirect to={`/schedules/${data.createSchedule.id}`} />
Expand All @@ -39,23 +38,21 @@ export default function ScheduleCreateDialog(props: {
title='Create New Schedule'
errors={nonFieldErrors(error)}
onSubmit={() =>
createSchedule({
variables: {
input: {
...value,
targets: [
{
target: { type: 'user', id: '__current_user' },
rules: [{}],
},
],
},
commit({
input: {
...value,
targets: [
{
target: { type: 'user', id: '__current_user' },
rules: [{}],
},
],
},
})
}
form={
<ScheduleForm
disabled={loading}
disabled={fetching}
errors={fieldErrors(error)}
value={value}
onChange={(value: Value) => setValue(value)}
Expand Down
31 changes: 17 additions & 14 deletions web/src/app/schedules/ScheduleDeleteDialog.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 { useQuery, gql } from 'urql'
import { gql, useQuery, useMutation } from 'urql'
import { get } from 'lodash'
import FormDialog from '../dialogs/FormDialog'
import Spinner from '../loading/components/Spinner'
Expand All @@ -13,6 +12,7 @@ const query = gql`
}
}
`

const mutation = gql`
mutation delete($input: [TargetInput!]!) {
deleteAll(input: $input)
Expand All @@ -28,16 +28,7 @@ export default function ScheduleDeleteDialog(props: {
variables: { id: props.scheduleID },
})

const [deleteSchedule, deleteScheduleStatus] = useMutation(mutation, {
variables: {
input: [
{
type: 'schedule',
id: props.scheduleID,
},
],
},
})
const [deleteScheduleStatus, commit] = useMutation(mutation)

if (!data && fetching) return <Spinner />

Expand All @@ -47,10 +38,22 @@ export default function ScheduleDeleteDialog(props: {
confirm
subTitle={`This will delete the schedule: ${get(data, 'schedule.name')}`}
caption='Deleting a schedule will also delete all associated rules and overrides.'
loading={deleteScheduleStatus.loading}
loading={deleteScheduleStatus.fetching}
errors={deleteScheduleStatus.error ? [deleteScheduleStatus.error] : []}
onClose={props.onClose}
onSubmit={() => deleteSchedule()}
onSubmit={() =>
commit(
{
input: [
{
type: 'schedule',
id: props.scheduleID,
},
],
},
{ additionalTypenames: ['Schedule'] },
)
}
/>
)
}
1 change: 1 addition & 0 deletions web/src/app/schedules/ScheduleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const query = gql`
name
description
}
query scheduleDetailsQuery($id: ID!) {
schedule(id: $id) {
...ScheduleTitleQuery
Expand Down
29 changes: 17 additions & 12 deletions web/src/app/schedules/ScheduleOverrideCreateDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react'
import { gql, useMutation } from '@apollo/client'
import { gql, useMutation } from 'urql'
import FormDialog from '../dialogs/FormDialog'
import { DateTime } from 'luxon'
import ScheduleOverrideForm from './ScheduleOverrideForm'
Expand Down Expand Up @@ -55,6 +55,7 @@ const mutation = gql`
}
}
`

export default function ScheduleOverrideCreateDialog({
scheduleID,
variant,
Expand All @@ -70,15 +71,7 @@ export default function ScheduleOverrideCreateDialog({

const notices = useOverrideNotices(scheduleID, value)

const [mutate, { loading, error }] = useMutation(mutation, {
variables: {
input: {
...value,
scheduleID,
},
},
onCompleted: onClose,
})
const [{ fetching, error }, commit] = useMutation(mutation)

return (
<FormDialog
Expand All @@ -87,13 +80,25 @@ export default function ScheduleOverrideCreateDialog({
subTitle={variantDetails[variant].desc}
errors={nonFieldErrors(error)}
notices={notices} // create and edit dialog
onSubmit={() => mutate()}
onSubmit={() =>
commit(
{
input: {
...value,
scheduleID,
},
},
{ additionalTypenames: ['UserOverrideConnection', 'Schedule'] },
).then((result) => {
if (!result.error) onClose()
})
}
form={
<ScheduleOverrideForm
add={variant !== 'remove'}
remove={variant !== 'add'}
scheduleID={scheduleID}
disabled={loading}
disabled={fetching}
errors={fieldErrors(error)}
value={value}
onChange={(newValue) => setValue(newValue)}
Expand Down
31 changes: 18 additions & 13 deletions web/src/app/schedules/ScheduleOverrideDialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useEffect, useState } from 'react'
import { gql, useMutation } from '@apollo/client'
import { gql, useMutation } from 'urql'
import p from 'prop-types'
import FormDialog from '../dialogs/FormDialog'
import { DateTime } from 'luxon'
Expand Down Expand Up @@ -32,6 +32,7 @@ const useStyles = makeStyles({
marginTop: '.3rem',
},
})

export default function ScheduleOverrideDialog(props) {
const { variantOptions = ['replace', 'remove', 'add', 'temp'] } = props
const classes = useStyles()
Expand All @@ -53,15 +54,7 @@ export default function ScheduleOverrideDialog(props) {

const notices = useOverrideNotices(props.scheduleID, value)

const [mutate, { loading, error }] = useMutation(mutation, {
variables: {
input: {
...value,
scheduleID: props.scheduleID,
},
},
onCompleted: props.onClose,
})
const [{ fetching, error }, commit] = useMutation(mutation)

useEffect(() => {
setFieldErrors(getFieldErrors(error))
Expand Down Expand Up @@ -93,7 +86,7 @@ export default function ScheduleOverrideDialog(props) {
}
errors={nonFieldErrors(error)}
notices={step === 0 ? [] : notices} // create and edit dialog
loading={loading}
loading={fetching}
form={
<React.Fragment>
{/* Step 0: Choose override variant page */}
Expand Down Expand Up @@ -131,7 +124,7 @@ export default function ScheduleOverrideDialog(props) {
add={activeVariant !== 'remove'}
remove={activeVariant !== 'add'}
scheduleID={props.scheduleID}
disabled={loading}
disabled={fetching}
errors={fieldErrors}
value={value}
onChange={(newValue) => setValue(newValue)}
Expand All @@ -140,7 +133,19 @@ export default function ScheduleOverrideDialog(props) {
)}
</React.Fragment>
}
onSubmit={() => mutate()}
onSubmit={() =>
commit(
{
input: {
...value,
scheduleID: props.scheduleID,
},
},
{ additionalTypenames: ['UserOverrideConnection', 'Schedule'] },
).then((result) => {
if (!result.error) props.onClose()
})
}
onNext={step < 1 ? onNext : null}
/>
)
Expand Down
3 changes: 1 addition & 2 deletions web/src/app/schedules/ScheduleOverrideList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Suspense, useCallback, useState } from 'react'
import { Button, Grid, FormControlLabel, Switch, Tooltip } from '@mui/material'
import { GroupAdd } from '@mui/icons-material'
import { DateTime } from 'luxon'
import { gql } from '@apollo/client'
import { gql } from 'urql'
import QueryList from '../lists/QueryList'
import { UserAvatar } from '../util/avatars'
import OtherActions from '../util/OtherActions'
Expand All @@ -20,7 +20,6 @@ import { defaultTempSchedValue } from './temp-sched/sharedUtils'
import ScheduleOverrideDialog from './ScheduleOverrideDialog'
import CreateFAB from '../lists/CreateFAB'

// the query name `scheduleOverrides` is used for refetch queries
const query = gql`
query scheduleOverrides($input: UserOverrideSearchOptions) {
userOverrides(input: $input) {
Expand Down
9 changes: 8 additions & 1 deletion web/src/app/schedules/ScheduleShiftList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ function ScheduleShiftList({
const scheduleTZDetails = `Active after ${schedStartTime} ${tzAbbr}`
const localTZDetails = `Active after ${localStartTime} ${localTzAbbr}`
return (
<Tooltip title={scheduleTZDetails} placement='right'>
<Tooltip
title={scheduleTZDetails}
placement='right'
PopperProps={{
// @ts-expect-error test id
'data-testid': 'shift-tooltip',
}}
>
<span>{localTZDetails}</span>
</Tooltip>
)
Expand Down

0 comments on commit ed35796

Please sign in to comment.