grafana/public/app/features/panel/panellinks/module.ts
kay delaney bad048b7ba
Performance: Standardize lodash imports to use destructured members (#33040)
* Performance: Standardize lodash imports to use destructured members
Changes lodash imports of the form `import x from 'lodash/x'` to
`import { x } from 'lodash'` to reduce bundle size.

* Remove unnecessary _ import from Graph component

* Enforce lodash import style

* Fix remaining lodash imports
2021-04-21 09:38:00 +02:00

64 lines
1.6 KiB
TypeScript

import angular from 'angular';
import { map, find, without } from 'lodash';
import './link_srv';
import { backendSrv } from 'app/core/services/backend_srv';
function panelLinksEditor() {
return {
scope: {
panel: '=',
},
restrict: 'E',
controller: 'PanelLinksEditorCtrl',
templateUrl: 'public/app/features/panel/panellinks/module.html',
link: () => {},
};
}
export class PanelLinksEditorCtrl {
/** @ngInject */
constructor($scope: any) {
$scope.panel.links = $scope.panel.links || [];
$scope.addLink = () => {
$scope.panel.links.push({
type: 'dashboard',
});
};
$scope.searchDashboards = (queryStr: string, callback: Function) => {
backendSrv.search({ query: queryStr }).then((hits) => {
const dashboards = map(hits, (dash) => {
return dash.title;
});
callback(dashboards);
});
};
$scope.dashboardChanged = (link: any) => {
backendSrv.search({ query: link.dashboard }).then((hits) => {
const dashboard: any = find(hits, { title: link.dashboard });
if (dashboard) {
if (dashboard.url) {
link.url = dashboard.url;
} else {
// To support legacy url's
link.dashUri = dashboard.uri;
}
link.title = dashboard.title;
}
});
};
$scope.deleteLink = (link: any) => {
$scope.panel.links = without($scope.panel.links, link);
};
}
}
angular
.module('grafana.directives')
.directive('panelLinksEditor', panelLinksEditor)
.controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);