mirror of https://github.com/grafana/grafana
Docs: added code comments for everything in the @grafana/runtime package. (#23456)
* added comments for the angular loader. * added code documentation for backendSrv. * docs for datasource_srv. * added some more docs. * added documentation for the locationsrv. * started to add docs for echo srv. * added docs for meta srv.2 * added docs for analytics. * draft documentation of the DataSourceWithBackend. * added docs for last files. * fixed all warnigns in api-extractor. * fixed some typos and captializations.pull/23587/head
parent
b3df2d007a
commit
ab8305fcb9
@ -1,19 +1,87 @@ |
|||||||
|
/** |
||||||
|
* Used to enable rendering of Angular components within a |
||||||
|
* React component without loosing proper typings. |
||||||
|
* |
||||||
|
* @example |
||||||
|
* ```typescript
|
||||||
|
* class Component extends PureComponent<Props> { |
||||||
|
* element: HTMLElement; |
||||||
|
* angularComponent: AngularComponent; |
||||||
|
* |
||||||
|
* componentDidMount() { |
||||||
|
* const template = '<angular-component />' // angular template here;
|
||||||
|
* const scopeProps = { ctrl: angularController }; // angular scope properties here
|
||||||
|
* const loader = getAngularLoader(); |
||||||
|
* this.angularComponent = loader.load(this.element, scopeProps, template); |
||||||
|
* } |
||||||
|
* |
||||||
|
* componentWillUnmount() { |
||||||
|
* if (this.angularComponent) { |
||||||
|
* this.angularComponent.destroy(); |
||||||
|
* } |
||||||
|
* } |
||||||
|
* |
||||||
|
* render() { |
||||||
|
* return ( |
||||||
|
* <div ref={element => (this.element = element)} /> |
||||||
|
* ); |
||||||
|
* } |
||||||
|
* } |
||||||
|
* ``` |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface AngularComponent { |
export interface AngularComponent { |
||||||
|
/** |
||||||
|
* Should be called when the React component will unmount. |
||||||
|
*/ |
||||||
destroy(): void; |
destroy(): void; |
||||||
|
/** |
||||||
|
* Can be used to trigger a re-render of the Angular component. |
||||||
|
*/ |
||||||
digest(): void; |
digest(): void; |
||||||
|
/** |
||||||
|
* Used to access the Angular scope from the React component. |
||||||
|
*/ |
||||||
getScope(): any; |
getScope(): any; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to load an Angular component from the context of a React component. |
||||||
|
* Please see the {@link AngularComponent} for a proper example. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface AngularLoader { |
export interface AngularLoader { |
||||||
|
/** |
||||||
|
* |
||||||
|
* @param elem - the element that the Angular component will be loaded into. |
||||||
|
* @param scopeProps - values that will be accessed via the Angular scope. |
||||||
|
* @param template - template used by the Angular component. |
||||||
|
*/ |
||||||
load(elem: any, scopeProps: any, template: string): AngularComponent; |
load(elem: any, scopeProps: any, template: string): AngularComponent; |
||||||
} |
} |
||||||
|
|
||||||
let instance: AngularLoader; |
let instance: AngularLoader; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used during startup by Grafana to set the AngularLoader so it is available |
||||||
|
* via the the {@link getAngularLoader} to the rest of the application. |
||||||
|
* |
||||||
|
* @internal |
||||||
|
*/ |
||||||
export function setAngularLoader(v: AngularLoader) { |
export function setAngularLoader(v: AngularLoader) { |
||||||
instance = v; |
instance = v; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to retrieve the {@link AngularLoader} that enables the use of Angular |
||||||
|
* components within a React component. |
||||||
|
* |
||||||
|
* Please see the {@link AngularComponent} for a proper example. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export function getAngularLoader(): AngularLoader { |
export function getAngularLoader(): AngularLoader { |
||||||
return instance; |
return instance; |
||||||
} |
} |
||||||
|
|||||||
@ -1,36 +1,84 @@ |
|||||||
|
/** |
||||||
|
* Passed as options to the {@link LocationSrv} to describe how the automatically navigation |
||||||
|
* should be performed. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface LocationUpdate { |
export interface LocationUpdate { |
||||||
|
/** |
||||||
|
* Target path where you automatically wants to navigate the user. |
||||||
|
*/ |
||||||
path?: string; |
path?: string; |
||||||
|
|
||||||
|
/** |
||||||
|
* Specify this value if you want to add values to the query string of the URL. |
||||||
|
*/ |
||||||
query?: UrlQueryMap; |
query?: UrlQueryMap; |
||||||
|
|
||||||
/** |
/** |
||||||
* Add the query argument to the existing URL |
* If set to true, the query argument will be added to the existing URL. |
||||||
*/ |
*/ |
||||||
partial?: boolean; |
partial?: boolean; |
||||||
|
|
||||||
/** |
/** |
||||||
* Do not change this unless you are the angular router |
* Used internally to sync the Redux state from Angular to make sure that the Redux location |
||||||
|
* state is in sync when navigating using the Angular router. |
||||||
|
* |
||||||
|
* @remarks |
||||||
|
* Do not change this unless you are the Angular router. |
||||||
|
* |
||||||
|
* @internal |
||||||
*/ |
*/ |
||||||
routeParams?: UrlQueryMap; |
routeParams?: UrlQueryMap; |
||||||
|
|
||||||
/* |
/* |
||||||
* If true this will replace url state (ie cause no new browser history) |
* If set to true, this will replace URL state (ie. cause no new browser history). |
||||||
*/ |
*/ |
||||||
replace?: boolean; |
replace?: boolean; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Type to represent the value of a single query variable. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export type UrlQueryValue = string | number | boolean | string[] | number[] | boolean[] | undefined | null; |
export type UrlQueryValue = string | number | boolean | string[] | number[] | boolean[] | undefined | null; |
||||||
|
|
||||||
|
/** |
||||||
|
* Type to represent the values parsed from the query string. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export type UrlQueryMap = Record<string, UrlQueryValue>; |
export type UrlQueryMap = Record<string, UrlQueryValue>; |
||||||
|
|
||||||
|
/** |
||||||
|
* If you need to automatically navigate the user to a new place in the application this should |
||||||
|
* be done via the LocationSrv and it will make sure to update the application state accordingly. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface LocationSrv { |
export interface LocationSrv { |
||||||
update(options: LocationUpdate): void; |
update(options: LocationUpdate): void; |
||||||
} |
} |
||||||
|
|
||||||
let singletonInstance: LocationSrv; |
let singletonInstance: LocationSrv; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used during startup by Grafana to set the LocationSrv so it is available |
||||||
|
* via the the {@link getLocationSrv} to the rest of the application. |
||||||
|
* |
||||||
|
* @internal |
||||||
|
*/ |
||||||
export function setLocationSrv(instance: LocationSrv) { |
export function setLocationSrv(instance: LocationSrv) { |
||||||
singletonInstance = instance; |
singletonInstance = instance; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to retrieve the {@link LocationSrv} that can be used to automatically navigate |
||||||
|
* the user to a new place in Grafana. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export function getLocationSrv(): LocationSrv { |
export function getLocationSrv(): LocationSrv { |
||||||
return singletonInstance; |
return singletonInstance; |
||||||
} |
} |
||||||
|
|||||||
@ -1,50 +1,92 @@ |
|||||||
/** |
/** |
||||||
* Currently implemented with: |
* Used to initiate a remote call via the {@link BackendSrv} |
||||||
* https://docs.angularjs.org/api/ng/service/$http#usage
|
* |
||||||
* but that will likely change in the future |
* @public |
||||||
*/ |
*/ |
||||||
export type BackendSrvRequest = { |
export type BackendSrvRequest = { |
||||||
url: string; |
url: string; |
||||||
|
/** |
||||||
|
* Number of times to retry the remote call if it fails. |
||||||
|
*/ |
||||||
retry?: number; |
retry?: number; |
||||||
|
|
||||||
|
/** |
||||||
|
* HTTP headers that should be passed along with the remote call. |
||||||
|
* Please have a look at {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | Fetch API}
|
||||||
|
* for supported headers. |
||||||
|
*/ |
||||||
headers?: any; |
headers?: any; |
||||||
|
|
||||||
|
/** |
||||||
|
* HTTP verb to perform in the remote call GET, POST, PUT etc. |
||||||
|
*/ |
||||||
method?: string; |
method?: string; |
||||||
|
|
||||||
// Show a message with the result
|
/** |
||||||
|
* If set to true an alert with the response message will be displayed |
||||||
|
* upon successful remote call |
||||||
|
*/ |
||||||
showSuccessAlert?: boolean; |
showSuccessAlert?: boolean; |
||||||
|
|
||||||
// A requestID is provided by the datasource as a unique identifier for a
|
/** |
||||||
// particular query. If the requestID exists, the promise it is keyed to
|
* Provided by the initiator to identify a particular remote call. An example |
||||||
// is canceled, canceling the previous datasource request if it is still
|
* of this is when a datasource plugin triggers a query. If the request id already |
||||||
// in-flight.
|
* exist the backendSrv will try to cancel and replace the previous call with the |
||||||
|
* new one. |
||||||
|
*/ |
||||||
requestId?: string; |
requestId?: string; |
||||||
|
|
||||||
// Allow any other parameters
|
|
||||||
[key: string]: any; |
[key: string]: any; |
||||||
}; |
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to communicate via http(s) to a remote backend such as the Grafana backend, |
||||||
|
* a datasource etc. The BackendSrv is using the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | Fetch API}
|
||||||
|
* under the hood to handle all the communication. |
||||||
|
* |
||||||
|
* The request function can be used to perform a remote call by specifing a {@link BackendSrvRequest}. |
||||||
|
* To make the BackendSrv a bit easier to use we have added a couple of shorthand functions that will |
||||||
|
* use default values executing the request. |
||||||
|
* |
||||||
|
* @remarks |
||||||
|
* By default Grafana will display an error message alert if the remote call fails. If you want |
||||||
|
* to prevent this from happending you need to catch the error thrown by the BackendSrv and |
||||||
|
* set the `isHandled = true` on the incoming error. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface BackendSrv { |
export interface BackendSrv { |
||||||
get(url: string, params?: any, requestId?: string): Promise<any>; |
get(url: string, params?: any, requestId?: string): Promise<any>; |
||||||
|
|
||||||
delete(url: string): Promise<any>; |
delete(url: string): Promise<any>; |
||||||
|
|
||||||
post(url: string, data?: any): Promise<any>; |
post(url: string, data?: any): Promise<any>; |
||||||
|
|
||||||
patch(url: string, data?: any): Promise<any>; |
patch(url: string, data?: any): Promise<any>; |
||||||
|
|
||||||
put(url: string, data?: any): Promise<any>; |
put(url: string, data?: any): Promise<any>; |
||||||
|
|
||||||
// If there is an error, set: err.isHandled = true
|
|
||||||
// otherwise the backend will show a message for you
|
|
||||||
request(options: BackendSrvRequest): Promise<any>; |
request(options: BackendSrvRequest): Promise<any>; |
||||||
|
|
||||||
// DataSource requests add hooks into the query inspector
|
/** |
||||||
|
* Special function used to communicate with datasources that will emit core |
||||||
|
* events that the Grafana QueryInspector and QueryEditor is listening for to be able |
||||||
|
* to display datasource query information. Can be skipped by adding `option.silent` |
||||||
|
* when initializing the request. |
||||||
|
*/ |
||||||
datasourceRequest(options: BackendSrvRequest): Promise<any>; |
datasourceRequest(options: BackendSrvRequest): Promise<any>; |
||||||
} |
} |
||||||
|
|
||||||
let singletonInstance: BackendSrv; |
let singletonInstance: BackendSrv; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used during startup by Grafana to set the BackendSrv so it is available |
||||||
|
* via the the {@link getBackendSrv} to the rest of the application. |
||||||
|
* |
||||||
|
* @internal |
||||||
|
*/ |
||||||
export const setBackendSrv = (instance: BackendSrv) => { |
export const setBackendSrv = (instance: BackendSrv) => { |
||||||
singletonInstance = instance; |
singletonInstance = instance; |
||||||
}; |
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to retrieve the {@link BackendSrv} that can be used to communicate |
||||||
|
* via http(s) to a remote backend such as the Grafana backend, a datasource etc. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export const getBackendSrv = (): BackendSrv => singletonInstance; |
export const getBackendSrv = (): BackendSrv => singletonInstance; |
||||||
|
|||||||
@ -1,15 +1,39 @@ |
|||||||
import { ScopedVars, DataSourceApi } from '@grafana/data'; |
import { ScopedVars, DataSourceApi } from '@grafana/data'; |
||||||
|
|
||||||
|
/** |
||||||
|
* This is the entry point for communicating with a datasource that is added as |
||||||
|
* a plugin (both external and internal). Via this service you will get access |
||||||
|
* to the {@link @grafana/data#DataSourceApi | DataSourceApi} that have a rich API for |
||||||
|
* communicating with the datasource. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface DataSourceSrv { |
export interface DataSourceSrv { |
||||||
|
/** |
||||||
|
* @param name - name of the datasource plugin you want to use. |
||||||
|
* @param scopedVars - variables used to interpolate a templated passed as name. |
||||||
|
*/ |
||||||
get(name?: string, scopedVars?: ScopedVars): Promise<DataSourceApi>; |
get(name?: string, scopedVars?: ScopedVars): Promise<DataSourceApi>; |
||||||
} |
} |
||||||
|
|
||||||
let singletonInstance: DataSourceSrv; |
let singletonInstance: DataSourceSrv; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used during startup by Grafana to set the DataSourceSrv so it is available |
||||||
|
* via the the {@link getDataSourceSrv} to the rest of the application. |
||||||
|
* |
||||||
|
* @internal |
||||||
|
*/ |
||||||
export function setDataSourceSrv(instance: DataSourceSrv) { |
export function setDataSourceSrv(instance: DataSourceSrv) { |
||||||
singletonInstance = instance; |
singletonInstance = instance; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to retrieve the {@link DataSourceSrv} that is the entry point for communicating with |
||||||
|
* a datasource that is added as a plugin (both external and internal). |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export function getDataSourceSrv(): DataSourceSrv { |
export function getDataSourceSrv(): DataSourceSrv { |
||||||
return singletonInstance; |
return singletonInstance; |
||||||
} |
} |
||||||
|
|||||||
@ -1,13 +1,32 @@ |
|||||||
import { VariableModel } from '@grafana/data'; |
import { VariableModel } from '@grafana/data'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Via the TemplateSrv consumers get access to all the available template variables |
||||||
|
* that can be used within the current active dashboard. |
||||||
|
* |
||||||
|
* For a mor in-depth description visit: https://grafana.com/docs/grafana/latest/reference/templating
|
||||||
|
* @public |
||||||
|
*/ |
||||||
export interface TemplateSrv { |
export interface TemplateSrv { |
||||||
getVariables(): VariableModel[]; |
getVariables(): VariableModel[]; |
||||||
} |
} |
||||||
|
|
||||||
let singletonInstance: TemplateSrv; |
let singletonInstance: TemplateSrv; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used during startup by Grafana to set the TemplateSrv so it is available |
||||||
|
* via the the {@link getTemplateSrv} to the rest of the application. |
||||||
|
* |
||||||
|
* @internal |
||||||
|
*/ |
||||||
export const setTemplateSrv = (instance: TemplateSrv) => { |
export const setTemplateSrv = (instance: TemplateSrv) => { |
||||||
singletonInstance = instance; |
singletonInstance = instance; |
||||||
}; |
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* Used to retrieve the {@link TemplateSrv} that can be used to fetch available |
||||||
|
* template variables. |
||||||
|
* |
||||||
|
* @public |
||||||
|
*/ |
||||||
export const getTemplateSrv = (): TemplateSrv => singletonInstance; |
export const getTemplateSrv = (): TemplateSrv => singletonInstance; |
||||||
|
|||||||
Loading…
Reference in new issue