1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00
unleash.unleash/frontend/src/component/environments/EnvironmentTable/EnvironmentRow/EnvironmentRow.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

62 lines
2.0 KiB
TypeScript

import { MoveListItem, useDragItem } from 'hooks/useDragItem';
import { Row } from 'react-table';
import { styled, TableRow } from '@mui/material';
import { TableCell } from 'component/common/Table';
import { useSearchHighlightContext } from 'component/common/Table/SearchHighlightContext/SearchHighlightContext';
import { UPDATE_ENVIRONMENT } from 'component/providers/AccessProvider/permissions';
import AccessContext from 'contexts/AccessContext';
import { ForwardedRef, useContext, useRef } from 'react';
const StyledTableRow = styled(TableRow)(() => ({
'&:hover': {
'.drag-handle .drag-icon': {
display: 'inherit',
cursor: 'grab',
},
},
}));
interface IEnvironmentRowProps {
row: Row;
moveListItem: MoveListItem;
}
export const EnvironmentRow = ({ row, moveListItem }: IEnvironmentRowProps) => {
const { hasAccess } = useContext(AccessContext);
const dragHandleRef = useRef(null);
const { searchQuery } = useSearchHighlightContext();
const draggable = !searchQuery && hasAccess(UPDATE_ENVIRONMENT);
const dragItemRef = useDragItem<HTMLTableRowElement>(
row.index,
moveListItem,
dragHandleRef,
);
const renderCell = (cell: any, ref: ForwardedRef<HTMLElement>) => {
if (draggable && cell.column.isDragHandle) {
return (
<TableCell
{...cell.getCellProps()}
ref={ref}
className='drag-handle'
>
{cell.render('Cell')}
</TableCell>
);
} else {
return (
<TableCell {...cell.getCellProps()}>
{cell.render('Cell')}
</TableCell>
);
}
};
return (
<StyledTableRow hover ref={draggable ? dragItemRef : undefined}>
{row.cells.map((cell: any) => renderCell(cell, dragHandleRef))}
</StyledTableRow>
);
};