forked from buerokratt/Buerokratt-Chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1068 Displaying chats for deletion (buerokratt#1069)
* Added updated SQL to display proper chats. * Refactored initial form with dates, to display. * Added new dsl, updated GUI, added new component
- Loading branch information
Showing
9 changed files
with
873 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
WITH ChatsToDelete AS ( | ||
SELECT COUNT(*) AS total_count | ||
FROM chat c | ||
WHERE c.ended IS NOT NULL | ||
AND c.status = 'ENDED' | ||
AND ( | ||
(end_user_id IS NOT NULL AND end_user_id <> '' AND ended::date <= :auth_date::date) | ||
OR | ||
(end_user_id IS NULL OR end_user_id = '' AND ended::date <= :anon_date::date) | ||
) | ||
AND EXISTS ( | ||
SELECT 1 | ||
FROM message m | ||
WHERE m.chat_base_id = c.base_id | ||
AND m.content IS NOT NULL | ||
AND m.content <> '' | ||
) | ||
) | ||
SELECT total_count | ||
FROM ChatsToDelete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
WITH MaxChatHistoryComments AS ( | ||
SELECT MAX(id) AS maxId | ||
FROM chat_history_comments | ||
GROUP BY chat_id | ||
), | ||
ChatHistoryComments AS ( | ||
SELECT comment, chat_id | ||
FROM chat_history_comments | ||
JOIN MaxChatHistoryComments ON id = maxId | ||
), | ||
MessageWithContent AS ( | ||
SELECT | ||
MAX(id) AS maxId, | ||
MIN(id) AS minId | ||
FROM message | ||
WHERE content <> '' | ||
AND content <> 'message-read' | ||
GROUP BY chat_base_id | ||
), | ||
FirstContentMessage AS ( | ||
SELECT created, chat_base_id | ||
FROM message | ||
JOIN MessageWithContent ON message.id = MessageWithContent.minId | ||
), | ||
LastContentMessage AS ( | ||
SELECT content, chat_base_id | ||
FROM message | ||
JOIN MessageWithContent ON message.id = MessageWithContent.maxId | ||
), | ||
TitleVisibility AS ( | ||
SELECT value | ||
FROM configuration | ||
WHERE key = 'is_csa_title_visible' | ||
AND NOT deleted | ||
ORDER BY id DESC | ||
LIMIT 1 | ||
), | ||
FulfilledMessages AS ( | ||
SELECT MAX(id) AS maxId | ||
FROM message | ||
WHERE event = 'contact-information-fulfilled' | ||
GROUP BY chat_base_id | ||
), | ||
ContactsMessage AS ( | ||
SELECT chat_base_id, content | ||
FROM message | ||
JOIN FulfilledMessages ON id = maxId | ||
), | ||
MaxMessages AS ( | ||
SELECT MAX(id) AS maxId | ||
FROM message | ||
GROUP BY chat_base_id | ||
), | ||
Messages AS ( | ||
SELECT event, updated, chat_base_id | ||
FROM message | ||
JOIN MaxMessages ON id = maxID | ||
), | ||
MaxChats AS ( | ||
SELECT MAX(id) AS maxId | ||
FROM chat | ||
WHERE ended IS NOT NULL | ||
AND status <> 'IDLE' | ||
AND ( | ||
(end_user_id IS NOT NULL AND end_user_id <> '' AND ended::date <= :auth_date::date) | ||
OR | ||
(end_user_id IS NULL OR end_user_id = '' AND ended::date <= :anon_date::date) | ||
) | ||
GROUP BY base_id | ||
), | ||
EndedChatMessages AS ( | ||
SELECT | ||
base_id, | ||
customer_support_id, | ||
customer_support_display_name, | ||
csa_title, | ||
end_user_id, | ||
end_user_first_name, | ||
end_user_last_name, | ||
end_user_email, | ||
end_user_phone, | ||
end_user_os, | ||
end_user_url, | ||
status, | ||
updated, | ||
ended, | ||
forwarded_to_name, | ||
received_from, | ||
labels, | ||
created, | ||
feedback_text, | ||
feedback_rating | ||
FROM chat | ||
RIGHT JOIN MaxChats ON id = maxId | ||
), | ||
RatedChats AS ( | ||
SELECT MAX(feedback_rating) AS rating | ||
FROM chat | ||
WHERE feedback_rating IS NOT NULL | ||
GROUP BY base_id | ||
), | ||
RatedChatsCount AS ( | ||
SELECT COUNT(rating) AS total FROM RatedChats | ||
), | ||
Promoters AS ( | ||
SELECT COUNT(rating) AS p FROM RatedChats WHERE rating >= 9 | ||
), | ||
Detractors AS ( | ||
SELECT COUNT(rating) AS d FROM RatedChats WHERE rating <= 6 | ||
), | ||
NPS AS ( | ||
SELECT ROUND(((p / (GREATEST(total, 1) * 1.0)) - (d / (GREATEST(total, 1) * 1.0))) * 100.0, 2) AS nps | ||
FROM RatedChatsCount | ||
CROSS JOIN Promoters | ||
CROSS JOIN Detractors | ||
) | ||
SELECT c.base_id AS id, | ||
c.customer_support_id, | ||
c.customer_support_display_name, | ||
(CASE WHEN TitleVisibility.value = 'true' THEN c.csa_title ELSE '' END) AS csa_title, | ||
c.end_user_id, | ||
c.end_user_first_name, | ||
c.end_user_last_name, | ||
c.end_user_email, | ||
c.end_user_phone, | ||
c.end_user_os, | ||
c.end_user_url, | ||
c.status, | ||
FirstContentMessage.created, | ||
c.updated, | ||
c.ended, | ||
c.forwarded_to_name, | ||
c.received_from, | ||
c.labels, | ||
s.comment, | ||
LastContentMessage.content AS last_message, | ||
(CASE WHEN m.event = '' THEN NULL ELSE LOWER(m.event) END) AS last_message_event, | ||
ContactsMessage.content AS contacts_message, | ||
m.updated AS last_message_timestamp, | ||
c.feedback_text, | ||
c.feedback_rating, | ||
nps, | ||
CEIL(COUNT(*) OVER() / :page_size::DECIMAL) AS total_pages | ||
FROM EndedChatMessages AS c | ||
JOIN Messages AS m ON c.base_id = m.chat_base_id | ||
LEFT JOIN ChatHistoryComments AS s ON s.chat_id = m.chat_base_id | ||
JOIN LastContentMessage ON c.base_id = LastContentMessage.chat_base_id | ||
JOIN FirstContentMessage ON c.base_id = FirstContentMessage.chat_base_id | ||
LEFT JOIN ContactsMessage ON ContactsMessage.chat_base_id = c.base_id | ||
CROSS JOIN TitleVisibility | ||
CROSS JOIN NPS | ||
WHERE ( | ||
:search IS NULL OR | ||
:search = '' OR | ||
LOWER(c.customer_support_display_name) LIKE LOWER('%' || :search || '%') OR | ||
LOWER(c.end_user_first_name) LIKE LOWER('%' || :search || '%') OR | ||
LOWER(ContactsMessage.content) LIKE LOWER('%' || :search || '%') OR | ||
LOWER(s.comment) LIKE LOWER('%' || :search || '%') OR | ||
LOWER(c.status) LIKE LOWER('%' || :search || '%') OR | ||
LOWER(m.event) LIKE LOWER('%' || :search || '%') OR | ||
LOWER(c.base_id) LIKE LOWER('%' || :search || '%') OR | ||
TO_CHAR(FirstContentMessage.created, 'DD.MM.YYYY HH24:MI:SS') LIKE '%' || :search || '%' OR | ||
TO_CHAR(c.ended, 'DD.MM.YYYY HH24:MI:SS') LIKE '%' || :search || '%' OR | ||
EXISTS ( | ||
SELECT 1 | ||
FROM message AS msg | ||
WHERE msg.chat_base_id = c.base_id | ||
AND LOWER(msg.content) LIKE LOWER('%' || :search || '%') | ||
) | ||
) | ||
ORDER BY | ||
CASE WHEN :sorting = 'created asc' THEN FirstContentMessage.created END ASC, | ||
CASE WHEN :sorting = 'created desc' THEN FirstContentMessage.created END DESC, | ||
CASE WHEN :sorting = 'ended asc' THEN c.ended END ASC, | ||
CASE WHEN :sorting = 'ended desc' THEN c.ended END DESC, | ||
CASE WHEN :sorting = 'customerSupportDisplayName asc' THEN c.customer_support_display_name END ASC, | ||
CASE WHEN :sorting = 'customerSupportDisplayName desc' THEN c.customer_support_display_name END DESC, | ||
CASE WHEN :sorting = 'endUserName asc' THEN c.end_user_first_name END ASC, | ||
CASE WHEN :sorting = 'endUserName desc' THEN c.end_user_first_name END DESC, | ||
CASE WHEN :sorting = 'endUserId asc' THEN c.end_user_id END ASC, | ||
CASE WHEN :sorting = 'endUserId desc' THEN c.end_user_id END desc, | ||
CASE WHEN :sorting = 'contactsMessage asc' THEN ContactsMessage.content END ASC, | ||
CASE WHEN :sorting = 'contactsMessage desc' THEN ContactsMessage.content END DESC, | ||
CASE WHEN :sorting = 'comment asc' THEN s.comment END ASC, | ||
CASE WHEN :sorting = 'comment desc' THEN s.comment END DESC, | ||
CASE WHEN :sorting = 'labels asc' THEN c.labels END ASC, | ||
CASE WHEN :sorting = 'labels desc' THEN c.labels END DESC, | ||
CASE WHEN :sorting = 'status asc' THEN c.status END ASC, | ||
CASE WHEN :sorting = 'status desc' THEN c.status END DESC, | ||
CASE WHEN :sorting = 'id asc' THEN c.base_id END ASC, | ||
CASE WHEN :sorting = 'id desc' THEN c.base_id END DESC | ||
OFFSET ((GREATEST(:page, 1) - 1) * :page_size) LIMIT :page_size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
declaration: | ||
call: declare | ||
version: 0.1 | ||
description: "Decription placeholder for 'ENDED-CHATS'" | ||
method: post | ||
accepts: json | ||
returns: json | ||
namespace: backoffice | ||
allowlist: | ||
body: | ||
- field: endDate | ||
type: string | ||
description: "Body field 'endDate'" | ||
- field: startDate | ||
type: string | ||
description: "Body field 'startDate'" | ||
- field: page | ||
type: number | ||
description: "Body field 'page'" | ||
- field: page_size | ||
type: number | ||
description: "Body field 'page_size'" | ||
- field: sorting | ||
type: string | ||
description: "Body field 'sorting'" | ||
- field: search | ||
type: string | ||
description: "Body field 'search'" | ||
|
||
extractRequestData: | ||
assign: | ||
startDate: "${incoming.body.startDate}" | ||
endDate: "${incoming.body.endDate}" | ||
|
||
getEndedChats: | ||
call: http.post | ||
args: | ||
url: "[#CHATBOT_RESQL]/get-chats-to-be-removed" | ||
body: | ||
auth_date: ${startDate} | ||
anon_date: ${endDate} | ||
page: ${incoming.body.page} | ||
page_size: ${incoming.body.page_size} | ||
sorting: ${incoming.body.sorting} | ||
search: ${incoming.body.search} | ||
result: res | ||
|
||
returnSuccess: | ||
return: ${res.response.body} | ||
next: end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
declaration: | ||
call: declare | ||
version: 0.1 | ||
description: "Decription placeholder for 'ENDED-CHATS-COUNT'" | ||
method: post | ||
accepts: json | ||
returns: json | ||
namespace: backoffice | ||
allowlist: | ||
body: | ||
- field: authDate | ||
type: string | ||
description: "Body field 'authDate'" | ||
- field: anonDate | ||
type: string | ||
description: "Body field 'anonDate'" | ||
|
||
extractRequestData: | ||
assign: | ||
authDate: "${incoming.body.authDate}" | ||
anonDate: "${incoming.body.anonDate}" | ||
|
||
getEndedChats: | ||
call: http.post | ||
args: | ||
url: "[#CHATBOT_RESQL]/get-chats-to-be-removed-count" | ||
body: | ||
auth_date: ${authDate} | ||
anon_date: ${anonDate} | ||
result: res | ||
|
||
returnSuccess: | ||
return: ${res.response.body} | ||
next: end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
GUI/src/components/DeletionChatOverview/DeletionChatOverview.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@import 'src/styles/tools/spacing'; | ||
@import 'src/styles/tools/color'; | ||
@import 'src/styles/settings/variables/other'; | ||
@import 'src/styles/settings/variables/typography'; | ||
|
||
.full-width { | ||
width: 100% | ||
} | ||
|
||
.margin-auto { | ||
padding-right: 20px; | ||
padding-bottom: 20px ; | ||
margin: auto; | ||
} |
Oops, something went wrong.