From c740c8a8d3d4d71413bd62aa6711647512b8b7b1 Mon Sep 17 00:00:00 2001 From: hemahg Date: Fri, 13 Sep 2024 01:17:53 +0530 Subject: [PATCH] Minor refactor Signed-off-by: hemahg --- .../reset-offset/LoadingPage.stories.tsx | 13 + .../[groupId]/reset-offset/LoadingPage.tsx | 27 ++ .../reset-offset/ResetConsumerOffset.tsx | 250 +++--------------- ...et.stories.tsx => ResetOffset.stories.tsx} | 11 +- .../[groupId]/reset-offset/ResetOffset.tsx | 243 +++++++++++++++++ .../[groupId]/reset-offset/page.tsx | 2 +- 6 files changed, 322 insertions(+), 224 deletions(-) create mode 100644 ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.stories.tsx create mode 100644 ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.tsx rename ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/{ResetConsumerOffset.stories.tsx => ResetOffset.stories.tsx} (67%) create mode 100644 ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.tsx diff --git a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.stories.tsx b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.stories.tsx new file mode 100644 index 000000000..8a93fd364 --- /dev/null +++ b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.stories.tsx @@ -0,0 +1,13 @@ +import { Meta, StoryObj } from "@storybook/react"; +import { LoadingPage } from "./LoadingPage"; + +export default { + component: LoadingPage, + args: {}, +} as Meta; + +type Story = StoryObj; + +export const Default: Story = { + args: {}, +}; diff --git a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.tsx b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.tsx new file mode 100644 index 000000000..67a3c47d7 --- /dev/null +++ b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/LoadingPage.tsx @@ -0,0 +1,27 @@ +import { + Bullseye, + Grid, + GridItem, + Spinner, +} from "@/libs/patternfly/react-core"; +import { useTranslations } from "next-intl"; + +export function LoadingPage() { + const t = useTranslations("ConsumerGroupsTable"); + return ( + + + + + + + + {t("reseting_consumer_group_offsets_text")} + + + ); +} diff --git a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.tsx b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.tsx index 1f10bdab5..69fc85477 100644 --- a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.tsx +++ b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.tsx @@ -1,37 +1,5 @@ "use client"; -import { - Divider, - Panel, - PanelHeader, - PanelMain, - PanelMainBody, - TextContent, - Text, - TextVariants, - Radio, - Form, - FormGroup, - FormSection, - Select, - SelectList, - SelectOption, - MenuToggle, - MenuToggleElement, - TextInput, - ActionGroup, - Button, - SelectProps, - PageSection, - Page, - Bullseye, - Spinner, - Flex, - FlexItem, - Grid, - GridItem, - Alert, -} from "@/libs/patternfly/react-core"; import { useTranslations } from "next-intl"; import { useState } from "react"; import { @@ -40,8 +8,6 @@ import { TopicSelection, partitionSelection, } from "../types"; -import { TypeaheadSelect } from "./TypeaheadSelect"; -import { OffsetSelect } from "./OffsetSelect"; import { useRouter } from "@/navigation"; import { getDryrunResult, @@ -49,6 +15,9 @@ import { } from "@/api/consumerGroups/actions"; import { UpdateConsumerGroupErrorSchema } from "@/api/consumerGroups/schema"; import { Dryrun } from "./Dryrun"; +import { LoadingPage } from "./LoadingPage"; +import { ResetOffset } from "./ResetOffset"; +import { Page } from "@/libs/patternfly/react-core"; export type Offset = { topicId: string; @@ -71,15 +40,13 @@ export function ResetConsumerOffset({ partitions: number[]; baseurl: string; }) { - const t = useTranslations("ConsumerGroupsTable"); - const router = useRouter(); const [selectedConsumerTopic, setSelectedConsumerTopic] = - useState(); + useState("allTopics"); const [selectedPartition, setSelectedPartition] = - useState(); + useState("allPartitions"); const [selectedOffset, setSelectedOffset] = useState("custom"); @@ -109,6 +76,8 @@ export function ResetConsumerOffset({ setSelectedPartition(value); }; + const onOffsetSelect = (value: OffsetValue) => setSelectedOffset(value); + const onDateTimeSelect = (value: DateTimeFormatSelection) => { setSelectDateTimeFormat(value); }; @@ -297,20 +266,7 @@ export function ResetConsumerOffset({ return ( {isLoading ? ( - - - - - - - - {t("reseting_consumer_group_offsets_text")} - - + ) : showDryRun ? ( ) : ( - - - - - {t("reset_consumer_offset")} - - - - {t.rich("consumer_name", { consumerGroupName })} - - - - - - {error && } -
- - - onTopicSelect("allTopics")} - /> - onTopicSelect("selectedTopic")} - /> - - {selectedConsumerTopic === "selectedTopic" && ( - topic.topicName)} - onChange={handleTopicChange} - placeholder={"Select topic"} - /> - )} - {selectedConsumerTopic === "selectedTopic" && ( - - onPartitionSelect("allPartitions")} - /> - onPartitionSelect("selectedPartition")} - /> - - )} - {selectedConsumerTopic === "selectedTopic" && - selectedPartition === "selectedPartition" && ( - - )} - - - - - - {selectedOffset === "custom" && ( - - handleOffsetChange(value)} - type="number" - /> - - )} - {selectedOffset === "specificDateTime" && ( - <> - - onDateTimeSelect("ISO")} - /> - onDateTimeSelect("Epoch")} - /> - - - - handleDateTimeChange(value) - } - /> - - - )} - - - - - - -
-
-
-
+ )}
); diff --git a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.stories.tsx b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.stories.tsx similarity index 67% rename from ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.stories.tsx rename to ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.stories.tsx index 1d1840ebc..dcc6f7fb9 100644 --- a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetConsumerOffset.stories.tsx +++ b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.stories.tsx @@ -1,11 +1,11 @@ import { Meta, StoryObj } from "@storybook/react"; -import { ResetConsumerOffset } from "./ResetConsumerOffset"; +import { ResetOffset } from "./ResetOffset"; export default { - component: ResetConsumerOffset, -} as Meta; + component: ResetOffset, +} as Meta; -type Story = StoryObj; +type Story = StoryObj; export const Default: Story = { args: { @@ -16,6 +16,9 @@ export const Default: Story = { { topicId: "234", topicName: "console_datagen_002-c" }, { topicId: "431", topicName: "console_datagen_002-d" }, ], + selectTopic: "allTopics", partitions: [1, 2, 3], + selectOffset: "latest", + isLoading: false, }, }; diff --git a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.tsx b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.tsx new file mode 100644 index 000000000..bf706f68e --- /dev/null +++ b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/ResetOffset.tsx @@ -0,0 +1,243 @@ +import { + Divider, + Panel, + PanelHeader, + PanelMain, + PanelMainBody, + TextContent, + Text, + TextVariants, + Radio, + Form, + FormGroup, + FormSection, + TextInput, + ActionGroup, + Button, + Alert, +} from "@/libs/patternfly/react-core"; +import { useTranslations } from "next-intl"; +import { + DateTimeFormatSelection, + OffsetValue, + TopicSelection, + partitionSelection, +} from "../types"; +import { TypeaheadSelect } from "./TypeaheadSelect"; +import { OffsetSelect } from "./OffsetSelect"; + +export type Offset = { + topicId: string; + topicName: string; + partition: number; + offset: string | number; + metadeta?: string; +}; + +export function ResetOffset({ + consumerGroupName, + topics, + partitions, + selectTopic, + selectPartition, + error, + onTopicSelect, + selectOffset, + onPartitionSelect, + offset, + isLoading, + selectDateTimeFormat, + openDryrun, + closeResetOffset, + handleDateTimeChange, + handleOffsetChange, + handlePartitionChange, + handleTopichange, + handleSave, + onDateTimeSelect, + onOffsetSelect, +}: { + consumerGroupName: string; + topics: { topicId: string; topicName: string }[]; + partitions: number[]; + selectTopic: TopicSelection; + selectPartition: partitionSelection; + selectOffset: OffsetValue; + error: string | undefined; + onTopicSelect: (value: TopicSelection) => void; + onPartitionSelect: (value: partitionSelection) => void; + offset: Offset; + isLoading: boolean; + selectDateTimeFormat: DateTimeFormatSelection; + handleTopichange: (topicName: string | number) => void; + handlePartitionChange: (partition: number | string) => void; + handleOffsetChange: (value: string) => void; + closeResetOffset: () => void; + openDryrun: () => void; + handleDateTimeChange: (value: string) => void; + handleSave: () => void; + onDateTimeSelect: (value: DateTimeFormatSelection) => void; + onOffsetSelect: (value: OffsetValue) => void; +}) { + const t = useTranslations("ConsumerGroupsTable"); + return ( + + + + {t("reset_consumer_offset")} + + + {t.rich("consumer_name", { consumerGroupName })} + + + + + + {error && } +
+ + + onTopicSelect("allTopics")} + /> + onTopicSelect("selectedTopic")} + /> + + {selectTopic === "selectedTopic" && ( + topic.topicName)} + onChange={handleTopichange} + placeholder={"Select topic"} + /> + )} + {selectTopic === "selectedTopic" && ( + + onPartitionSelect("allPartitions")} + /> + onPartitionSelect("selectedPartition")} + /> + + )} + {selectTopic === "selectedTopic" && + selectPartition === "selectedPartition" && ( + + )} + + + + + + {selectOffset === "custom" && ( + + handleOffsetChange(value)} + type="number" + /> + + )} + {selectOffset === "specificDateTime" && ( + <> + + onDateTimeSelect("ISO")} + /> + onDateTimeSelect("Epoch")} + /> + + + handleDateTimeChange(value)} + /> + + + )} + + + + + + +
+
+
+
+ ); +} diff --git a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/page.tsx b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/page.tsx index e81829e7f..3a3e74eec 100644 --- a/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/page.tsx +++ b/ui/app/[locale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/page.tsx @@ -20,7 +20,7 @@ export default function ResetOffsetPage({ consumerGroupName={groupId} topics={[]} partitions={[]} - baseurl={`/kafka/${kafkaId}/consumer-groups/${groupId}`} + baseurl={`/kafka/${kafkaId}/consumer-groups`} /> } >