diff --git a/.changes/unreleased/component-type-category.yaml b/.changes/unreleased/component-type-category.yaml new file mode 100644 index 00000000..a6d3a346 --- /dev/null +++ b/.changes/unreleased/component-type-category.yaml @@ -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. diff --git a/component_test.go b/component_test.go index 3a0da9e9..99b3abd4 100644 --- a/component_test.go +++ b/component_test.go @@ -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{}, @@ -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" }} }}}`, ) @@ -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) { @@ -83,6 +85,9 @@ 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) { @@ -90,6 +95,7 @@ func TestComponentTypeUpdate(t *testing.T) { 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{}, @@ -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" }} }}}`, ) @@ -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) { diff --git a/input.go b/input.go index bff7ca4f..7b1972e8 100644 --- a/input.go +++ b/input.go @@ -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) diff --git a/object.go b/object.go index 1f829124..c9cd3e98 100644 --- a/object.go +++ b/object.go @@ -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) diff --git a/testdata/templates/component_type.tpl b/testdata/templates/component_type.tpl index 445cbefb..1cbaa557 100644 --- a/testdata/templates/component_type.tpl +++ b/testdata/templates/component_type.tpl @@ -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" }} { @@ -8,6 +8,7 @@ "example1" ], "name": "Example1", + "category": "infrastructure", "description": "Description", "href": "https://app.opslevel-staging.com/catalog/domains/platformdomain", "icon": { @@ -49,6 +50,7 @@ "example2" ], "name": "Example2", + "category": "default", "description": "Description", "href": "https://app.opslevel-staging.com/catalog/domains/platformdomain", "icon": {