Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: template editor component #136

Merged
merged 7 commits into from
Apr 29, 2024
Merged
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
3 changes: 2 additions & 1 deletion app/prom_server/internal/service/promservice/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"os"

"github.com/go-kratos/kratos/v2/log"
"github.com/aide-family/moon/api"
pb "github.com/aide-family/moon/api/server/prom/strategy"
"github.com/aide-family/moon/app/prom_server/internal/biz"
"github.com/aide-family/moon/app/prom_server/internal/biz/bo"
"github.com/aide-family/moon/app/prom_server/internal/biz/vobj"
"github.com/aide-family/moon/pkg/strategy"
"github.com/aide-family/moon/pkg/util/slices"
"github.com/go-kratos/kratos/v2/log"
)

type StrategyService struct {
Expand Down Expand Up @@ -206,6 +206,7 @@ func (s *StrategyService) TestNotifyTemplate(ctx context.Context, req *pb.TestTe
Template: req.GetTemplate(),
StrategyId: req.GetStrategyId(),
}
s.log.Debugw("testParams", testParams.Template)
if err := s.notifyBiz.TestNotifyTemplate(ctx, testParams); err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"@prometheus-io/codemirror-promql": "^0.47.2",
"@types/crypto-js": "^4.1.1",
"@types/react-syntax-highlighter": "^15.5.11",
"antd": "^5.13.2",
"antd": "^5.16.5",
"axios": "^1.5.0",
"crypto-js": "^4.1.1",
"dayjs": "^1.11.9",
"echarts": "^5.4.3",
"js-yaml": "^4.1.0",
"monaco-editor": "^0.48.0",
"qs": "^6.11.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
26 changes: 13 additions & 13 deletions web/src/apis/data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button } from 'antd'
import { Button, Space } from 'antd'
import {
Category,
DatasourceType,
Expand Down Expand Up @@ -128,40 +128,40 @@ export const NotifyTemplateTypeData: Record<
React.ReactNode
> = {
[NotifyTemplateType.NotifyTemplateTypeEmail]: (
<span>
<Space size={8}>
<IconFont type="icon-youjian" />
邮件
</span>
</Space>
),
[NotifyTemplateType.NotifyTemplateTypeCustom]: (
<span>
<Space size={8}>
<IconFont type="icon-zidingyi" />
自定义hook
</span>
</Space>
),
[NotifyTemplateType.NotifyTemplateTypeDingDing]: (
<span>
<Space size={8}>
<IconFont type="icon-dingding" />
钉钉
</span>
</Space>
),
[NotifyTemplateType.NotifyTemplateTypeSms]: (
<span>
<Space size={8}>
<IconFont type="icon-duanxin" />
短信
</span>
</Space>
),
[NotifyTemplateType.NotifyTemplateTypeFeiShu]: (
<span>
<Space size={8}>
<IconFont type="icon-feishu" />
飞书
</span>
</Space>
),
[NotifyTemplateType.NotifyTemplateTypeWeChatWork]: (
<span>
<Space size={8}>
<IconFont type="icon-qiyeweixin" />
企业微信
</span>
</Space>
)
}

Expand Down
50 changes: 50 additions & 0 deletions web/src/components/Data/DataInput/DataInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ import {
TemplateAutoComplete,
TemplateAutoCompleteProps
} from '../TemplateAutoComplete'
import {
EmailTemplateEditor,
EmailTemplateEditorProps
} from './child/EmailTemplateEditor'
import {
WechatTemplateEditor,
WechatTemplateEditorProps
} from './child/WechatTemplateEditor'
import {
JsonTemplateEditor,
JsonTemplateEditorProps
} from './child/JsonTemplateEditor'
import {
FeishuTemplateEditor,
FeishuTemplateEditorProps
} from './child/FeishuTemplateEditor'
import {
DingTemplateEditor,
DingTemplateEditorProps
} from './child/DingTemplateEditor'

export type DataInputProps =
| (
Expand Down Expand Up @@ -86,6 +106,26 @@ export type DataInputProps =
type: 'template-auto-complete'
parentProps?: TemplateAutoCompleteProps
}
| {
type: 'email-template-editor'
parentProps?: EmailTemplateEditorProps
}
| {
type: 'wechat-template-editor'
parentProps?: WechatTemplateEditorProps
}
| {
type: 'json-template-editor'
parentProps?: JsonTemplateEditorProps
}
| {
type: 'feishu-template-editor'
parentProps?: FeishuTemplateEditorProps
}
| {
type: 'ding-template-editor'
parentProps?: DingTemplateEditorProps
}
) & {
width?: number | string
value?: any
Expand Down Expand Up @@ -217,6 +257,16 @@ const DataInput: FC<DataInputProps> = (props) => {
options={parentProps?.options || []}
/>
)
case 'email-template-editor':
return <EmailTemplateEditor {...props} {...parentProps} />
case 'wechat-template-editor':
return <WechatTemplateEditor {...props} {...parentProps} />
case 'json-template-editor':
return <JsonTemplateEditor {...props} {...parentProps} />
case 'feishu-template-editor':
return <FeishuTemplateEditor {...props} {...parentProps} />
case 'ding-template-editor':
return <DingTemplateEditor {...props} {...parentProps} />
default:
return (
<Input
Expand Down
Loading
Loading