Introduce a user preference for sidebar on diff page
This will be used to automatically open the user's preferred sidebar on
diff pages in the UI.
Google-Bug-Id: b/275059901
Release-Notes: Add a user preference for sidebar on the diff page.
Change-Id: Idd8c492aa6cd4cc90bd1b6d581a7cafeb9adee13
diff --git a/Documentation/rest-api-accounts.txt b/Documentation/rest-api-accounts.txt
index 64bdce0..9ecef3f 100644
--- a/Documentation/rest-api-accounts.txt
+++ b/Documentation/rest-api-accounts.txt
@@ -1314,6 +1314,7 @@
"publish_comments_on_push": true,
"work_in_progress_by_default": true,
"allow_browser_notifications": true,
+ "diff_page_sidebar": "plugin-foo",
"default_base_for_merges": "FIRST_PARENT",
"my": [
{
@@ -1367,6 +1368,7 @@
"disable_keyboard_shortcuts": true,
"disable_token_highlighting": true,
"allow_browser_notifications": false,
+ "diff_page_sidebar": "NONE",
"diff_view": "SIDE_BY_SIDE",
"mute_common_path_prefixes": true,
"my": [
@@ -2714,6 +2716,10 @@
inline edit feature.
|`allow_browser_notifications` |not set if `false`|
Whether to prompt user to enable browser notification in browser.
+|`diff_page_sidebar` |optional|
+String indicating which sidebar should be open on the diff page. Set to "NONE"
+if no sidebars should be open. Plugin-supplied sidebars will be prefixed with
+"plugin-".
|`my` ||
The menu items of the `MY` top menu as a list of
link:rest-api-config.html#top-menu-item-info[TopMenuItemInfo] entities.
@@ -2785,6 +2791,10 @@
inline edit feature.
|`allow_browser_notifications` |not set if `false`|
Whether to prompt user to enable browser notification in browser.
+|`diff_page_sidebar` |optional|
+String indicating which sidebar should be open on the diff page. Set to "NONE"
+if no sidebars should be open. Plugin-supplied sidebars will be prefixed with
+"plugin-".
|`my` |optional|
The menu items of the `MY` top menu as a list of
link:rest-api-config.html#top-menu-item-info[TopMenuItemInfo] entities.
diff --git a/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java b/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java
index 5b33aca..5c48aaf 100644
--- a/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java
+++ b/java/com/google/gerrit/extensions/client/GeneralPreferencesInfo.java
@@ -142,6 +142,13 @@
public List<MenuItem> my;
public List<String> changeTable;
public Boolean allowBrowserNotifications;
+ /**
+ * The sidebar section that the user prefers to have open on the diff page, or "NONE" if all
+ * sidebars should be closed.
+ *
+ * <p>Sidebars supplied by plugins are prefixed with "plugin-".
+ */
+ public String diffPageSidebar;
public DateFormat getDateFormat() {
if (dateFormat == null) {
@@ -205,7 +212,8 @@
&& Objects.equals(this.workInProgressByDefault, other.workInProgressByDefault)
&& Objects.equals(this.my, other.my)
&& Objects.equals(this.changeTable, other.changeTable)
- && Objects.equals(this.allowBrowserNotifications, other.allowBrowserNotifications);
+ && Objects.equals(this.allowBrowserNotifications, other.allowBrowserNotifications)
+ && Objects.equals(this.diffPageSidebar, other.diffPageSidebar);
}
@Override
@@ -232,7 +240,8 @@
workInProgressByDefault,
my,
changeTable,
- allowBrowserNotifications);
+ allowBrowserNotifications,
+ diffPageSidebar);
}
@Override
@@ -260,6 +269,7 @@
.add("my", my)
.add("changeTable", changeTable)
.add("allowBrowserNotifications", allowBrowserNotifications)
+ .add("diffPageSidebar", diffPageSidebar)
.toString();
}
@@ -285,6 +295,7 @@
p.disableTokenHighlighting = false;
p.workInProgressByDefault = false;
p.allowBrowserNotifications = true;
+ p.diffPageSidebar = "NONE";
return p;
}
}
diff --git a/java/com/google/gerrit/server/config/UserPreferencesConverter.java b/java/com/google/gerrit/server/config/UserPreferencesConverter.java
index 2dccabd..4a052d7 100644
--- a/java/com/google/gerrit/server/config/UserPreferencesConverter.java
+++ b/java/com/google/gerrit/server/config/UserPreferencesConverter.java
@@ -111,6 +111,7 @@
builder =
setIfNotNull(
builder, builder::setAllowBrowserNotifications, info.allowBrowserNotifications);
+ builder = setIfNotNull(builder, builder::setDiffPageSidebar, info.diffPageSidebar);
return builder.build();
}
@@ -171,6 +172,7 @@
res.changeTable = proto.getChangeTableCount() != 0 ? proto.getChangeTableList() : null;
res.allowBrowserNotifications =
proto.hasAllowBrowserNotifications() ? proto.getAllowBrowserNotifications() : null;
+ res.diffPageSidebar = proto.hasDiffPageSidebar() ? proto.getDiffPageSidebar() : null;
return res;
}
diff --git a/javatests/com/google/gerrit/acceptance/api/accounts/GeneralPreferencesIT.java b/javatests/com/google/gerrit/acceptance/api/accounts/GeneralPreferencesIT.java
index 2379e6a..eed9de8 100644
--- a/javatests/com/google/gerrit/acceptance/api/accounts/GeneralPreferencesIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/accounts/GeneralPreferencesIT.java
@@ -84,6 +84,7 @@
i.muteCommonPathPrefixes ^= true;
i.signedOffBy ^= true;
i.allowBrowserNotifications ^= false;
+ i.diffPageSidebar = "plugin-insight";
i.diffView = DiffView.UNIFIED_DIFF;
i.my = new ArrayList<>();
i.my.add(new MenuItem("name", "url"));
@@ -96,6 +97,7 @@
assertThat(o.changeTable).containsExactlyElementsIn(i.changeTable);
assertThat(o.theme).isEqualTo(i.theme);
assertThat(o.allowBrowserNotifications).isEqualTo(i.allowBrowserNotifications);
+ assertThat(o.diffPageSidebar).isEqualTo(i.diffPageSidebar);
assertThat(o.disableKeyboardShortcuts).isEqualTo(i.disableKeyboardShortcuts);
}
diff --git a/javatests/com/google/gerrit/server/config/UserPreferencesConverterTest.java b/javatests/com/google/gerrit/server/config/UserPreferencesConverterTest.java
index bbc3c0a..c6ca3e4 100644
--- a/javatests/com/google/gerrit/server/config/UserPreferencesConverterTest.java
+++ b/javatests/com/google/gerrit/server/config/UserPreferencesConverterTest.java
@@ -109,6 +109,7 @@
.build()))
.addAllChangeTable(ImmutableList.of("table1", "table2"))
.setAllowBrowserNotifications(true)
+ .setDiffPageSidebar("plugin-insight")
.build();
UserPreferences.GeneralPreferencesInfo resProto =
GeneralPreferencesInfoConverter.toProto(
diff --git a/polygerrit-ui/app/constants/constants.ts b/polygerrit-ui/app/constants/constants.ts
index d28f33f..24fb5c0 100644
--- a/polygerrit-ui/app/constants/constants.ts
+++ b/polygerrit-ui/app/constants/constants.ts
@@ -263,6 +263,7 @@
email_strategy: EmailStrategy.ATTENTION_SET_ONLY,
default_base_for_merges: DefaultBase.AUTO_MERGE,
allow_browser_notifications: false,
+ diff_page_sidebar: 'NONE',
};
}
diff --git a/polygerrit-ui/app/types/common.ts b/polygerrit-ui/app/types/common.ts
index 8396abc..9992f8b 100644
--- a/polygerrit-ui/app/types/common.ts
+++ b/polygerrit-ui/app/types/common.ts
@@ -253,6 +253,8 @@
export type UserId = AccountId | GroupId | EmailAddress;
+export type DiffPageSidebar = 'NONE' | `plugin-${string}`;
+
// Must be kept in sync with the ListChangesOption enum.
// See: java/com/google/gerrit/extensions/client/ListChangesOption.java
export const ListChangesOption = {
@@ -1333,6 +1335,7 @@
// The email_format doesn't mentioned in doc, but exists in Java class GeneralPreferencesInfo
email_format?: EmailFormat;
allow_browser_notifications?: boolean;
+ diff_page_sidebar?: DiffPageSidebar;
}
/**
diff --git a/proto/entities.proto b/proto/entities.proto
index 372426a..3412291 100644
--- a/proto/entities.proto
+++ b/proto/entities.proto
@@ -172,7 +172,7 @@
// Proto representation of the User preferences classes
// Next ID: 4
message UserPreferences {
- // Next ID: 23
+ // Next ID: 24
message GeneralPreferencesInfo {
// Number of changes to show in a screen.
optional int32 changes_per_page = 1 [default = 25];
@@ -251,6 +251,7 @@
repeated string change_table = 18;
optional bool allow_browser_notifications = 19 [default = true];
+ optional string diff_page_sidebar = 23 [default = "NONE"];
}
optional GeneralPreferencesInfo general_preferences_info = 1;