Skip to content
Open
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
2 changes: 2 additions & 0 deletions .changes/unreleased/component-type-category.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kind: Feature
body: Add `Category` field to `ComponentType` and `ComponentTypeInput` for creating and reading component type categories (`default`, `infrastructure`). Gated on the backend behind the `infra_component_types_ui` feature flag — accounts without the flag will see an empty `Category` and cannot send the field on input.
11 changes: 9 additions & 2 deletions component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestComponentTypeCreate(t *testing.T) {
input := autopilot.Register[ol.ComponentTypeInput]("component_type_create_input",
ol.ComponentTypeInput{
Alias: ol.RefOf("example"),
Category: ol.RefOf("infrastructure"),
Name: ol.RefOf("Example"),
Description: ol.RefOf("Example Description"),
Properties: &[]ol.ComponentTypePropertyDefinitionInput{},
Expand All @@ -31,7 +32,7 @@ func TestComponentTypeCreate(t *testing.T) {

testRequest := autopilot.NewTestRequest(
`mutation ComponentTypeCreate($input:ComponentTypeInput!){componentTypeCreate(input:$input){componentType{{ template "component_type_graphql" }},errors{message,path}}}`,
`{"input": {"alias": "example", "name": "Example", "description": "Example Description", "properties": [], "ownerRelationship": {"managementRules": [{"operator": "EQUALS", "sourceProperty": "tag_key_eq:owner", "sourcePropertyBuiltin": true, "targetProperty": "name", "targetPropertyBuiltin": true, "targetType": "team"}]} }}`,
`{"input": {"alias": "example", "category": "infrastructure", "name": "Example", "description": "Example Description", "properties": [], "ownerRelationship": {"managementRules": [{"operator": "EQUALS", "sourceProperty": "tag_key_eq:owner", "sourcePropertyBuiltin": true, "targetProperty": "name", "targetPropertyBuiltin": true, "targetType": "team"}]} }}`,
`{"data": {"componentTypeCreate": {"componentType": {{ template "component_type_1_response" }} }}}`,
)

Expand All @@ -41,6 +42,7 @@ func TestComponentTypeCreate(t *testing.T) {
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "infrastructure", result.Category)
}

func TestComponentTypeGet(t *testing.T) {
Expand Down Expand Up @@ -83,13 +85,17 @@ func TestComponentTypeList(t *testing.T) {
autopilot.Equals(t, "Example1", result[0].Name)
autopilot.Equals(t, "Example2", result[1].Name)
autopilot.Equals(t, "Example3", result[2].Name)
autopilot.Equals(t, "infrastructure", result[0].Category)
autopilot.Equals(t, "default", result[1].Category)
autopilot.Equals(t, "", result[2].Category)
}

func TestComponentTypeUpdate(t *testing.T) {
// Arrange
input := autopilot.Register[ol.ComponentTypeInput]("component_type_update_input",
ol.ComponentTypeInput{
Alias: ol.RefOf("example"),
Category: ol.RefOf("infrastructure"),
Name: ol.RefOf("Example"),
Description: ol.RefOf("Example Description"),
Properties: &[]ol.ComponentTypePropertyDefinitionInput{},
Expand All @@ -109,7 +115,7 @@ func TestComponentTypeUpdate(t *testing.T) {

testRequest := autopilot.NewTestRequest(
`mutation ComponentTypeUpdate($input:ComponentTypeInput!$target:IdentifierInput!){componentTypeUpdate(componentType:$target,input:$input){componentType{{ template "component_type_graphql" }},errors{message,path}}}`,
`{"input": {"alias": "example", "name": "Example", "description": "Example Description", "properties": [], "ownerRelationship": {"managementRules": [{"operator": "EQUALS", "sourceProperty": "tag_key_eq:owner", "sourcePropertyBuiltin": true, "targetProperty": "name", "targetPropertyBuiltin": true, "targetType": "team"}]}}, "target": { {{ template "id1" }} }}`,
`{"input": {"alias": "example", "category": "infrastructure", "name": "Example", "description": "Example Description", "properties": [], "ownerRelationship": {"managementRules": [{"operator": "EQUALS", "sourceProperty": "tag_key_eq:owner", "sourcePropertyBuiltin": true, "targetProperty": "name", "targetPropertyBuiltin": true, "targetType": "team"}]}}, "target": { {{ template "id1" }} }}`,
`{"data": {"componentTypeUpdate": {"componentType": {{ template "component_type_1_response" }} }}}`,
)

Expand All @@ -119,6 +125,7 @@ func TestComponentTypeUpdate(t *testing.T) {
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, id1, result.Id)
autopilot.Equals(t, "infrastructure", result.Category)
}

func TestComponentTypeDelete(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ type ComponentTypeIconInput struct {
// ComponentTypeInput Specifies the input fields used to create a component type
type ComponentTypeInput struct {
Alias *Nullable[string] `json:"alias,omitempty" yaml:"alias,omitempty" example:"example_value"` // The unique alias of the component type (Optional)
Category *Nullable[string] `json:"category,omitempty" yaml:"category,omitempty" example:"infrastructure"` // The category of the component type. One of "default", "infrastructure", "people" (Optional)
Description *Nullable[string] `json:"description,omitempty" yaml:"description,omitempty" example:"example_value"` // The description of the component type (Optional)
Icon *ComponentTypeIconInput `json:"icon,omitempty" yaml:"icon,omitempty"` // The icon associated with the component type (Optional)
Name *Nullable[string] `json:"name,omitempty" yaml:"name,omitempty" example:"example_value"` // The unique name of the component type (Optional)
Expand Down
1 change: 1 addition & 0 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type ComponentTypeId struct {
// ComponentType Information about a particular component type
type ComponentType struct {
ComponentTypeId
Category string // The category of the component type. One of "default", "infrastructure", "people" (Optional)
Description string // The description of the component type (Optional)
Href string // The relative path to link to the component type (Required)
Icon ComponentTypeIcon // The icon associated with the component type (Required)
Expand Down
4 changes: 3 additions & 1 deletion testdata/templates/component_type.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- define "component_type_graphql" }}
{id,aliases,description,href,icon{color,name},isDefault,name,ownerRelationship{managementRules{operator,sourceProperty,sourcePropertyBuiltin,targetCategory,targetProperty,targetPropertyBuiltin,targetType}},systemRelationship{managementRules{operator,sourceProperty,sourcePropertyBuiltin,targetCategory,targetProperty,targetPropertyBuiltin,targetType}},timestamps{createdAt,updatedAt}}
{id,aliases,category,description,href,icon{color,name},isDefault,name,ownerRelationship{managementRules{operator,sourceProperty,sourcePropertyBuiltin,targetCategory,targetProperty,targetPropertyBuiltin,targetType}},systemRelationship{managementRules{operator,sourceProperty,sourcePropertyBuiltin,targetCategory,targetProperty,targetPropertyBuiltin,targetType}},timestamps{createdAt,updatedAt}}
{{end}}
{{- define "component_type_1_response" }}
{
Expand All @@ -8,6 +8,7 @@
"example1"
],
"name": "Example1",
"category": "infrastructure",
"description": "Description",
"href": "https://app.opslevel-staging.com/catalog/domains/platformdomain",
"icon": {
Expand Down Expand Up @@ -49,6 +50,7 @@
"example2"
],
"name": "Example2",
"category": "default",
"description": "Description",
"href": "https://app.opslevel-staging.com/catalog/domains/platformdomain",
"icon": {
Expand Down
Loading