Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show GitHub buttons only when repository is selected #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/__tests__/initial-query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ describe("Initial Query Behavior", () => {
it("should clear initial query when clearInitialQuery is dispatched", () => {
// Set up initial query in the store
store.dispatch(setInitialQuery("test query"));
expect(store.getState().initalQuery.initialQuery).toBe("test query");
expect(store.getState().initialQuery.initialQuery).toBe("test query");

// Clear the initial query
store.dispatch(clearInitialQuery());

// Verify initial query is cleared
expect(store.getState().initalQuery.initialQuery).toBeNull();
expect(store.getState().initialQuery.initialQuery).toBeNull();
});
});
7 changes: 6 additions & 1 deletion frontend/src/components/features/chat/action-suggestions.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import posthog from "posthog-js";
import React from "react";
import { useSelector } from "react-redux";
import { SuggestionItem } from "#/components/features/suggestions/suggestion-item";
import { useAuth } from "#/context/auth-context";
import { DownloadModal } from "#/components/shared/download-modal";
import type { RootState } from "#/store";

interface ActionSuggestionsProps {
onSuggestionsClick: (value: string) => void;
Expand All @@ -12,6 +14,9 @@ export function ActionSuggestions({
onSuggestionsClick,
}: ActionSuggestionsProps) {
const { gitHubToken } = useAuth();
const { selectedRepository } = useSelector(
(state: RootState) => state.initialQuery,
);

const [isDownloading, setIsDownloading] = React.useState(false);
const [hasPullRequest, setHasPullRequest] = React.useState(false);
Expand All @@ -27,7 +32,7 @@ export function ActionSuggestions({
onClose={handleDownloadClose}
isOpen={isDownloading}
/>
{gitHubToken ? (
{gitHubToken && selectedRepository ? (
<div className="flex flex-row gap-2 justify-center w-full">
{!hasPullRequest ? (
<>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/features/chat/chat-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function ChatInterface() {
const [feedbackModalIsOpen, setFeedbackModalIsOpen] = React.useState(false);
const [messageToSend, setMessageToSend] = React.useState<string | null>(null);
const { selectedRepository, importedProjectZip } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const handleSendMessage = async (content: string, files: File[]) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/features/controls/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function Controls({
}: ControlsProps) {
const { gitHubToken } = useAuth();
const { selectedRepository } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const projectMenuCardData = React.useMemo(
Expand Down
25 changes: 0 additions & 25 deletions frontend/src/components/features/project-menu/ProjectMenuCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from "react";
import posthog from "posthog-js";
import EllipsisH from "#/icons/ellipsis-h.svg?react";
import { createChatMessage } from "#/services/chat-service";
import { ProjectMenuCardContextMenu } from "./project.menu-card-context-menu";
import { ProjectMenuDetailsPlaceholder } from "./project-menu-details-placeholder";
import { ProjectMenuDetails } from "./project-menu-details";
import { useWsClient } from "#/context/ws-client-provider";
import { ConnectToGitHubModal } from "#/components/shared/modals/connect-to-github-modal";
import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";
import { DownloadModal } from "#/components/shared/download-modal";
Expand All @@ -23,8 +21,6 @@ export function ProjectMenuCard({
isConnectedToGitHub,
githubData,
}: ProjectMenuCardProps) {
const { send } = useWsClient();

const [contextMenuIsOpen, setContextMenuIsOpen] = React.useState(false);
const [connectToGitHubModalOpen, setConnectToGitHubModalOpen] =
React.useState(false);
Expand All @@ -34,26 +30,6 @@ export function ProjectMenuCard({
setContextMenuIsOpen((prev) => !prev);
};

const handlePushToGitHub = () => {
posthog.capture("push_to_github_button_clicked");
const rawEvent = {
content: `
Please push the changes to GitHub and open a pull request.
`,
imageUrls: [],
timestamp: new Date().toISOString(),
pending: false,
};
const event = createChatMessage(
rawEvent.content,
rawEvent.imageUrls,
rawEvent.timestamp,
);

send(event); // send to socket
setContextMenuIsOpen(false);
};

const handleDownloadWorkspace = () => {
posthog.capture("download_workspace_button_clicked");
setDownloading(true);
Expand All @@ -69,7 +45,6 @@ Please push the changes to GitHub and open a pull request.
<ProjectMenuCardContextMenu
isConnectedToGitHub={isConnectedToGitHub}
onConnectToGitHub={() => setConnectToGitHubModalOpen(true)}
onPushToGitHub={handlePushToGitHub}
onDownloadWorkspace={handleDownloadWorkspace}
onClose={() => setContextMenuIsOpen(false)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import { I18nKey } from "#/i18n/declaration";
interface ProjectMenuCardContextMenuProps {
isConnectedToGitHub: boolean;
onConnectToGitHub: () => void;
onPushToGitHub: () => void;
onDownloadWorkspace: () => void;
onClose: () => void;
}

export function ProjectMenuCardContextMenu({
isConnectedToGitHub,
onConnectToGitHub,
onPushToGitHub,
onDownloadWorkspace,
onClose,
}: ProjectMenuCardContextMenuProps) {
Expand All @@ -31,11 +29,6 @@ export function ProjectMenuCardContextMenu({
{t(I18nKey.PROJECT_MENU_CARD_CONTEXT_MENU$CONNECT_TO_GITHUB_LABEL)}
</ContextMenuListItem>
)}
{isConnectedToGitHub && (
<ContextMenuListItem onClick={onPushToGitHub}>
{t(I18nKey.PROJECT_MENU_CARD_CONTEXT_MENU$PUSH_TO_GITHUB_LABEL)}
</ContextMenuListItem>
)}
<ContextMenuListItem onClick={onDownloadWorkspace}>
{t(I18nKey.PROJECT_MENU_CARD_CONTEXT_MENU$DOWNLOAD_FILES_LABEL)}
</ContextMenuListItem>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/shared/task-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const TaskForm = React.forwardRef<HTMLFormElement>((_, ref) => {
const { settings } = useUserPrefs();

const { selectedRepository, files } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const [text, setText] = React.useState("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useHandleRuntimeActive = () => {
const runtimeActive = status === WsClientProviderStatus.ACTIVE;

const { importedProjectZip } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const userId = React.useMemo(() => {
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/routes/_oh.app/hooks/use-ws-status-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
import { createChatMessage } from "#/services/chat-service";
import { setCurrentAgentState } from "#/state/agent-slice";
import { addUserMessage } from "#/state/chat-slice";
import {
clearSelectedRepository,
clearFiles,
clearInitialQuery,
} from "#/state/initial-query-slice";
import { clearFiles, clearInitialQuery } from "#/state/initial-query-slice";
import { RootState } from "#/store";
import AgentState from "#/types/agent-state";

Expand All @@ -24,11 +20,11 @@ export const useWSStatusChange = () => {
const statusRef = React.useRef<WsClientProviderStatus | null>(null);

const { selectedRepository } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const { files, importedProjectZip, initialQuery } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const sendInitialQuery = (query: string, base64Files: string[]) => {
Expand All @@ -51,7 +47,6 @@ export const useWSStatusChange = () => {
let additionalInfo = "";

if (gitHubToken && selectedRepository) {
dispatch(clearSelectedRepository());
additionalInfo = `Repository ${selectedRepository} has been cloned to /workspace. Please check the /workspace for files.`;
} else if (importedProjectZip) {
// if there's an uploaded project zip, add it to the chat
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/_oh.app/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function AppContent() {
useConversationConfig();

const { selectedRepository } = useSelector(
(state: RootState) => state.initalQuery,
(state: RootState) => state.initialQuery,
);

const { updateCount } = useSelector((state: RootState) => state.browser);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import statusReducer from "./state/status-slice";

export const rootReducer = combineReducers({
fileState: fileStateReducer,
initalQuery: initialQueryReducer,
initialQuery: initialQueryReducer,
browser: browserReducer,
chat: chatReducer,
code: codeReducer,
Expand Down
Loading