This PR syncs labels of the values in the group by variable similarly to what we introduced for ad-hoc filters.
Unlike ad-hoc filters, group by is a little bit more of a special case hence the reason why some of the changes below. The solution might not be optimal, so please feel free to suggested changes and improvements.
Changes:
introduced custom URL sync handler
it works similarly to the ad-hoc filters one
this is needed as currently we use the one multi-value variable one and we don't want this changed for all variables
the state of group by variable received a new prop: urlOptions where we store the options that we received via the URL
when fetching the options, we concat the urlOptions with what we receive from the datasource (or with the defaultOptions)
this is needed because of validateAndUpdate and also because changeValueTo is sometimes called without the texts array
we leverage the fact that the value of the MultiSelect can be a SelectableValue hence we can enforce the labels on values
moved some common functions to variables utils
The gotcha: let's assume we pass a value via URL. This value is not returned by the datasource hence we consider it a custom value. We then remove the custom value using the UI button. When opening the dropdown again, the custom value can be found in the dropdown. Is this a behavior we want to keep? You can also see this behavior in the demo below.
PS: tests will come in a subsequent push. For the time being I'm trying to decide upon edge cases.
📦 Published PR as canary version: 4.20.0--canary.705.9031064372.0
:sparkles: Test out this PR locally via:
```bash
npm install @grafana/scenes@4.20.0--canary.705.9031064372.0
# or
yarn add @grafana/scenes@4.20.0--canary.705.9031064372.0
```
This PR syncs labels of the values in the group by variable similarly to what we introduced for ad-hoc filters.
Unlike ad-hoc filters, group by is a little bit more of a special case hence the reason why some of the changes below. The solution might not be optimal, so please feel free to suggested changes and improvements.
Changes:
urlOptions
where we store the options that we received via the URLurlOptions
with what we receive from the datasource (or with thedefaultOptions
)validateAndUpdate
and also becausechangeValueTo
is sometimes called without the texts arrayMultiSelect
can be aSelectableValue
hence we can enforce the labels on valuesThe gotcha: let's assume we pass a value via URL. This value is not returned by the datasource hence we consider it a custom value. We then remove the custom value using the UI button. When opening the dropdown again, the custom value can be found in the dropdown. Is this a behavior we want to keep? You can also see this behavior in the demo below.
PS: tests will come in a subsequent push. For the time being I'm trying to decide upon edge cases.
Demo:
https://github.com/grafana/scenes/assets/9215315/54ca86b9-9db9-4ac1-ac8e-144a8cd576f2
📦 Published PR as canary version:
4.20.0--canary.705.9031064372.0
:sparkles: Test out this PR locally via: ```bash npm install @grafana/scenes@4.20.0--canary.705.9031064372.0 # or yarn add @grafana/scenes@4.20.0--canary.705.9031064372.0 ```