search: Manually add items to search stack
Created by: fkling
This commit changes the behavior of the search stack to allow items being added manually instead of automatically.
As a consequence this change also removes the detection of duplicate items (the same file/search could be added multiple times if desired). Whether or not this is desirable (or whether an item should be highlighted somehow when it matches the current query/file) needs to be discussed.
Instead of having the search stack component automatically detect whether it's opened on a page that can be added to the stack, I'm keeping the existing API (the pages "push" to the stack). I decided against having the component detect the page because the only way I could see that working is via inspect and parsing the URLs, and that appeared too fragile to me (and also the URLs might not contain all the information we want). But if URL parsing is considered to be good enough then this could be considered in the future.
Clicking any of the "add" buttons will make the button disappear but we could also consider to keep it visible.
https://user-images.githubusercontent.com/179026/153200857-1cc4efaf-d710-4ddb-8b9b-eb2caa6ae0f1.mp4
Test plan
- Go to https://sourcegraph.com/search and submit a search
- On the search result page, open the search stack widget.
- A button for adding the current search should be shown.
- Clicking the button should add a search entry to the stack
- Click on the file link of one of the search results
- This should open the file.
- A button for adding the current file should be shown.
- Clicking the button should add a search entry to the stack
- Go back to the search results and click on one of the search results
- This should open file and the matched line should be highlighed.
- Open the search stack widget if necessary.
- It should show two buttons, one for adding a file and one for adding a line range
- Click on the "add file" button, a new file entry should be added.
- Refresh the page.
- Open the search stack widget.
- Click on the "add range" button, a new line range entry should be added.