diff --git a/frontend/src/components/settings/CommitSection.jsx b/frontend/src/components/settings/CommitSection.jsx
index 98ca0c6..04b92cd 100644
--- a/frontend/src/components/settings/CommitSection.jsx
+++ b/frontend/src/components/settings/CommitSection.jsx
@@ -1,22 +1,10 @@
import React from "react";
-import {
- CheckSquare,
- GitCommit,
- RotateCcw,
- Loader,
- Download,
-} from "lucide-react";
import Textarea from "../ui/TextArea";
-import Tooltip from "../ui/Tooltip";
const CommitSection = ({
status,
commitMessage,
setCommitMessage,
- handleStageAll,
- handleCommitAll,
- handleRevertAll,
- loadingAction,
hasIncomingChanges,
}) => {
const hasUnstagedChanges = status.outgoing_changes.some(
@@ -43,70 +31,23 @@ const CommitSection = ({
const randomMessage =
funMessages[Math.floor(Math.random() * funMessages.length)];
- const CommitButton = () => (
-
- );
-
return (
-
Changes:
{hasAnyChanges || hasIncomingChanges ? (
<>
{hasStagedChanges && (
-
- {isIncoming && changes.length > 0 && (
-
-
-
- )}
);
+ const getStageButtonTooltip = () => {
+ if (selectionType === "staged") {
+ return "These files are already staged";
+ }
+ if (selectedOutgoingChanges.length === 0) {
+ return "Select files to stage";
+ }
+ return "Stage selected files";
+ };
+
+ const getCommitButtonTooltip = () => {
+ if (selectionType === "unstaged") {
+ return "You can only commit staged files";
+ }
+ if (selectedOutgoingChanges.length === 0) {
+ return "Select files to commit";
+ }
+ if (!commitMessage.trim()) {
+ return "Enter a commit message";
+ }
+ return "Commit selected files";
+ };
+
+ const getRevertButtonTooltip = () => {
+ if (selectedOutgoingChanges.length === 0) {
+ return "Select files to revert";
+ }
+ return "Revert selected files";
+ };
+
const handleViewDiff = async (change) => {
setLoadingDiff(true); // Start loading
try {
@@ -253,56 +308,33 @@ const SettingsPage = () => {
}
};
- const handleAddFile = async (filePath) => {
- setLoadingAction(`add-${filePath}`);
- try {
- const response = await addFiles([filePath]);
- if (response.success) {
- await fetchGitStatus(); // Refresh status
- Alert.success(response.message);
- } else {
- Alert.error(response.error);
- }
- } catch (error) {
- Alert.error("An unexpected error occurred while adding the file.");
- console.error("Error adding untracked file:", error);
- } finally {
- setLoadingAction("");
- }
- };
-
- const handleStageAll = async () => {
- const unstagedChanges = status.outgoing_changes.filter(
- (change) => !change.staged || (change.staged && change.modified)
- );
-
- if (unstagedChanges.length === 0) {
- Alert.warning("There are no changes to stage.");
+ const handleStageSelectedChanges = async () => {
+ if (selectedOutgoingChanges.length === 0) {
+ Alert.warning("Please select at least one change to stage.");
return;
}
- setLoadingAction("stage_all");
+
+ setLoadingAction("stage_selected");
try {
- const response = await addFiles([]);
+ const response = await addFiles(selectedOutgoingChanges);
if (response.success) {
await fetchGitStatus();
+ setSelectedOutgoingChanges([]); // Clear the selected changes after staging
Alert.success(response.message);
} else {
Alert.error(response.error);
}
} catch (error) {
- Alert.error("An unexpected error occurred while staging files.");
- console.error("Error staging files:", error);
+ Alert.error("An unexpected error occurred while staging changes.");
+ console.error("Error staging changes:", error);
} finally {
setLoadingAction("");
}
};
- const handleCommitAll = async () => {
- if (
- !status.outgoing_changes ||
- !status.outgoing_changes.some((change) => change.staged)
- ) {
- Alert.warning("There are no staged changes to commit.");
+ const handleCommitSelectedChanges = async () => {
+ if (selectedOutgoingChanges.length === 0) {
+ Alert.warning("Please select at least one change to commit.");
return;
}
@@ -311,100 +343,47 @@ const SettingsPage = () => {
return;
}
- setLoadingAction("commit_all");
+ setLoadingAction("commit_selected");
try {
- const stagedFiles = status.outgoing_changes
- .filter((change) => change.staged)
- .map((change) => change.file_path);
- const response = await pushFiles(stagedFiles, commitMessage);
+ const response = await pushFiles(selectedOutgoingChanges, commitMessage);
if (response.success) {
await fetchGitStatus();
+ setSelectedOutgoingChanges([]); // Clear the selected changes after committing
setCommitMessage("");
Alert.success(response.message);
} else {
Alert.error(response.error);
}
} catch (error) {
- Alert.error("An unexpected error occurred while committing files.");
- console.error("Error committing files:", error);
+ Alert.error("An unexpected error occurred while committing changes.");
+ console.error("Error committing changes:", error);
} finally {
setLoadingAction("");
}
};
- const handleRevertFile = async (filePath) => {
- const fileToRevert = status.changes.find(
- (change) => change.file_path === filePath
- );
-
- const isDeletedFile =
- fileToRevert && fileToRevert.status.includes("Deleted");
-
- if (
- !fileToRevert ||
- (!fileToRevert.staged && !fileToRevert.modified && !isDeletedFile)
- ) {
- Alert.warning("There is nothing to revert for this file.");
+ const handleRevertSelectedChanges = async () => {
+ if (selectedOutgoingChanges.length === 0) {
+ Alert.warning("Please select at least one change to revert.");
return;
}
- setLoadingAction(`revert-${filePath}`);
+ setLoadingAction("revert_selected");
try {
- const response = await revertFile(filePath);
- if (response.success) {
+ const response = await Promise.all(
+ selectedOutgoingChanges.map((filePath) => revertFile(filePath))
+ );
+ const allSuccessful = response.every((res) => res.success);
+ if (allSuccessful) {
await fetchGitStatus();
- Alert.success(response.message);
+ setSelectedOutgoingChanges([]); // Clear the selected changes after reverting
+ Alert.success("Selected changes have been reverted successfully.");
} else {
- Alert.error(response.error);
+ Alert.error("Some changes could not be reverted. Please try again.");
}
} catch (error) {
- Alert.error("An unexpected error occurred while reverting the file.");
- console.error("Error reverting file:", error);
- } finally {
- setLoadingAction("");
- }
- };
-
- const handleRevertAll = async () => {
- const hasChangesToRevert = status.changes.some(
- (change) => change.staged || change.modified
- );
-
- if (!hasChangesToRevert) {
- Alert.warning("There are no changes to revert.");
- return;
- }
-
- setLoadingAction("revert_all");
- try {
- const response = await revertAll();
- if (response.success) {
- await fetchGitStatus();
- Alert.success(response.message);
- } else {
- Alert.error(response.error);
- }
- } catch (error) {
- Alert.error("An unexpected error occurred while reverting all changes.");
- console.error("Error reverting all changes:", error);
- } finally {
- setLoadingAction("");
- }
- };
-
- const handleDeleteFile = async (filePath) => {
- setLoadingAction(`delete-${filePath}`);
- try {
- const response = await deleteFile(filePath);
- if (response.success) {
- await fetchGitStatus(); // Refresh the status after deletion
- Alert.success(`File ${filePath} has been deleted.`);
- } else {
- Alert.error(response.error);
- }
- } catch (error) {
- Alert.error("An unexpected error occurred while deleting the file.");
- console.error("Error deleting file:", error);
+ Alert.error("An unexpected error occurred while reverting changes.");
+ console.error("Error reverting changes:", error);
} finally {
setLoadingAction("");
}
@@ -435,47 +414,39 @@ const SettingsPage = () => {
}
};
- const handleSelectChange = (filePath) => {
- setSelectedIncomingChanges((prevSelected) => {
- if (prevSelected.includes(filePath)) {
- return prevSelected.filter((path) => path !== filePath);
- } else {
- return [...prevSelected, filePath];
- }
- });
- };
-
- const getActionButton = (change) => {
- if (change.status === "Untracked") {
- return (
-
- );
+ const handleSelectChange = (filePath, isIncoming) => {
+ if (isIncoming) {
+ setSelectedIncomingChanges((prevSelected) => {
+ if (prevSelected.includes(filePath)) {
+ return prevSelected.filter((path) => path !== filePath);
+ } else {
+ return [...prevSelected, filePath];
+ }
+ });
} else {
- return (
-
+ const change = status.outgoing_changes.find(
+ (c) => c.file_path === filePath
);
+ const isStaged = change.staged;
+
+ setSelectedOutgoingChanges((prevSelected) => {
+ if (prevSelected.includes(filePath)) {
+ const newSelection = prevSelected.filter((path) => path !== filePath);
+ if (newSelection.length === 0) setSelectionType(null);
+ return newSelection;
+ } else {
+ if (
+ prevSelected.length === 0 ||
+ (isStaged && selectionType === "staged") ||
+ (!isStaged && selectionType === "unstaged")
+ ) {
+ setSelectionType(isStaged ? "staged" : "unstaged");
+ return [...prevSelected, filePath];
+ } else {
+ return prevSelected;
+ }
+ }
+ });
}
};
@@ -522,8 +493,10 @@ const SettingsPage = () => {
return ;
case "Custom Format":
return ;
+ case "Quality Profile":
+ return ;
default:
- return ;
+ return ;
}
};
@@ -597,12 +570,69 @@ const SettingsPage = () => {
status={status}
commitMessage={commitMessage}
setCommitMessage={setCommitMessage}
- handleStageAll={handleStageAll}
- handleCommitAll={handleCommitAll}
- handleRevertAll={handleRevertAll}
loadingAction={loadingAction}
hasIncomingChanges={status.incoming_changes.length > 0}
/>
+
+ {/* Buttons Below Commit Section */}
+
+ {/* Conditionally render Stage button */}
+ {selectedOutgoingChanges.length > 0 &&
+ selectionType !== "staged" && (
+
+
+
+ )}
+
+ {/* Conditionally render Commit button */}
+ {selectedOutgoingChanges.length > 0 &&
+ commitMessage.trim() &&
+ selectionType !== "unstaged" && (
+
+
+
+ )}
+
+ {/* Conditionally render Revert button */}
+ {selectedOutgoingChanges.length > 0 && (
+
+
+
+ )}
+
>
)
)}
diff --git a/frontend/src/components/ui/Navbar.jsx b/frontend/src/components/ui/Navbar.jsx
index caf91c5..9b9ba89 100644
--- a/frontend/src/components/ui/Navbar.jsx
+++ b/frontend/src/components/ui/Navbar.jsx
@@ -101,7 +101,7 @@ function Navbar({ darkMode, setDarkMode }) {
: "text-gray-300 hover:bg-gray-700 hover:text-white"
}`}
>
- Profiles
+ Quality Profiles