Skip to content

Commit

Permalink
CHE-4678: Add all/local/remote filter in Git branches dialog (eclipse…
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig authored and Dmytro Nochevnov committed Aug 16, 2017
1 parent f08b69c commit 56f3737
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ public interface GitLocalizationConstant extends Messages {
@Key("view.branch.delete_ask")
String branchDeleteAsk(String name);

@Key("view.branch.filter.label")
String branchFilterLabel();

@Key("view.branch.title")
String branchTitle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.che.api.core.ErrorCodes;
import org.eclipse.che.api.git.shared.Branch;
import org.eclipse.che.api.git.shared.BranchListMode;
import org.eclipse.che.api.git.shared.CheckoutRequest;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
Expand All @@ -29,7 +30,6 @@

import javax.validation.constraints.NotNull;

import static org.eclipse.che.api.git.shared.BranchListMode.LIST_ALL;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode;
Expand Down Expand Up @@ -170,7 +170,7 @@ public void onCheckoutClicked() {

/** Get the list of branches. */
private void getBranches() {
service.branchList(project.getLocation(), LIST_ALL)
service.branchList(project.getLocation(), BranchListMode.from(view.getFilterValue()))
.then(branches -> {
if (branches.isEmpty()) {
dialogFactory.createMessageDialog(constant.branchTitle(),
Expand Down Expand Up @@ -212,6 +212,11 @@ public void onBranchUnselected() {
view.setEnableDeleteButton(false);
}

@Override
public void onFilterValueChanged() {
getBranches();
}

@Override
public void onBranchSelected(@NotNull Branch branch) {
selectedBranch = branch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface ActionDelegate {
void onCreateClicked();

/**
* Performs any action in response to the user having select branch.
* Performs any action in response to the user having selected branch.
*
* @param branch
* selected revision
Expand All @@ -49,6 +49,11 @@ public interface ActionDelegate {

/** Performs any action in response to the user do not have any selected branch. */
void onBranchUnselected();

/**
* Performs any action in response to the user having selected branch filter.
*/
void onFilterValueChanged();
}

/**
Expand Down Expand Up @@ -83,6 +88,11 @@ public interface ActionDelegate {
*/
void setEnableRenameButton(boolean enabled);

/**
* Returns selected branch filter.
*/
String getFilterValue();

/** Close dialog. */
void close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import org.vectomatic.dom.svg.ui.SVGResource;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;
Expand Down Expand Up @@ -60,6 +63,8 @@ interface BranchViewImplUiBinder extends UiBinder<Widget, BranchViewImpl> {
Button btnCheckout;
@UiField
ScrollPanel branchesPanel;
@UiField
ListBox filter;
@UiField(provided = true)
final GitResources res;
@UiField(provided = true)
Expand Down Expand Up @@ -128,9 +133,18 @@ public Element createElement() {
.create((SimpleList.View)breakPointsElement, coreRes.defaultSimpleListCss(), listBranchesRenderer, listBranchesDelegate);
this.branchesPanel.add(branches);

this.filter.addItem("All", "all");
this.filter.addItem("Local", "local");
this.filter.addItem("Remote", "remote");

createButtons();
}

@UiHandler("filter")
public void onFilterChanged(ChangeEvent event) {
delegate.onFilterValueChanged();
}

private void createButtons() {
btnClose = createButton(locale.buttonClose(), "git-branches-close", new ClickHandler() {

Expand Down Expand Up @@ -249,6 +263,11 @@ public void setEnableRenameButton(boolean enabled) {
btnRename.setEnabled(enabled);
}

@Override
public String getFilterValue() {
return filter.getSelectedValue();
}

/** {@inheritDoc} */
@Override
public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
.emptyBorder {
margin: 6px;
}

.alignLeft {
float: left;
}
</ui:style>
<g:DockLayoutPanel unit="PX" width="450px" height="600px" addStyleNames="{style.emptyBorder}" debugId="git-branches-mainForm">
<g:DockLayoutPanel unit="PX" width="450px" height="500px" addStyleNames="{style.emptyBorder}" debugId="git-branches-mainForm">
<g:north size="25" addStyleNames="{style.emptyBorder}">
<g:FlowPanel >
<g:Label text="{locale.branchFilterLabel}" width="85px" addStyleNames="{style.alignLeft}"/>
<g:ListBox ui:field="filter" width="80px" addStyleNames="{style.alignLeft}"/>
</g:FlowPanel>
</g:north>
<g:center>
<g:ScrollPanel ui:field="branchesPanel" addStyleNames="{res.gitCSS.simpleListContainer}" debugId="git-branches-branchesPanel"/>
</g:center>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ view.branch.title_rename=Enter branch name
view.branch.type_rename=Name:
view.branch.delete=Delete branch
view.branch.delete_ask=Are you sure you want to delete branch <b>{0}</b>?
view.branch.filter.label=Show branches:
view.branch.title=Branches
#Reset
view.reset.files.title=Select files to reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.ext.git.client.branch;

import org.eclipse.che.api.git.shared.Branch;
import org.eclipse.che.api.git.shared.BranchListMode;
import org.eclipse.che.api.git.shared.CheckoutRequest;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
Expand Down Expand Up @@ -55,24 +56,24 @@
public class BranchPresenterTest extends BaseTest {

@Captor
private ArgumentCaptor<InputCallback> inputCallbackCaptor;
private ArgumentCaptor<InputCallback> inputCallbackCaptor;
@Captor
private ArgumentCaptor<ConfirmCallback> confirmCallbackCaptor;
private ArgumentCaptor<ConfirmCallback> confirmCallbackCaptor;

public static final String BRANCH_NAME = "branchName";
public static final String REMOTE_BRANCH_NAME = "origin/branchName";
public static final boolean IS_REMOTE = true;
public static final boolean IS_ACTIVE = true;
@Mock
private BranchView view;
private BranchView view;
@Mock
private Branch selectedBranch;
private Branch selectedBranch;
@Mock
private DialogFactory dialogFactory;
private DialogFactory dialogFactory;
@Mock
private DtoFactory dtoFactory;
private DtoFactory dtoFactory;
@Mock
private CheckoutRequest checkoutRequest;
private CheckoutRequest checkoutRequest;

private BranchPresenter presenter;

Expand All @@ -98,6 +99,7 @@ public void disarm() {
when(service.branchList(anyObject(), anyObject())).thenReturn(branchListPromise);
when(branchListPromise.then(any(Operation.class))).thenReturn(branchListPromise);
when(branchListPromise.catchError(any(Operation.class))).thenReturn(branchListPromise);
when(view.getFilterValue()).thenReturn("all");
}

@Test
Expand All @@ -120,6 +122,50 @@ public void testShowBranchesWhenGetBranchesRequestIsSuccessful() throws Exceptio
verify(constant, never()).branchesListFailed();
}

@Test
public void shouldShowLocalBranchesWheBranchesFilterIsSetToLocal() throws Exception {
//given
final List<Branch> branches = Collections.singletonList(selectedBranch);
when(service.branchList(anyObject(), eq(BranchListMode.LIST_LOCAL))).thenReturn(branchListPromise);
when(branchListPromise.then(any(Operation.class))).thenReturn(branchListPromise);
when(branchListPromise.catchError(any(Operation.class))).thenReturn(branchListPromise);
when(view.getFilterValue()).thenReturn("local");

//when
presenter.showBranches(project);
verify(branchListPromise).then(branchListCaptor.capture());
branchListCaptor.getValue().apply(branches);

//then
verify(view).showDialogIfClosed();
verify(view).setBranches(eq(branches));
verify(console, never()).printError(anyString());
verify(notificationManager, never()).notify(anyString(), any(ProjectConfigDto.class));
verify(constant, never()).branchesListFailed();
}

@Test
public void shouldShowRemoteBranchesWheBranchesFilterIsSetToRemote() throws Exception {
//given
final List<Branch> branches = Collections.singletonList(selectedBranch);
when(service.branchList(anyObject(), eq(BranchListMode.LIST_LOCAL))).thenReturn(branchListPromise);
when(branchListPromise.then(any(Operation.class))).thenReturn(branchListPromise);
when(branchListPromise.catchError(any(Operation.class))).thenReturn(branchListPromise);
when(view.getFilterValue()).thenReturn("remote");

//when
presenter.showBranches(project);
verify(branchListPromise).then(branchListCaptor.capture());
branchListCaptor.getValue().apply(branches);

//then
verify(view).showDialogIfClosed();
verify(view).setBranches(eq(branches));
verify(console, never()).printError(anyString());
verify(notificationManager, never()).notify(anyString(), any(ProjectConfigDto.class));
verify(constant, never()).branchesListFailed();
}

@Test
public void testOnCloseClicked() throws Exception {
presenter.onCloseClicked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,18 @@ public enum BranchListMode {
* Show only local branches. <br/>
* Corresponds to -l or empty option in console git.
*/
LIST_LOCAL
LIST_LOCAL;

public static BranchListMode from(String mode) {
switch (mode.toLowerCase()) {
case "all":
return LIST_ALL;
case "remote":
return LIST_REMOTE;
case "local":
return LIST_LOCAL;
default:
return null;
}
}
}

0 comments on commit 56f3737

Please sign in to comment.