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

Henry/dtra 282/rewrite contract type info component #9352

Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f23fa41
fix: initialize
henry-deriv Jun 12, 2023
40398ec
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jun 14, 2023
5bcd845
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jun 14, 2023
a2ff546
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jul 4, 2023
c701b6b
fix: ts migrate and add test coverage to ContractType folder
henry-deriv Jul 4, 2023
83427ac
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jul 4, 2023
fba7a58
fix: remove unused import
henry-deriv Jul 4, 2023
eff7100
fix: TS Error due to name and value not being intrinsic attribute to …
henry-deriv Jul 4, 2023
52c01cf
fix: add test cases
henry-deriv Jul 5, 2023
2e657cb
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jul 5, 2023
62fe2af
fix: code smells
henry-deriv Jul 5, 2023
3c8392f
fix: consistency issue
henry-deriv Jul 5, 2023
bf41388
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jul 5, 2023
fd4b375
fix: code smell
henry-deriv Jul 5, 2023
c2f778e
fix: minor change
henry-deriv Jul 5, 2023
d57cd20
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jul 5, 2023
bc35be6
Merge branch 'master' of github.com:binary-com/deriv-app into henry/t…
henry-deriv Jul 14, 2023
fdd4a4c
fix: rewrite contract-type-info to get rid of visual bug when switchi…
henry-deriv Jul 14, 2023
39e4416
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv Jul 14, 2023
e0b1124
fix: remove unused import
henry-deriv Jul 14, 2023
cfdab01
fix: remove unused css
henry-deriv Jul 14, 2023
4dd6725
fix: refactor component
henry-deriv Jul 15, 2023
a7a2f35
fix: small word change
henry-deriv Jul 18, 2023
b314f0f
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv Jul 18, 2023
73b55b7
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv Jul 20, 2023
f44cee2
fix: resolve comments
henry-deriv Jul 20, 2023
e7b9aa9
fix: resolve comments
henry-deriv Jul 20, 2023
1857bf2
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv Jul 20, 2023
bc20a17
fix: empty commit
henry-deriv Jul 21, 2023
03a2d0b
fix: code smells
henry-deriv Jul 21, 2023
f14c077
fix: circleCI
henry-deriv Jul 21, 2023
61f476d
fix: resolve comments
henry-deriv Jul 21, 2023
a3e7d81
fix: missing import
henry-deriv Jul 21, 2023
a8fa242
fix: remove scroll for contract-type-info
henry-deriv Jul 21, 2023
dc7d35f
fix: resolve conflicts
henry-deriv Aug 1, 2023
0ec4f23
fix: resolve conflicts and merge master
henry-deriv Aug 1, 2023
50b98b6
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv Aug 1, 2023
13e96e7
fix: resolve conflicts
henry-deriv Aug 10, 2023
ebe5a0b
fix: remove useeffect as per comment
henry-deriv Aug 10, 2023
21049cb
fix: remove css styling
henry-deriv Aug 15, 2023
a0913b5
fix: resolve conflicts
henry-deriv Aug 16, 2023
d43075e
fix: circleCI
henry-deriv Aug 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const VerticalTabHeaderGroup = ({
})}
onClick={handleClick}
>
<HeaderIcon icon={group.icon} is_active={selected} />
<HeaderIcon icon={group.icon ?? ''} is_active={selected} />
<Header text={label} />
{is_collapsible && (
<Icon
Expand All @@ -83,7 +83,7 @@ const VerticalTabHeaderGroup = ({
})}
onClick={handleClick}
>
<HeaderIcon icon={group.icon} is_active={selected} />
<HeaderIcon icon={group.icon ?? ''} is_active={selected} />
<Header text={label} />
{is_collapsible && (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ export type THeader = {
};

export type TItem = {
component?: typeof React.Component;
component?: JSX.Element | null;
count?: number;
default?: boolean;
getTitle?: () => string;
has_side_note?: boolean;
icon: string;
icon?: string;
is_hidden?: boolean;
is_disabled?: boolean;
key?: string;
label?: string;
path?: string;
subitems?: number[];
Expand Down Expand Up @@ -88,7 +89,7 @@ const VerticalTabHeader = ({
'dc-vertical-tab__header--active': is_active,
})}
>
<HeaderIcon icon={item.icon} is_active={is_active} />
<HeaderIcon icon={item.icon ?? ''} is_active={is_active} />
<Header text={label} path={item.path} />
{!!count && <Counter count={count} className='dc-vertical-tab__header__counter' />}
{children}
Expand All @@ -102,7 +103,7 @@ const VerticalTabHeader = ({
})}
onClick={handleClick}
>
<HeaderIcon icon={item.icon} is_active={is_active} />
<HeaderIcon icon={item.icon ?? ''} is_active={is_active} />
<Header text={label} />
{children}
<>{item.component}</>
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/utils/route/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react';
// TODO: Add test cases for this
type TRoute = {
component?: React.ComponentType;
component?: JSX.Element | null;
default?: boolean;
exact?: boolean;
getTitle?: () => string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { findContractCategory } from 'Modules/Trading/Helpers/contract-type';
import { observer, useStore } from '@deriv/stores';

type TContractType = {
text: string;
text?: string;
value: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ContractTypeGlossary = ({ category }: { category: string }) => {
{
type: 'paragraph',
text: localize(
'The spot price may change by the time your order reaches our servers. When this happens, your payout maybe affected.'
'The spot price may change by the time your order reaches our servers. When this happens, your payout may be affected.'
),
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Icon, Text } from '@deriv/components';

const Header = ({ onClickGoBack, text_size = 's', title }) => (
type THeader = {
onClickGoBack?: () => void;
text_size?: string;
title: string;
};

const Header = ({ onClickGoBack, text_size = 's', title }: THeader) => (
<div className='contract-type-info__action-bar'>
<span className='contract-type-info__icon' id='dt_contract_info_back_nav' onClick={onClickGoBack}>
<Icon icon='IcArrowLeftBold' />
Expand All @@ -13,10 +18,4 @@ const Header = ({ onClickGoBack, text_size = 's', title }) => (
</div>
);

Header.propTypes = {
onClickGoBack: PropTypes.func,
text_size: PropTypes.string,
title: PropTypes.string,
};

export default Header;
Original file line number Diff line number Diff line change
@@ -1,77 +1,74 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Button, ThemedScrollbars, Carousel, ButtonToggle } from '@deriv/components';
import { Button, ThemedScrollbars, ButtonToggle } from '@deriv/components';
import { isMobile } from '@deriv/shared';
import { localize } from '@deriv/translations';
import TradeCategories from 'Assets/Trading/Categories/trade-categories.jsx';
import TradeCategoriesGIF from 'Assets/Trading/Categories/trade-categories-gif.jsx';
import { getContractTypes } from '../../../../Helpers/contract-type';
import ContractTypeGlossary from './contract-type-glossary';
import classNames from 'classnames';
import { TContractType, TList } from '../types';

type TInfo = {
handleSelect: (
type: TContractType,
e: React.MouseEvent<HTMLDivElement | HTMLButtonElement | HTMLInputElement>
) => void;
item: TContractType;
list: TList[];
};

const TABS = {
DESCRIPTION: 'description',
GLOSSARY: 'glossary',
};

const Info = ({ handleNavigationClick, handleSelect, initial_index, item, list }) => {
const [carousel_index, setCarouselIndex] = React.useState('');
const Info = ({ handleSelect, item, list }: TInfo) => {
const [selected_tab, setSelectedTab] = React.useState(TABS.DESCRIPTION);
const contract_types = getContractTypes(list, item).filter(
i => i.value !== 'rise_fall_equal' && i.value !== 'turbosshort'
const contract_types: TContractType[] | undefined = getContractTypes(list, item)?.filter(
(i: { value: TContractType['value'] }) => i.value !== 'rise_fall_equal' && i.value !== 'turbosshort'
);
const has_toggle_buttons = /accumulator|vanilla/i.test(carousel_index);
const has_toggle_buttons = /accumulator|vanilla/i.test(item.value);
const is_description_tab_selected = selected_tab === TABS.DESCRIPTION;
const is_glossary_tab_selected = selected_tab === TABS.GLOSSARY;
const width = isMobile() ? '328' : '528';
const scroll_bar_height = has_toggle_buttons ? '464px' : '560px';
const selected_contract_type = contract_types.find(type => type.value === carousel_index);

const onClickGlossary = () => setSelectedTab(TABS.GLOSSARY);
const handleItemSelect = active_index => {
setCarouselIndex(contract_types[active_index].value);
handleNavigationClick(contract_types[active_index]);
};

const cards = contract_types.map((type, idx) => {
const cards = contract_types?.map((type: TContractType) => {
if (type.value !== item.value) return null;
return (
<div key={idx} className='contract-type-info__card'>
<div key={type.value} className='contract-type-info__card'>
<ThemedScrollbars
className={classNames('contract-type-info__scrollbars', {
'contract-type-info__scrollbars-description--active': is_description_tab_selected,
'contract-type-info__scrollbars-glossary contract-type-info__scrollbars-glossary--active ':
is_glossary_tab_selected,
})}
style={{
left: `${is_description_tab_selected ? `-${width}` : width}px`,
transform: `translate3d(${is_description_tab_selected ? width : `-${width}`}px, 0, 0)`,
left: `${is_description_tab_selected ? '-' : ''}${width}px`,
transform: `translate3d(${is_description_tab_selected ? '' : '-'}${width}px, 0, 0)`,
}}
height={isMobile() ? '' : scroll_bar_height}
autohide={false}
>
<div
className={classNames({
'contract-type-info__gif--has-toggle-buttons': has_toggle_buttons,
'contract-type-info__content': is_glossary_tab_selected,
className={classNames('contract-type-info__content', {
'contract-type-info__gif': is_description_tab_selected,
'contract-type-info__gif--has-toggle-buttons': has_toggle_buttons,
'contract-type-info__gif--has-video':
carousel_index === 'accumulator' && is_description_tab_selected,
item.value === 'accumulator' && is_description_tab_selected,
})}
>
{is_description_tab_selected ? (
<TradeCategoriesGIF
category={type.value}
selected_contract_type={selected_contract_type?.value}
/>
<React.Fragment>
<TradeCategoriesGIF category={type.value} selected_contract_type={item?.value} />
<TradeCategories category={type.value} onClick={onClickGlossary} />
</React.Fragment>
) : (
<ContractTypeGlossary category={type.value} />
)}
</div>
<div className='contract-type-info__content'>
{is_description_tab_selected && (
<TradeCategories category={type.value} onClick={onClickGlossary} />
)}
</div>
</ThemedScrollbars>
</div>
);
Expand All @@ -96,25 +93,23 @@ const Info = ({ handleNavigationClick, handleSelect, initial_index, item, list }
/>
</div>
)}
<Carousel
<div
className={classNames('contract-type-info', {
'contract-type-info--has-toggle-buttons': has_toggle_buttons,
})}
disable_swipe={isMobile()}
onItemSelect={handleItemSelect}
initial_index={initial_index}
list={cards}
width={isMobile() ? 328 : 528}
show_bullet={false}
show_nav={false}
/>
style={{
width: isMobile() ? '328px' : '528px',
}}
>
{cards}
</div>
<div className='contract-type-info__trade-type-btn-wrapper'>
<Button
id={`dt_contract_info_${selected_contract_type?.value}_btn`}
id={`dt_contract_info_${item?.value}_btn`}
className='contract-type-info__button'
onClick={e => handleSelect(selected_contract_type, e)}
onClick={e => handleSelect(item, e)}
text={localize('Choose {{contract_type}}', {
contract_type: selected_contract_type?.text,
contract_type: item?.text,
interpolation: { escapeValue: false },
})}
secondary
Expand All @@ -124,12 +119,4 @@ const Info = ({ handleNavigationClick, handleSelect, initial_index, item, list }
);
};

Info.propTypes = {
handleSelect: PropTypes.func,
initial_index: PropTypes.number,
item: PropTypes.object,
list: PropTypes.array,
handleNavigationClick: PropTypes.func,
};

export default Info;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Info from './contract-type-info.jsx';
import Info from './contract-type-info';

export { default as Header } from './contract-type-info-header.jsx';
export { default as Header } from './contract-type-info-header';

export default Info;
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import PropTypes from 'prop-types';
import React from 'react';
import { CSSTransition } from 'react-transition-group';
import { Loading, ThemedScrollbars, VerticalTab } from '@deriv/components';
import { localize } from '@deriv/translations';
import SearchInput from './search-input.jsx';
import NoResultsMessage from './no-results-message.jsx';
import { Header } from '../ContractTypeInfo';
import SearchInput from './search-input';
import NoResultsMessage from './no-results-message';
import { Header } from '../ContractTypeInfo/index.js';
import { getContractCategoryKey } from '../../../../Helpers/contract-type';
import { TList } from '../types';
import ContractType from '../contract-type';

type TDialog = {
categories: TList[];
item: React.ComponentProps<typeof ContractType.Info>['item'];
selected?: string;
children?: React.ReactNode;
is_info_dialog_open?: boolean;
is_open?: boolean;
onBackButtonClick?: () => void;
onCategoryClick?: (e: React.ComponentProps<typeof VerticalTab.Headers>['selected']) => void;
onChangeInput?: (e: string) => void;
show_loading?: boolean;
};

const Dialog = ({
categories,
Expand All @@ -19,19 +33,16 @@ const Dialog = ({
onCategoryClick,
onChangeInput,
show_loading,
}) => {
const input_ref = React.useRef(null);

}: React.PropsWithChildren<TDialog>) => {
const input_ref = React.useRef<(HTMLInputElement & HTMLTextAreaElement) | null>(null);
const [input_value, setInputValue] = React.useState('');

const contract_category = getContractCategoryKey(categories, item);
const selected_item = selected ? { key: selected } : contract_category;
const selected_item = selected ? { key: selected } : { key: contract_category };
const selected_category_contract = !categories?.find(category => category.key === selected_item.key)
?.contract_categories.length;

const onChange = e => {
?.contract_categories?.length;
const onChange: React.ComponentProps<typeof VerticalTab.Headers>['onChange'] = e => {
if (is_info_dialog_open) {
onBackButtonClick();
onBackButtonClick?.();
}
if (input_value) {
onClickClearInput();
Expand All @@ -41,15 +52,15 @@ const Dialog = ({
}
};

const onChangeInputValue = e => {
const onChangeInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
onChangeInput(e.target.value);
onChangeInput?.(e.target.value);
};

const onClickClearInput = () => {
input_ref.current.focus();
input_ref?.current?.focus();
setInputValue('');
onChangeInput('');
onChangeInput?.('');
};

const renderChildren = () => {
Expand All @@ -66,7 +77,6 @@ const Dialog = ({
value={input_value}
/>
);

return (
<CSSTransition
in={is_open}
Expand Down Expand Up @@ -105,7 +115,7 @@ const Dialog = ({
) : (
<React.Fragment>
<div className='dc-vertical-tab__action-bar dc-vertical-tab__action-bar--contract-type-info-header'>
<Header title={item.text} onClickGoBack={onBackButtonClick} />
<Header title={item.text || ''} onClickGoBack={onBackButtonClick} />
</div>
{renderChildren()}
</React.Fragment>
Expand All @@ -118,18 +128,4 @@ const Dialog = ({
);
};

Dialog.propTypes = {
categories: PropTypes.array,
children: PropTypes.node,
is_info_dialog_open: PropTypes.bool,
is_open: PropTypes.bool,
selected: PropTypes.string,
show_loading: PropTypes.bool,
item: PropTypes.object,
list: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
onBackButtonClick: PropTypes.func,
onCategoryClick: PropTypes.func,
onChangeInput: PropTypes.func,
};

export default Dialog;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Dialog from './contract-type-menu.jsx';
import Dialog from './contract-type-menu';

export default Dialog;
Loading