Skip to content

Commit

Permalink
[ui] Edit Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Sep 1, 2023
1 parent e9dbded commit cb098cf
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 14 deletions.
66 changes: 66 additions & 0 deletions ododevapispec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,72 @@ paths:
example:
message: "Error deleting the resource"

patch:
tags:
- devstate
description: Update a Kubernetes resource
parameters:
- name: resourceName
in: path
description: Resource name to update
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
inlined:
type: string
uri:
type: string
responses:
'200':
description: resource was successfully updated
content:
application/json:
schema:
$ref: '#/components/schemas/DevfileContent'
example:
{
"content": "schemaVersion: 2.2.0\n",
"commands": [],
"containers": [],
"images": [],
"resources": [],
"events": {
"preStart": null,
"postStart": null,
"preStop": null,
"postStop": null
},
"metadata": {
"name": "",
"version": "",
"displayName": "",
description": "",
"tags": "",
"architectures": "",
"icon": "",
"globalMemoryLimit": "",
"projectType": "",
"language": "",
"website": "",
"provider": "",
"supportUrl": ""
}
}
'500':
description: Error updating the resource
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "Error updating the resource"

/devstate/volume:
post:
tags:
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver-gen/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/apiserver-gen/go/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions pkg/apiserver-gen/go/api_devstate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/apiserver-impl/devstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,18 @@ func (s *DevstateApiService) DevstateVolumeVolumeNamePatch(ctx context.Context,
}), nil
}
return openapi.Response(http.StatusOK, newContent), nil
}

func (s *DevstateApiService) DevstateResourceResourceNamePatch(ctx context.Context, name string, patch openapi.DevstateResourceResourceNamePatchRequest) (openapi.ImplResponse, error) {
newContent, err := s.devfileState.PatchResource(
name,
patch.Inlined,
patch.Uri,
)
if err != nil {
return openapi.Response(http.StatusInternalServerError, openapi.GeneralError{
Message: fmt.Sprintf("Error updating the resource: %s", err),
}), nil
}
return openapi.Response(http.StatusOK, newContent), nil
}
29 changes: 29 additions & 0 deletions pkg/apiserver-impl/devstate/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ func (o *DevfileState) AddResource(name string, inlined string, uri string, depl
return o.GetContent()
}

func (o *DevfileState) PatchResource(name string, inlined string, uri string) (DevfileContent, error) {
if inlined != "" && uri != "" {
return DevfileContent{}, errors.New("both inlined and uri cannot be set at the same time")
}
found, err := o.Devfile.Data.GetComponents(common.DevfileOptions{
ComponentOptions: common.ComponentOptions{
ComponentType: v1alpha2.KubernetesComponentType,
},
FilterByName: name,
})
if err != nil {
return DevfileContent{}, err
}
if len(found) != 1 {
return DevfileContent{}, fmt.Errorf("%d Resource found with name %q", len(found), name)
}

resource := found[0]
resource.Kubernetes.Inlined = inlined
resource.Kubernetes.Uri = uri

err = o.Devfile.Data.UpdateComponent(resource)
if err != nil {
return DevfileContent{}, err
}

return o.GetContent()
}

func (o *DevfileState) DeleteResource(name string) (DevfileContent, error) {

err := o.checkResourceUsed(name)
Expand Down
66 changes: 66 additions & 0 deletions pkg/apiserver-impl/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,72 @@ paths:
example:
message: "Error deleting the resource"

patch:
tags:
- devstate
description: Update a Kubernetes resource
parameters:
- name: resourceName
in: path
description: Resource name to update
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
inlined:
type: string
uri:
type: string
responses:
'200':
description: resource was successfully updated
content:
application/json:
schema:
$ref: '#/components/schemas/DevfileContent'
example:
{
"content": "schemaVersion: 2.2.0\n",
"commands": [],
"containers": [],
"images": [],
"resources": [],
"events": {
"preStart": null,
"postStart": null,
"preStop": null,
"postStop": null
},
"metadata": {
"name": "",
"version": "",
"displayName": "",
description": "",
"tags": "",
"architectures": "",
"icon": "",
"globalMemoryLimit": "",
"projectType": "",
"language": "",
"website": "",
"provider": "",
"supportUrl": ""
}
}
'500':
description: Error updating the resource
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "Error updating the resource"

/devstate/volume:
post:
tags:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver-impl/ui/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apiserver-impl/ui/main.2b64963ea59fd11e.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/apiserver-impl/ui/main.32ba016d46c6a398.js

This file was deleted.

22 changes: 22 additions & 0 deletions ui/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,28 @@ describe('devfile editor spec', () => {
.should('contain.text', 'No, disabled');
});

it('displays an updated resource, with manifest', () => {
cy.init();

cy.selectTab(TAB_RESOURCES);
cy.getByDataCy('resource-name').type('created-resource');
cy.getByDataCy('resource-toggle-inlined').click();
cy.getByDataCy('resource-manifest').type('a-resource-manifest');
cy.getByDataCy('resource-create').click();

cy.getByDataCy('resource-info').first()
.should('contain.text', 'created-resource')
.should('contain.text', 'a-resource-manifest');

cy.getByDataCy('resource-edit').click();
cy.getByDataCy('resource-manifest').type('{selectAll}{del}another-resource-manifest');
cy.getByDataCy('resource-save').click();

cy.getByDataCy('resource-info').first()
.should('contain.text', 'created-resource')
.should('contain.text', 'another-resource-manifest');
});

it('displays a created volume', () => {
cy.init();

Expand Down
1 change: 1 addition & 0 deletions ui/src/app/api-gen/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cb098cf

Please sign in to comment.