diff --git a/cue/data/gen.cue b/cue/data/gen.cue index d793254ae2d..e8dadab0ffa 100644 --- a/cue/data/gen.cue +++ b/cue/data/gen.cue @@ -133,10 +133,6 @@ Family: scuemata.#Family & { // The values depend on panel type options: {...} - libraryPanel?: { - name: string, - uid: string - } fieldConfig: { defaults: { ... diff --git a/docs/sources/dashboards/export-import.md b/docs/sources/dashboards/export-import.md index 5fe0f3ea01a..3cb8f4a0f28 100644 --- a/docs/sources/dashboards/export-import.md +++ b/docs/sources/dashboards/export-import.md @@ -15,7 +15,7 @@ Dashboards are exported in Grafana JSON format, and contain everything you need The export feature is accessed in the share window which you open by clicking the share button in the dashboard menu. -{{< docs-imagebox img="/img/docs/export/export-modal.png" max-width="800px" >}} +{{< docs-imagebox img="/img/docs/export/export-modal-8-0.png" max-width="800px" >}} ### Making a dashboard portable @@ -25,7 +25,13 @@ add template variables for things like a metric prefix (use constant variable) a A template variable of the type `Constant` will automatically be hidden in the dashboard, and will also be added as a required input when the dashboard is imported. -## Importing a dashboard +### Export dashboard without default values + +To export a dashboard without the default values in order to reduce the exported JSON file size, check the toggle **Export with default values removed** option. + +During import, the removed default values are automatically added back to the dashboard. + +## Import a dashboard To import a dashboard click the + icon in the side menu, and then click **Import**. diff --git a/docs/sources/http_api/dashboard.md b/docs/sources/http_api/dashboard.md index b64d61f7e19..11c0273ed77 100644 --- a/docs/sources/http_api/dashboard.md +++ b/docs/sources/http_api/dashboard.md @@ -440,6 +440,100 @@ Content-Type: application/json ## Dashboard Search See [Folder/Dashboard Search API]({{< relref "folder_dashboard_search.md" >}}). +## Remove default values in dashboard + +`POST /api/dashboards/trim` + +Will remove default values from input dashboard JSON. + +**Example Request for trimming dashboard JSON**: + +```http +POST /api/dashboards/uid/trim HTTP/1.1 +Accept: application/json +Content-Type: application/json +Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk + +{ + "meta": { + "isStarred": false, + "url": "/d/cIBgcSjkk/production-overview", + "folderId": 2, + "folderUid": "l3KqBxCMz", + "slug": "production-overview" + }, + "dashboard": { + "id": 112, + "panels": [ + { + "datasource": null, + "description": "", + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "feedUrl": "https://grafana.com/blog/news.xml", + "showImage": true + }, + "pluginVersion": "8.1.0-pre", + "title": "Panel Title", + "type": "news" + } + ], + "title": "test dashboard", + "uid": "9lzdzI3Mz", + "version": 2 + } +} +``` + +**Example Response**: + +```http +HTTP/1.1 200 +Content-Type: application/json + +{ + "meta": { + "folderId": 2, + "folderUid": "l3KqBxCMz", + "isStarred": false, + "slug": "production-overview", + "url": "/d/cIBgcSjkk/production-overview" + }, + "dashboard": { + "id": 112, + "panels": [ + { + "gridPos": {}, + "id": 2, + "options": { + "feedUrl": "https://grafana.com/blog/news.xml", + "showImage": true + }, + "pluginVersion": "8.1.0-pre", + "title": "Panel Title", + "type": "news" + } + ], + "title": "test dashboard", + "uid": "9lzdzI3Mz", + "version": 2 + } +} +``` + +Status Codes: + +- **200** – Trimmed +- **400** – Errors (invalid json, missing or invalid fields, etc) +- **401** – Unauthorized +- **403** – Access denied + ## Deprecated resources Please note that these resource have been deprecated and will be removed in a future release. diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 3bd65069afd..75d7d5699d7 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -52,11 +52,9 @@ func (hs *HTTPServer) TrimDashboard(c *models.ReqContext, cmd models.TrimDashboa meta := cmd.Meta trimedResult := *dash - if !hs.LoadSchemaService.IsDisabled() { - trimedResult, err = hs.LoadSchemaService.DashboardTrimDefaults(*dash) - if err != nil { - return response.Error(500, "Error while trim default value from dashboard json", err) - } + trimedResult, err = hs.LoadSchemaService.DashboardTrimDefaults(*dash) + if err != nil { + return response.Error(500, "Error while trim default value from dashboard json", err) } dto := dtos.TrimDashboardFullWithMeta{ @@ -279,13 +277,6 @@ func (hs *HTTPServer) PostDashboard(c *models.ReqContext, cmd models.SaveDashboa var err error cmd.OrgId = c.OrgId cmd.UserId = c.UserId - trimDefaults := c.QueryBoolWithDefault("trimdefaults", false) - if trimDefaults && !hs.LoadSchemaService.IsDisabled() { - cmd.Dashboard, err = hs.LoadSchemaService.DashboardApplyDefaults(cmd.Dashboard) - if err != nil { - return response.Error(500, "Error while applying default value to the dashboard json", err) - } - } if cmd.FolderUid != "" { folders := dashboards.NewFolderService(c.OrgId, c.SignedInUser, hs.SQLStore) folder, err := folders.GetFolderByUID(cmd.FolderUid) diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index 48e75d4b972..b7d3486729e 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -213,7 +213,7 @@ func (hs *HTTPServer) ImportDashboard(c *models.ReqContext, apiCmd dtos.ImportDa } trimDefaults := c.QueryBoolWithDefault("trimdefaults", true) - if trimDefaults && !hs.LoadSchemaService.IsDisabled() { + if trimDefaults { apiCmd.Dashboard, err = hs.LoadSchemaService.DashboardApplyDefaults(apiCmd.Dashboard) if err != nil { return response.Error(500, "Error while applying default value to the dashboard json", err) diff --git a/pkg/services/schemaloader/schemaloader.go b/pkg/services/schemaloader/schemaloader.go index 647c6b206eb..b922eb40dd9 100644 --- a/pkg/services/schemaloader/schemaloader.go +++ b/pkg/services/schemaloader/schemaloader.go @@ -50,12 +50,6 @@ func (rs *SchemaLoaderService) Init() error { } return nil } -func (rs *SchemaLoaderService) IsDisabled() bool { - if rs.Cfg == nil { - return true - } - return !rs.Cfg.IsTrimDefaultsEnabled() -} func (rs *SchemaLoaderService) DashboardApplyDefaults(input *simplejson.Json) (*simplejson.Json, error) { val, _ := input.Map() diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index f34386e8b88..dfd554c8c6b 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -391,11 +391,6 @@ func (cfg Cfg) IsNgAlertEnabled() bool { return cfg.FeatureToggles["ngalert"] } -// IsTrimDefaultsEnabled returns whether the standalone trim dashboard default feature is enabled. -func (cfg Cfg) IsTrimDefaultsEnabled() bool { - return cfg.FeatureToggles["trimDefaults"] -} - // IsDatabaseMetricsEnabled returns whether the database instrumentation feature is enabled. func (cfg Cfg) IsDatabaseMetricsEnabled() bool { return cfg.FeatureToggles["database_metrics"] diff --git a/public/app/features/dashboard/components/ShareModal/ShareExport.tsx b/public/app/features/dashboard/components/ShareModal/ShareExport.tsx index 4feeec45b6c..e76dd006409 100644 --- a/public/app/features/dashboard/components/ShareModal/ShareExport.tsx +++ b/public/app/features/dashboard/components/ShareModal/ShareExport.tsx @@ -7,7 +7,6 @@ import { DashboardExporter } from 'app/features/dashboard/components/DashExportM import { appEvents } from 'app/core/core'; import { ShowModalReactEvent } from 'app/types/events'; import { ViewJsonModal } from './ViewJsonModal'; -import { config } from '@grafana/runtime'; interface Props { dashboard: DashboardModel; @@ -138,11 +137,9 @@ export class ShareExport extends PureComponent { - {config.featureToggles.trimDefaults && ( - - - - )} + + +