diff --git a/packages/common/src/directives.ts b/packages/common/src/directives.ts index 59d4e8a..35517e3 100644 --- a/packages/common/src/directives.ts +++ b/packages/common/src/directives.ts @@ -35,5 +35,6 @@ export const schemaPrepend = gql` visualizations: Boolean icon: String autoSync: Boolean + card: String ) on OBJECT ` diff --git a/packages/plugin-terraform/examples/output/example.tf b/packages/plugin-terraform/examples/output/example.tf index 7e5ae95..af29a38 100644 --- a/packages/plugin-terraform/examples/output/example.tf +++ b/packages/plugin-terraform/examples/output/example.tf @@ -31,7 +31,9 @@ resource "amplience_content_type_schema" "test" { resource "amplience_content_type" "test" { content_type_uri = amplience_content_type_schema.test.schema_id label = "Test" - status = "ACTIVE" + card { + } + status = "ACTIVE" } resource "amplience_content_type_assignment" "test" { @@ -49,7 +51,9 @@ resource "amplience_content_type_schema" "test_auto_sync_false" { resource "amplience_content_type" "test_auto_sync_false" { content_type_uri = amplience_content_type_schema.test_auto_sync_false.schema_id label = "Test Auto Sync False" - status = "ACTIVE" + card { + } + status = "ACTIVE" } resource "amplience_content_type_assignment" "test_auto_sync_false" { @@ -67,7 +71,9 @@ resource "amplience_content_type_schema" "test_auto_sync_true" { resource "amplience_content_type" "test_auto_sync_true" { content_type_uri = amplience_content_type_schema.test_auto_sync_true.schema_id label = "Test Auto Sync True" - status = "ACTIVE" + card { + } + status = "ACTIVE" } resource "amplience_content_type_assignment" "test_auto_sync_true" { @@ -75,6 +81,32 @@ resource "amplience_content_type_assignment" "test_auto_sync_true" { repository_id = data.amplience_content_repository.website1.id } +resource "amplience_content_type_schema" "test_card" { + body = file("${path.module}/schemas/test-card.json") + schema_id = "https://schema-examples.com/test-card" + validation_level = "CONTENT_TYPE" +} + +resource "amplience_content_type" "test_card" { + content_type_uri = amplience_content_type_schema.test_card.schema_id + label = "Test Card" + card { + headline = "" + image0 = "" + imageAlt0 = "" + image1 = "" + imageAlt1 = "" + image3 = "" + imageAlt3 = "" + } + status = "ACTIVE" +} + +resource "amplience_content_type_assignment" "test_card" { + content_type_id = amplience_content_type.test_card.id + repository_id = data.amplience_content_repository.website1.id +} + resource "amplience_content_type_schema" "test_no_auto_sync" { body = file("${path.module}/schemas/test-no-auto-sync.json") schema_id = "https://schema-examples.com/test-no-auto-sync" @@ -84,7 +116,9 @@ resource "amplience_content_type_schema" "test_no_auto_sync" { resource "amplience_content_type" "test_no_auto_sync" { content_type_uri = amplience_content_type_schema.test_no_auto_sync.schema_id label = "Test No Auto Sync" - status = "ACTIVE" + card { + } + status = "ACTIVE" } resource "amplience_content_type_assignment" "test_no_auto_sync" { @@ -101,7 +135,9 @@ resource "amplience_content_type_schema" "test_other_repository" { resource "amplience_content_type" "test_other_repository" { content_type_uri = amplience_content_type_schema.test_other_repository.schema_id label = "Test Other Repository" - status = "ACTIVE" + card { + } + status = "ACTIVE" } resource "amplience_content_type_assignment" "test_other_repository" { @@ -118,7 +154,9 @@ resource "amplience_content_type_schema" "test_slot" { resource "amplience_content_type" "test_slot" { content_type_uri = amplience_content_type_schema.test_slot.schema_id label = "Test Slot" - status = "ACTIVE" + card { + } + status = "ACTIVE" } resource "amplience_content_type_assignment" "test_slot" { @@ -135,7 +173,9 @@ resource "amplience_content_type_schema" "test_visualizations" { resource "amplience_content_type" "test_visualizations" { content_type_uri = amplience_content_type_schema.test_visualizations.schema_id label = "Test Visualizations" - status = "ACTIVE" + card { + } + status = "ACTIVE" dynamic "visualization" { for_each = var.variables["VISUALIZATION_HOST"] content { diff --git a/packages/plugin-terraform/examples/schema.graphql b/packages/plugin-terraform/examples/schema.graphql index 5ca525b..e31f19c 100644 --- a/packages/plugin-terraform/examples/schema.graphql +++ b/packages/plugin-terraform/examples/schema.graphql @@ -1,5 +1,9 @@ type Test @amplienceContentType { - name: String + name: String, +} + +type TestCard @amplienceContentType(card: "gallery") { + name: String, } # Use a different repository than the default (first) repository. diff --git a/packages/plugin-terraform/src/lib/visitor.ts b/packages/plugin-terraform/src/lib/visitor.ts index 1dd1105..8c35482 100644 --- a/packages/plugin-terraform/src/lib/visitor.ts +++ b/packages/plugin-terraform/src/lib/visitor.ts @@ -69,12 +69,45 @@ export const createObjectTypeVisitor = ? maybeDirectiveValue(directive, 'icon')?.value : undefined + const cardType = directive + ? maybeDirectiveValue(directive, 'card')?.value + : undefined + + let cardTypeValue; + + switch (cardType) { + case 'photo': + cardTypeValue = { image: '', imageAlt: '' } + break; + + case 'gallery': + cardTypeValue = { headline: '', image0: '', imageAlt0: '', image1: '', imageAlt1: '', image3: '', imageAlt3: '' } + break; + + case 'summary': + cardTypeValue = { headline: '', image: '', imageAlt: '' } + break; + + case 'text': + cardTypeValue = { headline: '' } + break; + + case 'custom': + cardTypeValue = { cardUrl: '' } + break; + + default: + cardTypeValue = {} + break; + } + const dynamicVisualization = visualization?.find(hasProperty('for_each')) const contentType = tfg.resource('amplience_content_type', name, { content_type_uri: schema.attr('schema_id'), label: capitalCase(node.name.value), icon: iconUrl ? { size: 256, url: iconUrl } : undefined, + card: cardTypeValue, status: 'ACTIVE', 'dynamic"visualization"': shouldVisualize && dynamicVisualization