PromucFlow_constructor/app/client/src/git/components/GitQuickActions/index.tsx
Rudraprasad Das 0808b279fa
chore: git mod - adding init saga and connecting components to ctx (#38088)
## Description
- Adds more selectors
- Adds more sagas
- Introduces init steps for git
- Improvements upon CtxAwareGitQuickActions

Fixes #37800 
Fixes #36814 


## Automation

/ok-to-test tags="@tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12295168481>
> Commit: ea1ab497cad677aac36f044462e623e526d421d1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12295168481&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Thu, 12 Dec 2024 12:06:09 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
  - Introduced a context provider for managing Git-related state.
  - Added a `GitQuickActions` component for various Git actions.
- Implemented custom hooks for managing Git branches, metadata,
operations, and settings.
- Added Redux Saga functions for fetching Git metadata and protected
branches.
  - Enhanced autocommit functionality with polling for progress.
- Introduced actions for managing the autocommit process and fetching
protected branches.
- Added new actions to initialize Git for editor context and manage
loading states.

- **Bug Fixes**
  - Improved error handling in various action creators and sagas.

- **Chores**
- Updated action creators and types for better type safety and clarity.
- Refined test cases for components to ensure accurate button selection.
- Modified request functions to utilize Axios promises directly for
better consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-12-12 23:18:09 +08:00

181 lines
5.2 KiB
TypeScript

import React, { useCallback } from "react";
import styled from "styled-components";
import {
COMMIT_CHANGES,
createMessage,
GIT_SETTINGS,
MERGE,
} from "ee/constants/messages";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import { GitOpsTab } from "../../constants/enums";
import { GitSettingsTab } from "../../constants/enums";
import ConnectButton from "./ConnectButton";
import QuickActionButton from "./QuickActionButton";
import Statusbar from "../Statusbar";
import getPullBtnStatus from "./helpers/getPullButtonStatus";
import noop from "lodash/noop";
const Container = styled.div`
height: 100%;
display: flex;
align-items: center;
`;
interface GitQuickActionsProps {
discard: () => void;
isAutocommitEnabled: boolean;
isAutocommitPolling: boolean;
isConnectPermitted: boolean;
isDiscardLoading: boolean;
isFetchStatusLoading: boolean;
isGitConnected: boolean;
isProtectedMode: boolean;
isPullFailing: boolean;
isPullLoading: boolean;
isStatusClean: boolean;
pull: () => void;
statusBehindCount: number;
statusChangeCount: number;
toggleGitConnectModal: (open: boolean) => void;
toggleGitOpsModal: (open: boolean, tab: keyof typeof GitOpsTab) => void;
toggleGitSettingsModal: (
open: boolean,
tab: keyof typeof GitSettingsTab,
) => void;
}
function GitQuickActions({
discard = noop,
isAutocommitEnabled = false,
isAutocommitPolling = false,
isConnectPermitted = false,
isDiscardLoading = false,
isFetchStatusLoading = false,
isGitConnected = false,
isProtectedMode = false,
isPullFailing = false,
isPullLoading = false,
isStatusClean = false,
pull = noop,
statusBehindCount = 0,
statusChangeCount = 0,
toggleGitConnectModal = noop,
toggleGitOpsModal = noop,
toggleGitSettingsModal = noop,
}: GitQuickActionsProps) {
const { isDisabled: isPullDisabled, message: pullTooltipMessage } =
getPullBtnStatus({
isStatusClean,
isProtectedMode,
isPullFailing,
statusBehindCount,
});
const isPullButtonLoading =
isDiscardLoading || isPullLoading || isFetchStatusLoading;
const onCommitBtnClick = useCallback(() => {
if (!isFetchStatusLoading && !isProtectedMode) {
toggleGitOpsModal(true, GitOpsTab.Deploy);
AnalyticsUtil.logEvent("GS_DEPLOY_GIT_MODAL_TRIGGERED", {
source: "BOTTOM_BAR_GIT_COMMIT_BUTTON",
});
}
}, [isFetchStatusLoading, isProtectedMode, toggleGitOpsModal]);
const onPullBtnClick = useCallback(() => {
if (!isPullButtonLoading && !isPullDisabled) {
AnalyticsUtil.logEvent("GS_PULL_GIT_CLICK", {
source: "BOTTOM_BAR_GIT_PULL_BUTTON",
});
if (isProtectedMode) {
discard();
} else {
// ! case: why is triggeredFromBottomBar this needed?
// pull({ triggeredFromBottomBar: true });
pull();
}
}
}, [discard, isProtectedMode, pull, isPullDisabled, isPullButtonLoading]);
const onMergeBtnClick = useCallback(() => {
AnalyticsUtil.logEvent("GS_MERGE_GIT_MODAL_TRIGGERED", {
source: "BOTTOM_BAR_GIT_MERGE_BUTTON",
});
toggleGitOpsModal(true, GitOpsTab.Merge);
}, [toggleGitOpsModal]);
const onSettingsClick = useCallback(() => {
toggleGitSettingsModal(true, GitSettingsTab.General);
AnalyticsUtil.logEvent("GS_SETTING_CLICK", {
source: "BOTTOM_BAR_GIT_SETTING_BUTTON",
});
}, [toggleGitSettingsModal]);
const onConnectBtnClick = useCallback(() => {
AnalyticsUtil.logEvent("GS_CONNECT_GIT_CLICK", {
source: "BOTTOM_BAR_GIT_CONNECT_BUTTON",
});
toggleGitConnectModal(true);
}, [toggleGitConnectModal]);
return isGitConnected ? (
<Container>
{/* <BranchButton /> */}
{isAutocommitEnabled && isAutocommitPolling ? (
<Statusbar completed={!isAutocommitPolling} />
) : (
<>
<QuickActionButton
className="t--bottom-bar-commit"
count={isProtectedMode ? undefined : statusChangeCount}
disabled={!isFetchStatusLoading && isProtectedMode}
icon="plus"
key="commit-action-btn"
loading={isFetchStatusLoading}
onClick={onCommitBtnClick}
tooltipText={createMessage(COMMIT_CHANGES)}
/>
<QuickActionButton
className="t--bottom-bar-pull"
count={statusBehindCount}
disabled={!isPullButtonLoading && isPullDisabled}
icon="down-arrow-2"
key="pull-action-btn"
loading={isPullButtonLoading}
onClick={onPullBtnClick}
tooltipText={pullTooltipMessage}
/>
<QuickActionButton
className="t--bottom-bar-merge"
disabled={isProtectedMode}
icon="fork"
key="merge-action-btn"
onClick={onMergeBtnClick}
tooltipText={createMessage(MERGE)}
/>
<QuickActionButton
className="t--bottom-git-settings"
icon="settings-v3"
key="settings-action-btn"
onClick={onSettingsClick}
tooltipText={createMessage(GIT_SETTINGS)}
/>
</>
)}
</Container>
) : (
<ConnectButton
isConnectPermitted={isConnectPermitted}
onClick={onConnectBtnClick}
/>
);
}
export default GitQuickActions;