浏览代码

dashboard import to folder: minor fixes

Alexander Zobnin 7 年之前
父节点
当前提交
25504e84ed

+ 2 - 2
pkg/api/index.go

@@ -95,14 +95,14 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
 	if hasEditPermissionInFoldersQuery.Result {
 		children := []*dtos.NavLink{
 			{Text: "Dashboard", Icon: "gicon gicon-dashboard-new", Url: setting.AppSubUrl + "/dashboard/new"},
-			{Text: "Import", SubTitle: "Import dashboard from file or Grafana.com", Id: "import", Icon: "gicon gicon-dashboard-import", Url: setting.AppSubUrl + "/dashboard/import"},
 		}
 
 		if c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR {
 			children = append(children, &dtos.NavLink{Text: "Folder", SubTitle: "Create a new folder to organize your dashboards", Id: "folder", Icon: "gicon gicon-folder-new", Url: setting.AppSubUrl + "/dashboards/folder/new"})
-			children = append(children, &dtos.NavLink{Text: "Import", SubTitle: "Import dashboard from file or Grafana.com", Id: "import", Icon: "gicon gicon-dashboard-import", Url: setting.AppSubUrl + "/dashboard/import"})
 		}
 
+		children = append(children, &dtos.NavLink{Text: "Import", SubTitle: "Import dashboard from file or Grafana.com", Id: "import", Icon: "gicon gicon-dashboard-import", Url: setting.AppSubUrl + "/dashboard/import"})
+
 		data.NavTree = append(data.NavTree, &dtos.NavLink{
 			Text:     "Create",
 			Id:       "create",

+ 2 - 2
public/app/features/dashboard/dashboard_import_ctrl.ts

@@ -154,11 +154,11 @@ export class DashboardImportCtrl {
   }
 
   onExitFolderCreation() {
-    this.inputsValid = true;
+    this.inputValueChanged();
   }
 
   isValid() {
-    return this.inputsValid && !this.hasNameValidationError && this.folderId !== null;
+    return this.inputsValid && this.folderId !== null;
   }
 
   saveDashboard() {

+ 13 - 13
public/app/features/dashboard/folder_picker/folder_picker.ts

@@ -132,24 +132,24 @@ export class FolderPickerCtrl {
   }
 
   private loadInitialValue() {
+    const resetFolder = { text: this.initialTitle, value: null };
+    const rootFolder = { text: this.rootName, value: 0 };
     this.getOptions('').then(result => {
-      if (!_.isNil(this.initialFolderId)) {
-        // If initialFolderId is set, try to find it in result or return null
-        this.folder = _.find(result, { value: this.initialFolderId });
-        if (!this.folder) {
-          this.folder = { text: this.initialTitle, value: null };
-        }
-      } else {
-        // If initialFolderId isn't set, return General folder for Editor
-        // or first available for user, otherwise return null
+      let folder;
+      if (this.initialFolderId) {
+        folder = _.find(result, { value: this.initialFolderId });
+      } else if (this.enableReset && this.initialTitle && this.initialFolderId === null) {
+        folder = resetFolder;
+      }
+
+      if (!folder) {
         if (this.isEditor) {
-          this.folder = { text: this.rootName, value: 0 };
-        } else if (result.length > 0) {
-          this.folder = result[0];
+          folder = rootFolder;
         } else {
-          this.folder = { text: this.initialTitle, value: null };
+          folder = result.length > 0 ? result[0] : resetFolder;
         }
       }
+      this.folder = folder;
       this.onFolderLoad();
     });
   }

+ 8 - 8
public/app/features/dashboard/partials/dashboard_import.html

@@ -82,14 +82,14 @@
 
       <div class="gf-form-inline">
         <div class="gf-form gf-form--grow">
-          <folder-picker initial-folder-id="ctrl.folderId"
-            initial-title="ctrl.initialFolderTitle"
-            on-change="ctrl.onFolderChange($folder)"
-            on-load="ctrl.onFolderChange($folder)"
-            enter-folder-creation="ctrl.onEnterFolderCreation()"
-            exit-folder-creation="ctrl.onExitFolderCreation()"
-            enable-create-new="true"
-            label-class="width-15">
+          <folder-picker  label-class="width-15"
+                          initial-folder-id="ctrl.folderId"
+                          initial-title="ctrl.initialFolderTitle"
+                          on-change="ctrl.onFolderChange($folder)"
+                          on-load="ctrl.onFolderChange($folder)"
+                          enter-folder-creation="ctrl.onEnterFolderCreation()"
+                          exit-folder-creation="ctrl.onExitFolderCreation()"
+                          enable-create-new="true">
           </folder-picker>
         </div>
       </div>