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

Do not show the Add to Filters action button if the filter exists #285

Merged
merged 4 commits into from
Jan 20, 2025

Conversation

joey-grafana
Copy link
Collaborator

Fixes #123

@joey-grafana joey-grafana added area/ux issues related to UX, UI or research area/frontend labels Jan 9, 2025
@joey-grafana joey-grafana self-assigned this Jan 9, 2025
@joey-grafana joey-grafana marked this pull request as ready for review January 13, 2025 15:10
@joey-grafana joey-grafana requested a review from a team January 13, 2025 15:10
Copy link
Collaborator

@adrapereira adrapereira left a comment

Choose a reason for hiding this comment

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

I have one comment which greatly impacts the feature, so can't approve yet. The approach makes sense though!

We might have to make the logic to check if the filter exists a bit smarter, for example if the existing filter operator is = or =~ say filter exists, otherwise check if key and value match.

@@ -61,3 +66,8 @@ export const addToFilters = (variable: AdHocFiltersVariable, label: string, valu
],
});
};

export const filterExistsForKey = (model: AdHocFiltersVariable, key: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're only checking if the label/key matches, which means that we can't build queries like { foo != "abc" && foo != "xyz" }. We don't have include/exclude buttons for now but we might add them soon and the ability to exclude multiple values for the same attribute may be useful.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, update to follow

Copy link
Collaborator

@ifrost ifrost left a comment

Choose a reason for hiding this comment

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

Works great!

Out of curiosity - why name of the field is wrapped in " and forces us to sanitize it with value.replace(/"/g, '')?

Screenshot 2025-01-16 at 11 55 30

@adrapereira
Copy link
Collaborator

@ifrost I cleaned this up a bit in my exemplars PR which will only wrap it in quotes when absolutely needed.

The reason is that Tempo is aware of the type of the values, so the value "123" is a string and 123 is a number. In order to keep it accurate and differentiate this in graphs we wrap strings in quotes.

@joey-grafana joey-grafana dismissed adrapereira’s stale review January 20, 2025 09:20

approved but forgotten

@joey-grafana joey-grafana merged commit dd1c705 into main Jan 20, 2025
4 checks passed
@joey-grafana joey-grafana deleted the joey/dont-show-add-filter-if-exists branch January 20, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend area/ux issues related to UX, UI or research
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't display "Add to filters" option when filter is already applied
3 participants