schema: Use generated dashboard model in frontend (#55769)
Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com> Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com> Co-authored-by: polinaboneva <polina.boneva@grafana.com>
This commit is contained in:
co-authored by
Ivan Ortega
Josh Hunt
Dominik Prokop
polinaboneva
parent
a553040441
commit
f86abf096d
@@ -79,7 +79,7 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(decl *DeclForGen, tf *
|
||||
sels := p.Selectors()
|
||||
switch len(sels) {
|
||||
case 0:
|
||||
name = strings.Title(lin.Name())
|
||||
name = comm.Name
|
||||
fallthrough
|
||||
case 1:
|
||||
// Only deal with subpaths that are definitions, for now
|
||||
@@ -110,12 +110,24 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(decl *DeclForGen, tf *
|
||||
has = has || tgt.target == "type"
|
||||
}
|
||||
if has {
|
||||
custom = append(custom, *pair.T)
|
||||
// enums can't use 'export type'
|
||||
if pair.isEnum {
|
||||
customD = append(customD, *pair.T)
|
||||
} else {
|
||||
custom = append(custom, *pair.T)
|
||||
}
|
||||
|
||||
if pair.D != nil {
|
||||
customD = append(customD, *pair.D)
|
||||
}
|
||||
} else {
|
||||
raw = append(raw, *pair.T)
|
||||
// enums can't use 'export type'
|
||||
if pair.isEnum {
|
||||
rawD = append(rawD, *pair.T)
|
||||
} else {
|
||||
raw = append(raw, *pair.T)
|
||||
}
|
||||
|
||||
if pair.D != nil {
|
||||
rawD = append(rawD, *pair.D)
|
||||
}
|
||||
@@ -146,7 +158,7 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(decl *DeclForGen, tf *
|
||||
}
|
||||
if len(rawD) > 0 {
|
||||
ret = append(ret, ast.ExportSet{
|
||||
CommentList: []ast.Comment{ts.CommentFromString(fmt.Sprintf("Raw generated default consts from %s kind.", lin.Name()), 80, false)},
|
||||
CommentList: []ast.Comment{ts.CommentFromString(fmt.Sprintf("Raw generated enums and default consts from %s kind.", lin.Name()), 80, false)},
|
||||
TypeOnly: false,
|
||||
Exports: rawD,
|
||||
From: ast.Str{Value: fmt.Sprintf("./raw/%s/%s/%s_types.gen", comm.MachineName, vpath, comm.MachineName)},
|
||||
@@ -187,7 +199,8 @@ func (gen *genTSVeneerIndex) extractTSIndexVeneerElements(decl *DeclForGen, tf *
|
||||
}
|
||||
|
||||
type declPair struct {
|
||||
T, D *ast.Ident
|
||||
T, D *ast.Ident
|
||||
isEnum bool
|
||||
}
|
||||
|
||||
type tsVeneerAttr struct {
|
||||
@@ -206,6 +219,7 @@ func findDeclNode(name string, tf *ast.File) declPair {
|
||||
case ast.TypeDecl:
|
||||
if x.Name.Name == name {
|
||||
p.T = &x.Name
|
||||
_, p.isEnum = x.Type.(ast.EnumType)
|
||||
}
|
||||
case ast.VarDecl:
|
||||
if x.Names.Idents[0].Name == "default"+name {
|
||||
|
||||
@@ -83,6 +83,19 @@ const (
|
||||
HeatmapPanelTypeHeatmap HeatmapPanelType = "heatmap"
|
||||
)
|
||||
|
||||
// Defines values for LoadingState.
|
||||
const (
|
||||
LoadingStateDone LoadingState = "Done"
|
||||
|
||||
LoadingStateError LoadingState = "Error"
|
||||
|
||||
LoadingStateLoading LoadingState = "Loading"
|
||||
|
||||
LoadingStateNotStarted LoadingState = "NotStarted"
|
||||
|
||||
LoadingStateStreaming LoadingState = "Streaming"
|
||||
)
|
||||
|
||||
// Defines values for MappingType.
|
||||
const (
|
||||
MappingTypeRange MappingType = "range"
|
||||
@@ -162,6 +175,37 @@ const (
|
||||
ValueMapTypeValue ValueMapType = "value"
|
||||
)
|
||||
|
||||
// Defines values for VariableHide.
|
||||
const (
|
||||
VariableHideN0 VariableHide = 0
|
||||
|
||||
VariableHideN1 VariableHide = 1
|
||||
|
||||
VariableHideN2 VariableHide = 2
|
||||
)
|
||||
|
||||
// Defines values for VariableModelHide.
|
||||
const (
|
||||
VariableModelHideN0 VariableModelHide = 0
|
||||
|
||||
VariableModelHideN1 VariableModelHide = 1
|
||||
|
||||
VariableModelHideN2 VariableModelHide = 2
|
||||
)
|
||||
|
||||
// Defines values for VariableModelState.
|
||||
const (
|
||||
VariableModelStateDone VariableModelState = "Done"
|
||||
|
||||
VariableModelStateError VariableModelState = "Error"
|
||||
|
||||
VariableModelStateLoading VariableModelState = "Loading"
|
||||
|
||||
VariableModelStateNotStarted VariableModelState = "NotStarted"
|
||||
|
||||
VariableModelStateStreaming VariableModelState = "Streaming"
|
||||
)
|
||||
|
||||
// Defines values for VariableModelType.
|
||||
const (
|
||||
VariableModelTypeAdhoc VariableModelType = "adhoc"
|
||||
@@ -204,7 +248,7 @@ const (
|
||||
type Dashboard struct {
|
||||
Annotations *struct {
|
||||
// TODO docs
|
||||
List []AnnotationQuery `json:"list"`
|
||||
List *[]AnnotationQuery `json:"list,omitempty"`
|
||||
} `json:"annotations,omitempty"`
|
||||
|
||||
// Description of dashboard.
|
||||
@@ -232,11 +276,17 @@ type Dashboard struct {
|
||||
// TODO docs
|
||||
Refresh *interface{} `json:"refresh,omitempty"`
|
||||
|
||||
// Version of the current dashboard data
|
||||
Revision int `json:"revision"`
|
||||
|
||||
// Version of the JSON schema, incremented each time a Grafana update brings
|
||||
// changes to said schema.
|
||||
// TODO this is the existing schema numbering system. It will be replaced by Thema's themaVersion
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
|
||||
// TODO docs
|
||||
Snapshot *Snapshot `json:"snapshot,omitempty"`
|
||||
|
||||
// Theme of dashboard.
|
||||
Style Style `json:"style"`
|
||||
|
||||
@@ -244,7 +294,7 @@ type Dashboard struct {
|
||||
Tags *[]string `json:"tags,omitempty"`
|
||||
Templating *struct {
|
||||
// TODO docs
|
||||
List []VariableModel `json:"list"`
|
||||
List *[]VariableModel `json:"list,omitempty"`
|
||||
} `json:"templating,omitempty"`
|
||||
|
||||
// Time range for dashboard, e.g. last 6 hours, last 7 days, etc
|
||||
@@ -346,20 +396,29 @@ type DashboardCursorSync int
|
||||
// TODO docs
|
||||
type DashboardLink struct {
|
||||
AsDropdown bool `json:"asDropdown"`
|
||||
Icon *string `json:"icon,omitempty"`
|
||||
Icon string `json:"icon"`
|
||||
IncludeVars bool `json:"includeVars"`
|
||||
KeepTime bool `json:"keepTime"`
|
||||
Tags []string `json:"tags"`
|
||||
TargetBlank bool `json:"targetBlank"`
|
||||
Title string `json:"title"`
|
||||
Tooltip *string `json:"tooltip,omitempty"`
|
||||
Tooltip string `json:"tooltip"`
|
||||
Type DashboardLinkType `json:"type"`
|
||||
Url *string `json:"url,omitempty"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// DashboardLinkType defines model for DashboardLink.Type.
|
||||
type DashboardLinkType string
|
||||
|
||||
// Ref to a DataSource instance
|
||||
type DataSourceRef struct {
|
||||
// The plugin type-id
|
||||
Type *string `json:"type,omitempty"`
|
||||
|
||||
// Specific datasource instance
|
||||
Uid *string `json:"uid,omitempty"`
|
||||
}
|
||||
|
||||
// DynamicConfigValue defines model for dashboard.DynamicConfigValue.
|
||||
type DynamicConfigValue struct {
|
||||
Id string `json:"id"`
|
||||
@@ -498,13 +557,18 @@ type FieldConfigSource struct {
|
||||
} `json:"overrides"`
|
||||
}
|
||||
|
||||
// GraphPanel defines model for dashboard.GraphPanel.
|
||||
// Support for legacy graph and heatmap panels.
|
||||
type GraphPanel struct {
|
||||
// Support for legacy graph and heatmap panels.
|
||||
// @deprecated this is part of deprecated graph panel
|
||||
Legend *struct {
|
||||
Show bool `json:"show"`
|
||||
Sort *string `json:"sort,omitempty"`
|
||||
SortDesc *bool `json:"sortDesc,omitempty"`
|
||||
} `json:"legend,omitempty"`
|
||||
Type GraphPanelType `json:"type"`
|
||||
}
|
||||
|
||||
// Support for legacy graph and heatmap panels.
|
||||
// GraphPanelType defines model for GraphPanel.Type.
|
||||
type GraphPanelType string
|
||||
|
||||
// GridPos defines model for dashboard.GridPos.
|
||||
@@ -533,6 +597,9 @@ type HeatmapPanel struct {
|
||||
// HeatmapPanelType defines model for HeatmapPanel.Type.
|
||||
type HeatmapPanelType string
|
||||
|
||||
// LoadingState defines model for dashboard.LoadingState.
|
||||
type LoadingState string
|
||||
|
||||
// TODO docs
|
||||
type MappingType string
|
||||
|
||||
@@ -643,8 +710,12 @@ type Panel struct {
|
||||
|
||||
// Direction to repeat in if 'repeat' is set.
|
||||
// "h" for horizontal, "v" for vertical.
|
||||
// TODO this is probably optional
|
||||
RepeatDirection PanelRepeatDirection `json:"repeatDirection"`
|
||||
|
||||
// Id of the repeating panel.
|
||||
RepeatPanelId *int64 `json:"repeatPanelId,omitempty"`
|
||||
|
||||
// TODO docs
|
||||
Tags *[]string `json:"tags,omitempty"`
|
||||
|
||||
@@ -681,6 +752,7 @@ type Panel struct {
|
||||
|
||||
// Direction to repeat in if 'repeat' is set.
|
||||
// "h" for horizontal, "v" for vertical.
|
||||
// TODO this is probably optional
|
||||
type PanelRepeatDirection string
|
||||
|
||||
// TODO docs
|
||||
@@ -741,6 +813,42 @@ type RowPanel struct {
|
||||
// RowPanelType defines model for RowPanel.Type.
|
||||
type RowPanelType string
|
||||
|
||||
// TODO docs
|
||||
type Snapshot struct {
|
||||
// TODO docs
|
||||
Created string `json:"created"`
|
||||
|
||||
// TODO docs
|
||||
Expires string `json:"expires"`
|
||||
|
||||
// TODO docs
|
||||
External bool `json:"external"`
|
||||
|
||||
// TODO docs
|
||||
ExternalUrl string `json:"externalUrl"`
|
||||
|
||||
// TODO docs
|
||||
Id int `json:"id"`
|
||||
|
||||
// TODO docs
|
||||
Key string `json:"key"`
|
||||
|
||||
// TODO docs
|
||||
Name string `json:"name"`
|
||||
|
||||
// TODO docs
|
||||
OrgId int `json:"orgId"`
|
||||
|
||||
// TODO docs
|
||||
Updated string `json:"updated"`
|
||||
|
||||
// TODO docs
|
||||
Url *string `json:"url,omitempty"`
|
||||
|
||||
// TODO docs
|
||||
UserId int `json:"userId"`
|
||||
}
|
||||
|
||||
// TODO docs
|
||||
type SpecialValueMap struct {
|
||||
Options struct {
|
||||
@@ -842,16 +950,39 @@ type ValueMappingResult struct {
|
||||
Text *string `json:"text,omitempty"`
|
||||
}
|
||||
|
||||
// TODO: There is a bug generating the names, they are always title case
|
||||
type VariableHide int
|
||||
|
||||
// FROM: packages/grafana-data/src/types/templateVars.ts
|
||||
// TODO docs
|
||||
// TODO what about what's in public/app/features/types.ts?
|
||||
// TODO there appear to be a lot of different kinds of [template] vars here? if so need a disjunction
|
||||
type VariableModel struct {
|
||||
Label *string `json:"label,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Type VariableModelType `json:"type"`
|
||||
// Ref to a DataSource instance
|
||||
Datasource *DataSourceRef `json:"datasource,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Error *map[string]interface{} `json:"error,omitempty"`
|
||||
Global bool `json:"global"`
|
||||
Hide VariableModelHide `json:"hide"`
|
||||
Id string `json:"id"`
|
||||
Index int `json:"index"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Name string `json:"name"`
|
||||
|
||||
// TODO: Move this into a separated QueryVariableModel type
|
||||
Query *interface{} `json:"query,omitempty"`
|
||||
RootStateKey *string `json:"rootStateKey,omitempty"`
|
||||
SkipUrlSync bool `json:"skipUrlSync"`
|
||||
State VariableModelState `json:"state"`
|
||||
Type VariableModelType `json:"type"`
|
||||
}
|
||||
|
||||
// VariableModelHide defines model for VariableModel.Hide.
|
||||
type VariableModelHide int
|
||||
|
||||
// VariableModelState defines model for VariableModel.State.
|
||||
type VariableModelState string
|
||||
|
||||
// VariableModelType defines model for VariableModel.Type.
|
||||
type VariableModelType string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user