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 5 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
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"
}
}
]
}
]
}
}
}
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