Skip to content

Commit a250c17

Browse files
authored
action add timeout input (#3125)
1 parent 39b1dc0 commit a250c17

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

modules/openapi/component-protocol/scenarios/action/components/actionForm/render.go

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/erda-project/erda/apistructs"
2727
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
28+
"github.com/erda-project/erda/pkg/i18n"
2829
"github.com/erda-project/erda/pkg/parser/diceyml"
2930
)
3031

@@ -108,6 +109,21 @@ func GenHeaderProps(actionExt *apistructs.ExtensionVersion, versions []VersionOp
108109
return
109110
}
110111

112+
func GenTimeoutProps(local *i18n.LocaleResource) (props []apistructs.FormPropItem, err error) {
113+
timeout := apistructs.FormPropItem{
114+
Label: local.Get("wb.content.action.input.label.timeout"),
115+
Component: "inputNumber",
116+
Key: "timeout",
117+
ComponentProps: map[string]interface{}{
118+
"placeholder": local.Get("wb.content.action.input.label.timeoutPlaceholder"),
119+
},
120+
DefaultValue: "3600",
121+
}
122+
123+
props = append(props, timeout)
124+
return
125+
}
126+
111127
func GenResourceProps(actionExt *apistructs.ExtensionVersion) (props []apistructs.FormPropItem, err error) {
112128
if actionExt == nil {
113129
err = fmt.Errorf("empty action extension")
@@ -263,6 +279,7 @@ func GenActionProps(ctx context.Context, c *apistructs.Component, name, version
263279
}
264280
// 默认请求时,version为空,需要以默认版本覆盖
265281
c.State["version"] = actionExt.Version
282+
local := bdl.Bdl.GetLocale(bdl.Locale)
266283

267284
header, err := GenHeaderProps(actionExt, versions)
268285
if err != nil {
@@ -282,11 +299,18 @@ func GenActionProps(ctx context.Context, c *apistructs.Component, name, version
282299
return
283300
}
284301

302+
timeouts, err := GenTimeoutProps(local)
303+
if err != nil {
304+
logrus.Errorf("generate action timeout props failed, name: %s, version: %s, err:%v", name, version, err)
305+
return
306+
}
307+
285308
var props []apistructs.FormPropItem
286309
props = append(props, header...)
287310
props = append(props, params...)
288311
props = append(props, resource...)
289312
props = append(props, loop...)
313+
props = append(props, timeouts...)
290314
c.Props = map[string]interface{}{
291315
"fields": props,
292316
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 action
16+
17+
import (
18+
"reflect"
19+
"testing"
20+
21+
"github.com/erda-project/erda/apistructs"
22+
"github.com/erda-project/erda/pkg/i18n"
23+
)
24+
25+
func TestGenTimeoutProps1(t *testing.T) {
26+
type args struct {
27+
local *i18n.LocaleResource
28+
}
29+
tests := []struct {
30+
name string
31+
args args
32+
wantProps []apistructs.FormPropItem
33+
wantErr bool
34+
}{
35+
{
36+
name: "test",
37+
args: args{
38+
local: &i18n.LocaleResource{},
39+
},
40+
wantProps: []apistructs.FormPropItem{
41+
{
42+
Label: "wb.content.action.input.label.timeout",
43+
Component: "inputNumber",
44+
Key: "timeout",
45+
ComponentProps: map[string]interface{}{
46+
"placeholder": "wb.content.action.input.label.timeoutPlaceholder",
47+
},
48+
DefaultValue: "3600",
49+
},
50+
},
51+
wantErr: false,
52+
},
53+
}
54+
for _, tt := range tests {
55+
t.Run(tt.name, func(t *testing.T) {
56+
gotProps, err := GenTimeoutProps(tt.args.local)
57+
if (err != nil) != tt.wantErr {
58+
t.Errorf("GenTimeoutProps() error = %v, wantErr %v", err, tt.wantErr)
59+
return
60+
}
61+
if !reflect.DeepEqual(gotProps, tt.wantProps) {
62+
t.Errorf("GenTimeoutProps() gotProps = %v, want %v", gotProps, tt.wantProps)
63+
}
64+
})
65+
}
66+
}

pkg/erda-configs/i18n/action.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"zh-CN": {
3+
"wb.content.action.input.label.timeout": "超时时间",
4+
"wb.content.action.input.label.timeoutPlaceholder": "请输入执行超时时间"
5+
},
6+
"en-US": {
7+
"wb.content.action.input.label.timeout": "timeout",
8+
"wb.content.action.input.label.timeoutPlaceholder": "please enter the execution timeout"
9+
}
10+
}
11+

0 commit comments

Comments
 (0)