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

Feat: set up card type to all ampliance types #7

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/common/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export const schemaPrepend = gql`
visualizations: Boolean
icon: String
autoSync: Boolean
card: String
) on OBJECT
`
54 changes: 47 additions & 7 deletions packages/plugin-terraform/examples/output/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand All @@ -67,14 +71,42 @@ 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" {
content_type_id = amplience_content_type.test_auto_sync_true.id
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"
Expand All @@ -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" {
Expand All @@ -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" {
Expand All @@ -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" {
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-terraform/examples/schema.graphql
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
33 changes: 33 additions & 0 deletions packages/plugin-terraform/src/lib/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,45 @@ export const createObjectTypeVisitor =
? maybeDirectiveValue<StringValueNode>(directive, 'icon')?.value
: undefined

const cardType = directive
? maybeDirectiveValue<StringValueNode>(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
Expand Down