Skip to content

Commit

Permalink
queues. No queue selection as standard inside queues filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 committed Sep 19, 2024
1 parent 921979b commit de466cc
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 87 deletions.
66 changes: 35 additions & 31 deletions components/queueManager/NotManaged/NotManagedCalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const NotManagedCalls: FC<NotManagedCallsProps> = ({ className }): JSX.El
}

const [queueManagerFilter, setQueueManagerFilter]: any = useState([])
const [emptyQueueFilter, setEmptyQueueFilter]: any = useState(false)

const updateQueueManagerFilter = (newQueuesFilter: string[]) => {
setQueueManagerFilter(newQueuesFilter)
setPageNum(1)
Expand All @@ -79,38 +81,40 @@ export const NotManagedCalls: FC<NotManagedCallsProps> = ({ className }): JSX.El
const fetchCalls = async (numHours: number) => {
let selectedQueues = queueManagerFilter

if (isEmpty(selectedQueues)) {
selectedQueues = Object.keys(queueManagerStore.queues)
}

try {
setCallsError('')
setCallsLoaded(false)

const res = await retrieveAndFilterQueueCalls(
pageNum,
textFilter.trim(),
outcomeFilter,
selectedQueues,
numHours,
)

res.rows = res.rows.map((call: any) => {
call.queueId = call.queuename
call.queueName = queueManagerStore.queues[call.queuename]?.name

// queuename attribute name is misleading
delete call.queuename

return call
})
setCalls(res)
setLastUpdated(new Date())
} catch (e) {
console.error(e)
setCallsError(t('Queues.Cannot retrieve calls') || '')
if (!isEmpty(selectedQueues)) {
setEmptyQueueFilter(false)
try {
setCallsError('')
setCallsLoaded(false)

const res = await retrieveAndFilterQueueCalls(
pageNum,
textFilter.trim(),
outcomeFilter,
selectedQueues,
numHours,
)

res.rows = res.rows.map((call: any) => {
call.queueId = call.queuename
call.queueName = queueManagerStore.queues[call.queuename]?.name

// queuename attribute name is misleading
delete call.queuename

return call
})
setCalls(res)
setLastUpdated(new Date())
} catch (e) {
console.error(e)
setCallsError(t('Queues.Cannot retrieve calls') || '')
}
setCallsLoaded(true)
} else {
setCallsLoaded(true)
setEmptyQueueFilter(true)
}
setCallsLoaded(true)
}

// retrieve calls
Expand Down
31 changes: 20 additions & 11 deletions components/queueManager/NotManaged/NotManagedCallsFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ import { ComponentPropsWithRef, forwardRef, useRef } from 'react'
import classNames from 'classnames'
import { TextInput } from '../../common'
import { Fragment, useState, useEffect } from 'react'
import { Dialog, DialogPanel, Disclosure, DisclosureButton, DisclosurePanel, Popover, PopoverButton, PopoverGroup, PopoverPanel, Transition, TransitionChild } from '@headlessui/react'
import {
Dialog,
DialogPanel,
Disclosure,
DisclosureButton,
DisclosurePanel,
Popover,
PopoverButton,
PopoverGroup,
PopoverPanel,
Transition,
TransitionChild,
} from '@headlessui/react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faChevronDown, faCircleXmark, faXmark } from '@fortawesome/free-solid-svg-icons'
import { useSelector } from 'react-redux'
Expand Down Expand Up @@ -97,17 +109,16 @@ export const NotManagedCallsFilter = forwardRef<HTMLButtonElement, NotManagedCal
updateOutcomeFilter(filterValues.outcome)

if (isEmpty(filterValues.selectedQueues)) {
// select all queues
const allQueueCodes = Object.values(queueManagerStore.queues).map((queue: any) => {
return queue.queue
})
// set empty array if no queues are selected
const allQueueCodes: any = []
setSelectedQueues(allQueueCodes)
updateQueueManagerFilter(allQueueCodes)
} else {
// select queues from preferences
setSelectedQueues(filterValues.selectedQueues)
updateQueueManagerFilter(filterValues.selectedQueues)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

// outcome label
Expand All @@ -128,8 +139,8 @@ export const NotManagedCallsFilter = forwardRef<HTMLButtonElement, NotManagedCal
if (!isEmpty(selectedQueues)) {
setQueuesLabel(selectedQueues.join(', '))
} else {
// if no queues are selected, it's equivalent to select all of them
const allQueueCodes = queueManagerFilter.options.map((queue: any) => queue.value)
// if no queues are selected, set label to an empty array
const allQueueCodes: any = []
setQueuesLabel(allQueueCodes.join(', '))
}
}, [selectedQueues, queueManagerFilter.options])
Expand All @@ -142,10 +153,8 @@ export const NotManagedCallsFilter = forwardRef<HTMLButtonElement, NotManagedCal
updateOutcomeFilter(DEFAULT_OUTCOME_FILTER) // notify parent component
savePreference('queuesOutcomeFilter', DEFAULT_OUTCOME_FILTER, auth.username)

// select all queues
const allQueueCodes = Object.values(queueManagerStore.queues).map((queue: any) => {
return queue.queue
})
// deselect all queues
const allQueueCodes: any = []
setSelectedQueues(allQueueCodes)
updateQueueManagerFilter(allQueueCodes)
savePreference('queueManagerSelectedQueues', allQueueCodes, auth.username)
Expand Down
67 changes: 36 additions & 31 deletions components/queues/CallsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const CallsView: FC<CallsViewProps> = ({ className }): JSX.Element => {
}

const [queuesFilter, setQueuesFilter]: any = useState([])
const [emptyQueueFilter, setEmptyQueueFilter]: any = useState(false)

const updateQueuesFilter = (newQueuesFilter: string[]) => {
setQueuesFilter(newQueuesFilter)
setPageNum(1)
Expand All @@ -72,38 +74,41 @@ export const CallsView: FC<CallsViewProps> = ({ className }): JSX.Element => {
const fetchCalls = async (numHours: number) => {
let selectedQueues = queuesFilter

if (isEmpty(selectedQueues)) {
selectedQueues = Object.keys(queuesStore.queues)
}

try {
setCallsError('')
setCallsLoaded(false)

const res = await retrieveAndFilterQueueCalls(
pageNum,
textFilter.trim(),
outcomeFilter,
selectedQueues,
numHours,
)

res.rows = res.rows.map((call: any) => {
call.queueId = call.queuename
call.queueName = queuesStore.queues[call.queuename]?.name

// queuename attribute name is misleading
delete call.queuename

return call
})
setCalls(res)
setLastUpdated(new Date())
} catch (e) {
console.error(e)
setCallsError(t('Queues.Cannot retrieve calls') || '')
//avoid fetching calls if no queues are selected
if (!isEmpty(selectedQueues)) {
setEmptyQueueFilter(false)
try {
setCallsError('')
setCallsLoaded(false)

const res = await retrieveAndFilterQueueCalls(
pageNum,
textFilter.trim(),
outcomeFilter,
selectedQueues,
numHours,
)

res.rows = res.rows.map((call: any) => {
call.queueId = call.queuename
call.queueName = queuesStore.queues[call.queuename]?.name

// queuename attribute name is misleading
delete call.queuename

return call
})
setCalls(res)
setLastUpdated(new Date())
} catch (e) {
console.error(e)
setCallsError(t('Queues.Cannot retrieve calls') || '')
}
setCallsLoaded(true)
} else {
setCallsLoaded(true)
setEmptyQueueFilter(true)
}
setCallsLoaded(true)
}

// retrieve calls
Expand Down
36 changes: 22 additions & 14 deletions components/queues/CallsViewFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ import { ComponentPropsWithRef, forwardRef, useRef } from 'react'
import classNames from 'classnames'
import { TextInput } from '../common'
import { Fragment, useState, useEffect } from 'react'
import { Dialog, DialogPanel, Disclosure, DisclosureButton, DisclosurePanel, Popover, PopoverButton, PopoverGroup, PopoverPanel, Transition, TransitionChild } from '@headlessui/react'
import {
Dialog,
DialogPanel,
Disclosure,
DisclosureButton,
DisclosurePanel,
Popover,
PopoverButton,
PopoverGroup,
PopoverPanel,
Transition,
TransitionChild,
} from '@headlessui/react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faChevronDown, faCircleXmark, faXmark } from '@fortawesome/free-solid-svg-icons'
import { useSelector } from 'react-redux'
Expand Down Expand Up @@ -93,17 +105,16 @@ export const CallsViewFilter = forwardRef<HTMLButtonElement, CallsViewFilterProp
updateOutcomeFilter(filterValues.outcome)

if (isEmpty(filterValues.selectedQueues)) {
// select all queues
const allQueueCodes = Object.values(queuesStore.queues).map((queue: any) => {
return queue.queue
})
// set empty array if no queues are selected
const allQueueCodes: any = []
setSelectedQueues(allQueueCodes)
updateQueuesFilter(allQueueCodes)
} else {
// select queues from preferences
// select queues from preferences
setSelectedQueues(filterValues.selectedQueues)
updateQueuesFilter(filterValues.selectedQueues)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

// outcome label
Expand All @@ -124,8 +135,8 @@ export const CallsViewFilter = forwardRef<HTMLButtonElement, CallsViewFilterProp
if (!isEmpty(selectedQueues)) {
setQueuesLabel(selectedQueues.join(', '))
} else {
// if no queues are selected, it's equivalent to select all of them
const allQueueCodes = queuesFilter.options.map((queue: any) => queue.value)
// if no queues are selected, set label to an empty array
const allQueueCodes: any = []
setQueuesLabel(allQueueCodes.join(', '))
}
}, [selectedQueues, queuesFilter.options])
Expand All @@ -137,11 +148,8 @@ export const CallsViewFilter = forwardRef<HTMLButtonElement, CallsViewFilterProp
setOutcome(DEFAULT_OUTCOME_FILTER)
updateOutcomeFilter(DEFAULT_OUTCOME_FILTER) // notify parent component
savePreference('queuesOutcomeFilter', DEFAULT_OUTCOME_FILTER, auth.username)

// select all queues
const allQueueCodes = Object.values(queuesStore.queues).map((queue: any) => {
return queue.queue
})
// deselect all queues
const allQueueCodes: any = []
setSelectedQueues(allQueueCodes)
updateQueuesFilter(allQueueCodes)
savePreference('queuesSelectedQueues', allQueueCodes, auth.username)
Expand Down Expand Up @@ -335,7 +343,7 @@ export const CallsViewFilter = forwardRef<HTMLButtonElement, CallsViewFilterProp
<div className='flex items-center'>
<div className='flex items-center'>
<TextInput
placeholder={t('Queues.Filter calls') || ""}
placeholder={t('Queues.Filter calls') || ''}
className='max-w-sm'
value={textFilter}
onChange={changeTextFilter}
Expand Down

0 comments on commit de466cc

Please sign in to comment.