Skip to content

Commit

Permalink
Mahdiyeh/ Refactor: Reports monorepo package (binary-com#5620)
Browse files Browse the repository at this point in the history
* add initial config of reports monorepo

* add config to core

* fix event-source-polyfil version

* resolve build errors

* move validator to utils

* fix trader files

* delete reports, change imports

* fix root_store error

* fix chunkName

* fix direcory path

* fix jest errors

* fix directory

* make separate emptyPrtfolioMessage in trader

* fix aliases

* add translation

* fix code smell

* reload tests

* fix empty-portfolio-message conflicts

* remove unnecessary css files and functions

* remove deriv-charts package and unnecessary related files

* fix import from trader in reports

* remove duplicated files

* change BinaryLink to NavLink

* rerun tests

* fix circular dependency

* fix  EHOIST_PKG_VERSION error

* fix test

* remove position-drawer-card from trader

* remove duplicated scss

* remove bottom-widget

* fix reports loader

* add contract, portfolio and chartbarrier stores to the core

* use core portfolio and contract store in trader and reports

* move markers component, helpers and constants to the core

* remove all duplicated files from trader and reports

* remove contract store from core exports

* update reports packages version

* remove commented imports

* add getContactValidationRules to contact core

* move duration test to shared

* fix active_symbols store

* fix moduleLoader in routes.config error

* fix stores constructor

* move contract-type file to trader

* move validation-rules to trading

* remove serverTime from shared

* remove .js from imports

* remove all commented lines

* fix error when the trade_store in localStorage in not existd yet

* clean the code

* fix is_multiplier error issue using it from portfolio store

* add props type to open-positions and position-drawer

* change portfolio file name

* add action for updating contract_type observable in portfolio store

* update with latest master

* remove comments

* add shared to translation scripts/add deriv/reports to the build

* remove redundant comment in contract-replay.jsx

* remove connectionWithContractUpdate from reports

* fix openPositions default tab issue

* fix to not remove closed contracts when navigating from reporst to trader

* prevent unmounting the portfolio component when redirecting to reports packge

* fix performance issue on profit_loss input

* fix circular dependancy

Co-authored-by: Carol Sachdeva <58209918+carol-binary@users.noreply.github.com>
  • Loading branch information
2 people authored and likhith-deriv committed Jul 15, 2022
1 parent d68f87f commit 5fadc00
Show file tree
Hide file tree
Showing 220 changed files with 8,372 additions and 985 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ commands:
- "packages/cfd/node_modules"
- "packages/indicators/node_modules"
- "packages/p2p/node_modules"
- "packages/reports/node_modules"
- "packages/shared/node_modules"
- "packages/trader/node_modules"
- "packages/translations/node_modules"
Expand Down
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@

/packages/trader/**/* @matin-binary @balakrishna-binary @akmal-binary

# ==============================================================
# deriv-app/reports
# ==============================================================

/packages/reports/**/* @matin-binary @balakrishna-binary

# ==============================================================
# deriv-app/publisher
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
"build": "f () { lerna exec --scope=@deriv/${1:-'*'} -- npm run build $2 ;}; f",
"build:publish": "f () { lerna exec --scope=@deriv/${1:-'*'} -- npm run build:publish $2 ;}; f",
"build:local": "f () { lerna exec --scope @deriv/trader --scope @deriv/bot-web-ui --parallel -- npm run build $1 ;}; f",
"build:travis": "lerna exec --scope @deriv/shared --scope @deriv/components --scope @deriv/translations --scope @deriv/cashier --scope @deriv/account --scope @deriv/p2p --scope @deriv/cfd -- npm run build:travis",
"build:travis": "lerna exec --scope @deriv/shared --scope @deriv/components --scope @deriv/translations --scope @deriv/cashier --scope @deriv/account --scope @deriv/p2p --scope @deriv/cfd --scope @deriv/reports -- npm run build:travis",
"build:prod": "export NODE_ENV=staging && npm run build && export NODE_ENV=",
"build:storybook": "cd packages/components && build-storybook --output-dir .out",
"build:gh-pages": "f () { lerna exec --scope @deriv/components --scope @deriv/p2p -- npm run build && lerna exec --scope @deriv/cashier --scope @deriv/account --scope @deriv/cfd -- npm run build $1 && npm run build:local $1 ;}; f",
"build:gh-pages": "f () { lerna exec --scope @deriv/components --scope @deriv/p2p -- npm run build && lerna exec --scope @deriv/cashier --scope @deriv/account --scope @deriv/cfd --scope @deriv/reports -- npm run build $1 && npm run build:local $1 ;}; f",
"clean": "echo \"Remove $(git rev-parse --show-toplevel)/node_modules\" && lerna clean && rm -rf \"$(git rev-parse --show-toplevel)/node_modules\"",
"deploy": "f () { npm run build:travis && npm run build:local && lerna exec --scope @deriv/core -- npm run deploy $@ ;}; f",
"deploy:clean": "f () { npm run build:travis && npm run build:local && lerna exec --scope @deriv/core -- npm run deploy:clean $@ ;}; f",
Expand Down
1 change: 0 additions & 1 deletion packages/cfd/src/Containers/cfd-password-manager-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const CountdownComponent = ({ count_from = 60, onTimeout }: TCountdownComponent)
}

