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

Add support for conditional settings #73

Merged
merged 7 commits into from
Jul 18, 2024
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
3 changes: 3 additions & 0 deletions .changes/unreleased/Added-20240711-160714.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: add support for conditional_settings in component schema
time: 2024-07-11T16:07:14.380066+02:00
1 change: 1 addition & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tasks:
format:
cmds:
- go fmt ./...
- terraform fmt -recursive -write=true ./examples/

test:
cmds:
Expand Down
122 changes: 93 additions & 29 deletions examples/resources/storyblok_component/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,126 @@ resource "storyblok_component" "banner" {

// advanced example
resource "storyblok_component" "advanced_component" {
name = "advanced-component"
space_id = "<my-space-id>"
is_root = true
name = "advanced-component"
space_id = "<my-space-id>"
is_root = true
is_nestable = false

schema = {
title = {
type = "text"
position = 1
required = true // The field is required. Default is false.
max_length = 200 // Set the max length of the input string
type = "text"
position = 1
required = true // The field is required. Default is false.
max_length = 200 // Set the max length of the input string
description = "Title of the component" // Description shown in the editor interface
}

introduction = {
type = "rich_text"
position = 2
type = "rich_text"
position = 2
rich_markdown = true // Enable rich markdown view by default
description = "Introduction text with rich text editor"
description = "Introduction text with rich text editor"
}

image = {
type = "image"
position = 3
asset_folder_id = 1 // Default asset folder numeric id to store uploaded image of that field
add_https = true // Prepends https: to stop usage of relative protocol
image_crop = true // Activate force crop for images
type = "image"
position = 3
asset_folder_id = 1 // Default asset folder numeric id to store uploaded image of that field
add_https = true // Prepends https: to stop usage of relative protocol
image_crop = true // Activate force crop for images
}

release_date = {
type = "date"
position = 4
type = "date"
position = 4
disable_time = true // Disables time selection from date picker
description = "Release date of the content"
description = "Release date of the content"
}

tags = {
type = "multi_option"
position = 5
type = "multi_option"
position = 5
datasource_slug = "tags" // Define selectable datasources string
description = "Tags for the component"
description = "Tags for the component"
}

rating = {
type = "number"
position = 6
description = "Rating of the content"
type = "number"
position = 6
description = "Rating of the content"
default_value = "3" // Default value for the field
}

content = {
type = "bloks"
position = 7
type = "bloks"
position = 7
component_whitelist = ["text", "image", "video"] // Array of component/content type names
maximum = 10 // Maximum amount of added bloks in this blok field
description = "Content blocks"
maximum = 10 // Maximum amount of added bloks in this blok field
description = "Content blocks"
}
}
}
}

// conditional content
resource "storyblok_component" "conditional_settings" {
name = "conditional settings component"
space_id = "<your space id>"
is_root = false
is_nestable = true


schema = {
content = {
position = 0
translatable = true
display_name = "Content"
required = true
type = "text"
}

more_content = {
position = 1
translatable = true
display_name = "more content"
required = true
type = "text"
}

conditionalContent = {
position = 2
display_name = "conditinal content"
required = true
type = "text"

conditional_settings = [
{
modifications = [
{
required = false
}
]

// make "conditional content" optional of either:
// 1. content is empty
// 2. more content equals "test"
rule_match = "any"
rule_conditions = [
{
validation = "empty"
validated_object = {
field_key = "content"
}
},
{
value = "test"
validation = "equals"
validated_object = {
field_key = "more_content"
}
}
]
}
]
}
}
}
8 changes: 4 additions & 4 deletions examples/resources/storyblok_component_group/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ resource "storyblok_component_group" "my_component_group" {
}

