PromucFlow_constructor/app/client/src/git/components/QuickActions/BranchButton.tsx
Rudraprasad Das e9ac154a57
chore: git mod - connect modal and branches (#38171)
## Description
- Connects connect modal to store
- Adds component for branch list

Fixes #37814
Fixes #37802 

## 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/12376713895>
> Commit: 34d96b492e20118aa5d82bfa10b9f09315b2bc60
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12376713895&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Tue, 17 Dec 2024 16:59:28 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

- **New Features**
- Introduced a `ConnectInitialize` component for Git provider
connections.
	- Added `ConnectSuccess` modal to display successful Git connections.
	- Implemented `ImportModal` for Git import functionality.
	- Added `LocalProfileView` for managing user profile settings.
- Introduced `BranchList` component for displaying and managing
branches.

- **Bug Fixes**
	- Enhanced error handling and state management in various components.

- **Refactor**
- Streamlined prop handling and state management in multiple components.
	- Updated action and selector names for clarity and consistency.

- **Tests**
- Expanded test coverage for new and modified components, ensuring
accurate behavior under various conditions.

- **Chores**
- Updated import paths and removed unused files to improve project
structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-12-23 16:33:17 +08:00

116 lines
3.0 KiB
TypeScript

import { Button, Icon, Tooltip } from "@appsmith/ads";
import React, { useCallback, useMemo } from "react";
import styled from "styled-components";
import noop from "lodash/noop";
import BranchList from "../BranchList";
import { Popover2 } from "@blueprintjs/popover2";
// internal dependencies
import { isEllipsisActive } from "utils/helpers";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
const ButtonContainer = styled(Button)`
display: flex;
align-items: center;
margin: 0 ${(props) => props.theme.spaces[4]}px;
max-width: 122px;
min-width: unset !important;
:active {
border: 1px solid var(--ads-v2-color-border-muted);
}
`;
const BranchButtonIcon = styled(Icon)`
margin-right: 4px;
`;
const BranchButtonLabel = styled.span`
max-width: 82px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;
const popoverModifiers: { offset: Record<string, unknown> } = {
offset: { enabled: true, options: { offset: [7, 10] } },
};
interface BranchButtonProps {
currentBranch: string | null;
isAutocommitPolling: boolean;
isBranchPopupOpen: boolean;
isProtectedMode: boolean;
isStatusClean: boolean;
isTriggerAutocommitLoading: boolean;
toggleBranchPopup: (open: boolean) => void;
}
export default function BranchButton({
currentBranch = null,
isAutocommitPolling = false,
isBranchPopupOpen = false,
isProtectedMode = false,
isStatusClean = false,
isTriggerAutocommitLoading = false,
toggleBranchPopup = noop,
}: BranchButtonProps) {
const labelTarget = React.useRef<HTMLSpanElement>(null);
const isDisabled = isTriggerAutocommitLoading || isAutocommitPolling;
const onPopoverInteraction = useCallback(
(nextState: boolean) => {
toggleBranchPopup(nextState);
if (nextState) {
AnalyticsUtil.logEvent("GS_OPEN_BRANCH_LIST_POPUP", {
source: "BOTTOM_BAR_ACTIVE_BRANCH_NAME",
});
}
},
[toggleBranchPopup],
);
const content = useMemo(() => {
return <BranchList />;
}, []);
return (
<Popover2
content={content}
data-testid={"t--git-branch-button-popover"}
disabled={isDisabled}
hasBackdrop
isOpen={isBranchPopupOpen}
minimal
modifiers={popoverModifiers}
onInteraction={onPopoverInteraction}
placement="top-start"
>
<Tooltip
content={currentBranch}
isDisabled={!isEllipsisActive(labelTarget.current)}
placement="topLeft"
>
<ButtonContainer
className="t--branch-button"
data-testid={"t--branch-button-currentBranch"}
isDisabled={isDisabled}
kind="secondary"
>
{isProtectedMode ? (
<BranchButtonIcon name="protected-icon" />
) : (
<BranchButtonIcon name={"git-branch"} />
)}
<BranchButtonLabel ref={labelTarget}>
{currentBranch}
</BranchButtonLabel>
{!isStatusClean && !isProtectedMode && "*"}
</ButtonContainer>
</Tooltip>
</Popover2>
);
}