PublicDashboards: support time range selection on the backend (#60203)

This commit is contained in:
Ezequiel Victorero
2022-12-15 10:44:33 -03:00
committed by GitHub
parent 6928ad2949
commit 8d5b19bc61
6 changed files with 176 additions and 22 deletions

View File

@@ -3,6 +3,7 @@ package validation
import (
"github.com/grafana/grafana/pkg/models"
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
"github.com/grafana/grafana/pkg/tsdb/legacydata"
)
func ValidatePublicDashboard(dto *SavePublicDashboardDTO, dashboard *models.Dashboard) error {
@@ -19,7 +20,7 @@ func hasTemplateVariables(dashboard *models.Dashboard) bool {
return len(templateVariables) > 0
}
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO, pd *PublicDashboard) error {
if req.IntervalMs < 0 {
return ErrInvalidInterval.Errorf("ValidateQueryPublicDashboardRequest: intervalMS should be greater than 0")
}
@@ -28,5 +29,18 @@ func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
return ErrInvalidMaxDataPoints.Errorf("ValidateQueryPublicDashboardRequest: maxDataPoints should be greater than 0")
}
if pd.TimeSelectionEnabled {
timeRange := legacydata.NewDataTimeRange(req.TimeRange.From, req.TimeRange.To)
_, err := timeRange.ParseFrom()
if err != nil {
return ErrInvalidTimeRange.Errorf("ValidateQueryPublicDashboardRequest: time range from is invalid")
}
_, err = timeRange.ParseTo()
if err != nil {
return ErrInvalidTimeRange.Errorf("ValidateQueryPublicDashboardRequest: time range to is invalid")
}
}
return nil
}