Skip to content

Commit

Permalink
Add permalinks to coredumps and executables
Browse files Browse the repository at this point in the history
The permalink is actually a direct search link, which allows for future
tricks like complex searches shortcuts, metadata search, etc.
  • Loading branch information
elwinar committed Apr 4, 2020
1 parent 02e1240 commit eea1c35
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pagination in the API
- Pagination of the results in the webapp
- Add a special display for empty results
- Permalink to coredump and executable searchs
### Changed
- Design improvements:
- Change the background color of hovered result rows
Expand Down
2 changes: 1 addition & 1 deletion bin/rcoredumpd/internal/statik.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/rcoredumpd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (s *service) searchCore(w http.ResponseWriter, r *http.Request, _ httproute

order := r.FormValue("order")
if len(order) == 0 {
sort = "desc"
order = "desc"
}
switch order {
case "asc", "desc":
Expand Down
33 changes: 29 additions & 4 deletions web/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function decodeQuery(q) {
return JSON.parse(atob(q));
}

function queryTo(s) {
return `/?q=${encodeQuery({q: s})}`
}

// Return a human-readable version of a size in Bytes.
function formatSize(bytes) {
const threshold = 1000;
Expand Down Expand Up @@ -89,6 +93,27 @@ function App() {
});
}, [query]);

// Intercept clicks on all internal links, and hijack them to allow
// changing the query instead of reloading the page. This allows for
// internal query links anywhere in the hierarchy while keeping the
// standard browser actions for links.
React.useEffect(function() {
window.addEventListener('click', function(event){
if (event.target.nodeName !== "A") {
return;
}

const url = new URL(event.target.href);
if (url.hostname !== window.location.hostname || url.pathname !== window.location.pathname) {
return;
}

event.preventDefault();
setQuery(decodeQuery(new URLSearchParams(url.search).get('q')));
return false;
});
}, []);

React.useEffect(function() {
window.addEventListener('popstate', function(event){
setQuery(decodeQuery(new URLSearchParams(window.location.search).get('q')));
Expand Down Expand Up @@ -269,17 +294,17 @@ function Core(props) {
return (
<React.Fragment>
<ul>
<li><a class={styles.Button} href={`${document.config.baseURL}/cores/${core.uid}`}>download core ({formatSize(core.size, true)})</a></li>
<li><a class={styles.Button} href={`${document.config.baseURL}/executables/${core.executable_hash}`}>download executable ({formatSize(core.executable_size, true)})</a></li>
<li><a className={styles.Button} href={`${document.config.baseURL}/cores/${core.uid}`}>download core ({formatSize(core.size, true)})</a></li>
<li><a className={styles.Button} href={`${document.config.baseURL}/executables/${core.executable_hash}`}>download executable ({formatSize(core.executable_size, true)})</a></li>
</ul>
<h2>executable</h2>
<dl>
<dt>executable_hash</dt><dd>{core.executable_hash}</dd>
<dt>executable_hash</dt><dd><a href={queryTo(`executable_hash:"${core.executable_hash}"`)}>{core.executable_hash}</a></dd>
<dt>executable_path</dt><dd>{core.executable_path}</dd>
</dl>
<h2>coredump</h2>
<dl>
<dt>uid</dt><dd>{core.uid}</dd>
<dt>uid</dt><dd><a href={queryTo(`uid:"${core.uid}"`)}>{core.uid}</a></dd>
{Object.keys(core.metadata).map(x => {
return (
<React.Fragment key={x}>
Expand Down

0 comments on commit eea1c35

Please sign in to comment.