From ed762216b2640b06a9e6b0033cae5e0154c4f774 Mon Sep 17 00:00:00 2001 From: maryia-matskevich-deriv <103181650+maryia-matskevich-deriv@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:12:54 +0300 Subject: [PATCH] [BOT]maryia/feat: [Server Bot] - [Improvement] - Summary and Journal panels (#16809) * feat: [Server Bot] - [Improvement] - Summary and Journal panels * fix: change some logic * fix: change approach of showing pop-up dialog on Journal and Transactions tabs * refactor: solution * refactor: solution(2) * chore: remove unused prop * fix: change the variant of passing function prop to minimize re-renders --- .../bot-list/clear-journal-transactions.tsx | 42 +++++++++++++++++++ .../pages/server-side-bot/journal/journal.tsx | 11 +++-- .../performance-panel/performance-panel.tsx | 26 ++++++++---- .../pages/server-side-bot/summary/summary.tsx | 18 ++++++-- 4 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 packages/bot-web-ui/src/pages/server-side-bot/bot-list/clear-journal-transactions.tsx diff --git a/packages/bot-web-ui/src/pages/server-side-bot/bot-list/clear-journal-transactions.tsx b/packages/bot-web-ui/src/pages/server-side-bot/bot-list/clear-journal-transactions.tsx new file mode 100644 index 000000000000..d3df464d65f3 --- /dev/null +++ b/packages/bot-web-ui/src/pages/server-side-bot/bot-list/clear-journal-transactions.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { Dialog, Text } from '@deriv/components'; +import { Localize, localize } from '@deriv/translations'; +import { useDBotStore } from 'Stores/useDBotStore'; +import { observer } from '@deriv/stores'; + +type TDeleteServerBot = { + is_open: boolean; + setVisibility: (is_open: boolean) => void; +}; + +const ClearJournalTransactions = observer(({ is_open, setVisibility }: TDeleteServerBot) => { + const { server_bot } = useDBotStore(); + const { resetJournal, resetTransactions } = server_bot; + const onOkButtonClick = () => { + resetJournal(); + resetTransactions(); + setVisibility(false); + }; + + return ( + setVisibility(false)} + onClose={() => setVisibility(false)} + is_mobile_full_width={false} + className={'dc-dialog__wrapper--fixed'} + portal_element_id='modal_root' + has_close_icon + > + + + + + ); +}); + +export default ClearJournalTransactions; diff --git a/packages/bot-web-ui/src/pages/server-side-bot/journal/journal.tsx b/packages/bot-web-ui/src/pages/server-side-bot/journal/journal.tsx index e26ae1a14dc5..eefd30ef98cb 100644 --- a/packages/bot-web-ui/src/pages/server-side-bot/journal/journal.tsx +++ b/packages/bot-web-ui/src/pages/server-side-bot/journal/journal.tsx @@ -9,17 +9,20 @@ import { useDBotStore } from 'Stores/useDBotStore'; type TJournal = { setActiveTabIndex: (index: number) => void; + setClearDialogVisibility: (is_clear_dialog_visible: boolean) => void; }; -const Journal: React.FC = observer(({ setActiveTabIndex }) => { +const Journal = observer(({ setActiveTabIndex, setClearDialogVisibility }: TJournal) => { const { client: { currency }, } = useStore(); const { server_bot } = useDBotStore(); - const { journal, resetJournal, downloadJournal } = server_bot; + const { active_bot, journal, downloadJournal } = server_bot; const has_journal = !!journal.length; const font_size = 'xxs'; const uid = 'journal'; + const is_bot_running = active_bot?.status !== 'stopped'; + const should_disable = !has_journal || is_bot_running; React.useEffect(() => { const last_journal = journal?.[journal.length - 1]; @@ -137,10 +140,10 @@ const Journal: React.FC = observer(({ setActiveTabIndex }) => { )}
- -
diff --git a/packages/bot-web-ui/src/pages/server-side-bot/performance-panel/performance-panel.tsx b/packages/bot-web-ui/src/pages/server-side-bot/performance-panel/performance-panel.tsx index cca468714c2f..53b9734a6a87 100644 --- a/packages/bot-web-ui/src/pages/server-side-bot/performance-panel/performance-panel.tsx +++ b/packages/bot-web-ui/src/pages/server-side-bot/performance-panel/performance-panel.tsx @@ -3,18 +3,26 @@ import { Tabs } from '@deriv/components'; import { localize } from '@deriv/translations'; import Journal from '../journal'; import Summary from '../summary'; +import ClearJournalTransactions from '../bot-list/clear-journal-transactions'; -const PerformancePanel: React.FC = () => { +const PerformancePanel = () => { const [active_index, setActiveTabIndex] = React.useState(0); + const [is_clear_dialog_visible, setClearDialogVisibility] = React.useState(false); return ( - -
- -
-
- -
-
+ <> + +
+ +
+
+ +
+
+ + ); }; diff --git a/packages/bot-web-ui/src/pages/server-side-bot/summary/summary.tsx b/packages/bot-web-ui/src/pages/server-side-bot/summary/summary.tsx index a4b961b4d3b0..6ea4c1c65da3 100644 --- a/packages/bot-web-ui/src/pages/server-side-bot/summary/summary.tsx +++ b/packages/bot-web-ui/src/pages/server-side-bot/summary/summary.tsx @@ -5,6 +5,10 @@ import { observer, useStore } from '@deriv/stores'; import { Localize } from '@deriv/translations'; import { useDBotStore } from 'Stores/useDBotStore'; +type TSummary = { + setClearDialogVisibility: (is_clear_dialog_visible: boolean) => void; +}; + const STATUS = Object.freeze({ open: { text: , @@ -29,16 +33,20 @@ const STATUS = Object.freeze({ }, }); -const Summary: React.FC = observer(() => { +const Summary = observer(({ setClearDialogVisibility }: TSummary) => { const { server_bot } = useDBotStore(); const { client } = useStore(); const { currency } = client; - const { transactions, active_bot, performance, resetTransactions } = server_bot; + const { transactions, active_bot, performance } = server_bot; const { bot_id } = active_bot; const bot_transactions = bot_id ? transactions[bot_id] : {}; const txns = bot_transactions ? Object.values(bot_transactions) : []; const has_summary = !!txns?.length; + // when we allow multiple bots to run at the same time, it should be an array + // const is_some_bot_running = active_bots.every(item => item.status !== 'stopped'); + const is_bot_running = active_bot?.status !== 'stopped'; + return (
@@ -147,7 +155,11 @@ const Summary: React.FC = observer(() => {
-