Skip to content
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

Rupato/358/rerender-previous-active-tab-on-reload #8992

37 changes: 35 additions & 2 deletions packages/bot-web-ui/src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { initTrashCan } from '@deriv/bot-skeleton/src/scratch/hooks/trashcan';
import { DesktopWrapper, Dialog, MobileWrapper, Tabs } from '@deriv/components';
import { isMobile } from '@deriv/shared';
import { useStore } from '@deriv/stores';
import { localize } from '@deriv/translations';
import Chart from 'Components/chart';
import { DBOT_TABS, TAB_IDS } from 'Constants/bot-contents';
Expand Down Expand Up @@ -81,13 +82,44 @@
setTourDialogVisibility,
setHasTourEnded,
}: TDashboard) => {
const { DASHBOARD, BOT_BUILDER, CHART } = DBOT_TABS;
const { DASHBOARD, BOT_BUILDER, CHART, TUTORIAL } = DBOT_TABS;

Check warning on line 85 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L85

Added line #L85 was not covered by tests
const is_tour_complete = React.useRef(true);
let bot_tour_token: string | number = '';
let onboard_tour_token: string | number = '';
let storage = '';
let tour_status: { [key: string]: string };
const is_mobile = isMobile();
const init_render = React.useRef(true);
const { ui } = useStore();
const { url_hashed_values } = ui;

Check warning on line 94 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L92-L94

Added lines #L92 - L94 were not covered by tests

let tab_value = active_tab;
const GetHashedValue = (tab: number) => {
tab_value = url_hashed_values?.split('#')[1];

Check warning on line 98 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L96-L98

Added lines #L96 - L98 were not covered by tests
if (tab_value === 'dashboard') return DASHBOARD;
if (tab_value === 'bot_builder') return BOT_BUILDER;
if (tab_value === 'chart') return CHART;
if (tab_value === 'tutorial') return TUTORIAL;
if (isNaN(tab_value) || isNaN(tab)) return active_tab;
if (tab_value > 4 || tab > 4) return active_tab;
return tab_value;

Check warning on line 105 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L105

Added line #L105 was not covered by tests
};
const active_hash_tab = GetHashedValue(active_tab);

Check warning on line 107 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L107

Added line #L107 was not covered by tests

React.useEffect(() => {

Check warning on line 109 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L109

Added line #L109 was not covered by tests
if (init_render.current) {
setActiveTab(Number(active_hash_tab));

Check warning on line 111 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L111

Added line #L111 was not covered by tests
if (is_mobile) handleTabChange(Number(active_hash_tab));
init_render.current = false;

Check warning on line 113 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L113

Added line #L113 was not covered by tests
} else {
let active_tab_name = 'dashboard';

Check warning on line 115 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L115

Added line #L115 was not covered by tests
if (active_tab === 0) active_tab_name = 'dashboard';
if (active_tab === 1) active_tab_name = 'bot_builder';
if (active_tab === 2) active_tab_name = 'chart';
if (active_tab === 3) active_tab_name = 'tutorial';
window.location.hash = active_tab_name;

Check warning on line 120 in packages/bot-web-ui/src/components/dashboard/dashboard.tsx

View check run for this annotation

Codecov / codecov/patch

packages/bot-web-ui/src/components/dashboard/dashboard.tsx#L120

Added line #L120 was not covered by tests
}
}, [active_tab]);

const setTourStatus = (status: { [key: string]: string }) => {
if (status) {
Expand Down Expand Up @@ -210,7 +242,8 @@
'dashboard__container--active': has_tour_started && active_tab === DASHBOARD && is_mobile,
})}
>
<TourTriggrerDialog />
{(active_tab === DASHBOARD || active_tab === BOT_BUILDER) && <TourTriggrerDialog />}

{has_tour_started &&
active_tab === DASHBOARD &&
(is_mobile ? (
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/Stores/ui-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
const store_name = 'ui_store';

export default class UIStore extends BaseStore {
url_hashed_values = '';

Check warning on line 9 in packages/core/src/Stores/ui-store.js

View check run for this annotation

Codecov / codecov/patch

packages/core/src/Stores/ui-store.js#L9

Added line #L9 was not covered by tests
rupato-deriv marked this conversation as resolved.
Show resolved Hide resolved
is_account_settings_visible = false;
is_positions_drawer_on = false;
is_reports_visible = false;
Expand Down Expand Up @@ -317,6 +318,7 @@
is_mobile: computed,
is_tablet: computed,
is_warning_scam_message_modal_visible: computed,
url_hashed_values: observable,
notifyAppInstall: action.bound,
onChangeUiStore: action.bound,
openAccountNeededModal: action.bound,
Expand All @@ -341,6 +343,7 @@
setCurrentFocus: action.bound,
setDarkMode: action.bound,
setHasOnlyForwardingContracts: action.bound,
setHashedValue: action.bound,
setIsAcuityModalOpen: action.bound,
setIsClosingCreateRealAccountModal: action.bound,
setIsNativepickerVisible: action.bound,
Expand Down Expand Up @@ -439,7 +442,12 @@
this.is_new_account = localStorage.getItem('isNewAccount') || false;
}

setHashedValue(url_hashed_values) {
this.url_hashed_values = url_hashed_values;

Check warning on line 446 in packages/core/src/Stores/ui-store.js

View check run for this annotation

Codecov / codecov/patch

packages/core/src/Stores/ui-store.js#L446

Added line #L446 was not covered by tests
}

init(notification_messages) {
this.setHashedValue(window.location.hash);

Check warning on line 450 in packages/core/src/Stores/ui-store.js

View check run for this annotation

Codecov / codecov/patch

packages/core/src/Stores/ui-store.js#L450

Added line #L450 was not covered by tests
this.notification_messages_ui = notification_messages;
}

Expand Down