From deddf09ed4ef35fa6a150f79ebb10049a0ede662 Mon Sep 17 00:00:00 2001 From: Kirill Morozov Date: Fri, 22 Apr 2022 16:51:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1lone=20topic=20functionality=20(FE)=20(#1?= =?UTF-8?q?825)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added Copy button in list of topics * Added copy topic functionality * Whitespaces removed * Removed extra string wrapper * Copy component removed, routing fixed, tests fixed * Ternary and returning null removed * Dublicated code refactored * Added tests for ternary header * Added enum for the form fields Co-authored-by: k.morozov Co-authored-by: Roman Zabaluev --- .../src/components/Topics/List/List.tsx | 31 +++++++++++++++- .../src/components/Topics/New/New.tsx | 26 ++++++++++++- .../Topics/New/__test__/New.spec.tsx | 37 ++++++++++++++++++- .../src/components/Topics/Topics.tsx | 6 +++ .../Topics/shared/Form/TopicForm.tsx | 20 ++++++++-- kafka-ui-react-app/src/lib/paths.ts | 2 + 6 files changed, 114 insertions(+), 8 deletions(-) diff --git a/kafka-ui-react-app/src/components/Topics/List/List.tsx b/kafka-ui-react-app/src/components/Topics/List/List.tsx index 334ff6a917..362010d1fc 100644 --- a/kafka-ui-react-app/src/components/Topics/List/List.tsx +++ b/kafka-ui-react-app/src/components/Topics/List/List.tsx @@ -6,7 +6,7 @@ import { TopicName, } from 'redux/interfaces'; import { useParams } from 'react-router-dom'; -import { clusterTopicNewPath } from 'lib/paths'; +import { clusterTopicCopyPath, clusterTopicNewPath } from 'lib/paths'; import usePagination from 'lib/hooks/usePagination'; import ClusterContext from 'components/contexts/ClusterContext'; import PageLoader from 'components/common/PageLoader/PageLoader'; @@ -125,6 +125,21 @@ const List: React.FC = ({ } ); + const getSelectedTopic = (): string => { + const name = Array.from(tableState.selectedIds)[0]; + const selectedTopic = + tableState.data.find( + (topic: TopicWithDetailedInfo) => topic.name === name + ) || {}; + + return Object.keys(selectedTopic) + .map((x: string) => { + const value = selectedTopic[x as keyof typeof selectedTopic]; + return value && x !== 'partitions' ? `${x}=${value}` : null; + }) + .join('&'); + }; + const handleSwitch = React.useCallback(() => { setShowInternal(!showInternal); history.push(`${pathname}?page=1&perPage=${perPage || PER_PAGE}`); @@ -295,6 +310,20 @@ const List: React.FC = ({ > Delete selected topics + {tableState.selectedCount === 1 && ( + + )} +