onTimeout();

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [count]);
return <span className='countdown'>{count}</span>;
Expand Down
3 changes: 1 addition & 2 deletions packages/cfd/src/Containers/cfd-password-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ const getCancelButtonLabel = ({

const handlePasswordInputChange = (
e: React.ChangeEvent<HTMLInputElement>,
// eslint-disable-next-line no-shadow
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void,
handleChange: (el: React.ChangeEvent<HTMLInputElement>) => void,
validateForm: (values?: TCFDPasswordFormValues) => Promise<FormikErrors<TCFDPasswordFormValues>>,
setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => void
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const ContractUpdateForm = props => {
validation_errors,
} = contract;

const [contract_profit_or_loss, setContractProfitOrLoss] = React.useState({
contract_update_take_profit,
contract_update_stop_loss,
});

const { buy_price, currency, is_valid_to_cancel, is_sold } = contract_info;
const { stop_loss, take_profit } = getLimitOrderAmount(contract_info.limit_order);
const { contract_update_stop_loss: stop_loss_error, contract_update_take_profit: take_profit_error } =
Expand Down Expand Up @@ -77,7 +82,10 @@ const ContractUpdateForm = props => {

const onChange = e => {
const { name, value } = e.target;

setContractProfitOrLoss({
...contract_profit_or_loss,
[name]: value,
});
if (typeof contract.onChange === 'function') {
contract.onChange({
name,
Expand Down Expand Up @@ -107,7 +115,7 @@ const ContractUpdateForm = props => {
name='contract_update_take_profit'
onChange={onChange}
error_message_alignment={error_message_alignment || 'right'}
value={contract_update_take_profit}
value={contract_profit_or_loss.contract_update_take_profit}
is_disabled={!!is_valid_to_cancel}
setCurrentFocus={setCurrentFocus}
/>
Expand All @@ -130,7 +138,7 @@ const ContractUpdateForm = props => {
name='contract_update_stop_loss'
onChange={onChange}
error_message_alignment={error_message_alignment || 'right'}
value={contract_update_stop_loss}
value={contract_profit_or_loss.contract_update_stop_loss}
is_disabled={!!is_valid_to_cancel}
setCurrentFocus={setCurrentFocus}
/>
Expand Down
8 changes: 8 additions & 0 deletions packages/core/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ const copyConfig = base => {
from: path.resolve(__dirname, '../node_modules/@deriv/trader/dist/trader'),
to: 'trader',
},
{
from: path.resolve(__dirname, '../node_modules/@deriv/reports/dist/reports/js/'),
to: 'reports/js',
},
{
from: path.resolve(__dirname, '../node_modules/@deriv/reports/dist/reports/css/'),
to: 'reports/css',
},
{
from: path.resolve(__dirname, '../node_modules/@deriv/cfd/dist/cfd'),
to: 'cfd',
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@deriv/deriv-api": "^1.0.8",
"@deriv/deriv-charts": "^0.6.0",
"@deriv/p2p": "^0.7.3",
"@deriv/reports": "^1.0.0",
"@deriv/shared": "^1.0.0",
"@deriv/trader": "^3.8.0",
"@deriv/translations": "^1.0.0",
Expand All @@ -116,6 +117,7 @@
"js-cookie": "^2.2.1",
"loadjs": "^4.2.0",
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"mobx": "^5.15.7",
"mobx-react": "6.3.1",
"mobx-utils": "^5.5.5",
Expand Down
61 changes: 33 additions & 28 deletions packages/core/src/App/Constants/routes-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const Trader = React.lazy(() =>
})
);

const Reports = React.lazy(() => {
// eslint-disable-next-line import/no-unresolved
return import(/* webpackChunkName: "reports" */ '@deriv/reports');
});

const CFD = React.lazy(() =>
moduleLoader(() => {
// eslint-disable-next-line import/no-unresolved
Expand Down Expand Up @@ -59,6 +64,34 @@ const getModules = ({ is_appstore }, is_social_signup) => {
// Don't use `Localize` component since native html tag like `option` cannot render them
getTitle: () => localize('Bot'),
},
{
path: routes.reports,
component: Reports,
getTitle: () => localize('Reports'),
icon_component: 'IcReports',
is_authenticated: true,
routes: [
{
path: routes.positions,
component: Reports,
getTitle: () => localize('Open positions'),
icon_component: 'IcOpenPositions',
default: true,
},
{
path: routes.profit,
component: Reports,
getTitle: () => localize('Profit table'),
icon_component: 'IcProfitTable',
},
{
path: routes.statement,
component: Reports,
getTitle: () => localize('Statement'),
icon_component: 'IcStatement',
},
],
},
{
path: routes.dxtrade,
component: props => <CFD {...props} platform='dxtrade' />,
Expand Down Expand Up @@ -235,34 +268,6 @@ const getModules = ({ is_appstore }, is_social_signup) => {
component: Trader,
getTitle: () => localize('Trader'),
routes: [
{
path: routes.reports,
component: Trader,
getTitle: () => localize('Reports'),
icon_component: 'IcReports',
is_authenticated: true,
routes: [
{
path: routes.positions,
component: Trader,
getTitle: () => localize('Open positions'),
icon_component: 'IcOpenPositions',
default: true,
},
{
path: routes.profit,
component: Trader,
getTitle: () => localize('Profit table'),
icon_component: 'IcProfitTable',
},
{
path: routes.statement,
component: Trader,
getTitle: () => localize('Statement'),
icon_component: 'IcStatement',
},
],
},
{
path: routes.contract,
component: Trader,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { expect } from 'chai';
import { configure, shallow, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import MarkerSpotLabel from '../marker-spot-label.jsx';

configure({ adapter: new Adapter() });

describe('MarkerSpotLabel', () => {
it('should render one <MarkerSpotLabel /> component', () => {
const wrapper = shallow(<MarkerSpotLabel />);
expect(wrapper).to.have.length(1);
});
it('should have class .chart-spot-label__time-value-container--top if align_label top is passed in props', () => {
const wrapper = shallow(<MarkerSpotLabel align_label={'top'} />);
expect(wrapper.find('.chart-spot-label__time-value-container--top').exists()).to.be.true;
});
it('should have class .chart-spot-label__time-value-container--bottom if align_label bottom is passed in props', () => {
const wrapper = shallow(<MarkerSpotLabel align_label={'bottom'} />);
expect(wrapper.find('.chart-spot-label__time-value-container--bottom').exists()).to.be.true;
});
it('should have class .chart-spot-label__time-value-container--top if no align_label is passed in props', () => {
const wrapper = shallow(<MarkerSpotLabel />);
expect(wrapper.find('.chart-spot-label__time-value-container--top').exists()).to.be.true;
expect(wrapper.find('.chart-spot-label__time-value-container--bottom').exists()).to.be.false;
});
it('should toggle label on hover if has_hover_toggle is passed in props', async () => {
const wrapper = mount(<MarkerSpotLabel has_hover_toggle={true} />);
expect(wrapper.find('.chart-spot-label__info-container').exists()).to.be.false;

wrapper.find('.marker-hover-container').simulate('mouseenter');
wrapper.update();
expect(wrapper.find('.chart-spot-label__info-container').exists()).to.be.true;

wrapper.find('.marker-hover-container').simulate('mouseleave');
wrapper.update();
expect(wrapper.find('.chart-spot-label__info-container').exists()).to.be.false;
});
it('should not toggle label on hover if has_label_toggle is not passed in props', () => {
const wrapper = shallow(<MarkerSpotLabel />);
expect(wrapper.find('.chart-spot-label__info-container').exists()).to.be.true;
expect(wrapper.find('.marker-hover-container').exists()).to.equal(false);
});
it('should have class .chart-spot-label__value-container--won if status won is passed in props', () => {
const wrapper = shallow(<MarkerSpotLabel status={'won'} />);
expect(wrapper.find('.chart-spot-label__value-container--won').exists()).to.be.true;
});
it('should have class .chart-spot-label__value-container--lost if status lost is passed in props', () => {
const wrapper = shallow(<MarkerSpotLabel status={'lost'} />);
expect(wrapper.find('.chart-spot-label__value-container--lost').exists()).to.be.true;
});
});
20 changes: 20 additions & 0 deletions packages/core/src/Components/markers/__tests__/marker-spot.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { expect } from 'chai';
import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import MarkerSpot from '../marker-spot.jsx';

configure({ adapter: new Adapter() });

describe('MarkerSpot', () => {
it('should render one <MarkerSpot /> component', () => {
const wrapper = shallow(<MarkerSpot />);
expect(wrapper).to.have.length(1);
});
it('should not have class .chart-spot__spot--lost or .chart-spot__spot--won if no status is passed in props', () => {
const wrapper = shallow(<MarkerSpot />);
expect(wrapper.find('.chart-spot__spot--lost').exists()).to.be.false;
expect(wrapper.find('.chart-spot__spot--lost').exists()).to.be.false;
expect(wrapper.find('.chart-spot').exists()).to.be.true;
});
});
38 changes: 38 additions & 0 deletions packages/core/src/Components/markers/marker-line.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import classNames from 'classnames';
import { observer } from 'mobx-react';
import PropTypes from 'prop-types';
import React from 'react';
import { Icon } from '@deriv/components';

const MarkerLine = ({ label, line_style, marker_config, status }) => {
// TODO: Find a more elegant solution
if (!marker_config) return <div />;
return (
<div className={classNames('chart-marker-line__wrapper', `chart-marker-line--${line_style}`)}>
{label === marker_config.LINE_END.content_config.label && (
<Icon
icon='IcContractExitTimeCircle'
className='chart-marker-line__icon'
color={status === 'lost' ? 'red' : 'green'}
size={24}
/>
)}
{label === marker_config.LINE_START.content_config.label && (
<Icon
icon='IcContractStartTimeCircle'
className='chart-marker-line__icon chart-marker-line__icon--time'
color='secondary'
size={24}
/>
)}
</div>
);
};

MarkerLine.propTypes = {
label: PropTypes.string,
line_style: PropTypes.string,
marker_config: PropTypes.object,
status: PropTypes.oneOf(['won', 'lost']),
};
export default observer(MarkerLine);
Loading

0 comments on commit 5fadc00

Please sign in to comment.