mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 23:42:51 +08:00
Deprecation: use locationService in favor of getLocationSrv (#44813)
* deprecated * updating documentation. * added deprecation notice. * Replacing deprecated getLocationSrv. * Update docs/sources/developers/plugins/migration-guide.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/developers/plugins/migration-guide.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/developers/plugins/migration-guide.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/developers/plugins/migration-guide.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * updating according to feedback. * Update docs/sources/developers/plugins/migration-guide.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/developers/plugins/migration-guide.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
@ -80,26 +80,19 @@ For more information on the available variable formats, refer to [Advanced varia
|
||||
|
||||
## Set a variable from your plugin
|
||||
|
||||
Not only can you read the value of a variable, you can also update the variable from your plugin. Use LocationSrv.update()
|
||||
Not only can you read the value of a variable, you can also update the variable from your plugin. Use `locationService.partial(query, replace)`.
|
||||
|
||||
The following example shows how to update a variable called `service`.
|
||||
|
||||
- `query` contains the query parameters you want to update. Query parameters controlling variables are prefixed with `var-`.
|
||||
- `partial: true` makes the update only affect the query parameters listed in `query`, and leaves the other query parameters unchanged.
|
||||
- `replace: true` tells Grafana to update the current URL state, rather than creating a new history entry.
|
||||
|
||||
```ts
|
||||
import { getLocationSrv } from '@grafana/runtime';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
```
|
||||
|
||||
```ts
|
||||
getLocationSrv().update({
|
||||
query: {
|
||||
'var-service': 'billing',
|
||||
},
|
||||
partial: true,
|
||||
replace: true,
|
||||
});
|
||||
locationService.partial({ 'var-service': 'billing' }, true);
|
||||
```
|
||||
|
||||
> **Note:** Grafana queries your data source whenever you update a variable. Excessive updates to variables can slow down Grafana and lead to a poor user experience.
|
||||
|
@ -15,6 +15,8 @@ This guide helps you identify the steps you need to take based on the Grafana ve
|
||||
- [From version 8.3.x to 8.4.x](#from-version-83x-to-84x)
|
||||
- [Value Mapping Editor has been removed from @grafana-ui library](#value-mapping-editor-has-been-removed-from-grafana-ui-library)
|
||||
- [Thresholds Editor has been removed from @grafana-ui library](#thresholds-editor-has-been-removed-from-grafana-ui-library)
|
||||
- [8.4 Deprecations](#84-deprecations)
|
||||
- [LocationService replaces getLocationSrv](#locationservice-replaces-getlocationsrv)
|
||||
- [From version 7.x.x to 8.x.x](#from-version-7xx-to-8xx)
|
||||
- [Backend plugin v1 support has been dropped](#backend-plugin-v1-support-has-been-dropped)
|
||||
- [1. Add dependency on grafana-plugin-sdk-go](#1-add-dependency-on-grafana-plugin-sdk-go)
|
||||
@ -48,6 +50,81 @@ Removed due to being an internal component.
|
||||
|
||||
Removed due to being an internal component.
|
||||
|
||||
### 8.4 deprecations
|
||||
|
||||
#### LocationService replaces getLocationSrv
|
||||
|
||||
In a previous release, we migrated to use a new routing system and introduced a new service for managing locations, navigation, and related information. In this release, we are making that new service the primary service.
|
||||
|
||||
**Example:** Import the service.
|
||||
|
||||
```ts
|
||||
// before
|
||||
import { getLocationSrv } from '@grafana/runtime';
|
||||
|
||||
// after
|
||||
import { locationService } from '@grafana/runtime';
|
||||
```
|
||||
|
||||
**Example:** Navigate to a path and add a new record in the navigation history so that you can navigate back to the previous one.
|
||||
|
||||
```ts
|
||||
// before
|
||||
getLocationSrv.update({
|
||||
path: '/route-to-navigate-to',
|
||||
replace: false,
|
||||
});
|
||||
|
||||
// after
|
||||
locationService.push('/route-to-navigate-to');
|
||||
```
|
||||
|
||||
**Example:** Navigate to a path and replace the current record in the navigation history.
|
||||
|
||||
```ts
|
||||
// before
|
||||
getLocationSrv.update({
|
||||
path: '/route-to-navigate-to',
|
||||
replace: true,
|
||||
});
|
||||
|
||||
// after
|
||||
locationService.replace('/route-to-navigate-to');
|
||||
```
|
||||
|
||||
**Example:** Update the search or query parameter for the current route and add a new record in the navigation history so that you can navigate back to the previous one.
|
||||
|
||||
```ts
|
||||
// How to navigate to a new path
|
||||
// before
|
||||
getLocationSrv.update({
|
||||
query: {
|
||||
value: 1,
|
||||
},
|
||||
partial: true,
|
||||
replace: false,
|
||||
});
|
||||
|
||||
// after
|
||||
locationService.partial({ value: 1 });
|
||||
```
|
||||
|
||||
**Example:** Update the search or query parameter for the current route and add replacing it in the navigation history.
|
||||
|
||||
```ts
|
||||
// before
|
||||
getLocationSrv.update({
|
||||
query: {
|
||||
'var-variable': 1,
|
||||
},
|
||||
partial: true,
|
||||
replace: true,
|
||||
});
|
||||
|
||||
// after
|
||||
locationService.partial({ 'var-variable': 1 }, true);
|
||||
```
|
||||
|
||||
## From version 7.x.x to 8.x.x
|
||||
|
||||
This section explains how to migrate Grafana v7.x.x plugins to the updated plugin system available in Grafana v8.x.x. Depending on your plugin, you need to perform one or more of the following steps. We have documented the breaking changes in Grafana v8.x.x and the steps you need to take to upgrade your plugin.
|
||||
|
Reference in New Issue
Block a user