| 1 | import { CheckIcon, PlayIcon, XMarkIcon } from "@heroicons/react/24/outline"; |
| 2 | import { ApplyState } from "core"; |
| 3 | import { getMetaKeyLabel } from "../../../util"; |
| 4 | import Spinner from "../../gui/Spinner"; |
| 5 | import { ToolTip } from "../../gui/Tooltip"; |
| 6 | import HoverItem from "../../mainInput/InputToolbar/HoverItem"; |
| 7 | import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip"; |
| 8 | |
| 9 | interface ApplyActionsProps { |
| 10 | disableManualApply?: boolean; |
| 11 | applyState?: ApplyState; |
| 12 | onClickAccept: () => void; |
| 13 | onClickReject: () => void; |
| 14 | onClickApply?: () => void; |
| 15 | } |
| 16 | |
| 17 | export function ApplyActions(props: ApplyActionsProps) { |
| 18 | function onClickReject() { |
| 19 | props.onClickReject(); |
| 20 | } |
| 21 | |
| 22 | switch (props.applyState ? props.applyState.status : null) { |
| 23 | case "streaming": |
| 24 | return ( |
| 25 | <div className="bg-badge flex select-none items-center rounded pl-2 pr-1"> |
| 26 | <span className="text-lightgray inline-flex items-center gap-2 text-center text-xs"> |
| 27 | Applying |
| 28 | <Spinner /> |
| 29 | </span> |
| 30 | </div> |
| 31 | ); |
| 32 | case "done": |
| 33 | return ( |
| 34 | <div className="bg-badge flex select-none items-center rounded sm:gap-1 md:px-1.5"> |
| 35 | <span className="text-lightgray flex items-center text-center text-xs max-md:hidden"> |
| 36 | {`${props.applyState?.numDiffs === 1 ? "1 diff" : `${props.applyState?.numDiffs} diffs`}`} |
| 37 | </span> |
| 38 | |
| 39 | <div className="flex items-center"> |
| 40 | <ToolbarButtonWithTooltip |
| 41 | data-testid="codeblock-toolbar-reject" |
| 42 | onClick={onClickReject} |
| 43 | tooltipContent={`Reject all (${getMetaKeyLabel()}⇧⌫)`} |
| 44 | > |
| 45 | <XMarkIcon className="text-error h-3.5 w-3.5 flex-shrink-0 hover:brightness-125" /> |
| 46 | </ToolbarButtonWithTooltip> |
| 47 | |
| 48 | <ToolbarButtonWithTooltip |
| 49 | data-testid="codeblock-toolbar-accept" |
| 50 | onClick={props.onClickAccept} |
| 51 | tooltipContent={`Accept all (${getMetaKeyLabel()}⇧⏎)`} |
| 52 | > |
| 53 | <CheckIcon className="text-success h-3.5 w-3.5 flex-shrink-0 hover:brightness-125" /> |
| 54 | </ToolbarButtonWithTooltip> |
| 55 | </div> |
| 56 | </div> |
| 57 | ); |
| 58 | case "closed": |
| 59 | default: |
| 60 | if (props.disableManualApply) { |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | return ( |
| 65 | <ToolTip place="top" content="Apply Code"> |
| 66 | <HoverItem |
| 67 | data-tooltip-id="codeblock-apply-code-button-tooltip" |
| 68 | className="!p-0" |
| 69 | > |
| 70 | <button |
| 71 | data-testid="codeblock-toolbar-apply" |
| 72 | className="text-lightgray flex cursor-pointer items-center border-none bg-transparent pl-0 text-xs outline-none hover:brightness-125" |
| 73 | onClick={props.onClickApply} |
| 74 | > |
| 75 | <div className="text-lightgray flex items-center gap-1"> |
| 76 | <PlayIcon className="h-3.5 w-3.5" /> |
| 77 | <span className="xs:inline hidden">Apply</span> |
| 78 | </div> |
| 79 | </button> |
| 80 | </HoverItem> |
| 81 | </ToolTip> |
| 82 | ); |
| 83 | } |
| 84 | } |