Skip to content

Commit

Permalink
fix(console): webhook notification template fixed (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfan committed Dec 6, 2020
1 parent 9ce96c3 commit afeb2da
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class EditResource extends React.Component<Props, State> {
const theSpec = state.resource.properties.spec;
if (theSpec.pick === 'webhook') {
const headers = theSpec.properties.webhook.properties.headers;
// let headers = state.resource.properties.spec.properties.webhook.properties.headers;
if (headers && headers.value) {
let headerArr = [];
Object.keys(headers.value).forEach(key => {
Expand Down Expand Up @@ -169,15 +168,19 @@ export class EditResource extends React.Component<Props, State> {
}

// 将headers字符串转换为对象
if (json.spec && json.spec.webhook && json.spec.webhook.headers) {
let headersObj = {};
json.spec.webhook.headers.split(';').forEach(headerStr => {
if (headerStr) {
let headerArr = headerStr.split(':');
headersObj[headerArr[0]] = headerArr[1];
}
});
json.spec.webhook.headers = headersObj;
if (json.spec && json.spec.webhook) {
if (json.spec.webhook.headers) {
let headersObj = {};
json.spec.webhook.headers.split(';').forEach(headerStr => {
if (headerStr) {
let headerArr = headerStr.split(':');
headersObj[headerArr[0]] = headerArr[1];
}
});
json.spec.webhook.headers = headersObj;
}
json.spec.text = Object.assign({}, json.spec.webhook);
json.spec.webhook = undefined;
}

let jsonData = JSON.stringify(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,59 @@ import { ResourceTable } from './ResourceTable';
import { t, Trans } from '@tencent/tea-app/lib/i18n';
import { TablePanelColumnProps } from '@tencent/ff-component';
import { Resource } from '../../../common';
import { router } from '../../router';
const TypeMapping = {
smtp: t('邮件'),
text: t('邮件'),
tencentCloudSMS: t('短信'),
wechat: t('微信公众号'),
webhook: t('webhook'),
};

export class ResourceTableChannel extends ResourceTable {
getColumns(): TablePanelColumnProps<Resource>[] {
const resourceName = getThisResourceName.call(this);
function getThisResourceName() {
const urlParams = router.resolve(this.props.route);
return urlParams['resourceName'] || '';
}

return [
{
key: 'type',
header: t('类型'),
render: x => {
if (x.spec.smtp || x.spec.text) {
return t('邮件');
}
if (x.spec.tencentCloudSMS) {
return t('短信');
render: resource => {
let channel = getChannel.call(this);
function getChannel() {
switch (resourceName) {
case 'channel':
const channel = resource;
return channel;
case 'template':
const template = resource;
const channelName = template.metadata.namespace;
const channelList = this.props.channel.list.data.records;
function getChannelRecord(name) {
return channelList.find(channel => channel.metadata.name === name);
}
return getChannelRecord(channelName);
}
}
if (x.spec.wechat) {
return t('微信公众号');

if (!channel || !channel.spec) {
return '-';
}
if (x.spec.webhook) {
return 'webhook';

function getTypeDesc(channelSpec) {
for (const type in TypeMapping) {
if (channelSpec.hasOwnProperty(type)) {
return TypeMapping[type];
}
}
return '-';
}

return '-';
return getTypeDesc(channel.spec);
}
}
];
Expand Down

0 comments on commit afeb2da

Please sign in to comment.