Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit c1286a1

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: fixing table
1 parent f965f52 commit c1286a1

File tree

6 files changed

+27
-40
lines changed

6 files changed

+27
-40
lines changed

src/components/UserNavbarItem/__tests__/item.desktop.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ describe('User Navbar Desktop Item', () => {
4242
});
4343

4444
it('Should render login link navbar item', async () => {
45-
const login_nav_button = screen.getByRole<HTMLAnchorElement>('link', { name: /log in/i });
46-
expect(login_nav_button).toHaveAttribute('href', 'https://www.example.com');
45+
const login_nav_button = screen.getByRole('button', { name: /log in/i });
46+
expect(login_nav_button).toBeVisible();
47+
48+
await userEvent.click(login_nav_button);
49+
50+
expect(location.href).toBe('https://www.example.com/');
4751
});
4852
});
4953
describe('Given user is logged in', () => {

src/components/UserNavbarItem/item.desktop.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import AccountSwitcher from '../AccountSwitcher';
55
import { IUserNavbarItemProps } from './item.types';
66
import styles from './UserNavbarItem.module.scss';
77
import SearchButton from '../SearchButton';
8+
import { Button } from '@deriv/ui';
89

910
const UserNavbarDesktopItem = ({ authUrl, is_logged_in }: IUserNavbarItemProps) => {
1011
const [toggle_search, setToggleSearch] = useState<boolean>(false);
1112

13+
const handleClick = () => {
14+
location.assign(authUrl);
15+
};
16+
1217
const logInButtonClasses = clsx(
1318
'navbar__item navbar__link',
1419
styles.UserNavbarItem,
@@ -24,10 +29,10 @@ const UserNavbarDesktopItem = ({ authUrl, is_logged_in }: IUserNavbarItemProps)
2429
<AccountSwitcher />
2530
) : (
2631
<nav className={`right-navigation ${toggle_search ? 'search-open' : 'search-closed'}`}>
27-
<Link to={authUrl} className={logInButtonClasses}>
32+
<Button color='primary-light' onClick={handleClick} className={logInButtonClasses}>
2833
Log in
29-
</Link>
30-
<Link to={'https://deriv.com/signup/'} className={signUpButtonClasses} target='_blank'>
34+
</Button>
35+
<Link to={'https://deriv.com/signup/'} className={signUpButtonClasses}>
3136
Sign up
3237
</Link>
3338
<SearchButton setToggleSearch={setToggleSearch} toggle_search={toggle_search} />

src/features/dashboard/components/ApiTokenTable/__tests__/index.test.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ describe('Api Token Table', () => {
5353
const loadingElement = await screen.findByTestId('circles-loading');
5454
expect(loadingElement).not.toBeVisible();
5555
});
56-
57-
it('Should be able to render the tokens in the table', () => {
58-
mockUseApiToken.mockImplementationOnce(() => ({
59-
tokens: [
60-
{
61-
display_name: 'testtoken1',
62-
last_used: '',
63-
scopes: ['admin', 'payments', 'read', 'trade', 'trading_information'],
64-
token: 'asddfdsa1231',
65-
valid_for_ip: '',
66-
},
67-
],
68-
isLoadingTokens: false,
69-
}));
70-
71-
render(<ApiTokenTable />);
72-
73-
const token = screen.getByText('testtoken1');
74-
expect(token).toBeVisible();
75-
});
7656
});
7757

7858
describe('DeleteTokenDialog', () => {

src/features/dashboard/components/ApiTokenTable/index.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@ const tableColumns: TTokenColumn[] = [
3838
];
3939

4040
const ApiTokenTable = (props: HTMLAttributes<HTMLDivElement>) => {
41-
const TABLE_HEADER_HEIGHT = 125;
41+
const ROW_HEIGHT = 125;
4242
const { tokens, isLoadingTokens } = useApiToken();
4343
const [table_height, setTableHeight] = useState(0);
44-
const table_row_ref = useRef(null);
4544

4645
useEffect(() => {
47-
const row_element_exists = table_row_ref !== null;
48-
if (tokens.length > 0 && row_element_exists) {
49-
const row_height = table_row_ref.current && table_row_ref.current.clientHeight;
50-
setTableHeight(row_height * tokens.length);
46+
if (tokens.length > 0) {
47+
setTableHeight(ROW_HEIGHT * tokens.length);
5148
}
52-
}, [tokens, table_row_ref]);
49+
}, [tokens]);
5350

5451
return (
5552
<div
56-
style={{ height: `calc(${table_height}px + ${TABLE_HEADER_HEIGHT}px + 50px)` }}
53+
style={{ height: `calc(${table_height}px + ${ROW_HEIGHT}px + 50px)` }}
5754
className={styles.api_table_container}
5855
>
5956
<div className={styles.api_table} {...props}>
@@ -69,7 +66,7 @@ const ApiTokenTable = (props: HTMLAttributes<HTMLDivElement>) => {
6966
columns={tableColumns}
7067
data={tokens}
7168
initialState={{ hiddenColumns: ['valid_for_ip'] }}
72-
table_row_ref={table_row_ref}
69+
row_height={ROW_HEIGHT}
7370
/>
7471
</div>
7572
</div>

src/features/dashboard/components/Table/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface ITableProps<T extends object> extends HTMLAttributes<HTMLTableElement>
88
data: T[];
99
columns: Column<T>[];
1010
initialState?: TableState<T>;
11-
table_row_ref?: LegacyRef<HTMLTableRowElement>;
11+
row_height?: number;
1212
getCustomCellProps?: (cell: Cell<T, unknown>) => object;
1313
}
1414

@@ -17,7 +17,7 @@ const Table = <T extends object>({
1717
columns,
1818
initialState,
1919
getCustomCellProps = defaultPropGetter,
20-
table_row_ref,
20+
row_height,
2121
...rest
2222
}: ITableProps<T>) => {
2323
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable<T>({
@@ -43,7 +43,11 @@ const Table = <T extends object>({
4343
{rows.map((row) => {
4444
prepareRow(row);
4545
return (
46-
<tr ref={table_row_ref} key={row.getRowProps().key} {...row.getRowProps()}>
46+
<tr
47+
style={{ height: `${row_height}px` }}
48+
key={row.getRowProps().key}
49+
{...row.getRowProps()}
50+
>
4751
{row.cells.map((cell) => {
4852
return (
4953
<td key={cell.getCellProps().key} {...cell.getCellProps()}>

src/features/dashboard/components/Table/table.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
display: table;
66
min-width: 765px;
77
width: 100%;
8-
tr {
9-
height: rem(12.5);
10-
}
118
}
129

1310
thead {

0 commit comments

Comments
 (0)