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:
sam boyer
2022-12-20 15:04:14 +01:00
committed by GitHub
co-authored by Ivan Ortega Josh Hunt Dominik Prokop polinaboneva
parent a553040441
commit f86abf096d
53 changed files with 879 additions and 334 deletions
+19 -5
View File
@@ -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 {