PromucFlow_constructor/app/client/src/git/components/QuickActions/BranchButton.tsx
Rudraprasad Das c169d48888
chore: git mod - minor fixes (#38563)
## Description
- Fixes initial loading state for status
- Includes module instances and source module count
- Fixes discard flow

## 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/12692930817>
> Commit: 6689c8e113bc4795cecd533fe5b7eff6ee221283
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12692930817&attempt=4"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
> Spec:
> <hr>Fri, 10 Jan 2025 08:32:22 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 new focus on source modules instead of packages
	- Enhanced tracking of module instances and source module changes

- **Bug Fixes**
- Updated status change calculations to more accurately reflect module
modifications
	- Improved handling of artifact identification in discard operations

- **Refactor**
- Renamed and restructured various status-related interfaces and
functions
- Modified selectors and reducers to support new module tracking
approach

- **Chores**
	- Updated type definitions and selector implementations
	- Removed deprecated package-related tracking mechanisms

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-01-10 12:16:55 +01:00

115 lines
2.9 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 = true,
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
data-testid={"t--git-quick-actions-branch"}
isDisabled={isDisabled}
kind="secondary"
>
{isProtectedMode ? (
<BranchButtonIcon name="protected-icon" />
) : (
<BranchButtonIcon name="git-branch" />
)}
<BranchButtonLabel ref={labelTarget}>
{currentBranch}
</BranchButtonLabel>
{!isStatusClean && !isProtectedMode && "*"}
</ButtonContainer>
</Tooltip>
</Popover2>
);
}