Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): sync search in comparison view #661

Closed
wants to merge 18 commits into from

Conversation

GorvGoyl
Copy link

No description provided.

@CLAassistant
Copy link

CLAassistant commented Dec 26, 2021

CLA assistant check
All committers have signed the CLA.

@GorvGoyl
Copy link
Author

reference #286

@codecov
Copy link

codecov bot commented Dec 27, 2021

Codecov Report

Merging #661 (0a8e8f3) into main (556a4c6) will decrease coverage by 0.74%.
The diff coverage is 68.36%.

❗ Current head 0a8e8f3 differs from pull request most recent head 96ee4ff. Consider uploading reports for the commit 96ee4ff to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
- Coverage   77.08%   76.34%   -0.73%     
==========================================
  Files          59       60       +1     
  Lines        2037     2109      +72     
  Branches      366      391      +25     
==========================================
+ Hits         1570     1610      +40     
- Misses        439      471      +32     
  Partials       28       28              
Impacted Files Coverage Δ
...pp/javascript/components/ProfilerHeader.module.css 61.54% <ø> (ø)
webapp/javascript/redux/reducers/search.ts 38.24% <38.24%> (ø)
webapp/javascript/components/Toolbar.tsx 86.17% <90.70%> (-4.74%) ⬇️
webapp/javascript/ui/Button.tsx 80.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 556a4c6...96ee4ff. Read the comment docs.

@eh-am
Copy link
Collaborator

eh-am commented Jan 3, 2022

/create-server

@Rperry2174
Copy link
Contributor

/create-server

@Rperry2174
Copy link
Contributor

Reposting thoughts regarding tests to get input from others:
image

Here there are two issues I think:

      <DebounceInput
        data-testid="flamegraph-search"
        data-testname={`flamegraph-search-${viewSide}`}
        className={`${styles.search} ${
          showMode === 'small' ? styles['search-small'] : ''
        } ${
          searchInputType === 'linked' ? styles['linked-search-input'] : ''
        } ${isSearchLinked === true ? styles.active : ''}`}

So here there is a space between each ternary. so even when the ternaries return '' they really return [space]'' for each ternary. Might be a cleaner way to add these additional classes in this case.

For the other part data-testname="flamegraph-search-undefined" did you change anything that would cause for viewSide to go from being left or right to being undefined?

It looks from this PR like you added data-testname not sure if we need it (?)

cc/ @eh-am

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 5, 2022

So here there is a space between each ternary. so even when the ternaries return '' they really return [space]'' for each ternary. Might be a cleaner way to add these additional classes in this case.

extra space at the end in class shouldn't cause any issues in UI. Similar scenario for Single View page when the search bar is not small.

className={`${styles.search} ${
          showMode === 'small' ? styles['search-small'] : ''
        }

I did some refactoring but extra space is still there unless I do some more string manipulation. Instead, is it possible to update the snapshot so it matches the latest test result?

It looks from this PR like you added data-testname not sure if we need it

correct, I refactored the code to use data-testid for linked search test case

Copy link
Collaborator

@eh-am eh-am left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, that's pretty cool! I have a few comments:


Maybe it's just me, but I found a bit weird how removing the link also deletes the search. For comparison, in grafana, when you unsync 2 time ranges, they continue the same, just unlinked.


Functionality is missing on the Adhoc Comparison page.
image


How is the button going to work when we add a button to clear the search, like ?


I would love to see some unit tests here!


The button is missing a hover cursor.

};
const toggleLinkedSearch = (side) => {
const { isSearchLinked } = linkedSearch;
if (isSearchLinked) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return early here if isSearchLinked is false? The nesting here doesn't add much value IMO.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

const toggleLinkedSearch = (side) => {
const { isSearchLinked } = linkedSearch;
if (isSearchLinked) {
if (side === 'left') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use switch/case here? This file isn't using typescript yet, but in the future we can update it to use exhaustive case checks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus these cases are pretty similar, so we can just build an args parameter and then declaratively use it?

Eg

let args;
if (side === 'right') {
  args = { resetLinkedSearchSide: 'left' }
}
if (side === 'both') {
  args = { sSearchLinked: false, resetLinkedSearchSide: '' }
}
(...)

setLinkedSearch((x) => {
   return { ...x,  ...args };
});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think having all this logic here bloats this file. These files (Coparison, SingleView, ComparisonDiff) are the entrypoints for our pages, ie the first or second thing people should read to understand what the page is about. Having this logic makes it harder for people to understand it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eh-am where would you put this instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use switch/case here
declarative way

done.

Comment on lines 109 to 113
isSearchLinked={linkedSearch.isSearchLinked}
setSearchQuery={setSearchQuery}
linkedSearchQuery={linkedSearch.linkedSearchQuery}
toggleLinkedSearch={toggleLinkedSearch}
resetLinkedSearchSide={linkedSearch.resetLinkedSearchSide}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is case where lifting state up makes the parent component too bloated. I think you can infer based on the toolbar viewType whether to show the link, and then dispatch a redux action to enable/disable the link functionality.

isSearchLinked === true ? styles.active : ''
}`}
>
<svg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Found one matching link icon (solid though) https://fontawesome.com/v5.15/icons?d=gallery&p=2&q=link

