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(LabelsView): Include/exclude panel actions #210

Merged
merged 19 commits into from
Oct 31, 2024

Conversation

grafakus
Copy link
Contributor

@grafakus grafakus commented Oct 3, 2024

✨ Description

Related issue(s): solves #204

Similarly to what the Explore Logs app provides to easily manipulate filters (e.g. see the "Patterns" tab in the Grafana's playground), this PR introduces the "Include" and "Exclude" buttons on the "Labels" view:

image

📖 Summary of the changes

This PR introduces the new IncludeExcludeAction Scene action, responsible for publishing an event when one of its button is clicked. In turn, this event is captured by their ancestor SceneGroupByLabels, which is responsible for updating the app filters.

Note that the app filters remain the only source of truth: the status of the "Include" / "Exclude" buttons is determined by parsing the app filters. To mitigate performance issues when there are many buttons rendered on the screen, this PR uses memoization.

See diff tab for specific comments.

🧪 How to test?

  • The build with the new unit tests should pass
  • Manually, after checking this PR in local

@github-actions github-actions bot added the feat label Oct 3, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 2024

Unit test coverage

Lines Statements Branches Functions
Coverage: 12%
12.34% (486/3937) 9.73% (136/1397) 8.88% (111/1249)

# Conflicts:
#	src/pages/ProfilesExplorerView/domain/variables/FiltersVariable/filters-ops.tsx
@grafakus grafakus self-assigned this Oct 14, 2024
@grafakus grafakus requested a review from ifrost October 30, 2024 16:01
@grafakus grafakus marked this pull request as ready for review October 30, 2024 16:13
@@ -176,16 +176,6 @@ test.describe('Labels view', () => {
stylePath: './e2e/fixtures/css/hide-all-controls.css',
});
});

test('Add to filters action', async ({ exploreProfilesPage }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exchanged for unit tests below

import { isRegexOperator } from '@shared/components/QueryBuilder/domain/helpers/isRegexOperator';
import { CompleteFilter, OperatorKind } from '@shared/components/QueryBuilder/domain/types';

export const convertPyroscopeToVariableFilter = (filter: CompleteFilter): AdHocVariableFilter => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the .tsx extension has been changed, this file appears as new. But what this PR did is to keep this function and to add the 3 new functions below.

@ifrost
Copy link
Contributor

ifrost commented Oct 31, 2024

Works really nice! I'll have a look a the code in a bit. There's one case that I found confusing:

  • Use "not equal filter" manually, e.g.: vehicle != "car"
  • Click "Exclude" on another label (e.g. "bike")
  • The filters change to vehicle not in bike dropping previously excluded car
Screen.Recording.2024-10-31.at.11.11.45.mov

It was also confusing that after including I need to click twice to actually exclude the same filter:

Screen.Recording.2024-10-31.at.11.13.02.mov

ifrost
ifrost previously approved these changes Oct 31, 2024
filters
.filter((f) => f.key === key && (f.operator === '=~' || f.operator === '!~'))
.some((f) => {
if (!f.value.split('|').includes(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

note: Probably gonna work in 99% of cases but it may lead to weird edge-case scenarios, e.g.

Screen.Recording.2024-10-31.at.11.25.45.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I guess the query builder should strip the ()in this case

@ifrost
Copy link
Contributor

ifrost commented Oct 31, 2024

I would also be great to add some user tracking 👍

@grafakus
Copy link
Contributor Author

grafakus commented Oct 31, 2024

Works really nice! I'll have a look a the code in a bit. There's one case that I found confusing:

  • Use "not equal filter" manually, e.g.: vehicle != "car"
  • Click "Exclude" on another label (e.g. "bike")
  • The filters change to vehicle not in bike dropping previously excluded car

It was also confusing that after including I need to click twice to actually exclude the same filter:

I think the 1st attempt was too complex. So I simplified the logic to make the UI more intuitive IMO... In summary:

  • Include always include and clears excluded values, if any
  • Exclude always exclude and clears included values, if any
  • Clicking on an included button will clear it
  • Clicking on an excluded button will clear it

@grafakus
Copy link
Contributor Author

I would also be great to add some user tracking 👍

Done!

@grafakus grafakus merged commit 2c2d5f5 into main Oct 31, 2024
4 of 5 checks passed
@grafakus grafakus deleted the feat/label-views-include-exclude-actions branch October 31, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants