Skip to content

Commit

Permalink
361 display csa name (#365)
Browse files Browse the repository at this point in the history
* Moved common elements to analytics module

* Updated base elements and stylings, added and updated missing queries

* updated view button logic

* Updated SQL to fetch coversations, updated page to display conversation that been taken
  • Loading branch information
ExiRain authored Jan 4, 2025
1 parent d43516f commit 0f365ed
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 38 deletions.
91 changes: 56 additions & 35 deletions DSL/Resql/feedback-chats-with-negative-feedback.sql
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
WITH n_chats AS (
SELECT
SELECT
base_id,
MAX(created) AS created
FROM chat
WHERE STATUS = 'ENDED'
AND created::date BETWEEN :start::date AND :end::date
AND feedback_rating IS NOT NULL
AND feedback_rating <= 5
GROUP BY base_id
),
c_chat AS (
SELECT
base_id,
MAX(created) AS created
FROM chat
WHERE STATUS = 'ENDED'
AND created::date BETWEEN :start::date AND :end::date
AND feedback_rating IS NOT NULL
AND feedback_rating <= 5
GROUP BY base_id
),
c_chat AS (
SELECT base_id,
MIN(created) AS created,
MAX(ended) AS ended
FROM chat
GROUP BY base_id
)
SELECT n_chats.base_id,
c_chat.created,
c_chat.ended,
chat.feedback_rating AS rating,
chat.feedback_text AS feedback,
CEIL(COUNT(*) OVER() / :page_size::DECIMAL) AS total_pages
FROM chat
GROUP BY base_id
),
deduplicated_users AS (
SELECT
id_code,
first_name,
last_name
FROM (
SELECT
id_code,
first_name,
last_name,
ROW_NUMBER() OVER (PARTITION BY id_code ORDER BY first_name, last_name) AS row_num
FROM "user"
) AS ranked_users
WHERE row_num = 1
)
SELECT
n_chats.base_id,
c_chat.created,
c_chat.ended,
chat.feedback_rating AS rating,
chat.feedback_text AS feedback,
deduplicated_users.first_name AS first_name,
deduplicated_users.last_name AS last_name,
CEIL(COUNT(*) OVER() / :page_size::DECIMAL) AS total_pages
FROM n_chats
LEFT JOIN chat ON n_chats.base_id = chat.base_id
JOIN c_chat ON c_chat.base_id = chat.base_id AND n_chats.created = chat.created
LEFT JOIN chat ON n_chats.base_id = chat.base_id
LEFT JOIN c_chat ON c_chat.base_id = chat.base_id AND n_chats.created = chat.created
LEFT JOIN deduplicated_users ON chat.customer_support_id = deduplicated_users.id_code
WHERE chat.feedback_rating IS NOT NULL
AND chat.ended IS NOT NULL
ORDER BY
CASE WHEN :sorting = 'created desc' THEN n_chats.created END DESC,
CASE WHEN :sorting = 'created asc' THEN n_chats.created END ASC,
CASE WHEN :sorting = 'ended desc' THEN n_chats.created END DESC,
CASE WHEN :sorting = 'ended asc' THEN n_chats.created END ASC,
CASE WHEN :sorting = 'base_id desc' THEN n_chats.base_id END DESC,
CASE WHEN :sorting = 'base_id asc' THEN n_chats.base_id END ASC,
CASE WHEN :sorting = 'feedback desc' THEN feedback_text END DESC,
CASE WHEN :sorting = 'feedback asc' THEN feedback_text END ASC,
CASE WHEN :sorting = 'rating desc' THEN feedback_rating END DESC,
CASE WHEN :sorting = 'rating asc' THEN feedback_rating END ASC
OFFSET ((GREATEST(:page, 1) - 1) * :page_size) LIMIT :page_size;
AND chat.ended IS NOT NULL
ORDER BY
CASE WHEN :sorting = 'created desc' THEN n_chats.created END DESC,
CASE WHEN :sorting = 'created asc' THEN n_chats.created END ASC,
CASE WHEN :sorting = 'ended desc' THEN n_chats.created END DESC,
CASE WHEN :sorting = 'ended asc' THEN n_chats.created END ASC,
CASE WHEN :sorting = 'base_id desc' THEN n_chats.base_id END DESC,
CASE WHEN :sorting = 'base_id asc' THEN n_chats.base_id END ASC,
CASE WHEN :sorting = 'feedback desc' THEN feedback_text END DESC,
CASE WHEN :sorting = 'feedback asc' THEN feedback_text END ASC,
CASE WHEN :sorting = 'rating desc' THEN feedback_rating END DESC,
CASE WHEN :sorting = 'rating asc' THEN feedback_rating END ASC
OFFSET ((GREATEST(:page, 1) - 1) * :page_size)
LIMIT :page_size;
15 changes: 12 additions & 3 deletions GUI/src/components/ChatsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {CellContext, createColumnHelper, PaginationState, SortingState} from '@t
import React, {useEffect, useMemo, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {MdOutlineRemoveRedEye} from 'react-icons/md';
import {Chat} from '../../types/chat';
import {BACKOFFICE_NAME, Chat} from '../../types/chat';
import {formatDate} from '../../util/charts-utils';
import Button from '../Button';
import Card from '../Card';
Expand All @@ -28,7 +28,8 @@ type Props = {
const ChatsTable = (props: Props) => {
const [chats, setChats] = useState<Chat[]>([]);
const [selectedChat, setSelectedChat] = useState<Chat | null>(null);
const columnHelper = createColumnHelper<Chat>();
type CombinedRow = Chat & { firstName?: string; lastName?: string };
const columnHelper = createColumnHelper<CombinedRow>();
const {t} = useTranslation();

useEffect(() => {
Expand Down Expand Up @@ -69,6 +70,13 @@ const ChatsTable = (props: Props) => {
columnHelper.accessor('baseId', {
header: 'ID',
}),
columnHelper.accessor(
(row) => row.firstName ?`${row.firstName ?? ''} ${row.lastName ?? ''}` : BACKOFFICE_NAME.DEFAULT,
{
id: `name`,
header: t('chat.history.csaName') ?? '',
}
),
columnHelper.accessor('feedback', {
header: t('feedback.comment') ?? '',
}),
Expand Down Expand Up @@ -125,7 +133,8 @@ const ChatsTable = (props: Props) => {
<HistoricalChat
header_link={selectedChat.endUserUrl}
chat={selectedChat}
trigger={true}/>
trigger={true}
/>
</Drawer>
</div>
)}
Expand Down
26 changes: 26 additions & 0 deletions GUI/src/types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ROLES } from 'utils/constants';

export interface User {
login?: string;
fullName?: string;
firstName: string;
lastName: string;
idCode: string;
displayName: string;
csaTitle: string;
csaEmail: string;
authorities: ROLES[];
customerSupportStatus: 'online' | 'idle' | 'offline';
}

export interface UserDTO extends Pick<User, 'login' | 'firstName' | 'lastName' | 'fullName' | 'idCode' | 'authorities' | 'displayName' | 'csaTitle' | 'csaEmail'> {
}

export interface UserSearchFilters {
search_full_name: string;
search_id_code: string;
search_display_name: string;
search_csa_title: string;
search_csa_email: string;
search_authority: string;
}

0 comments on commit 0f365ed

Please sign in to comment.