resource "storyblok_component" "component1" {
name = "component1"
space_id = storyblok_component_group.my_component_group.space_id
name = "component1"
space_id = storyblok_component_group.my_component_group.space_id
component_group_uuid = storyblok_component_group.my_component_group.uuid

schema = {
Expand All @@ -17,8 +17,8 @@ resource "storyblok_component" "component1" {
}

resource "storyblok_component" "component2" {
name = "component2"
space_id = storyblok_component_group.my_component_group.space_id
name = "component2"
space_id = storyblok_component_group.my_component_group.space_id
component_group_uuid = storyblok_component_group.my_component_group.uuid

schema = {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.19.2
github.com/hashicorp/terraform-plugin-framework v1.8.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/labd/storyblok-go-sdk v0.5.0
github.com/labd/storyblok-go-sdk v0.6.0
github.com/wk8/go-ordered-map/v2 v2.1.8
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labd/storyblok-go-sdk v0.5.0 h1:Nv+sq6jJm1UfP3BArnNd/XbHRQl2AVyXiJ0fwoBI33Q=
github.com/labd/storyblok-go-sdk v0.5.0/go.mod h1:79Zb12MZIzs2qF0FLZKLLGC8ijubZLn3/VaK76XdvWs=
github.com/labd/storyblok-go-sdk v0.6.0 h1:yM6wVTn2/OqyjlnaVUJKVnnI+vSu5isjap9zIP/eWKM=
github.com/labd/storyblok-go-sdk v0.6.0/go.mod h1:79Zb12MZIzs2qF0FLZKLLGC8ijubZLn3/VaK76XdvWs=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down
36 changes: 18 additions & 18 deletions internal/assets/asset_folder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ interactions:
trailer: {}
content_length: 139
uncompressed: false
body: '{"asset_folder":{"id":576397,"name":"asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}'
body: '{"asset_folder":{"id":604728,"name":"asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 103.60975ms
duration: 253.17725ms
- id: 1
request:
proto: HTTP/1.1
Expand All @@ -46,7 +46,7 @@ interactions:
body: ""
form: {}
headers: {}
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728
method: GET
response:
proto: HTTP/2.0
Expand All @@ -56,13 +56,13 @@ interactions:
trailer: {}
content_length: 139
uncompressed: false
body: '{"asset_folder":{"id":576397,"name":"asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}'
body: '{"asset_folder":{"id":604728,"name":"asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 39.288459ms
duration: 102.269667ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -77,7 +77,7 @@ interactions:
body: ""
form: {}
headers: {}
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728
method: GET
response:
proto: HTTP/2.0
Expand All @@ -87,13 +87,13 @@ interactions:
trailer: {}
content_length: 139
uncompressed: false
body: '{"asset_folder":{"id":576397,"name":"asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}'
body: '{"asset_folder":{"id":604728,"name":"asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 262.893583ms
duration: 107.813083ms
- id: 3
request:
proto: HTTP/1.1
Expand All @@ -108,7 +108,7 @@ interactions:
body: '{"asset_folder":{"name":"new-asset-folder-name"}}'
form: {}
headers: {}
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728
method: PUT
response:
proto: HTTP/2.0
Expand All @@ -122,7 +122,7 @@ interactions:
headers: {}
status: 204 No Content
code: 204
duration: 146.615459ms
duration: 152.376458ms
- id: 4
request:
proto: HTTP/1.1
Expand All @@ -137,7 +137,7 @@ interactions:
body: ""
form: {}
headers: {}
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728
method: GET
response:
proto: HTTP/2.0
Expand All @@ -147,13 +147,13 @@ interactions:
trailer: {}
content_length: 143
uncompressed: false
body: '{"asset_folder":{"id":576397,"name":"new-asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}'
body: '{"asset_folder":{"id":604728,"name":"new-asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 40.777416ms
duration: 86.802167ms
- id: 5
request:
proto: HTTP/1.1
Expand All @@ -168,7 +168,7 @@ interactions:
body: ""
form: {}
headers: {}
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728
method: GET
response:
proto: HTTP/2.0
Expand All @@ -178,13 +178,13 @@ interactions:
trailer: {}
content_length: 143
uncompressed: false
body: '{"asset_folder":{"id":576397,"name":"new-asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}'
body: '{"asset_folder":{"id":604728,"name":"new-asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 40.8615ms
duration: 80.509792ms
- id: 6
request:
proto: HTTP/1.1
Expand All @@ -199,7 +199,7 @@ interactions:
body: ""
form: {}
headers: {}
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397
url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728
method: DELETE
response:
proto: HTTP/2.0
Expand All @@ -213,4 +213,4 @@ interactions:
headers: {}
status: 204 No Content
code: 204
duration: 174.791209ms
duration: 240.006791ms
Loading
Loading