2022-03-02 07:31:35 +00:00
|
|
|
import * as Tabs from '@radix-ui/react-tabs';
|
2022-03-02 02:08:42 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { useRouter } from 'next/router';
|
2022-03-30 09:49:48 +00:00
|
|
|
import type { ReactElement, ReactNode } from 'react';
|
|
|
|
import { Children, isValidElement, useEffect, useState } from 'react';
|
2022-03-02 02:08:42 +00:00
|
|
|
|
|
|
|
interface GridTabsProps {
|
2022-03-28 19:34:45 +00:00
|
|
|
children: ReactElement<GridTabProps>[];
|
2022-03-02 02:08:42 +00:00
|
|
|
group: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const GridTabs = ({ children, group }: GridTabsProps) => {
|
|
|
|
const { query, asPath, replace } = useRouter();
|
|
|
|
const [activeTab, setActiveTab] = useState<string>(() => {
|
2022-03-28 19:34:45 +00:00
|
|
|
const tab = query[group];
|
|
|
|
|
|
|
|
if (typeof tab === 'string') {
|
|
|
|
return tab;
|
2022-03-02 02:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default to first tab
|
2022-03-31 01:08:25 +00:00
|
|
|
return children[0].props.id;
|
2022-03-02 02:08:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// 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);
|
2022-03-02 07:40:38 +00:00
|
|
|
replace(`${url}?${searchParams.toString()}`);
|
|
|
|
// replace and using asPath causes a render loop
|
|
|
|
// eslint-disable-next-line
|
|
|
|
}, [activeTab, group]);
|
2022-03-02 02:08:42 +00:00
|
|
|
|
|
|
|
return (
|
2022-03-02 07:31:35 +00:00
|
|
|
<Tabs.Root
|
|
|
|
value={activeTab}
|
|
|
|
className="h-full grid grid-rows-[min-content_1fr]"
|
|
|
|
onValueChange={(value) => setActiveTab(value)}
|
|
|
|
>
|
2022-03-09 16:59:48 +00:00
|
|
|
<Tabs.List
|
2022-03-11 05:19:44 +00:00
|
|
|
className="flex flex-nowrap gap-4 overflow-x-auto"
|
2022-03-09 16:59:48 +00:00
|
|
|
role="tablist"
|
|
|
|
>
|
2022-03-02 02:08:42 +00:00
|
|
|
{Children.map(children, (child) => {
|
2022-03-02 07:31:35 +00:00
|
|
|
if (!isValidElement(child)) return null;
|
2022-03-31 01:08:25 +00:00
|
|
|
const isActive = child.props.id === activeTab;
|
2022-03-09 16:59:48 +00:00
|
|
|
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,
|
|
|
|
});
|
2022-03-02 07:31:35 +00:00
|
|
|
return (
|
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 15:11:27 +00:00
|
|
|
<Tabs.Trigger
|
|
|
|
data-testid={child.props.name}
|
|
|
|
value={child.props.id}
|
|
|
|
className={triggerClass}
|
|
|
|
>
|
2022-03-02 07:31:35 +00:00
|
|
|
{child.props.name}
|
|
|
|
</Tabs.Trigger>
|
|
|
|
);
|
2022-03-02 02:08:42 +00:00
|
|
|
})}
|
2022-03-09 16:59:48 +00:00
|
|
|
<div className="bg-black-10 dark:bg-white-10 grow"></div>
|
2022-03-02 07:31:35 +00:00
|
|
|
</Tabs.List>
|
2022-03-02 02:08:42 +00:00
|
|
|
<div className="h-full overflow-auto">
|
|
|
|
{Children.map(children, (child) => {
|
2022-03-02 07:31:35 +00:00
|
|
|
if (!isValidElement(child)) return null;
|
|
|
|
return (
|
2022-03-31 01:08:25 +00:00
|
|
|
<Tabs.Content value={child.props.id} className="h-full">
|
2022-03-02 07:31:35 +00:00
|
|
|
{child.props.children}
|
|
|
|
</Tabs.Content>
|
|
|
|
);
|
2022-03-02 02:08:42 +00:00
|
|
|
})}
|
|
|
|
</div>
|
2022-03-02 07:31:35 +00:00
|
|
|
</Tabs.Root>
|
2022-03-02 02:08:42 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface GridTabProps {
|
|
|
|
children: ReactNode;
|
2022-03-31 01:08:25 +00:00
|
|
|
id: string;
|
2022-03-02 02:08:42 +00:00
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const GridTab = ({ children }: GridTabProps) => {
|
|
|
|
return <div>{children}</div>;
|
|
|
|
};
|