Skip to content

Commit

Permalink
added sort to relevant models
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyal-Be committed Sep 5, 2024
1 parent 5fbad86 commit 318c968
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 15 deletions.
6 changes: 6 additions & 0 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ type (
EnumColors map[string]string `json:"enumColors,omitempty"`
}

EntitiesSortModel struct {
Property types.String `json:"property"`
Order types.String `json:"order"`
}

ActionProperty struct {
Type string `json:"type,omitempty"`
Title *string `json:"title,omitempty"`
Expand All @@ -91,6 +96,7 @@ type (
Dataset *Dataset `json:"dataset,omitempty"`
Encryption *string `json:"encryption,omitempty"`
Visible any `json:"visible,omitempty"`
Sort *EntitiesSortModel `json:"sort"`
}

SpecAuthentication struct {
Expand Down
17 changes: 17 additions & 0 deletions port/action/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ func arrayPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, pr
property.Visible = VisibleJqQueryMap
}

if prop.Sort != nil {
property.Sort = &cli.EntitiesSortModel{
Property: prop.Sort.Property,
Order: prop.Sort.Order,
}
}

props[propIdentifier] = property
}

Expand All @@ -215,6 +222,16 @@ func addArrayPropertiesToResource(v *cli.ActionProperty) (*ArrayPropModel, error
}
}

if v.Sort != nil {
switch v := v.Default.(type) {
case map[string]interface{}:
arrayProp.Sort = &EntitiesSortModel{
Property: types.StringValue(v["property"].(string)),
Order: types.StringValue(v["order"].(string)),
}
}
}

if v.Items != nil {
if v.Items["type"] != "" {
switch v.Items["type"] {
Expand Down
37 changes: 22 additions & 15 deletions port/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ type StringPropModel struct {
Visible types.Bool `tfsdk:"visible"`
VisibleJqQuery types.String `tfsdk:"visible_jq_query"`

Default types.String `tfsdk:"default"`
Blueprint types.String `tfsdk:"blueprint"`
Format types.String `tfsdk:"format"`
MaxLength types.Int64 `tfsdk:"max_length"`
MinLength types.Int64 `tfsdk:"min_length"`
Pattern types.String `tfsdk:"pattern"`
Enum types.List `tfsdk:"enum"`
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
Encryption types.String `tfsdk:"encryption"`
Default types.String `tfsdk:"default"`
Blueprint types.String `tfsdk:"blueprint"`
Format types.String `tfsdk:"format"`
MaxLength types.Int64 `tfsdk:"max_length"`
MinLength types.Int64 `tfsdk:"min_length"`
Pattern types.String `tfsdk:"pattern"`
Enum types.List `tfsdk:"enum"`
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
Encryption types.String `tfsdk:"encryption"`
Sort *EntitiesSortModel `tfsdk:"sort"`
}

// StringPropValidationModel is a model used for the validation of StringPropModel resources
Expand Down Expand Up @@ -206,6 +207,11 @@ type BooleanPropModel struct {
Default types.Bool `tfsdk:"default"`
}

type EntitiesSortModel struct {
Property types.String `tfsdk:"property"`
Order types.String `tfsdk:"order"`
}

type ArrayPropModel struct {
Title types.String `tfsdk:"title"`
Icon types.String `tfsdk:"icon"`
Expand All @@ -216,12 +222,13 @@ type ArrayPropModel struct {
Visible types.Bool `tfsdk:"visible"`
VisibleJqQuery types.String `tfsdk:"visible_jq_query"`

MaxItems types.Int64 `tfsdk:"max_items"`
MinItems types.Int64 `tfsdk:"min_items"`
StringItems *StringItems `tfsdk:"string_items"`
NumberItems *NumberItems `tfsdk:"number_items"`
BooleanItems *BooleanItems `tfsdk:"boolean_items"`
ObjectItems *ObjectItems `tfsdk:"object_items"`
MaxItems types.Int64 `tfsdk:"max_items"`
MinItems types.Int64 `tfsdk:"min_items"`
StringItems *StringItems `tfsdk:"string_items"`
NumberItems *NumberItems `tfsdk:"number_items"`
BooleanItems *BooleanItems `tfsdk:"boolean_items"`
ObjectItems *ObjectItems `tfsdk:"object_items"`
Sort *EntitiesSortModel `tfsdk:"sort"`
}

type ObjectPropModel struct {
Expand Down
36 changes: 36 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,24 @@ func StringPropertySchema() schema.Attribute {
},
},
},
"sort": schema.SingleNestedAttribute{
MarkdownDescription: "How to sort entities when users use the self service action form in the UI",
Optional: true,
Attributes: map[string]schema.Attribute{
"property": schema.StringAttribute{
MarkdownDescription: "The property to sort the entities by",
Required: true,
},
"order": schema.StringAttribute{
MarkdownDescription: "The order to sort the entities in",
Required: true,
Default: stringdefault.StaticString("ASC"),
Validators: []validator.String{
stringvalidator.OneOf("ASC", "DESC"),
},
},
},
},
}

utils.CopyMaps(stringPropertySchema, MetadataProperties())
Expand Down Expand Up @@ -831,6 +849,24 @@ func ArrayPropertySchema() schema.Attribute {
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("visible")),
},
},
"sort": schema.SingleNestedAttribute{
MarkdownDescription: "How to sort entities when users use the self service action form in the UI",
Optional: true,
Attributes: map[string]schema.Attribute{
"property": schema.StringAttribute{
MarkdownDescription: "The property to sort the entities by",
Required: true,
},
"order": schema.StringAttribute{
MarkdownDescription: "The order to sort the entities in",
Required: true,
Default: stringdefault.StaticString("ASC"),
Validators: []validator.String{
stringvalidator.OneOf("ASC", "DESC"),
},
},
},
},
}

utils.CopyMaps(arrayPropertySchema, MetadataProperties())
Expand Down
17 changes: 17 additions & 0 deletions port/action/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ func stringPropResourceToBody(ctx context.Context, d *SelfServiceTriggerModel, p
property.Visible = VisibleJqQueryMap
}

if prop.Sort != nil {
property.Sort = &cli.EntitiesSortModel{
Property: prop.Sort.Property,
Order: prop.Sort.Order,
}
}

props[propIdentifier] = property

if prop.Required.ValueBool() {
Expand Down Expand Up @@ -157,5 +164,15 @@ func addStringPropertiesToResource(ctx context.Context, v *cli.ActionProperty) *
stringProp.EnumJqQuery = types.StringNull()
}

if v.Sort != nil {
switch v := v.Default.(type) {
case map[string]interface{}:
stringProp.Sort = &EntitiesSortModel{
Property: types.StringValue(v["property"].(string)),
Order: types.StringValue(v["order"].(string)),
}
}
}

return stringProp
}

0 comments on commit 318c968

Please sign in to comment.