Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX2.0] Resolve Issue #381 #389

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 126 additions & 9 deletions gen/templates/profile_parcels/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,48 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- else if isNestedListSet .}}
{{- $list := (toGoName .TfName)}}
for i := range data.{{toGoName .TfName}} {
keys := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}}{{end}} }
keyValues := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()), {{else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{toGoName .TfName}}.ValueString(), {{end}}{{end}}{{end}} }
keyValuesVariables := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}{{if .Variable}}data.{{$list}}[i].{{toGoName .TfName}}Variable.ValueString(), {{else}}"", {{end}}{{end}}{{end}}{{end}} }
keys := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
keyValues := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{toGoName .TfName}}.ValueInt64(), 10),
{{- else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{toGoName .TfName}}.ValueBool()),
{{- else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{toGoName .TfName}}.ValueString(),
{{- else if (eq .Type "Set")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromSet(data.{{$list}}[i].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- else if (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromList(data.{{$list}}[i].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
keyValuesVariables := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64") (eq .Type "Set")}}
{{- if .Variable}}data.{{$list}}[i].{{toGoName .TfName}}Variable.ValueString(),
{{- else}}"",{{- end}}
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}
{{- if .Variable}}data.{{$list}}[i].{{toGoName .TfName}}Variable.ValueString(),
{{- else}}"",{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
}

var r gjson.Result
res.Get(path + "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}").ForEach(
Expand Down Expand Up @@ -580,9 +619,48 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- else if isNestedListSet .}}
{{- $clist := (toGoName .TfName)}}
for ci := range data.{{$list}}[i].{{toGoName .TfName}} {
keys := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}}{{end}} }
keyValues := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueBool()), {{else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueString(), {{end}}{{end}}{{end}} }
keyValuesVariables := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}{{if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}Variable.ValueString(), {{else}}"", {{end}}{{end}}{{end}}{{end}} }
keys := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
keyValues := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueInt64(), 10),
{{- else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueBool()),
{{- else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}.ValueString(),
{{- else if (eq .Type "Set")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromSet(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- else if (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromList(data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
keyValuesVariables := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}
{{- if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}Variable.ValueString(),
{{- else}}"",{{- end}}
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}
{{- if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}}Variable.ValueString(),
{{- else}}"",{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
}

var cr gjson.Result
r.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}").ForEach(
Expand Down Expand Up @@ -632,9 +710,48 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R
{{- else if isNestedListSet .}}
{{- $cclist := (toGoName .TfName)}}
for cci := range data.{{$list}}[i].{{$clist}}[ci].{{toGoName .TfName}} {
keys := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}", {{end}}{{end}}{{end}} }
keyValues := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueInt64(), 10), {{else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueBool()), {{else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueString(), {{end}}{{end}}{{end}} }
keyValuesVariables := [...]string{ {{$noId := not (hasId .Attributes)}}{{range .Attributes}}{{if or .Id $noId}}{{if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}{{if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}Variable.ValueString(), {{else}}"", {{end}}{{end}}{{end}}{{end}} }
keys := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}",{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
keyValues := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if eq .Type "Int64"}}strconv.FormatInt(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueInt64(), 10),
{{- else if eq .Type "Bool"}}strconv.FormatBool(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueBool()),
{{- else if or (eq .Type "String") (eq .Type "StringInt64")}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}.ValueString(),
{{- else if (eq .Type "Set")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromSet(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- else if (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}helpers.GetStringFromList(data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}).ValueString(),{{- end}}
{{- end}}
{{- end}}
{{- end}}
}
keyValuesVariables := [...]string{
{{- $noId := not (hasId .Attributes)}}
{{- range .Attributes}}
{{- if or .Id $noId}}
{{- if or (eq .Type "Int64") (eq .Type "Bool") (eq .Type "String") (eq .Type "StringInt64")}}
{{- if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}Variable.ValueString(),
{{- else}}"",{{- end}}
{{- else if or (eq .Type "Set") (eq .Type "List")}}
{{- if or (eq .ElementType "String") (eq .ElementType "Int64")}}
{{- if .Variable}}data.{{$list}}[i].{{$clist}}[ci].{{$cclist}}[cci].{{toGoName .TfName}}Variable.ValueString(),
{{- else}}"",{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
}

var ccr gjson.Result
cr.Get("{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}").ForEach(
Expand Down
17 changes: 17 additions & 0 deletions internal/provider/helpers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netascode/go-sdwan"
"github.com/tidwall/gjson"
Expand All @@ -42,6 +43,22 @@ func Contains(s []string, str string) bool {
return false
}

func GetStringFromList(list basetypes.ListValue) types.String {
v := make([]string, len(list.Elements()))
for r := range list.Elements() {
v[r] = list.Elements()[r].String()
}
return types.StringValue("[" + strings.Join(v, ",") + "]")
}

func GetStringFromSet(set basetypes.SetValue) types.String {
v := make([]string, len(set.Elements()))
for r := range set.Elements() {
v[r] = set.Elements()[r].String()
}
return types.StringValue("[" + strings.Join(v, ",") + "]")
}

func GetStringList(result []gjson.Result) types.List {
v := make([]attr.Value, len(result))
for r := range result {
Expand Down
Loading
Loading