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 99b4c82
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 15 deletions.
42 changes: 42 additions & 0 deletions docs/resources/port_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ description: |-
}
}]
}
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
number_props = {
Expand Down Expand Up @@ -69,6 +73,10 @@ description: |-
}]
})
}
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
}
Expand Down Expand Up @@ -169,6 +177,10 @@ resource "port_action" "create_microservice" {
jq_query = "\"specificValue\""
}
}]
}
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
Expand Down Expand Up @@ -208,6 +220,10 @@ resource "port_action" "create_microservice" {
}]
})
}
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
}
Expand Down Expand Up @@ -499,6 +515,7 @@ Optional:
- `number_items` (Attributes) An array of number items within the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--number_items))
- `object_items` (Attributes) An array of object items within the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--object_items))
- `required` (Boolean) Whether the property is required, by default not required, this property can't be set at the same time if `required_jq_query` is set, and only supports true as value
- `sort` (Attributes) How to sort entities when in the self service action form in the UI (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--sort))
- `string_items` (Attributes) An array of string items within the property (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--array_props--string_items))
- `title` (String) The title of the property
- `visible` (Boolean) The visibility of the array property
Expand Down Expand Up @@ -530,6 +547,18 @@ Optional:
- `default` (List of Map of String) The default values for the object items


<a id="nestedatt--self_service_trigger--user_properties--array_props--sort"></a>
### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query`

Required:

- `property` (String) The property to sort the entities by

Optional:

- `order` (String) The order to sort the entities in


<a id="nestedatt--self_service_trigger--user_properties--array_props--string_items"></a>
### Nested Schema for `self_service_trigger.user_properties.array_props.visible_jq_query`

Expand Down Expand Up @@ -617,6 +646,7 @@ Optional:
- `min_length` (Number) The min length of the string property
- `pattern` (String) The pattern of the string property
- `required` (Boolean) Whether the property is required, by default not required, this property can't be set at the same time if `required_jq_query` is set, and only supports true as value
- `sort` (Attributes) How to sort entities when in the self service action form in the UI (see [below for nested schema](#nestedatt--self_service_trigger--user_properties--string_props--sort))
- `title` (String) The title of the property
- `visible` (Boolean) The visibility of the string property
- `visible_jq_query` (String) The visibility condition jq query of the string property
Expand Down Expand Up @@ -652,6 +682,18 @@ Optional:



<a id="nestedatt--self_service_trigger--user_properties--string_props--sort"></a>
### Nested Schema for `self_service_trigger.user_properties.string_props.visible_jq_query`

Required:

- `property` (String) The property to sort the entities by

Optional:

- `order` (String) The order to sort the entities in





Expand Down
10 changes: 10 additions & 0 deletions examples/resources/port_action/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ resource "port_action" "restart_microservice" {
default = "https://example.com"
pattern = "^https://.*"
}
service = {
title = "Service"
description = "The service to restart"
format = "entity"
blueprint = "service"
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
}
}
Expand Down
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,omitempty"`
}

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
46 changes: 46 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,25 @@ func StringPropertySchema() schema.Attribute {
},
},
},
"sort": schema.SingleNestedAttribute{
MarkdownDescription: "How to sort entities when in 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",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("ASC"),
Validators: []validator.String{
stringvalidator.OneOf("ASC", "DESC"),
},
},
},
},
}

utils.CopyMaps(stringPropertySchema, MetadataProperties())
Expand Down Expand Up @@ -831,6 +850,25 @@ func ArrayPropertySchema() schema.Attribute {
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("visible")),
},
},
"sort": schema.SingleNestedAttribute{
MarkdownDescription: "How to sort entities when in 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",
Computed: true,
Optional: true,
Default: stringdefault.StaticString("ASC"),
Validators: []validator.String{
stringvalidator.OneOf("ASC", "DESC"),
},
},
},
},
}

utils.CopyMaps(arrayPropertySchema, MetadataProperties())
Expand Down Expand Up @@ -1072,6 +1110,10 @@ resource "port_action" "create_microservice" {
jq_query = "\"specificValue\""
}
}]
}
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
Expand Down Expand Up @@ -1111,6 +1153,10 @@ resource "port_action" "create_microservice" {
}]
})
}
sort = {
property = "$updatedAt"
order = "DESC"
}
}
}
}
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 99b4c82

Please sign in to comment.