mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add deprecation warnigns to $location patch (#31898)
This commit is contained in:
parent
b017c65409
commit
77a024abb3
@ -1,16 +1,35 @@
|
||||
import { locationSearchToObject, locationService, navigationLogger } from '@grafana/runtime';
|
||||
import { urlUtil } from '@grafana/data';
|
||||
import { deprecationWarning, urlUtil } from '@grafana/data';
|
||||
|
||||
// Ref: https://github.com/angular/angular.js/blob/ae8e903edf88a83fedd116ae02c0628bf72b150c/src/ng/location.js#L5
|
||||
const DEFAULT_PORTS: Record<string, number> = { http: 80, https: 443, ftp: 21 };
|
||||
|
||||
export class AngularLocationWrapper {
|
||||
constructor() {
|
||||
this.absUrl = this.wrapInDeprecationWarning(this.absUrl);
|
||||
this.hash = this.wrapInDeprecationWarning(this.hash);
|
||||
this.host = this.wrapInDeprecationWarning(this.host);
|
||||
this.path = this.wrapInDeprecationWarning(this.path);
|
||||
this.port = this.wrapInDeprecationWarning(this.port, 'window.location');
|
||||
this.protocol = this.wrapInDeprecationWarning(this.protocol, 'window.location');
|
||||
this.replace = this.wrapInDeprecationWarning(this.replace);
|
||||
this.search = this.wrapInDeprecationWarning(this.search);
|
||||
this.state = this.wrapInDeprecationWarning(this.state);
|
||||
this.url = this.wrapInDeprecationWarning(this.url);
|
||||
}
|
||||
|
||||
wrapInDeprecationWarning = (fn: Function, replacement?: string) => {
|
||||
deprecationWarning('$location', fn.name, replacement || 'locationService');
|
||||
return fn.bind(this);
|
||||
};
|
||||
|
||||
absUrl(): string {
|
||||
return `${window.location.origin}${this.url()}`;
|
||||
}
|
||||
|
||||
hash(newHash?: any) {
|
||||
hash(newHash?: string | null) {
|
||||
navigationLogger('AngularLocationWrapper', false, 'Angular compat layer: hash');
|
||||
|
||||
if (!newHash) {
|
||||
return locationService.getLocation().hash.substr(1);
|
||||
} else {
|
||||
|
@ -31,7 +31,7 @@ const interceptAngularLocation = () => {
|
||||
$provide.decorator('$location', [
|
||||
'$delegate',
|
||||
($delegate: ILocationService) => {
|
||||
$delegate = new AngularLocationWrapper() as ILocationService;
|
||||
$delegate = (new AngularLocationWrapper() as unknown) as ILocationService;
|
||||
return $delegate;
|
||||
},
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user