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

fix: use urlUtil instead of UrlSearchParams #994

Merged
merged 8 commits into from
Jan 10, 2025

Conversation

gtk-grafana
Copy link
Contributor

@gtk-grafana gtk-grafana commented Jan 9, 2025

Fixes bug introduced by URLSearchParams which will replace whitespace with + instead of %20
Fixes bug in line filter migration where escaped chars would not get unescaped.

@gtk-grafana gtk-grafana marked this pull request as ready for review January 10, 2025 00:28
@gtk-grafana gtk-grafana requested a review from a team as a code owner January 10, 2025 00:28
@gtk-grafana gtk-grafana self-assigned this Jan 10, 2025
@gtk-grafana gtk-grafana added this to the 1.0.6 milestone Jan 10, 2025
@gtk-grafana gtk-grafana added the bug Something isn't working label Jan 10, 2025
import { urlUtil } from '@grafana/data';

function removeEscapeChar(value: string) {
return value
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious about the unusual approach. Why not a regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was struggling to get the regex to work last night, I'll take another look

Copy link
Contributor Author

@gtk-grafana gtk-grafana Jan 10, 2025

Choose a reason for hiding this comment

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

Nevermind, I made this implementation more complicated to fix the user-entered escape char case, so I think it's beyond my regex abilities without dumping a bunch more time into this.

'page_url%3D%22https:%2F%2Fgrafana%5C.net%2Fexplore%5C%3Fleft%3D%5C%7B%22datasource%22:%22grafanacloud-prom%22,%22queries%22:%5C%5B%5C%7B%22datasource%22:%5C%7B%22type%22:%22prometheus%22,%22uid%22:%22grafanacloud-prom%22%5C%7D,%22expr%22:%22max%20by%20%5C%28kube_cluster_name,%20kube_namespace%5C%29%20%5C%28quantile_over_time%5C%280%5C.85,%20kubernetes_state_pod_age%5C%7Bplatform%3D%22data%22,kube_namespace%21~%22data-dev%5C%7Cdata-stg%22,pod_phase%3D%22pending%22%5C%7D%5C%5B5m%5C%5D%5C%29%5C%29%20%3E%20600%22,%22refId%22:%22A%22%5C%7D%5C%5D,%22range%22:%5C%7B%22from%22:%22now-1h%22,%22to%22:%22now%22%5C%7D%5C%7D%22%60';
const decodedAndUnescaped =
'page_url="https://grafana.net/explore?left={"datasource":"grafanacloud-prom","queries":[{"datasource":{"type":"prometheus","uid":"grafanacloud-prom"},"expr":"max by (kube_cluster_name, kube_namespace) (quantile_over_time(0.85, kubernetes_state_pod_age{platform="data",kube_namespace!~"data-dev|data-stg",pod_phase="pending"}[5m])) > 600","refId":"A"}],"range":{"from":"now-1h","to":"now"}}"';
await explorePage.gotoServicesOldUrlLineFilters('tempo-distributor', false, urlEncodedAndEscaped);
Copy link
Contributor

Choose a reason for hiding this comment

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

Took me a while to understand the trick with the string encoded/decoded.

@gtk-grafana gtk-grafana merged commit c435654 into main Jan 10, 2025
4 checks passed
@gtk-grafana gtk-grafana deleted the gtk-grafana/absolute-url-share-bug branch January 10, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants