-
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.
feat: Add dropdown with actions to run and copy CLI command (#1054)
* feat: Add dropdown with actions to run and copy CLI command Signed-off-by: hemahg <[email protected]> * add tooltip Signed-off-by: hemahg <[email protected]> --------- Signed-off-by: hemahg <[email protected]>
- Loading branch information
Showing
6 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...thorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/DryrunSelect.stories.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,16 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
import { DryrunSelect } from "./DryrunSelect"; | ||
|
||
export default { | ||
component: DryrunSelect, | ||
args: {}, | ||
} as Meta<typeof DryrunSelect>; | ||
|
||
type Story = StoryObj<typeof DryrunSelect>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
cliCommand: | ||
"$kafka-consumer-groups --bootstrap-server localhost:9092 --group my-consumer-group --reset-offsets --topic mytopic --to-earliest --dry-run", | ||
}, | ||
}; |
91 changes: 91 additions & 0 deletions
91
...ale]/(authorized)/kafka/[kafkaId]/consumer-groups/[groupId]/reset-offset/DryrunSelect.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,91 @@ | ||
import { | ||
Dropdown, | ||
DropdownItem, | ||
DropdownList, | ||
MenuToggle, | ||
MenuToggleAction, | ||
MenuToggleElement, | ||
Tooltip, | ||
} from "@/libs/patternfly/react-core"; | ||
import { CopyIcon, PlayIcon } from "@patternfly/react-icons"; | ||
import { useTranslations } from "next-intl"; | ||
import React from "react"; | ||
import { useState } from "react"; | ||
|
||
export function DryrunSelect({ | ||
openDryrun, | ||
cliCommand, | ||
}: { | ||
openDryrun: () => void; | ||
cliCommand: string; | ||
}) { | ||
const t = useTranslations("ConsumerGroupsTable"); | ||
|
||
const tooltipRef = React.useRef<HTMLButtonElement>(null); | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
const onToggleClick = () => { | ||
setIsOpen((prevIsOpen) => !prevIsOpen); | ||
}; | ||
|
||
return ( | ||
<Dropdown | ||
isOpen={isOpen} | ||
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( | ||
<MenuToggle | ||
ref={toggleRef} | ||
variant="secondary" | ||
splitButtonOptions={{ | ||
variant: "action", | ||
items: [ | ||
<MenuToggleAction | ||
id="split-button-action-secondary-with-toggle-button" | ||
key="split-action-secondary" | ||
aria-label={t("dry_run")} | ||
> | ||
{t("dry_run")} | ||
</MenuToggleAction>, | ||
], | ||
}} | ||
aria-label="dryrun toggle button" | ||
onClick={onToggleClick} | ||
/> | ||
)} | ||
> | ||
<DropdownList> | ||
<DropdownItem | ||
value={0} | ||
key={t("run_and_show_result")} | ||
onClick={openDryrun} | ||
> | ||
<PlayIcon /> {t("run_and_show_result")} | ||
</DropdownItem> | ||
<DropdownItem | ||
value={1} | ||
key={t("copy_dry_run_command")} | ||
onClick={() => { | ||
navigator.clipboard.writeText(cliCommand); | ||
setIsCopied(true); | ||
}} | ||
aria-describedby="tooltip-ref1" | ||
ref={tooltipRef} | ||
> | ||
<CopyIcon /> {t("copy_dry_run_command")} | ||
{isCopied && ( | ||
<Tooltip | ||
id="tooltip-ref1" | ||
isVisible={isCopied} | ||
content={<div>cli command copied</div>} | ||
triggerRef={tooltipRef} | ||
flipBehavior={"flip"} | ||
position="right" | ||
onTooltipHidden={() => setIsCopied(false)} | ||
/> | ||
)} | ||
</DropdownItem> | ||
</DropdownList> | ||
</Dropdown> | ||
); | ||
} |
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