kafka-ui/kafka-ui-react-app/src/components/Connect/List/ListItem.tsx
Mgrdich 71ac16357b
react router migration (#2045)
* remove withRouter HOC from FiltersContainer

* remove withRouter HOC from Topics DetailsContainer

* remove withRouter HOC from Topics TopicsConsumerGroupsContainer

* withRouter HOC from Topics TopicsConsumerGroupsContainer

* minor code refactor in the Details spec

* Routes code modifications to refactor strings representation to functions

* Settings and TopicsConsumer removal of HOC with Router

* Remove withRouter HOC from Overview file

* Remove withRouter HOC from Edit file

* replace Router path with functions instead of strings

* delete CustomParamsContainer and use the simple component in the TopicForm

* remove HOC from DangerZone container

* Remove withRouter HOC from Connect pages like Config , Overview , Tasks

* Remove withRouter HOC from Connect pages like Actions, Details, Edit, New

* Refactor Kafka Connect Codes

* Refactor Topics pages

* Remove HOC from Diff component and minor code refactor

* Route component migration into children instead of renderProps or component param in App Component

* Route component migration into children instead of renderProps or component param in Cluster Component

* Route component migration into children instead of renderProps or component param in Topics Component

* Route component migration into children instead of renderProps or component param in Topic Component

* Route component migration into children instead of renderProps or component param in Topic Component

* minor bug fix in the Overview selector spread

* change Router from component Render to child render
in ConsumerGroups page

* change Router from component Render to child render
in Schemas page

* change Router from component Render to child render
in KsqlDb page

* change Router from component Render to child render
in Connect page

* change Router from component Render to child render
in Connect Details page

* Overview Details styling code modifications

* All written path to paths with functions

* Route Parameters code fix with functions and params with variables

* Updating BreadCrumb Route

* Refactor Redirects

* WIP React Router v6 migration

* Remove unused imports from the file

* Make KsqlDb pages work with relative Routes

* WIP Make Connect pages work and fix the Schema page testing problem

* transforming consumer groups into relative path router

* Transform Topics pages into relative routes

* Transform Topic pages into relative routes

* Minor changes in Connect and KsqlDb test suites relative routes

* Minor changes in Connect and KsqlDb test suites relative routes

* change the Details into relative Routes

* Topics List naviagtion and caching issue fixed in tests suites

* Topic New Naviagation issue fix + tests suites

* Details navigate migrating into relative paths

* Send Message Submit Naviagttion with tests suites

* Topic Edit pages with working routes navigation

* Topic Details and ResetOffsets Pages tests suites and navigations

* Messages Table Tests suites

* BreadCrumbs Routes fixes

* ClusterMenu and Links styling minor code modifications

* ClusterMenu and Links styling minor code modifications

* Minor Code modifications

* Fix Lintter Problems

* fix Code Smells

* create custom useParams hook

* Adding Path tests

* minor code refactors

* Fix the Button Component redundant Props + transforming routes to relative

* Fix linter issues
2022-05-31 12:33:15 +03:00

110 lines
3.1 KiB
TypeScript

import React from 'react';
import { FullConnectorInfo } from 'generated-sources';
import { clusterConnectConnectorPath, clusterTopicPath } from 'lib/paths';
import { ClusterName } from 'redux/interfaces';
import { Link, NavLink } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { deleteConnector } from 'redux/reducers/connect/connectSlice';
import Dropdown from 'components/common/Dropdown/Dropdown';
import DropdownItem from 'components/common/Dropdown/DropdownItem';
import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal';
import { Tag } from 'components/common/Tag/Tag.styled';
import { TableKeyLink } from 'components/common/table/Table/TableKeyLink.styled';
import VerticalElipsisIcon from 'components/common/Icons/VerticalElipsisIcon';
import getTagColor from 'components/common/Tag/getTagColor';
import * as S from './List.styled';
export interface ListItemProps {
clusterName: ClusterName;
connector: FullConnectorInfo;
}
const ListItem: React.FC<ListItemProps> = ({
clusterName,
connector: {
name,
connect,
type,
connectorClass,
topics,
status,
tasksCount,
failedTasksCount,
},
}) => {
const dispatch = useDispatch();
const [
isDeleteConnectorConfirmationVisible,
setDeleteConnectorConfirmationVisible,
] = React.useState(false);
const handleDelete = () => {
if (clusterName && connect && name) {
dispatch(
deleteConnector({
clusterName,
connectName: connect,
connectorName: name,
})
);
}
setDeleteConnectorConfirmationVisible(false);
};
const runningTasks = React.useMemo(() => {
if (!tasksCount) return null;
return tasksCount - (failedTasksCount || 0);
}, [tasksCount, failedTasksCount]);
return (
<tr>
<TableKeyLink>
<NavLink to={clusterConnectConnectorPath(clusterName, connect, name)}>
{name}
</NavLink>
</TableKeyLink>
<td>{connect}</td>
<td>{type}</td>
<td>{connectorClass}</td>
<td>
<S.TagsWrapper>
{topics?.map((t) => (
<Tag key={t} color="gray">
<Link to={clusterTopicPath(clusterName, t)}>{t}</Link>
</Tag>
))}
</S.TagsWrapper>
</td>
<td>{status && <Tag color={getTagColor(status)}>{status.state}</Tag>}</td>
<td>
{runningTasks && (
<span>
{runningTasks} of {tasksCount}
</span>
)}
</td>
<td>
<div>
<Dropdown label={<VerticalElipsisIcon />} right up>
<DropdownItem
onClick={() => setDeleteConnectorConfirmationVisible(true)}
danger
>
Remove Connector
</DropdownItem>
</Dropdown>
</div>
<ConfirmationModal
isOpen={isDeleteConnectorConfirmationVisible}
onCancel={() => setDeleteConnectorConfirmationVisible(false)}
onConfirm={handleDelete}
>
Are you sure want to remove <b>{name}</b> connector?
</ConfirmationModal>
</td>
</tr>
);
};
export default ListItem;