File size: 2,850 Bytes
9b906ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { useTranslation } from "react-i18next";
import { ContextMenu } from "#/ui/context-menu";
import { ContextMenuListItem } from "../context-menu/context-menu-list-item";
import { ToolsContextMenuIconText } from "./tools-context-menu-icon-text";

import TachometerFastIcon from "#/icons/tachometer-fast.svg?react";
import PrStatusIcon from "#/icons/pr-status.svg?react";
import DocumentIcon from "#/icons/document.svg?react";
import WaterIcon from "#/icons/u-water.svg?react";
import { I18nKey } from "#/i18n/declaration";
import { useConversationStore } from "#/stores/conversation-store";
import { REPO_SUGGESTIONS } from "#/utils/suggestions/repo-suggestions";

const submenuListItemClassName = "!w-auto whitespace-nowrap";

interface MacrosSubmenuProps {
  onClose: () => void;
}

export function MacrosSubmenu({ onClose }: MacrosSubmenuProps) {
  const { t } = useTranslation("openhands");
  const { setMessageToSend } = useConversationStore();

  const onIncreaseTestCoverage = () => {
    setMessageToSend(REPO_SUGGESTIONS.INCREASE_TEST_COVERAGE);
    onClose();
  };
  const onFixReadme = () => {
    setMessageToSend(REPO_SUGGESTIONS.FIX_README);
    onClose();
  };
  const onAutoMergePRs = () => {
    setMessageToSend(REPO_SUGGESTIONS.AUTO_MERGE_PRS);
    onClose();
  };
  const onCleanDependencies = () => {
    setMessageToSend(REPO_SUGGESTIONS.CLEAN_DEPENDENCIES);
    onClose();
  };

  return (
    <ContextMenu testId="macros-submenu" className="overflow-visible">
      <ContextMenuListItem
        testId="increase-test-coverage-button"
        onClick={onIncreaseTestCoverage}
        className={submenuListItemClassName}
      >
        <ToolsContextMenuIconText
          icon={<TachometerFastIcon width={16} height={16} />}
          text={t(I18nKey.INCREASE_TEST_COVERAGE)}
        />
      </ContextMenuListItem>

      <ContextMenuListItem
        testId="fix-readme-button"
        onClick={onFixReadme}
        className={submenuListItemClassName}
      >
        <ToolsContextMenuIconText
          icon={<DocumentIcon width={16} height={16} />}
          text={t(I18nKey.FIX_README)}
        />
      </ContextMenuListItem>

      <ContextMenuListItem
        testId="auto-merge-prs-button"
        onClick={onAutoMergePRs}
        className={submenuListItemClassName}
      >
        <ToolsContextMenuIconText
          icon={<PrStatusIcon width={16} height={16} />}
          text={t(I18nKey.AUTO_MERGE_PRS)}
        />
      </ContextMenuListItem>

      <ContextMenuListItem
        testId="clean-dependencies-button"
        onClick={onCleanDependencies}
        className={submenuListItemClassName}
      >
        <ToolsContextMenuIconText
          icon={<WaterIcon width={16} height={16} />}
          text={t(I18nKey.CLEAN_DEPENDENCIES)}
        />
      </ContextMenuListItem>
    </ContextMenu>
  );
}