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

[DTRA] / DRAFT/ Kate / DTRA-497 / Trade Type section Updates #12984

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
16e1869
feat: add dropdown to the contract description section
kate-deriv Jan 15, 2024
47ebdad
feat: add learn more button
kate-deriv Jan 15, 2024
80737e3
refactor: removed info icons from menu and moved high low under ups a…
kate-deriv Jan 15, 2024
e9ece15
feat: add learn more functionality to trading page
kate-deriv Jan 16, 2024
df89e29
feat: add arrow to the trade type widget for mobile
kate-deriv Jan 16, 2024
cb43000
Merge branch 'binary-com:master' into kate/DTRA-497/description_funct…
kate-deriv Jan 19, 2024
e7e99df
feat: add info banner for unavailable contracts
kate-deriv Jan 19, 2024
85f860e
feat: add optional title for some conditions
kate-deriv Jan 19, 2024
b91b0ba
refactor: remove code smells
kate-deriv Jan 19, 2024
791f736
refactor: remove sonar cloud issue
kate-deriv Jan 19, 2024
a6113fb
refactor: finally remove sonarcloud issue
kate-deriv Jan 19, 2024
f30c4c7
refactor: add tests for shared and components packages
kate-deriv Jan 20, 2024
c3143d9
refactor: add tests for tradr package
kate-deriv Jan 20, 2024
9f8ef17
refactor: analytics
kate-deriv Jan 20, 2024
d1752b8
fix: analytics
kate-deriv Jan 20, 2024
c6056eb
refactor: apply suggestions
kate-deriv Jan 22, 2024
e05c6fe
fix: failling test case
kate-deriv Jan 22, 2024
6bb7675
refactor: add more tests
kate-deriv Jan 22, 2024
61fb350
refactor: apply suggestions
kate-deriv Jan 23, 2024
940d555
refactor: rename classnames
kate-deriv Jan 23, 2024
35b1c2f
Merge branch 'binary-com:master' into kate/DTRA-497/description_funct…
kate-deriv Jan 23, 2024
21a1c91
Merge branch 'binary-com:master' into kate/DTRA-497/description_funct…
kate-deriv Jan 23, 2024
eb1b62d
chore: empty commit to retrigger checks
kate-deriv Jan 23, 2024
88ae7eb
Merge branch 'binary-com:master' into kate/DTRA-497/description_funct…
kate-deriv Jan 24, 2024
c97a498
refactor: revert changes
kate-deriv Jan 24, 2024
ccf9449
chore: rename according to the new convention
kate-deriv Jan 24, 2024
7ec48f6
Merge branch 'binary-com:master' into kate/DTRA-497/description_funct…
kate-deriv Jan 24, 2024
c6bee47
fix: height for mobile
kate-deriv Jan 24, 2024
6282d15
refactor: increase chart space
kate-deriv Jan 24, 2024
c1e20d3
fix: bug with switching between description and glossary tabs
kate-deriv Feb 5, 2024
e905d8c
fix: margin for mobile dropdown
kate-deriv Feb 5, 2024
54cc46c
fix: background color
kate-deriv Feb 5, 2024
3c16de4
fix: margin mobile
kate-deriv Feb 5, 2024
9ce8c27
refactor: add fixed width for banner
kate-deriv Feb 5, 2024
12186b1
Merge branch 'binary-com:master' into kate/DTRA-497/description_funct…
kate-deriv Feb 5, 2024
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
@@ -0,0 +1,53 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ArrowButton from '../arrow-button';

const mockedTitle = 'mocked title';

const mockedDefaultProps = {
is_collapsed: false,
position: 'top' as React.ComponentProps<typeof ArrowButton>['position'],
onClick: jest.fn(),
title: mockedTitle,
handle_button: false,
};

