Skip to content

Commit

Permalink
ui/service: convert ServiceOnCallList to typescript (#3512)
Browse files Browse the repository at this point in the history
* use urql

* conver to typescript
  • Loading branch information
KatieMSB authored Dec 11, 2023
1 parent fb38017 commit c9fa58f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
2 changes: 1 addition & 1 deletion web/src/app/lists/FlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export interface FlatListItem extends ListItemProps {

export interface SectionTitle {
title: string
icon?: JSX.Element | null
icon?: React.ReactNode | null
subText?: JSX.Element | string
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react'
import { gql, useQuery } from '@apollo/client'
import { PropTypes as p } from 'prop-types'
import { gql, useQuery } from 'urql'
import Card from '@mui/material/Card'
import CardHeader from '@mui/material/CardHeader'
import { UserAvatar } from '../util/avatars'
import { CircularProgress } from '@mui/material'
import makeStyles from '@mui/styles/makeStyles'
import { styles as globalStyles } from '../styles/materialStyles'
import FlatList from '../lists/FlatList'
import FlatList, { SectionTitle } from '../lists/FlatList'
import { Error } from '@mui/icons-material'
import _ from 'lodash'
import { Warning } from '../icons'
import { Theme } from '@mui/material'

const useStyles = makeStyles((theme) => {
const useStyles = makeStyles((theme: Theme) => {
const { cardHeader } = globalStyles(theme)

return {
Expand Down Expand Up @@ -43,49 +42,38 @@ const query = gql`
}
`

const stepText = (s) => {
const stepText = (s: number): string => {
return `Step #${s + 1}`
}
const stepLengthText = (s) => {
const stepLengthText = (s: number): string => {
if (s > 0) {
if (s === 1) {
return `${s + 1} user assigned`
return `${s} user assigned`
}
return `${s + 1} users assigned`
return `${s} users assigned`
}
return 'No users assigned'
}
export default function ServiceOnCallList({ serviceID }) {
export default function ServiceOnCallList({
serviceID,
}: {
serviceID: string
}): React.ReactNode {
const classes = useStyles()
const { data, loading, error } = useQuery(query, {
const [{ data, error }] = useQuery({
query,
variables: { id: serviceID },
})

let items = []
let sections = []
const style = {}
let sections: SectionTitle[] = []
if (error) {
items = [
{
title: 'Error: ' + error.message,
icon: <Error />,
},
]
style.color = 'gray'
} else if (!data && loading) {
items = [
{
title: 'Fetching users...',
icon: <CircularProgress />,
},
]
style.color = 'gray'
sections = [
{
title: 'Fetching users...',
icon: <CircularProgress />,
},
]
} else {
const chainedSteps = _.chain(data?.service?.escalationPolicy?.steps)
const sortedItems = _.chain(data?.service?.onCallUsers)
Expand Down Expand Up @@ -131,6 +119,3 @@ export default function ServiceOnCallList({ serviceID }) {
</Card>
)
}
ServiceOnCallList.propTypes = {
serviceID: p.string.isRequired,
}

0 comments on commit c9fa58f

Please sign in to comment.