|
| 1 | +// Copyright (c) 2021 Terminus, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package referSceneSetButton |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + |
| 20 | + "github.com/erda-project/erda-infra/base/servicehub" |
| 21 | + "github.com/erda-project/erda-infra/providers/component-protocol/cptype" |
| 22 | + "github.com/erda-project/erda/apistructs" |
| 23 | + "github.com/erda-project/erda/modules/dop/component-protocol/components/auto-test-scenes/common/gshelper" |
| 24 | + "github.com/erda-project/erda/modules/openapi/component-protocol/components/base" |
| 25 | +) |
| 26 | + |
| 27 | +func init() { |
| 28 | + base.InitProviderWithCreator("auto-test-scenes", "referSceneSetButton", func() servicehub.Provider { |
| 29 | + return &ComponentAction{} |
| 30 | + }) |
| 31 | +} |
| 32 | + |
| 33 | +type ComponentAction struct { |
| 34 | + base.DefaultProvider |
| 35 | +} |
| 36 | + |
| 37 | +func (ca *ComponentAction) Render(ctx context.Context, c *cptype.Component, scenario cptype.Scenario, event cptype.ComponentEvent, gs *cptype.GlobalStateData) error { |
| 38 | + h := gshelper.NewGSHelper(gs) |
| 39 | + switch event.Operation { |
| 40 | + case cptype.OperationKey(apistructs.RefSceneSetOperationKey): |
| 41 | + c.State = map[string]interface{}{ |
| 42 | + "actionType": "addRefSceneSet", |
| 43 | + "visible": true, |
| 44 | + "sceneSetKey": h.GetGlobalSelectedSetID(), |
| 45 | + } |
| 46 | + case cptype.InitializeOperation, cptype.RenderingOperation: |
| 47 | + c.Type = "Button" |
| 48 | + c.Props = map[string]interface{}{ |
| 49 | + "text": "引用场景集", |
| 50 | + } |
| 51 | + c.Operations = map[string]interface{}{ |
| 52 | + "click": map[string]interface{}{ |
| 53 | + "key": apistructs.RefSceneSetOperationKey.String(), |
| 54 | + "reload": true, |
| 55 | + }, |
| 56 | + } |
| 57 | + } |
| 58 | + return nil |
| 59 | +} |
0 commit comments