Skip to content

Commit a19a0ac

Browse files
fix: sort results lexicographically by labels in their order of appearance (snakemake#3293)
<!--Add a description of your PR here--> ### QC <!-- Make sure that you can tick the boxes below. --> * [x] The PR contains a test case for the changes or the changes are already covered by an existing test case. * [x] The documentation (`docs/`) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - **Enhanced Results Display:** Results are now organized and sorted for clearer, more intuitive presentation. - **Improved Navigation:** Clicking the breadcrumb now takes you back to the main menu, streamlining the navigation experience. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8cfff37 commit a19a0ac

File tree

2 files changed

+44
-26
lines changed

2 files changed

+44
-26
lines changed

snakemake/report/html_reporter/template/components/abstract_results.js

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,38 @@ class AbstractResults extends React.Component {
100100
if (this.isLabelled()) {
101101
labels = this.getLabels();
102102
}
103-
return this.getResults().map(function ([path, entry]) {
103+
let entries = this.getResults().map(function ([path, entry]) {
104+
let entryLabels;
105+
let key;
106+
if (labels !== undefined) {
107+
entryLabels = labels.map(function (label) {
108+
return entry.labels[label] || "";
109+
});
110+
key = labels.join();
111+
} else {
112+
entryLabels = [path];
113+
key = path;
114+
}
115+
116+
return {
117+
key: key,
118+
path: path,
119+
labels: entryLabels
120+
};
121+
});
122+
123+
entries = entries.sort(function (a, b) {
124+
// sort labels lexicographically, first element is the most important
125+
for (let i = 0; i < a.labels.length; i++) {
126+
let comparison = a.labels[i].localeCompare(b.labels[i]);
127+
if (comparison !== 0) {
128+
return comparison;
129+
}
130+
}
131+
return 0;
132+
});
133+
134+
return entries.map(function (entry) {
104135
let actions = e(
105136
"td",
106137
{ className: "p-1 text-right" },
@@ -109,7 +140,7 @@ class AbstractResults extends React.Component {
109140
{ className: "inline-flex gap-1", role: "group" },
110141
e(
111142
ResultViewButton,
112-
{ resultPath: path, app: app }
143+
{ resultPath: entry.path, app: app }
113144
),
114145
e(
115146
Button,
@@ -122,34 +153,20 @@ class AbstractResults extends React.Component {
122153
)
123154
);
124155

125-
let entryLabels;
126-
let key;
127-
if (labels !== undefined) {
128-
entryLabels = labels.map(function (label) {
129-
return e(
130-
"td",
131-
{ className: "p-1" },
132-
entry.labels[label] || ""
133-
);
134-
});
135-
key = labels.join();
136-
} else {
137-
entryLabels = e(
138-
"td",
139-
{ className: "p-1" },
140-
path
141-
);
142-
key = path;
143-
}
144-
145156
return [
146157
e(
147158
"tr",
148-
{ key: key },
149-
entryLabels,
159+
{ key: entry.key },
160+
entry.labels.map(function (labelValue) {
161+
return e(
162+
"td",
163+
{ className: "p-1" },
164+
labelValue
165+
);
166+
}),
150167
actions
151168
)
152169
];
153-
})
170+
});
154171
}
155172
}

snakemake/report/html_reporter/template/components/navbar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ class Navbar extends React.Component {
205205
if (isSingleDefaultCategory()) {
206206
return undefined;
207207
}
208-
return { name: "Results", func: undefined };
208+
let setView = this.props.app.setView;
209+
return { name: "Results", func: function () { setView({ navbarMode: "menu", category: undefined, subcategory: undefined }) } };
209210
}
210211

211212
getSearchResultsBreadcrumb() {

0 commit comments

Comments
 (0)