describe('<ArrowButton/>', () => {
it('should render icon with title for top position if title is defined', () => {
render(<ArrowButton {...mockedDefaultProps} />);

expect(screen.getByText(mockedTitle)).toBeInTheDocument();
});

it('should not render icon with title for top position if title is undefined', () => {
render(<ArrowButton {...mockedDefaultProps} title={undefined} />);

expect(screen.queryByText(mockedTitle)).not.toBeInTheDocument();
});

it('should render icon with title for bottom position if title is defined', () => {
render(<ArrowButton {...mockedDefaultProps} position='bottom' />);

expect(screen.getByText(mockedTitle)).toBeInTheDocument();
});

it('should not render icon with title for bottom position if title is undefined', () => {
render(<ArrowButton {...mockedDefaultProps} title={undefined} position='bottom' />);

expect(screen.queryByText(mockedTitle)).not.toBeInTheDocument();
});

it('should render icon_flat with if handle_button === true', () => {
render(<ArrowButton {...mockedDefaultProps} handle_button />);

expect(screen.getByTestId('icon_handle')).toBeInTheDocument();
});

it('should call onClick function if user clicks on icon', () => {
render(<ArrowButton {...mockedDefaultProps} />);
userEvent.click(screen.getByText(mockedTitle));

expect(mockedDefaultProps.onClick).toHaveBeenCalled();
});
});
13 changes: 11 additions & 2 deletions packages/components/src/components/collapsible/arrow-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type TArrowButton = {
onClick: () => void;
title?: string;
position?: 'top' | 'bottom';
handle_button?: boolean;
};

