-
Notifications
You must be signed in to change notification settings - Fork 60
fix(widgets): fixed-consult-transfer-popover-epic-bugs #548
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,6 +612,28 @@ export const filterAvailableAgents = (agents: BuddyDetails[], logger?): BuddyDet | |
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Filters buddy agents by a free-text query across name, dn and id. | ||
| */ | ||
| export const filterAgentsByQuery = (agents: BuddyDetails[], query: string): BuddyDetails[] => { | ||
| const searchTerm = (query ?? '').trim().toLowerCase(); | ||
| if (!searchTerm) return agents ?? []; | ||
| return (agents ?? []).filter((agent) => | ||
| `${agent.agentName ?? ''}|${(agent as {dn?: string}).dn ?? ''}|${agent.agentId ?? ''}` | ||
| .toLowerCase() | ||
| .includes(searchTerm) | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Returns agents to display for current category, applying search only for Agents tab, since other tabs support via the SDK | ||
| */ | ||
| export const getAgentsForDisplay = ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason these 2 methods exist separately is because for the other tabs we have paginated lists and hence search was done in SDK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is alright for now but we can brainstorm and see how we can fit this in the SDK later. |
||
| selectedCategory: 'Agents' | string, | ||
| agents: BuddyDetails[], | ||
| query: string | ||
| ): BuddyDetails[] => (selectedCategory === 'Agents' ? filterAgentsByQuery(agents, query) : agents || []); | ||
|
|
||
| /** | ||
| * Filters available queues | ||
| */ | ||
|
|
@@ -655,3 +677,36 @@ export const debounce = <T extends (...args: unknown[]) => unknown>( | |
| }; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Helpers for Dial Number / Entry Point manual actions | ||
| */ | ||
| export const shouldAddConsultTransferAction = ( | ||
| selectedCategory: string, | ||
| isEntryPointTabVisible: boolean, | ||
| query: string, | ||
| entryPoints: {id: string; name: string}[], | ||
| onDialNumberSelect: ((dialNumber: string) => void) | undefined, | ||
| onEntryPointSelect: ((entryPointId: string, entryPointName: string) => void) | undefined | ||
| ): {visible: boolean; onClick?: () => void; title?: string} => { | ||
| const DN_REGEX = new RegExp('^[+1][0-9]{3,18}$|^[*#:][+1][0-9*#:]{3,18}$|^[0-9*#:]{3,18}$'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The validation here follows the same logic we have in agent desktop. |
||
|
|
||
| const isDial = selectedCategory === 'Dial Number'; | ||
| const isEntry = selectedCategory === 'Entry Point' && isEntryPointTabVisible; | ||
| const valid = DN_REGEX.test(query || ''); | ||
|
|
||
| if (isDial) { | ||
| return valid && onDialNumberSelect | ||
| ? {visible: true, onClick: () => onDialNumberSelect(query), title: query} | ||
| : {visible: false}; | ||
| } | ||
|
|
||
| if (isEntry) { | ||
| const match = query ? entryPoints?.find((e) => e.name === query || e.id === query) : null; | ||
| return valid && match && onEntryPointSelect | ||
| ? {visible: true, onClick: () => onEntryPointSelect(match.id, match.name), title: match.name} | ||
| : {visible: false}; | ||
| } | ||
|
|
||
| return {visible: false}; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added custom utils here so our presentational layer is not cluttered.
I've tried to optimise it as much as posisble with cursors's help.
Followed a similar logic to what I found in agent desktop.