fix: fixing unprotect logic in callout (#34244)
## Description Clicking "Unprotect branch" in the branch protection callout was making all the branches as unprotected. This PR fixes that and only allows the current branch to be unprotected Fixes #33310 #34005 ## 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/9511853863> > Commit: 1ccab8a270b12427eeda6f4cdbea0fb84b4d77ee > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9511853863&attempt=1" target="_blank">Click here!</a> <!-- 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** - Enhanced IDE with advanced branch protection management, including the ability to unprotect branches directly within the IDE. - **Bug Fixes** - Improved handling of current branch filtering to ensure accurate protected branch management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
4cb6ff03f9
commit
cae0114372
|
|
@ -6,8 +6,9 @@ import configureStore from "redux-mock-store";
|
|||
import IDE from ".";
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import "@testing-library/jest-dom";
|
||||
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
||||
|
||||
const getMockStore = (override: Record<string, any> = {}) => {
|
||||
const getMockStore = (override: Record<string, any> = {}): any => {
|
||||
const slice = {
|
||||
ui: {
|
||||
applications: {
|
||||
|
|
@ -39,7 +40,16 @@ jest.mock("./RightPane", () => () => <div />);
|
|||
jest.mock("./Sidebar", () => () => <div />);
|
||||
jest.mock("components/BottomBar", () => () => <div />);
|
||||
|
||||
describe("Protected view for IDE", () => {
|
||||
const dispatch = jest.fn();
|
||||
jest.mock("react-redux", () => {
|
||||
const originalModule = jest.requireActual("react-redux");
|
||||
return {
|
||||
...originalModule,
|
||||
useDispatch: () => dispatch,
|
||||
};
|
||||
});
|
||||
|
||||
describe("Protected callout test cases", () => {
|
||||
it("should render the protected view for IDE", () => {
|
||||
const store = getMockStore();
|
||||
const { getByTestId } = render(
|
||||
|
|
@ -78,4 +88,32 @@ describe("Protected view for IDE", () => {
|
|||
queryByTestId("t--git-protected-branch-callout"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
it("should unprotect only the current branch if clicked on unprotect cta", () => {
|
||||
const store = getMockStore({
|
||||
ui: {
|
||||
applications: {
|
||||
currentApplication: {
|
||||
gitApplicationMetadata: {
|
||||
branchName: "branch-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
gitSync: {
|
||||
protectedBranches: ["main", "branch-1", "branch-2"],
|
||||
},
|
||||
},
|
||||
});
|
||||
const { queryByTestId } = render(
|
||||
<Provider store={store}>
|
||||
<BrowserRouter>
|
||||
<IDE />
|
||||
</BrowserRouter>
|
||||
</Provider>,
|
||||
);
|
||||
queryByTestId("t--git-protected-unprotect-branch-cta")?.click();
|
||||
expect(dispatch).lastCalledWith({
|
||||
type: ReduxActionTypes.GIT_UPDATE_PROTECTED_BRANCHES_INIT,
|
||||
payload: { protectedBranches: ["main", "branch-2"] },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -6,7 +6,11 @@ import {
|
|||
setShowBranchPopupAction,
|
||||
updateGitProtectedBranchesInit,
|
||||
} from "actions/gitSyncActions";
|
||||
import { getIsUpdateProtectedBranchesLoading } from "selectors/gitSyncSelectors";
|
||||
import {
|
||||
getCurrentGitBranch,
|
||||
getIsUpdateProtectedBranchesLoading,
|
||||
getProtectedBranchesSelector,
|
||||
} from "selectors/gitSyncSelectors";
|
||||
import {
|
||||
BRANCH_PROTECTION_CALLOUT_CREATE_BRANCH,
|
||||
BRANCH_PROTECTION_CALLOUT_MSG,
|
||||
|
|
@ -23,15 +27,20 @@ const StyledCallout = styled(Callout)`
|
|||
function ProtectedCallout() {
|
||||
const dispatch = useDispatch();
|
||||
const isLoading = useSelector(getIsUpdateProtectedBranchesLoading);
|
||||
const currentBranch = useSelector(getCurrentGitBranch);
|
||||
const protectedBranches = useSelector(getProtectedBranchesSelector);
|
||||
|
||||
const handleClickOnNewBranch = () => {
|
||||
dispatch(setShowBranchPopupAction(true));
|
||||
};
|
||||
|
||||
const handleClickOnUnprotect = () => {
|
||||
const remainingBranches = protectedBranches.filter(
|
||||
(protectedBranch) => protectedBranch !== currentBranch,
|
||||
);
|
||||
dispatch(
|
||||
updateGitProtectedBranchesInit({
|
||||
protectedBranches: [],
|
||||
protectedBranches: remainingBranches,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
|
@ -44,11 +53,13 @@ function ProtectedCallout() {
|
|||
links={[
|
||||
{
|
||||
key: "create-branch",
|
||||
"data-testid": "t--git-protected-create-branch-cta",
|
||||
children: createMessage(BRANCH_PROTECTION_CALLOUT_CREATE_BRANCH),
|
||||
onClick: handleClickOnNewBranch,
|
||||
},
|
||||
{
|
||||
key: "unprotect",
|
||||
"data-testid": "t--git-protected-unprotect-branch-cta",
|
||||
children: isLoading
|
||||
? createMessage(BRANCH_PROTECTION_CALLOUT_UNPROTECT_LOADING)
|
||||
: createMessage(BRANCH_PROTECTION_CALLOUT_UNPROTECT),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user