Remove edit actions
The logic to decide which edit buttons should be displayed is rather simple. 'Delete Edit' is always displayed for an edit and depending on whether or not the edit is based on the current patch set 'Publish Edit' or 'Rebase Edit' is shown. This can easily be hard-coded in the UI and the whole overhead of edit actions, like transferring the edit actions as part of the REST response from the server to the client, is not needed. Change-Id: Ic58041e4372880bcd852a9ac32f0493831d827b5 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:

committed by
David Pursehouse

parent
57bf37fd51
commit
2460eb3823
@@ -4048,10 +4048,6 @@ The `EditInfo` entity contains information about a change edit.
|
||||
|`commit` ||The commit of change edit as
|
||||
link:#commit-info[CommitInfo] entity.
|
||||
|`baseRevision`||The revision of the patch set change edit is based on.
|
||||
|`actions` ||
|
||||
Actions the caller might be able to perform on this change edit. The
|
||||
information is a map of view name to link:#action-info[ActionInfo]
|
||||
entities.
|
||||
|`fetch` ||
|
||||
Information about how to fetch this patch set. The fetch information is
|
||||
provided as a map that maps the protocol name ("`git`", "`http`",
|
||||
|
@@ -19,7 +19,6 @@ import java.util.Map;
|
||||
public class EditInfo {
|
||||
public CommitInfo commit;
|
||||
public String baseRevision;
|
||||
public Map<String, ActionInfo> actions;
|
||||
public Map<String, FetchInfo> fetch;
|
||||
public Map<String, FileInfo> files;
|
||||
}
|
||||
|
@@ -496,23 +496,12 @@ public class ChangeScreen2 extends Screen {
|
||||
}
|
||||
|
||||
if (rev.is_edit()) {
|
||||
NativeMap<ActionInfo> actions = info.edit().has_actions()
|
||||
? info.edit().actions()
|
||||
: NativeMap.<ActionInfo> create();
|
||||
actions.copyKeysIntoChildren("id");
|
||||
|
||||
if (actions.containsKey("publish")) {
|
||||
if (isEditBasedOnCurrentPatchSet(info)) {
|
||||
publishEdit.setVisible(true);
|
||||
publishEdit.setTitle(actions.get("publish").title());
|
||||
}
|
||||
if (actions.containsKey("rebase")) {
|
||||
} else {
|
||||
rebaseEdit.setVisible(true);
|
||||
rebaseEdit.setTitle(actions.get("rebase").title());
|
||||
}
|
||||
if (actions.containsKey("/")) {
|
||||
deleteEdit.setVisible(true);
|
||||
deleteEdit.setTitle(actions.get("/").title());
|
||||
}
|
||||
deleteEdit.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -528,6 +517,13 @@ public class ChangeScreen2 extends Screen {
|
||||
info.revisions().values());
|
||||
}
|
||||
|
||||
private boolean isEditBasedOnCurrentPatchSet(ChangeInfo info) {
|
||||
JsArray<RevisionInfo> revList = info.revisions().values();
|
||||
RevisionInfo.sortRevisionInfoByNumber(revList);
|
||||
int currentPatchSetOrEdit = revList.get(revList.length() - 1)._number();
|
||||
return currentPatchSetOrEdit == 0;
|
||||
}
|
||||
|
||||
private void initEditMessageAction(ChangeInfo info, String revision) {
|
||||
RevisionInfo revisionInfo = info.revision(revision);
|
||||
NativeMap<ActionInfo> actions = revisionInfo.actions();
|
||||
|
@@ -15,16 +15,12 @@
|
||||
package com.google.gerrit.server.edit;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.extensions.common.ActionInfo;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.FetchInfo;
|
||||
import com.google.gerrit.extensions.config.DownloadCommand;
|
||||
import com.google.gerrit.extensions.config.DownloadScheme;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.webui.PrivateInternals_UiActionDescription;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.server.CommonConverters;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
@@ -56,7 +52,6 @@ public class ChangeEditJson {
|
||||
EditInfo out = new EditInfo();
|
||||
out.commit = fillCommit(edit.getEditCommit());
|
||||
out.baseRevision = edit.getBasePatchSet().getRevision().get();
|
||||
out.actions = fillActions(edit);
|
||||
if (downloadCommands) {
|
||||
out.fetch = fillFetchMap(edit);
|
||||
}
|
||||
@@ -82,35 +77,6 @@ public class ChangeEditJson {
|
||||
return commit;
|
||||
}
|
||||
|
||||
private static Map<String, ActionInfo> fillActions(ChangeEdit edit) {
|
||||
Map<String, ActionInfo> actions = Maps.newTreeMap();
|
||||
|
||||
UiAction.Description descr = new UiAction.Description();
|
||||
PrivateInternals_UiActionDescription.setId(descr, "/");
|
||||
PrivateInternals_UiActionDescription.setMethod(descr, "DELETE");
|
||||
descr.setTitle("Delete edit");
|
||||
actions.put(descr.getId(), new ActionInfo(descr));
|
||||
|
||||
// Only expose publish action when the edit is on top of current ps
|
||||
PatchSet.Id current = edit.getChange().currentPatchSetId();
|
||||
PatchSet basePs = edit.getBasePatchSet();
|
||||
if (basePs.getId().equals(current)) {
|
||||
descr = new UiAction.Description();
|
||||
PrivateInternals_UiActionDescription.setId(descr, "publish");
|
||||
PrivateInternals_UiActionDescription.setMethod(descr, "POST");
|
||||
descr.setTitle("Publish edit");
|
||||
actions.put(descr.getId(), new ActionInfo(descr));
|
||||
} else {
|
||||
descr = new UiAction.Description();
|
||||
PrivateInternals_UiActionDescription.setId(descr, "rebase");
|
||||
PrivateInternals_UiActionDescription.setMethod(descr, "POST");
|
||||
descr.setTitle("Rebase edit");
|
||||
actions.put(descr.getId(), new ActionInfo(descr));
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Map<String, FetchInfo> fillFetchMap(ChangeEdit edit) {
|
||||
Map<String, FetchInfo> r = Maps.newLinkedHashMap();
|
||||
for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
|
||||
|
Reference in New Issue
Block a user