vega-frontend-monorepo/apps/trading/pages/markets/grid-tabs.tsx
Joe Tsang 205f4124f1
Test/deal ticket tests (#161)
* scaffold dealticket package, remove trading views from react-helpers

* add deal ticket component, add intent utils, expand dialog and form group styles

* add splash component, show market not found message if market doesnt exist

* tidy up error handling

* add handleError method for vega tx hook

* add better testname for provider test, flesh out tests a bit more for deal ticket

* Add unit tests for useVegaTransaction and useOrderSubmit hooks

* add wrapper component for order dialog styles

* add vega styled loader to ui toolkit and use in order dialog

* add title prop to order dialog

* split limit and market tickets into own files

* add button radio component

* revert dialog styles

* move splash component to ui-toolkit, add story

* convert intent to enum

* Make button always type=button unless type prop is passed

* inline filter logic for tif selector

* add date-fns, add datetime to helpers

* add order types to wallet package, make price undefined if order type is market

* use enums in deal ticket logic

* tidy up order state by moving submit and transaction hooks out of deal ticket

* add comment for dialog styles

* remove decimal from price input

* add types package, delete old generated types from trading project

* rename types package to graphql

* update generate command to point to correct locations

* fix use order submit test

* BDD and navigation tests passing

* Remove commented steps

* Steps up to placing order

* Date picker and date-fns update

* Vega connector wallet tests

* Passing up to request sent, updated date picker

* Tests for sell orders and errors

* Update market feature

* Fix failing tests

* Update wallet login

* Readded tx hash assertion and remaining tests

* Add CI wallet import

* Update .github/workflows/cypress.yml

Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>

* Resolved PR comments

* Fix yaml error

* Attempt to fix failing tests in CI

* Run Cypress in Chrome

* Add reload if public key error displayed

* Fix wallet name

* Add force click and waits

* Increase timeout for deal ticket page

* Removed network list from yaml and using input error id

* Increase timeout to 8 seconds

* Re add deleted test id

Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
2022-04-04 16:11:27 +01:00

90 lines
2.7 KiB
TypeScript

import * as Tabs from '@radix-ui/react-tabs';
import classNames from 'classnames';
import { useRouter } from 'next/router';
import type { ReactElement, ReactNode } from 'react';
import { Children, isValidElement, useEffect, useState } from 'react';
interface GridTabsProps {
children: ReactElement<GridTabProps>[];
group: string;
}
export const GridTabs = ({ children, group }: GridTabsProps) => {
const { query, asPath, replace } = useRouter();
const [activeTab, setActiveTab] = useState<string>(() => {
const tab = query[group];
if (typeof tab === 'string') {
return tab;
}
// Default to first tab
return children[0].props.id;
});
// Update the query string in the url when the active tab changes
// uses group property as the query stirng key
useEffect(() => {
const [url, queryString] = asPath.split('?');
const searchParams = new URLSearchParams(queryString);
searchParams.set(group, activeTab as string);
replace(`${url}?${searchParams.toString()}`);
// replace and using asPath causes a render loop
// eslint-disable-next-line
}, [activeTab, group]);
return (
<Tabs.Root
value={activeTab}
className="h-full grid grid-rows-[min-content_1fr]"
onValueChange={(value) => setActiveTab(value)}
>
<Tabs.List
className="flex flex-nowrap gap-4 overflow-x-auto"
role="tablist"
>
{Children.map(children, (child) => {
if (!isValidElement(child)) return null;
const isActive = child.props.id === activeTab;
const triggerClass = classNames('py-4', 'px-12', 'capitalize', {
'text-black dark:text-vega-yellow': isActive,
'bg-white dark:bg-black': isActive,
'text-black dark:text-white': !isActive,
'bg-black-10 dark:bg-white-10': !isActive,
});
return (
<Tabs.Trigger
data-testid={child.props.name}
value={child.props.id}
className={triggerClass}
>
{child.props.name}
</Tabs.Trigger>
);
})}
<div className="bg-black-10 dark:bg-white-10 grow"></div>
</Tabs.List>
<div className="h-full overflow-auto">
{Children.map(children, (child) => {
if (!isValidElement(child)) return null;
return (
<Tabs.Content value={child.props.id} className="h-full">
{child.props.children}
</Tabs.Content>
);
})}
</div>
</Tabs.Root>
);
};
interface GridTabProps {
children: ReactNode;
id: string;
name: string;
}
export const GridTab = ({ children }: GridTabProps) => {
return <div>{children}</div>;
};