diff --git a/public/app/features/dashboard/dashboard_import_ctrl.ts b/public/app/features/dashboard/dashboard_import_ctrl.ts index d127e628a77..fe61d3f7a55 100644 --- a/public/app/features/dashboard/dashboard_import_ctrl.ts +++ b/public/app/features/dashboard/dashboard_import_ctrl.ts @@ -7,6 +7,7 @@ export class DashboardImportCtrl { jsonText: string; parseError: string; nameExists: boolean; + uidExists: boolean; dash: any; inputs: any[]; inputsValid: boolean; @@ -16,6 +17,10 @@ export class DashboardImportCtrl { titleTouched: boolean; hasNameValidationError: boolean; nameValidationError: any; + hasUidValidationError: boolean; + uidValidationError: any; + autoGenerateUid: boolean; + autoGenerateUidValue: string; /** @ngInject */ constructor(private backendSrv, private validationSrv, navModelSrv, private $location, $routeParams) { @@ -23,6 +28,9 @@ export class DashboardImportCtrl { this.step = 1; this.nameExists = false; + this.uidExists = false; + this.autoGenerateUid = true; + this.autoGenerateUidValue = 'auto-generated'; // check gnetId in url if ($routeParams.gnetId) { @@ -61,6 +69,7 @@ export class DashboardImportCtrl { this.inputsValid = this.inputs.length === 0; this.titleChanged(); + this.uidChanged(true); } setDatasourceOptions(input, inputModel) { @@ -107,6 +116,28 @@ export class DashboardImportCtrl { }); } + uidChanged(initial) { + this.uidExists = false; + this.hasUidValidationError = false; + + if (initial === true && this.dash.uid) { + this.autoGenerateUidValue = 'value set'; + } + + this.backendSrv + .getDashboardByUid(this.dash.uid) + .then(res => { + this.uidExists = true; + this.hasUidValidationError = true; + this.uidValidationError = `Dashboard named '${res.dashboard.title}' in folder '${ + res.meta.folderTitle + }' has the same uid`; + }) + .catch(err => { + err.isHandled = true; + }); + } + saveDashboard() { var inputs = this.inputs.map(input => { return { diff --git a/public/app/features/dashboard/partials/dashboard_import.html b/public/app/features/dashboard/partials/dashboard_import.html index 020bb98e8b0..51011ae2c3d 100644 --- a/public/app/features/dashboard/partials/dashboard_import.html +++ b/public/app/features/dashboard/partials/dashboard_import.html @@ -80,6 +80,34 @@ +
+
+ + Unique identifier (uid) + + The unique identifier (uid) of a dashboard can be used for uniquely identify a dashboard between multiple Grafana installs. + The uid allows having consistent URL’s for accessing dashboards so changing the title of a dashboard will not break any + bookmarked links to that dashboard. + + + + change + + +
+
+ +
+
+ +
+
+
- - Cancel diff --git a/public/app/features/dashboard/specs/dashboard_import_ctrl.jest.ts b/public/app/features/dashboard/specs/dashboard_import_ctrl.jest.ts index 737eb360461..d75bd42f0c1 100644 --- a/public/app/features/dashboard/specs/dashboard_import_ctrl.jest.ts +++ b/public/app/features/dashboard/specs/dashboard_import_ctrl.jest.ts @@ -15,6 +15,7 @@ describe('DashboardImportCtrl', function() { backendSrv = { search: jest.fn().mockReturnValue(Promise.resolve([])), + getDashboardByUid: jest.fn().mockReturnValue(Promise.resolve([])), get: jest.fn(), };