image

image

Comment on lines 252 to 254
title={`${
isSearchLinked === true ? 'Unsync search term' : 'Sync search term'
}`}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of using titles for this cases, but I guess until we have proper tooltip support this is fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. we can replace title once we have a generic tooltip.

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 5, 2022

Functionality is missing on the Adhoc Comparison page.

Is this different from /comparison page? what's the URL here?

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 5, 2022

  • add hover cursor to button.

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 5, 2022

How is the button going to work when we add a button to clear the search

clear input text button is already there on hover.
image

would love to see some unit tests here!

I added some tests in basic.ts file. Where do I add more tests?

@eh-am
Copy link
Collaborator

eh-am commented Jan 5, 2022

Functionality is missing on the Adhoc Comparison page.

Is this different from /comparison page? what's the URL here?

You have to run the server with --enable-experimental-adhoc-ui enabled, or via env var PYROSCOPE_ENABLE_EXPERIMENTAL_ADHOC_UI. We will release after @abeaumont finishes the implementation, which is almost done here #652

Then it will be enabled in the sidebar ->
image

How is the button going to work when we add a button to clear the search

clear input text button is already there on hover. image

Sorry, I don't see it, am I missing something?
image

But anyway, that answers my question, it will be inside the input, so it will still look good!

would love to see some unit tests here!

I added some tests in basic.ts file. Where do I add more tests?

That's a e2e/integration test. For that I would simply 1 - Type the search 2 - Click the link button 3 - Check if the query was copied to the other field.
There's no need to test the highlight again IMO.

Now for adding the unit tests, it depends how the code is organized. You can try putting 2 toolbars side by side and seeing if the sync works. Or if that's too difficult, to put 2 flamegraphs side by side. The advantage of unit test here is that it forces you to check the API. If it's too difficult to test, then it's too difficult to (re)use the component.

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 6, 2022

You have to run the server with --enable-experimental-adhoc-ui enabled, or via env var PYROSCOPE_ENABLE_EXPERIMENTAL_ADHOC_UI. We will release after @abeaumont finishes the implementation, which is almost done here #652

So, I was trying it and it looks like the profiler data is not able to load for the other view.

image

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 6, 2022

How is the button going to work when we add a button to clear the search. Sorry, I don't see it, am I missing something?

I'm using chromium browser (edge) and it's visible when I type something into the search box.

@GorvGoyl
Copy link
Author

GorvGoyl commented Jan 8, 2022

@eh-am I've moved the logic to redux as discussed as per my understanding. Toolbar component is used to access redux store but it's now causing issues with toolbar unit tests:

ProfileHeader › ViewSection › small mode › changes to Both view

    could not find react-redux context value; please ensure the component is wrapped in a <Provider>

      204 | }) {
      205 |   const [text, setText] = useState('');
    > 206 |   const isSearchLinkedState = useSelector(isSearchLinked);

Should we also include the provider for unit tests or is there an alternative way? I've limited experience with redux so not sure about the right approach.

Also, let me know if there are any other changes needed.

@GorvGoyl
Copy link
Author

@eh-am I think I've addressed the mentioned changes. Please review.

cc: @Rperry2174

@petethepig petethepig closed this Mar 1, 2022
korniltsev pushed a commit that referenced this pull request Jul 18, 2023
* fix-single-binary-deploy

* Make dashboards work for single-binary phlare
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants