Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Dec 11, 2024
1 parent 3d45ca7 commit 2b6ffc8
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 46 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ public String getSearchUrl() {
}

@Override
public SearchGroup getSearchGroup() {
public String getSearchGroup() {
return SearchGroup.COMPUTER;
}

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import hudson.scm.ChangeLogSet;
import hudson.scm.SCM;
import hudson.search.QuickSilver;
import hudson.search.SearchGroup;
import hudson.search.SearchIndex;
import hudson.search.SearchIndexBuilder;
import hudson.search.SearchItem;
Expand Down Expand Up @@ -524,6 +525,11 @@ public String getSearchIcon() {
return "symbol-status-" + this.getIconColor().getIconName();
}

@Override
public String getSearchGroup() {
return SearchGroup.PROJECT;
}

@Override
protected SearchIndexBuilder makeSearchIndex() {
return super.makeSearchIndex().add(new SearchIndex() {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.model.listeners.SaveableListener;
import hudson.search.SearchGroup;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.security.SecurityRealm;
Expand Down Expand Up @@ -283,6 +284,11 @@ public String getSearchIcon() {
return UserAvatarResolver.resolve(this, "48x48");
}

@Override
public String getSearchGroup() {
return SearchGroup.PEOPLE;
}

/**
* The URL of the user page.
*/
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import hudson.model.Descriptor.FormException;
import hudson.model.listeners.ItemListener;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchGroup;
import hudson.search.SearchIndexBuilder;
import hudson.security.ACL;
import hudson.security.AccessControlled;
Expand Down Expand Up @@ -565,6 +566,11 @@ public String getSearchIcon() {
return "symbol-jobs";
}

@Override
public String getSearchGroup() {
return SearchGroup.VIEW;
}

/**
* Returns the transient {@link Action}s associated with the top page.
*
Expand Down
18 changes: 5 additions & 13 deletions core/src/main/java/hudson/search/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void doSuggest(StaplerRequest2 req, StaplerResponse2 rsp, @QueryParameter

if (iconName.startsWith("symbol")) {
r.suggestions.add(new Item(curItem.getPath(), curItem.getUrl(),
Symbol.get(new SymbolRequest.Builder().withRaw(iconName).build())));
Symbol.get(new SymbolRequest.Builder().withRaw(iconName).build()), "symbol", curItem.item.getSearchGroup()));
} else {
r.suggestions.add(new Item(curItem.getPath(), curItem.getUrl(), iconName, "image", curItem.item.getSearchGroup()));
}
Expand Down Expand Up @@ -279,21 +279,13 @@ public static class Item {

private final String iconXml;

private final SearchGroup group;
private final String group;

public Item(String name) {
this(name, null, null);
this(name, null, null, null, null);
}

public Item(String name, String url, String iconXml) {
this.name = name;
this.url = url;
this.iconXml = iconXml;
this.type = "symbol";
this.group = null;
}

public Item(String name, String url, String iconXml, String type, SearchGroup group) {
public Item(String name, String url, String iconXml, String type, String group) {
this.name = name;
this.url = url;
this.iconXml = iconXml;
Expand All @@ -317,7 +309,7 @@ public String getType() {
}

@Exported
public SearchGroup getGroup() {
public String getGroup() {
return group;
}
}
Expand Down
29 changes: 7 additions & 22 deletions core/src/main/java/hudson/search/SearchGroup.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
package hudson.search;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
public final class SearchGroup {

@ExportedBean(defaultVisibility = 999)
public class SearchGroup {
public static final String VIEW = Messages.SearchGroup_views();

private final String displayName;
public static final String BUILD = Messages.SearchGroup_builds();

public SearchGroup(String displayName) {
this.displayName = displayName;
}
public static final String COMPUTER = Messages.SearchGroup_nodes();

@Exported
public String getDisplayName() {
return displayName;
}
public static final String PROJECT = Messages.SearchGroup_projects();

public static final SearchGroup VIEW = new SearchGroup(Messages.SearchGroup_views());
public static final String PEOPLE = Messages.SearchGroup_people();

public static final SearchGroup BUILD = new SearchGroup(Messages.SearchGroup_builds());

public static final SearchGroup COMPUTER = new SearchGroup(Messages.SearchGroup_nodes());

public static final SearchGroup PROJECT = new SearchGroup(Messages.SearchGroup_projects());

public static final SearchGroup PEOPLE = new SearchGroup(Messages.SearchGroup_people());

public static final SearchGroup OTHER = new SearchGroup(Messages.SearchGroup_other());
public static final String OTHER = Messages.SearchGroup_other();
}
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/search/SearchItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ default String getSearchIcon() {
return "symbol-search";
}

default SearchGroup getSearchGroup() {
default String getSearchGroup() {
return SearchGroup.OTHER;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/js/components/command-palette/datasources.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const JenkinsSearchSource = {
type: e.type,
label: e.name,
url: correctAddress(e.url),
group: e.group,
}),
);
}),
Expand Down
23 changes: 18 additions & 5 deletions src/main/js/components/command-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Symbols from "./symbols";
import makeKeyboardNavigable from "@/util/keyboard";
import { xmlEscape } from "@/util/security";
import { createElementFromHtml } from "@/util/dom";
import { groupResultsByCategory } from "@/components/command-palette/utils";

const datasources = [JenkinsSearchSource];

Expand Down Expand Up @@ -63,6 +64,7 @@ function init() {
label: i18n.dataset.getHelp,
url: headerCommandPaletteButton.dataset.searchHelpUrl,
isExternal: true,
group: null
}),
]);
} else {
Expand All @@ -72,15 +74,26 @@ function init() {
}

results.then((results) => {
results = groupResultsByCategory(results);

// Clear current search results
searchResults.innerHTML = "";

if (query.length === 0 || Object.keys(results).length > 0) {
results.forEach(function (obj) {
const link = createElementFromHtml(obj.render());
link.addEventListener("mouseenter", (e) => itemMouseEnter(e));
searchResults.append(link);
});
for (const [group, items] of Object.entries(results)) {
if (group !== 'null') {
const heading = document.createElement("p");
heading.className = "jenkins-command-palette__results__heading";
heading.innerText = group;
searchResults.append(heading);
}

items.forEach(function (obj) {
const link = createElementFromHtml(obj.render());
link.addEventListener("mouseenter", (e) => itemMouseEnter(e));
searchResults.append(link);
});
}

updateSelectedItem(0);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/main/js/components/command-palette/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { xmlEscape } from "@/util/security";
* @param {string} params.label
* @param {string} params.type
* @param {string} params.url
* @param {string | null} params.group
* @param {boolean | undefined} params.isExternal
*/
export function LinkResult(params) {
return {
label: params.label,
url: params.url,
group: params.group,
render: () => {
return `<a class="jenkins-command-palette__results__item" href="${xmlEscape(
params.url,
Expand Down
13 changes: 13 additions & 0 deletions src/main/js/components/command-palette/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Group results by 'group' field into a map
*/
export function groupResultsByCategory(array) {
return array.reduce((hash, obj) => {
if (obj.group === undefined) {
return hash;
}
return Object.assign(hash, {
[obj.group]: (hash[obj.group] || []).concat(obj),
});
}, {});
}
8 changes: 4 additions & 4 deletions src/main/scss/components/_command-palette.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@
font-weight: 500;
font-size: 0.875rem;
margin: 0;
padding: 0.75rem 0.75rem 0.625rem;
padding: 0.75rem 0.75rem 0.5rem;
color: var(--text-color-secondary);

&:not(:first-of-type) {
padding-top: 2rem;
padding-top: 1.5rem;
}
}

Expand Down Expand Up @@ -157,8 +157,8 @@
display: flex;
align-items: center;
justify-content: center;
width: 1.375rem;
height: 1.375rem;
width: 1.25rem;
height: 1.25rem;
margin-right: 0.75rem;
overflow: hidden;
pointer-events: none;
Expand Down

0 comments on commit 2b6ffc8

Please sign in to comment.