import React from 'react'; import { ColumnDef } from '@tanstack/react-table'; import { useTheme } from 'styled-components'; import PageHeading from 'components/common/PageHeading/PageHeading'; import Table from 'components/common/NewTable'; import DeleteIcon from 'components/common/Icons/DeleteIcon'; import { useConfirm } from 'lib/hooks/useConfirm'; import useAppParams from 'lib/hooks/useAppParams'; import { useAcls, useDeleteAcl } from 'lib/hooks/api/acl'; import { ClusterName } from 'redux/interfaces'; import { KafkaAcl, KafkaAclNamePatternType, KafkaAclPermissionEnum, } from 'generated-sources'; import * as S from './List.styled'; const ACList: React.FC = () => { const { clusterName } = useAppParams<{ clusterName: ClusterName }>(); const theme = useTheme(); const { data: aclList } = useAcls(clusterName); const { deleteResource } = useDeleteAcl(clusterName); const modal = useConfirm(true); const [rowId, setRowId] = React.useState(''); const onDeleteClick = (acl: KafkaAcl | null) => { if (acl) { modal('Are you sure want to delete this ACL record?', () => deleteResource(acl) ); } }; const columns = React.useMemo[]>( () => [ { header: 'Principal', accessorKey: 'principal', size: 257, }, { header: 'Resource', accessorKey: 'resourceType', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue }) => ( {getValue().toLowerCase()} ), size: 145, }, { header: 'Pattern', accessorKey: 'resourceName', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue, row }) => { let chipType; if ( row.original.namePatternType === KafkaAclNamePatternType.PREFIXED ) { chipType = 'default'; } if ( row.original.namePatternType === KafkaAclNamePatternType.LITERAL ) { chipType = 'secondary'; } return ( {getValue()} {chipType ? ( {row.original.namePatternType.toLowerCase()} ) : null} ); }, size: 257, }, { header: 'Host', accessorKey: 'host', size: 257, }, { header: 'Operation', accessorKey: 'operation', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue }) => ( {getValue().toLowerCase()} ), size: 121, }, { header: 'Permission', accessorKey: 'permission', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue }) => ( () === KafkaAclPermissionEnum.ALLOW ? 'success' : 'danger' } > {getValue().toLowerCase()} ), size: 111, }, { id: 'delete', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ row }) => { return ( onDeleteClick(row.original)}> ); }, size: 76, }, ], [rowId] ); const onRowHover = (value: unknown) => { if (value && typeof value === 'object' && 'id' in value) { setRowId(value.id as string); } }; return ( <> setRowId('')} /> ); }; export default ACList;