-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Reconciliation pause button to kafka details card (#1374)
* Move Reconcilation pause button to kafka details card Signed-off-by: hemahg <[email protected]> * Fix stories Signed-off-by: hemahg <[email protected]> * Hide error/ warning icon labels when there is no alerts Signed-off-by: hemahg <[email protected]> --------- Signed-off-by: hemahg <[email protected]>
- Loading branch information
Showing
8 changed files
with
121 additions
and
100 deletions.
There are no files selected for viewing
70 changes: 5 additions & 65 deletions
70
ui/app/[locale]/(authorized)/kafka/[kafkaId]/@header/overview/ConnectButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,15 @@ | ||
"use client"; | ||
|
||
import { updateKafkaCluster } from "@/api/kafka/actions"; | ||
import { useOpenClusterConnectionPanel } from "@/components/ClusterDrawerContext"; | ||
import { ReconciliationModal } from "@/components/ClusterOverview/ReconciliationModal"; | ||
import { useReconciliationContext } from "@/components/ReconciliationContext"; | ||
import { Button, Flex, FlexItem } from "@/libs/patternfly/react-core"; | ||
import { Button } from "@/libs/patternfly/react-core"; | ||
import { useTranslations } from "next-intl"; | ||
import { useState } from "react"; | ||
|
||
export function ConnectButton({ | ||
clusterId, | ||
managed, | ||
}: { | ||
clusterId: string; | ||
managed: boolean; | ||
}) { | ||
export function ConnectButton({ clusterId }: { clusterId: string }) { | ||
const t = useTranslations(); | ||
const open = useOpenClusterConnectionPanel(); | ||
|
||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); | ||
|
||
const { isReconciliationPaused, setReconciliationPaused } = | ||
useReconciliationContext(); | ||
|
||
const onClickUpdate = async (pausedState: boolean) => { | ||
try { | ||
const response = await updateKafkaCluster(clusterId, pausedState); | ||
|
||
if (response.errors) { | ||
console.log("Unknown error occurred", response.errors); | ||
} else { | ||
setReconciliationPaused(pausedState); | ||
setIsModalOpen(false); | ||
} | ||
} catch (e: unknown) { | ||
console.log("Unknown error occurred"); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Flex> | ||
{managed && ( | ||
<FlexItem> | ||
<Button | ||
variant="secondary" | ||
onClick={ | ||
isReconciliationPaused | ||
? () => onClickUpdate(false) | ||
: () => setIsModalOpen(true) | ||
} | ||
> | ||
{isReconciliationPaused | ||
? t("reconciliation.resume_reconciliation") | ||
: t("reconciliation.pause_reconciliation_button")} | ||
</Button> | ||
</FlexItem> | ||
)} | ||
<FlexItem> | ||
<Button onClick={() => open(clusterId)}> | ||
{t("ConnectButton.cluster_connection_details")} | ||
</Button> | ||
</FlexItem> | ||
</Flex> | ||
{isModalOpen && ( | ||
<ReconciliationModal | ||
isModalOpen={isModalOpen} | ||
onClickClose={() => setIsModalOpen(false)} | ||
onClickPauseReconciliation={() => onClickUpdate(true)} | ||
/> | ||
)} | ||
</> | ||
<Button onClick={() => open(clusterId)}> | ||
{t("ConnectButton.cluster_connection_details")} | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ui/components/ClusterOverview/ReconciliationPauseButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client"; | ||
|
||
import { updateKafkaCluster } from "@/api/kafka/actions"; | ||
import { ReconciliationModal } from "@/components/ClusterOverview/ReconciliationModal"; | ||
import { useReconciliationContext } from "@/components/ReconciliationContext"; | ||
import { Button } from "@/libs/patternfly/react-core"; | ||
import { useTranslations } from "next-intl"; | ||
import { useState } from "react"; | ||
import { PauseCircleIcon, PlayIcon } from "@/libs/patternfly/react-icons"; | ||
|
||
export function ReconciliationPauseButton({ | ||
clusterId, | ||
managed, | ||
}: { | ||
clusterId: string; | ||
managed: boolean; | ||
}) { | ||
const t = useTranslations(); | ||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); | ||
|
||
const { isReconciliationPaused, setReconciliationPaused } = | ||
useReconciliationContext(); | ||
|
||
const onClickUpdate = async (pausedState: boolean) => { | ||
try { | ||
const response = await updateKafkaCluster(clusterId, pausedState); | ||
|
||
if (response.errors) { | ||
console.log("Unknown error occurred", response.errors); | ||
} else { | ||
setReconciliationPaused(pausedState); | ||
setIsModalOpen(false); | ||
} | ||
} catch (e: unknown) { | ||
console.log("Unknown error occurred"); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{managed && ( | ||
<Button | ||
variant="link" | ||
icon={isReconciliationPaused ? <PlayIcon /> : <PauseCircleIcon />} | ||
onClick={ | ||
isReconciliationPaused | ||
? () => onClickUpdate(false) | ||
: () => setIsModalOpen(true) | ||
} | ||
> | ||
{isReconciliationPaused | ||
? t("reconciliation.resume_reconciliation") | ||
: t("reconciliation.pause_reconciliation_button")} | ||
</Button> | ||
)} | ||
{isModalOpen && ( | ||
<ReconciliationModal | ||
isModalOpen={isModalOpen} | ||
onClickClose={() => setIsModalOpen(false)} | ||
onClickPauseReconciliation={() => onClickUpdate(true)} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters