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

Commit 463d6eb

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: fixing table issue
1 parent bc14e9f commit 463d6eb

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

src/features/dashboard/components/ApiTokenTable/api-table.module.scss

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
.api_table_container {
44
position: relative;
5-
.api_table {
6-
height: rem(30);
7-
min-height: 10rem;
8-
table {
9-
position: absolute;
10-
}
5+
overflow-y: hidden;
6+
overflow-x: auto;
7+
.api_table table {
8+
position: absolute;
119
}
1210
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { HTMLAttributes } from 'react';
1+
import React, { HTMLAttributes, useEffect, useRef, useState } from 'react';
22
import { Circles } from 'react-loader-spinner';
33
import styles from './api-table.module.scss';
44
import useApiToken from '@site/src/hooks/useApiToken';
@@ -38,10 +38,24 @@ const tableColumns: TTokenColumn[] = [
3838
];
3939

4040
const ApiTokenTable = (props: HTMLAttributes<HTMLDivElement>) => {
41+
const TABLE_HEADER_HEIGHT = 125;
4142
const { tokens, isLoadingTokens } = useApiToken();
43+
const [table_height, setTableHeight] = useState(0);
44+
const table_row_ref = useRef(null);
45+
46+
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.clientHeight;
50+
setTableHeight(row_height * tokens.length);
51+
}
52+
}, [tokens, table_row_ref]);
4253

4354
return (
44-
<div className={styles.api_table_container}>
55+
<div
56+
style={{ height: `calc(${table_height}px + ${TABLE_HEADER_HEIGHT}px + 50px)` }}
57+
className={styles.api_table_container}
58+
>
4559
<div className={styles.api_table} {...props}>
4660
<Circles
4761
height='100'
@@ -55,6 +69,7 @@ const ApiTokenTable = (props: HTMLAttributes<HTMLDivElement>) => {
5569
columns={tableColumns}
5670
data={tokens}
5771
initialState={{ hiddenColumns: ['valid_for_ip'] }}
72+
table_row_ref={table_row_ref}
5873
/>
5974
</div>
6075
</div>

src/features/dashboard/components/NoApps/no-apps.module.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
position: relative;
1111
display: flex;
1212
flex-direction: column;
13-
justify-content: var(center);
13+
justify-content: center;
1414
align-items: center;
1515
width: calc(rem(32) - rem(3.2));
1616
position: relative;
@@ -28,13 +28,13 @@
2828
height: rem(10);
2929
}
3030

31-
.noAppsText {
31+
.noAppsText p {
3232
text-align: center;
33+
margin-bottom: rem(2);
3334
}
3435

3536
[data-state*="responsive.desktop"] {
3637
.noAppsWrapper {
37-
width: calc(100% - rem(12.5));
3838
position: relative;
3939
}
4040
.noApps {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { HTMLAttributes } from 'react';
1+
import React, { HTMLAttributes, LegacyRef, ReactNode } from 'react';
22
import { Cell, Column, TableState, useTable } from 'react-table';
33
import './table.scss';
44

@@ -8,6 +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>;
1112
getCustomCellProps?: (cell: Cell<T, unknown>) => object;
1213
}
1314

@@ -16,6 +17,7 @@ const Table = <T extends object>({
1617
columns,
1718
initialState,
1819
getCustomCellProps = defaultPropGetter,
20+
table_row_ref,
1921
...rest
2022
}: ITableProps<T>) => {
2123
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable<T>({
@@ -41,7 +43,7 @@ const Table = <T extends object>({
4143
{rows.map((row) => {
4244
prepareRow(row);
4345
return (
44-
<tr key={row.getRowProps().key} {...row.getRowProps()}>
46+
<tr ref={table_row_ref} key={row.getRowProps().key} {...row.getRowProps()}>
4547
{row.cells.map((cell) => {
4648
return (
4749
<td key={cell.getCellProps().key} {...cell.getCellProps()}>

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

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

1013
thead {

src/features/dashboard/components/Tabs/tabs.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@
5151
justify-content: space-around;
5252
align-items: center;
5353
padding: rem(2);
54+
overflow-y: auto;
5455
}

0 commit comments

Comments
 (0)