Skip to content

Commit

Permalink
JM-2368 canvas card positions, Add DisplayAttributes of Element (#1470)
Browse files Browse the repository at this point in the history
* JM-2368: Canvas DisplayAttributes

* make docs
  • Loading branch information
nicob-29 authored Jan 14, 2025
1 parent d37a573 commit ee50810
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/resources/journey_views.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Required:

Optional:

- `display_attributes` (Block List, Max: 1) Display Attributes on an element in a journey view. (see [below for nested schema](#nestedblock--elements--display_attributes))
- `filter` (Block List, Max: 1) A set of filters on an element within a journey view. (see [below for nested schema](#nestedblock--elements--filter))
- `followed_by` (Block List) A list of JourneyViewLink objects, listing the elements downstream of this element. (see [below for nested schema](#nestedblock--elements--followed_by))

Expand All @@ -145,6 +146,16 @@ Optional:
- `source` (String) The source for the element (e.g. IVR, Voice, Chat). Used for informational purposes only.


<a id="nestedblock--elements--display_attributes"></a>
### Nested Schema for `elements.display_attributes`

Required:

- `col` (Number) The column position for the element in the journey view canvas.
- `x` (Number) The horizontal position (x-coordinate) of the element on the journey view canvas.
- `y` (Number) The vertical position (y-coordinate) of the element on the journey view canvas.


<a id="nestedblock--elements--filter"></a>
### Nested Schema for `elements.filter`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ var (
},
},
}
elementDisplayAttributesResource = &schema.Resource{
Schema: map[string]*schema.Schema{
"x": {
Description: "The horizontal position (x-coordinate) of the element on the journey view canvas.",
Type: schema.TypeInt,
Required: true,
},
"y": {
Description: "The vertical position (y-coordinate) of the element on the journey view canvas.",
Type: schema.TypeInt,
Required: true,
},
"col": {
Description: "The column position for the element in the journey view canvas.",
Type: schema.TypeInt,
Required: true,
},
},
}
filtersResource = &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Expand Down Expand Up @@ -144,6 +163,13 @@ var (
Elem: attributesResource,
MaxItems: 1,
},
"display_attributes": {
Description: "Display Attributes on an element in a journey view.",
Type: schema.TypeList,
Optional: true,
Elem: elementDisplayAttributesResource,
MaxItems: 1,
},
"filter": {
Description: "A set of filters on an element within a journey view.",
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func TestAccResourceJourneyViewsBasic(t *testing.T) {
attributeType = "Event"
attributeId = "a416328b-167c-0365-d0e1-f072cd5d4ded"
attributeSource = "Voice"
elementDisplayAttributesX = 601
elementDisplayAttributesY = 240
elementDisplayAttributesCol = 1
filterType = "And"
predicatesDimension = "mediaType"
predicatesValues = "VOICE"
Expand Down Expand Up @@ -52,6 +55,7 @@ func TestAccResourceJourneyViewsBasic(t *testing.T) {
elementsId,
elementsName,
generateAttributes(attributeType, attributeId, attributeSource),
generateElementDisplayAttributes(elementDisplayAttributesX, elementDisplayAttributesY, elementDisplayAttributesCol),
generateFilter(filterType, generatePredicates(predicatesDimension, predicatesValues, predicatesOperator, predicatesNoValue)),
), generateChartsList([]string{
generateCharts(chartName, chartVersion,
Expand All @@ -74,6 +78,10 @@ func TestAccResourceJourneyViewsBasic(t *testing.T) {
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.attributes.0.type", attributeType),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.attributes.0.id", attributeId),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.attributes.0.source", attributeSource),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.#", "1"),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.0.x", fmt.Sprintf("%d", elementDisplayAttributesX)),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.0.y", fmt.Sprintf("%d", elementDisplayAttributesY)),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.0.col", fmt.Sprintf("%d", elementDisplayAttributesCol)),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.filter.#", "1"),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.filter.0.type", "And"),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.filter.0.predicates.#", "1"),
Expand Down Expand Up @@ -111,6 +119,7 @@ func TestAccResourceJourneyViewsBasic(t *testing.T) {
elementsId,
elementsName,
generateAttributes(attributeType, attributeId, attributeSource),
generateElementDisplayAttributes(elementDisplayAttributesX, elementDisplayAttributesY, elementDisplayAttributesCol),
generateFilter(filterType, generatePredicates(predicatesDimension, predicatesValues, predicatesOperator, predicatesNoValue)),
), generateCharts(chartName, chartVersion,
generateMetrics(metricId, elementsId, metricAggregate, metricDisplayLabel), chartGroupByTime, chartGroupByMax,
Expand All @@ -126,6 +135,10 @@ func TestAccResourceJourneyViewsBasic(t *testing.T) {
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.attributes.0.type", attributeType),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.attributes.0.id", attributeId),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.attributes.0.source", attributeSource),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.#", "1"),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.0.x", fmt.Sprintf("%d", elementDisplayAttributesX)),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.0.y", fmt.Sprintf("%d", elementDisplayAttributesY)),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.display_attributes.0.col", fmt.Sprintf("%d", elementDisplayAttributesCol)),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.filter.#", "1"),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.filter.0.type", "And"),
resource.TestCheckResourceAttr("genesyscloud_journey_views."+journeyResourceLabel, "elements.0.filter.0.predicates.#", "1"),
Expand Down Expand Up @@ -184,15 +197,16 @@ func generateJourneyView(journeyResourceLabel string, name string, duration stri
}())
}

func generateElements(id string, name string, attributesBlock string, filter string) string {
func generateElements(id string, name string, attributesBlock string, displayAttributesBlock, filter string) string {
return fmt.Sprintf(`
elements {
id = "%s"
name = "%s"
%s
%s
%s
}
`, id, name, attributesBlock, filter)
`, id, name, attributesBlock, displayAttributesBlock, filter)
}

func generateFilter(filterType string, nestedBlocks ...string) string {
Expand All @@ -204,6 +218,16 @@ func generateFilter(filterType string, nestedBlocks ...string) string {
`, filterType, strings.Join(nestedBlocks, "\n"))
}

func generateElementDisplayAttributes(attributeX int, attributeY int, attributeCol int) string {
return fmt.Sprintf(`
display_attributes {
x = %d
y = %d
col = %d
}
`, attributeX, attributeY, attributeCol)
}

func generateAttributes(attributeType string, attributeId string, attributeSource string) string {
return fmt.Sprintf(`
attributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func buildElements(d *schema.ResourceData) (*[]platformclientv2.Journeyvieweleme
element.Attributes = &attributes
}

if displayAttributesSlice, ok := elemMap["display_attributes"].([]interface{}); ok {
displayAttributes := buildJourneyViewElementDisplayAttributes(displayAttributesSlice)
element.DisplayAttributes = displayAttributes
}

if filterSlice, ok := elemMap["filter"].([]interface{}); ok {
filter := buildJourneyViewElementFilter(filterSlice)
element.Filter = filter
Expand Down Expand Up @@ -66,6 +71,22 @@ func buildJourneyViewElementAttributes(attributesSlice []interface{}) platformcl
return attributes
}

func buildJourneyViewElementDisplayAttributes(displayAttributesSlice []interface{}) *platformclientv2.Journeyviewelementdisplayattributes {
var displayAttributes platformclientv2.Journeyviewelementdisplayattributes
if len(displayAttributesSlice) == 0 {
return nil
}

for _, elem := range displayAttributesSlice {
if displayAttributesMap, ok := elem.(map[string]interface{}); ok {
displayAttributes.X = getIntPointerFromInterface(displayAttributesMap["x"])
displayAttributes.Y = getIntPointerFromInterface(displayAttributesMap["y"])
displayAttributes.Col = getIntPointerFromInterface(displayAttributesMap["col"])
}
}
return &displayAttributes
}

func buildJourneyViewElementFilter(filterSlice []interface{}) *platformclientv2.Journeyviewelementfilter {
var filter platformclientv2.Journeyviewelementfilter
for _, elem := range filterSlice {
Expand Down Expand Up @@ -289,6 +310,7 @@ func flattenElements(elements *[]platformclientv2.Journeyviewelement) []interfac
resourcedata.SetMapValueIfNotNil(elementsMap, "id", element.Id)
resourcedata.SetMapValueIfNotNil(elementsMap, "name", element.Name)
resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(elementsMap, "attributes", element.Attributes, flattenAttributes)
resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(elementsMap, "display_attributes", element.DisplayAttributes, flattenElementDisplayAttributes)
resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(elementsMap, "filter", element.Filter, flattenFilters)
resourcedata.SetMapInterfaceArrayWithFuncIfNotNil(elementsMap, "followed_by", element.FollowedBy, flattenJourneyViewLink)
elementsList = append(elementsList, elementsMap)
Expand All @@ -309,6 +331,19 @@ func flattenAttributes(attribute *platformclientv2.Journeyviewelementattributes)
return attributesList
}

func flattenElementDisplayAttributes(displayAttributes *platformclientv2.Journeyviewelementdisplayattributes) []interface{} {
if displayAttributes == nil {
return nil
}
var displayAttributesList []interface{}
displayAttributesMap := make(map[string]interface{})
resourcedata.SetMapValueIfNotNil(displayAttributesMap, "x", displayAttributes.X)
resourcedata.SetMapValueIfNotNil(displayAttributesMap, "y", displayAttributes.Y)
resourcedata.SetMapValueIfNotNil(displayAttributesMap, "col", displayAttributes.Col)
displayAttributesList = append(displayAttributesList, displayAttributesMap)
return displayAttributesList
}

func flattenFilters(filter *platformclientv2.Journeyviewelementfilter) []interface{} {
if filter == nil {
return nil
Expand Down

0 comments on commit ee50810

Please sign in to comment.