Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Oct 27, 2023
1 parent eed258f commit a75ddfd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/components/ProgressViewer/ProgressViewer.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.progress-viewer {
position: relative;
z-index: 0;

display: flex;
overflow: hidden;
Expand Down
38 changes: 14 additions & 24 deletions src/components/VirtualTable/TableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@ import type {Column, OnSort, SortOrderType, SortParams} from './types';
import {ASCENDING, DEFAULT_SORT_ORDER, DEFAULT_TABLE_ROW_HEIGHT, DESCENDING} from './constants';
import {b} from './shared';

// Icons similar to original DataTable icons to keep the same tables across diferent pages and tabs
const ICON_ASC = (
<svg className={b('icon')} viewBox="0 0 10 6" width="10" height="6">
<path fill="currentColor" d="M0 5h10l-5 -5z" />
</svg>
);
const ICON_DESC = (
<svg className={b('icon')} viewBox="0 0 10 6" width="10" height="6">
<path fill="currentColor" d="M0 1h10l-5 5z" />
</svg>
);

function getSortIcon(order?: SortOrderType) {
switch (order) {
case ASCENDING:
return ICON_ASC;
case DESCENDING:
return ICON_DESC;
default:
return false;
}
}
// Icon similar to original DataTable icons to keep the same tables across diferent pages and tabs
const SortIcon = ({order}: {order?: SortOrderType}) => {
return (
<svg
className={b('icon', {desc: order === DESCENDING})}
viewBox="0 0 10 6"
width="10"
height="6"
>
<path fill="currentColor" d="M0 5h10l-5 -5z" />
</svg>
);
};

interface ColumnSortIconProps {
sortOrder?: SortOrderType;
Expand All @@ -37,7 +28,7 @@ const ColumnSortIcon = ({sortOrder, sortable, defaultSortOrder}: ColumnSortIconP
if (sortable) {
return (
<span className={b('sort-icon', {shadow: !sortOrder})}>
{getSortIcon(sortOrder || defaultSortOrder)}
<SortIcon order={sortOrder || defaultSortOrder} />
</span>
);
} else {
Expand Down Expand Up @@ -117,7 +108,6 @@ export const TableHead = <T,>({
column.className,
)}
style={{
width: `${column.width}px`,
height: `${rowHeight}px`,
}}
onClick={() => {
Expand Down
16 changes: 2 additions & 14 deletions src/components/VirtualTable/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,14 @@ import {b} from './shared';

interface TableCellProps {
height: number;
width?: number;
align?: AlignType;
children: ReactNode;
className?: string;
}

const TableRowCell = ({
children,
width,
className,
height,
align = DEFAULT_ALIGN,
}: TableCellProps) => {
const TableRowCell = ({children, className, height, align = DEFAULT_ALIGN}: TableCellProps) => {
return (
<td
className={b('td', {align: align}, className)}
style={{width: width ? `${width}px` : undefined, height: `${height}px`}}
>
<td className={b('td', {align: align}, className)} style={{height: `${height}px`}}>
{children}
</td>
);
Expand All @@ -44,7 +34,6 @@ export const LoadingTableRow = <T,>({index, columns, height}: LoadingTableRowPro
return (
<TableRowCell
key={`${column.name}${index}`}
width={column.width}
height={height}
align={column.align}
className={column.className}
Expand Down Expand Up @@ -74,7 +63,6 @@ export const TableRow = <T,>({row, index, columns, getRowClassName, height}: Tab
return (
<TableRowCell
key={`${column.name}${index}`}
width={column.width}
height={height}
align={column.align}
className={column.className}
Expand Down
5 changes: 4 additions & 1 deletion src/components/VirtualTable/VirtualTable.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import '../../styles/mixins.scss';

.ydb-virtual-table {

$block: &;
$cell-border: 1px solid var(--virtual-table-border-color);
--virtual-table-cell-vertical-padding: 5px;
Expand Down Expand Up @@ -108,6 +107,10 @@

&__icon {
vertical-align: top;

&_desc {
transform: rotate(180deg);
}
}

&__td {
Expand Down
2 changes: 2 additions & 0 deletions src/components/VirtualTable/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const DEFAULT_SORT_ORDER = DESCENDING;
export const DEFAULT_REQUEST_TIMEOUT = 200;

export const DEFAULT_TABLE_ROW_HEIGHT = 40;

export const DEFAULT_INTERSECTION_OBSERVER_MARGIN = '100%';
3 changes: 2 additions & 1 deletion src/components/VirtualTable/useIntersectionObserver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useEffect, useRef} from 'react';

import type {OnEntry, OnLeave} from './types';
import {DEFAULT_INTERSECTION_OBSERVER_MARGIN} from './constants';

interface UseIntersectionObserverProps {
onEntry: OnEntry;
Expand Down Expand Up @@ -28,7 +29,7 @@ export const useIntersectionObserver = ({

observer.current = new IntersectionObserver(callback, {
root: parentContainer,
rootMargin: '50%',
rootMargin: DEFAULT_INTERSECTION_OBSERVER_MARGIN,
});

return () => {
Expand Down
7 changes: 1 addition & 6 deletions src/components/VirtualTable/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export const getArray = (arrayLength: number) => {
const rows = [];

for (let i = 0; i < arrayLength; i++) {
rows.push(i);
}
return rows;
return [...Array(arrayLength).keys()];
};

0 comments on commit a75ddfd

Please sign in to comment.