const IconArrow = ({ className }: { className?: string }) => (
Expand All @@ -29,7 +30,7 @@ const IconArrowWithTitle = ({ title, ...props }: TIconArrowWithTitle) => (
</React.Fragment>
);

const ArrowButton = ({ is_collapsed = false, position, onClick, title }: TArrowButton) => {
const ArrowButton = ({ is_collapsed = false, position, onClick, title, handle_button = false }: TArrowButton) => {
const [is_open, expand] = React.useState(!is_collapsed);

const toggleExpand = () => {
Expand Down Expand Up @@ -82,8 +83,16 @@ const ArrowButton = ({ is_collapsed = false, position, onClick, title }: TArrowB
);
}

if (handle_button) icon_arrow = <div className='dc-collapsible__icon--handle' data-testid='icon_handle' />;

return (
<div className='dc-collapsible__button' onClick={toggleExpand}>
<div
className={classNames('dc-collapsible__button', {
'dc-collapsible__button--handle': handle_button,
})}
onClick={toggleExpand}
onKeyDown={toggleExpand}
>
{icon_arrow}
</div>
);
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/components/collapsible/collapsible.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,23 @@
align-items: center;
justify-content: center;
height: 32px;

&--handle {
align-items: baseline;
height: 3.8rem;
}
}
&__icon {
transition: transform 0.3s ease-in-out;

&--handle {
width: 4rem;
height: 0.4rem;
margin-top: 0.8rem;
border-radius: 0.2rem;
background-color: var(--general-active);
}

&--top {
transform: rotate(180deg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type TCollapsible = {
position?: 'top' | 'bottom';
onClick: (state: boolean) => void;
title?: string;
handle_button?: boolean;
};

const swipe_config = {
Expand All @@ -24,6 +25,7 @@ const Collapsible = ({
children,
onClick,
title,
handle_button,
}: React.PropsWithChildren<TCollapsible>) => {
const [is_open, expand] = React.useState(!is_collapsed);
const [should_show_collapsible, setShouldShowCollapsible] = React.useState(false);
Expand Down Expand Up @@ -58,7 +60,13 @@ const Collapsible = ({
});

const arrow_button = (
<ArrowButton is_collapsed={!is_open} position={position} onClick={toggleExpand} title={title} />
<ArrowButton
is_collapsed={!is_open}
position={position}
onClick={toggleExpand}
title={title}
handle_button={handle_button}
/>
);
const CustomTag = as || 'div';
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import Items from '../items';

describe('<Items />', () => {
let mockedDefaultProps: React.ComponentProps<typeof Items>;

beforeEach(() => {
mockedDefaultProps = {
handleSelect: jest.fn(),
onKeyPressed: jest.fn(),
value: 'multiplier',
nodes: null,
items: [
{ text: 'Multipliers', value: 'multiplier' },
{ text: 'Accumulators', value: 'accumulator' },
],
setScrollHeight: jest.fn(),
};
});

it('should render list of passed items', () => {
render(<Items {...mockedDefaultProps} />);

expect(screen.getByText('Multipliers')).toBeInTheDocument();
expect(screen.getByText('Accumulators')).toBeInTheDocument();
});

it('should call setScrollHeight function if value === item.value', () => {
render(<Items {...mockedDefaultProps} />);

expect(mockedDefaultProps.setScrollHeight).toBeCalled();
});
it('should not call setScrollHeight function if value !== item.value', () => {
mockedDefaultProps.value = 'vanilla';
render(<Items {...mockedDefaultProps} />);

expect(mockedDefaultProps.setScrollHeight).not.toBeCalled();
});
});
3 changes: 2 additions & 1 deletion packages/components/src/components/dropdown/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@
min-width: 15rem;
width: 100%;

&:not(.cfd-personal-details-modal__form *):not(.trade-container__multiplier-dropdown):not(.dc-dropdown--left) {
&:not(.cfd-personal-details-modal__form *):not(.trade-container__multiplier-dropdown):not(
.dc-dropdown--left):not(.contract-type-info__dropdown) {
margin-top: unset;
}

Expand Down
20 changes: 19 additions & 1 deletion packages/components/src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type TDropdown = {
onClick?: () => void;
placeholder?: string;
suffix_icon?: string;
should_scroll_to_selected?: boolean;
should_autohide?: boolean;
test_id?: string;
value?: string | number;
classNameIcon?: string;
Expand All @@ -67,6 +69,8 @@ type TDropdownList = {
parent_ref: React.RefObject<HTMLElement>;
portal_id?: string;
suffix_icon?: string;
should_scroll_to_selected?: boolean;
should_autohide?: boolean;
value?: string | number;
};

Expand All @@ -89,11 +93,15 @@ const DropdownList = React.forwardRef<HTMLDivElement, TDropdownList>((props, lis
parent_ref,
portal_id,
suffix_icon,
should_scroll_to_selected,
should_autohide,
value,
} = props;

const [list_dimensions, setListDimensions] = React.useState([initial_offset, 0]);
const [style, setStyle] = React.useState({});
const [scroll_height, setScrollHeight] = React.useState<number>();

const is_portal = !!portal_id;

React.useEffect(() => {
Expand Down Expand Up @@ -188,7 +196,12 @@ const DropdownList = React.forwardRef<HTMLDivElement, TDropdownList>((props, lis
role='list'
ref={list_ref}
>
<ThemedScrollbars height={list_dimensions[1] || '200px'}>
<ThemedScrollbars
height={list_dimensions[1] || '200px'}
scroll_height={scroll_height}
should_scroll_to_selected={should_scroll_to_selected}
autohide={should_autohide}
>
{Array.isArray(list) ? (
<Items
onKeyPressed={onKeyPressed}
Expand All @@ -199,6 +212,7 @@ const DropdownList = React.forwardRef<HTMLDivElement, TDropdownList>((props, lis
is_align_text_left={is_align_text_left}
value={value}
nodes={nodes.current}
setScrollHeight={setScrollHeight}
/>
) : (
Object.keys(list).map((key, idx) => (
Expand Down Expand Up @@ -261,6 +275,8 @@ const Dropdown = ({
onClick,
placeholder,
suffix_icon,
should_scroll_to_selected,
should_autohide,
test_id,
value,
classNameIcon,
Expand Down Expand Up @@ -503,6 +519,8 @@ const Dropdown = ({
portal_id={list_portal_id}
ref={list_ref}
suffix_icon={suffix_icon}
should_scroll_to_selected={should_scroll_to_selected}
should_autohide={should_autohide}
value={value}
/>
</div>
Expand Down
22 changes: 20 additions & 2 deletions packages/components/src/components/dropdown/items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type TItem = {
is_align_text_left?: boolean;
nodes: Map<string, HTMLDivElement | null> | null;
item: TListItem;
setScrollHeight?: (new_value: number) => void;
};

type TItems = Omit<TItem, 'item'> & {
Expand All @@ -30,10 +31,21 @@ const Items = ({ items, ...props }: TItems) => {
);
};

const Item = ({ onKeyPressed, value, item, handleSelect, nodes, has_symbol, is_align_text_left, className }: TItem) => {
const Item = ({
onKeyPressed,
value,
item,
handleSelect,
nodes,
has_symbol,
is_align_text_left,
className,
setScrollHeight,
}: TItem) => {
const item_ref = React.useRef<HTMLDivElement>(null);
const symbol_type_class_name =
item.text && typeof item.text === 'string' ? `symbols--${item.text.toLowerCase()}` : null;
const is_selected = value === item.value;

React.useEffect(() => {
const removeListeners = () => {
Expand All @@ -51,11 +63,17 @@ const Item = ({ onKeyPressed, value, item, handleSelect, nodes, has_symbol, is_a
return () => removeListeners();
}, [item, nodes, onKeyPressed]);

React.useEffect(() => {
if (setScrollHeight && item_ref.current && is_selected) {
setScrollHeight(item_ref.current.offsetTop - item_ref.current.scrollHeight);
}
}, [item_ref, setScrollHeight, is_selected]);

return (
<div
className={classNames(
'dc-list__item',
{ 'dc-list__item--selected': value === item.value },
{ 'dc-list__item--selected': is_selected },
{ 'dc-list__item--disabled': item.disabled }
)}
data-testid='dti_list_item'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@
border-bottom: 0.01rem solid transparent;

.inline-message__information {
margin: 1.6rem 0.8rem;
margin: 1.6rem 0.8rem -0.8rem;
}

.learn-more {
height: 5rem;
width: calc(100% - 1.6rem);
margin: 1.6rem 0.8rem 0.8rem;
padding: 1.6rem;
display: flex;
justify-content: space-between;
align-items: center;
border: none;
background-color: var(--general-section-1);
cursor: pointer;
border-radius: $BORDER_RADIUS;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type TMobileDialog = {
title?: React.ReactNode;
visible?: boolean;
wrapper_classname?: string;
learn_more_banner?: React.ReactNode;
};

const MobileDialog = (props: React.PropsWithChildren<TMobileDialog>) => {
Expand All @@ -36,6 +37,7 @@ const MobileDialog = (props: React.PropsWithChildren<TMobileDialog>) => {
title,
visible,
wrapper_classname,
learn_more_banner,
} = props;

const footer_ref = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -100,16 +102,25 @@ const MobileDialog = (props: React.PropsWithChildren<TMobileDialog>) => {
<Div100vhContainer
className={classNames('dc-mobile-dialog__container', {
'dc-mobile-dialog__container--has-scroll': props.has_content_scroll,
'dc-mobile-dialog__container--has-info-banner': info_banner,
'dc-mobile-dialog__container--has-info-banner': info_banner || learn_more_banner,
})}
height_offset={props.content_height_offset || '8px'}
>
<ThemedScrollbars
is_bypassed={!info_banner}
is_bypassed={!info_banner && !learn_more_banner}
is_scrollbar_hidden
className={info_banner ? classNames('dc-mobile-dialog__header-wrapper', header_classname) : ''}
className={
info_banner || learn_more_banner
? classNames('dc-mobile-dialog__header-wrapper', header_classname)
: ''
}
>
<div className={classNames('dc-mobile-dialog__header', !info_banner && header_classname)}>
<div
className={classNames(
'dc-mobile-dialog__header',
!info_banner && !learn_more_banner && header_classname
)}
>
<Text
as='h2'
size='xs'
Expand All @@ -131,6 +142,7 @@ const MobileDialog = (props: React.PropsWithChildren<TMobileDialog>) => {
)}
</div>
{info_banner}
{learn_more_banner}
</ThemedScrollbars>
<div
className={classNames('dc-mobile-dialog__content', {
Expand Down
Loading
Loading