import React from 'react'; import { useHistory } from 'react-router'; import { TopicWithDetailedInfo, ClusterName, TopicName, } from 'redux/interfaces'; import { Link, useParams } from 'react-router-dom'; import { clusterTopicNewPath } from 'lib/paths'; import usePagination from 'lib/hooks/usePagination'; import ClusterContext from 'components/contexts/ClusterContext'; import PageLoader from 'components/common/PageLoader/PageLoader'; import Pagination from 'components/common/Pagination/Pagination'; import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal'; import { GetTopicsRequest, TopicColumnsToSort } from 'generated-sources'; import SortableColumnHeader from 'components/common/table/SortableCulumnHeader/SortableColumnHeader'; import Search from 'components/common/Search/Search'; import { PER_PAGE } from 'lib/constants'; import ListItem from './ListItem'; export interface TopicsListProps { areTopicsFetching: boolean; topics: TopicWithDetailedInfo[]; totalPages: number; fetchTopicsList(props: GetTopicsRequest): void; deleteTopic(topicName: TopicName, clusterName: ClusterName): void; deleteTopics(topicName: TopicName, clusterNames: ClusterName[]): void; clearTopicsMessages(topicName: TopicName, clusterNames: ClusterName[]): void; clearTopicMessages( topicName: TopicName, clusterName: ClusterName, partitions?: number[] ): void; search: string; orderBy: TopicColumnsToSort | null; setTopicsSearch(search: string): void; setTopicsOrderBy(orderBy: TopicColumnsToSort | null): void; } const List: React.FC = ({ areTopicsFetching, topics, totalPages, fetchTopicsList, deleteTopic, deleteTopics, clearTopicMessages, clearTopicsMessages, search, orderBy, setTopicsSearch, setTopicsOrderBy, }) => { const { isReadOnly } = React.useContext(ClusterContext); const { clusterName } = useParams<{ clusterName: ClusterName }>(); const { page, perPage, pathname } = usePagination(); const [showInternal, setShowInternal] = React.useState(true); const history = useHistory(); React.useEffect(() => { fetchTopicsList({ clusterName, page, perPage, orderBy: orderBy || undefined, search, showInternal, }); }, [ fetchTopicsList, clusterName, page, perPage, orderBy, search, showInternal, ]); const handleSwitch = React.useCallback(() => { setShowInternal(!showInternal); history.push(`${pathname}?page=1&perPage=${perPage || PER_PAGE}`); }, [showInternal]); const [confirmationModal, setConfirmationModal] = React.useState< '' | 'deleteTopics' | 'purgeMessages' >(''); const closeConfirmationModal = () => { setConfirmationModal(''); }; const [selectedTopics, setSelectedTopics] = React.useState>( new Set() ); const clearSelectedTopics = () => { setSelectedTopics(new Set()); }; const toggleTopicSelected = (topicName: string) => { setSelectedTopics((prevState) => { const newState = new Set(prevState); if (newState.has(topicName)) { newState.delete(topicName); } else { newState.add(topicName); } return newState; }); }; const deleteTopicsHandler = React.useCallback(() => { deleteTopics(clusterName, Array.from(selectedTopics)); closeConfirmationModal(); clearSelectedTopics(); }, [clusterName, selectedTopics]); const purgeMessagesHandler = React.useCallback(() => { clearTopicsMessages(clusterName, Array.from(selectedTopics)); closeConfirmationModal(); clearSelectedTopics(); }, [clusterName, selectedTopics]); return (
{!isReadOnly && ( Add a Topic )}
{areTopicsFetching ? ( ) : (
{selectedTopics.size > 0 && ( <>
{confirmationModal === 'deleteTopics' ? 'Are you sure you want to remove selected topics?' : 'Are you sure you want to purge messages of selected topics?'} )} {topics.map((topic) => ( ))} {topics.length === 0 && ( )}
Replication Factor Number of messages Size Type Clean Up Policy
No topics found
)}
); }; export default List;