fix(trading): welcome dialog with markets list click on market close window (#3404)

This commit is contained in:
Maciek 2023-04-11 11:34:44 +02:00 committed by GitHub
parent 29d57af2ba
commit b010c98346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 25 deletions

View File

@ -185,7 +185,7 @@ export const columns = (
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
onSelect(market.id, e.metaKey); onSelect(market.id, e.metaKey || e.ctrlKey);
}} }}
> >
<UILink>{market.tradableInstrument.instrument.code}</UILink> <UILink>{market.tradableInstrument.instrument.code}</UILink>
@ -366,7 +366,7 @@ export const columnsPositionMarkets = (
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
onSelect(market.id, e.metaKey); onSelect(market.id, e.metaKey || e.ctrlKey);
}} }}
> >
<UILink>{market.tradableInstrument.instrument.code}</UILink> <UILink>{market.tradableInstrument.instrument.code}</UILink>

View File

@ -44,7 +44,7 @@ export const SelectMarketTableRow = ({
<tr <tr
className={`hover:bg-neutral-200 dark:hover:bg-neutral-700 cursor-pointer relative h-[34px]`} className={`hover:bg-neutral-200 dark:hover:bg-neutral-700 cursor-pointer relative h-[34px]`}
onClick={(ev) => { onClick={(ev) => {
onSelect(marketId, ev.metaKey); onSelect(marketId, ev.metaKey || ev.ctrlKey);
}} }}
data-testid={`market-link-${marketId}`} data-testid={`market-link-${marketId}`}
> >

View File

@ -8,6 +8,10 @@ import type {
MarketData, MarketData,
} from '@vegaprotocol/market-list'; } from '@vegaprotocol/market-list';
import { SelectMarketLandingTable } from './welcome-landing-dialog'; import { SelectMarketLandingTable } from './welcome-landing-dialog';
const mockMarketClickHandler = jest.fn();
jest.mock('../../lib/hooks/use-market-click-handler', () => ({
useMarketClickHandler: () => mockMarketClickHandler,
}));
type Market = MarketMaybeWithCandles & MarketMaybeWithData; type Market = MarketMaybeWithCandles & MarketMaybeWithData;
type PartialMarket = Partial< type PartialMarket = Partial<
@ -174,4 +178,25 @@ describe('WelcomeLandingDialog', () => {
fireEvent.click(screen.getAllByTestId(`market-link-2`)[0]); fireEvent.click(screen.getAllByTestId(`market-link-2`)[0]);
expect(onClose).toHaveBeenCalled(); expect(onClose).toHaveBeenCalled();
}); });
it('should not call onClose when metaKey is held', () => {
const onClose = jest.fn();
render(
<MemoryRouter>
<SelectMarketLandingTable
markets={[MARKET_A as Market, MARKET_B as Market]}
onClose={onClose}
/>
</MemoryRouter>,
{ wrapper: MockedProvider }
);
fireEvent.click(screen.getAllByTestId(`market-link-1`)[0], {
metaKey: true,
});
expect(mockMarketClickHandler).toHaveBeenCalled();
expect(onClose).not.toHaveBeenCalled();
fireEvent.click(screen.getAllByTestId(`market-link-1`)[0]);
expect(onClose).toHaveBeenCalled();
});
}); });

View File

@ -12,9 +12,10 @@ import {
SelectMarketTableRow, SelectMarketTableRow,
} from '../select-market'; } from '../select-market';
import { WelcomeDialogHeader } from './welcome-dialog-header'; import { WelcomeDialogHeader } from './welcome-dialog-header';
import { Link, useNavigate, useParams } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { ProposedMarkets } from './proposed-markets'; import { ProposedMarkets } from './proposed-markets';
import { Links, Routes } from '../../pages/client-router'; import { Links, Routes } from '../../pages/client-router';
import { useMarketClickHandler } from '../../lib/hooks/use-market-click-handler';
export const SelectMarketLandingTable = ({ export const SelectMarketLandingTable = ({
markets, markets,
@ -23,23 +24,13 @@ export const SelectMarketLandingTable = ({
markets: MarketMaybeWithDataAndCandles[] | null; markets: MarketMaybeWithDataAndCandles[] | null;
onClose: () => void; onClose: () => void;
}) => { }) => {
const params = useParams(); const onSelect = useMarketClickHandler();
const navigate = useNavigate();
const marketId = params.marketId;
const onSelect = useCallback(
(id: string) => {
if (id && id !== marketId) {
navigate(Links[Routes.MARKET](id));
}
},
[marketId, navigate]
);
const onSelectMarket = useCallback( const onSelectMarket = useCallback(
(id: string) => { (id: string, metaKey?: boolean) => {
onSelect(id); onSelect(id, metaKey);
onClose(); if (!metaKey) {
onClose();
}
}, },
[onSelect, onClose] [onSelect, onClose]
); );
@ -73,7 +64,7 @@ export const SelectMarketLandingTable = ({
key={i} key={i}
detailed={false} detailed={false}
onSelect={onSelectMarket} onSelect={onSelectMarket}
columns={columns(market, onSelect, onCellClick)} columns={columns(market, onSelectMarket, onCellClick)}
/> />
))} ))}
</tbody> </tbody>

View File

@ -21,7 +21,7 @@ export const MarketNameCell = ({
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
if (onMarketClick) { if (onMarketClick) {
onMarketClick(id, ev.metaKey); onMarketClick(id, ev.metaKey || ev.ctrlKey);
} }
}, },
[id, onMarketClick] [id, onMarketClick]

View File

@ -78,7 +78,9 @@ export const compileGridData = (
label: ( label: (
<Link <Link
to={`/liquidity/${market.id}`} to={`/liquidity/${market.id}`}
onClick={(ev) => onSelect && onSelect(market.id, ev.metaKey)} onClick={(ev) =>
onSelect && onSelect(market.id, ev.metaKey || ev.ctrlKey)
}
> >
<UILink>{t('Current liquidity')}</UILink> <UILink>{t('Current liquidity')}</UILink>
</Link> </Link>

View File

@ -169,7 +169,7 @@ export const Info = ({ market, onSelect }: InfoProps) => {
<LiquidityInfoPanel market={market}> <LiquidityInfoPanel market={market}>
<Link <Link
to={`/liquidity/${market.id}`} to={`/liquidity/${market.id}`}
onClick={(ev) => onSelect?.(market.id, ev.metaKey)} onClick={(ev) => onSelect?.(market.id, ev.metaKey || ev.ctrlKey)}
data-testid="view-liquidity-link" data-testid="view-liquidity-link"
> >
<UILink>{t('View liquidity provision table')}</UILink> <UILink>{t('View liquidity provision table')}</UILink>

View File

@ -47,7 +47,8 @@ export const MarketsContainer = ({ onSelect }: MarketsContainerProps) => {
} }
onSelect( onSelect(
(data as MarketMaybeWithData).id, (data as MarketMaybeWithData).id,
(event as unknown as MouseEvent)?.metaKey (event as unknown as MouseEvent)?.metaKey ||
(event as unknown as MouseEvent)?.ctrlKey
); );
}} }}
onMarketClick={onSelect} onMarketClick={onSelect}