fix(测试跟踪): 支持实时检索的第三方平台缺陷字段显示的是选项值,不是选项名称

This commit is contained in:
chenjianxing 2023-02-27 11:20:15 +08:00 committed by jianxing
parent 210245d898
commit 3442559e00
7 changed files with 36 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import i18n from "../i18n";
import {getCurrentProjectID, getCurrentUser} from "../utils/token";
import { SYSTEM_FIELD_NAME_MAP } from "../utils/table-constants";
import {OPTION_LABEL_PREFIX} from "../utils/tableUtils";
function setDefaultValue(item, value) {
item.defaultValue = value;
@ -84,6 +85,15 @@ export function parseCustomField(data, template, rules, oldFields) {
} else {
setDefaultValue(item, customField.value);
}
if (customField.textValue && customField.textValue.startsWith(OPTION_LABEL_PREFIX)) {
// 处理 jira 的 sprint 字段,没有选项,则添加对应选项
if (item.options && item.options.filter(i => i.value === customField.value).length < 1) {
item.options.push({
'text': customField.textValue.substring(OPTION_LABEL_PREFIX.length),
'value': customField.value
});
}
}
item.isEdit = true;
} catch (e) {
console.error("JSON parse custom field value error.", e);

View File

@ -521,6 +521,8 @@ export function saveCustomTableWidth(key, fieldKey, colWith) {
localStorage.setItem(key + '_WITH', JSON.stringify(fields));
}
export const OPTION_LABEL_PREFIX = "optionLabel:";
/**
* 获取列表的自定义字段的显示值
* @param row
@ -533,6 +535,12 @@ export function getCustomFieldValue(row, field, members) {
for (let i = 0; i < row.fields.length; i++) {
let item = row.fields[i];
if (item.id === field.id) {
if (item.textValue && item.textValue.startsWith(OPTION_LABEL_PREFIX)) {
// 处理 jira 的 sprint 字段
if (field.options && field.options.filter(i => i.value === item.value).length < 1) {
return item.textValue.substring(OPTION_LABEL_PREFIX.length);
}
}
if (!item.value) return '';
if (field.type === 'member') {
for (let j = 0; j < members.length; j++) {
@ -700,7 +708,7 @@ export function parseCustomFilesForItem(data) {
if (data.value) {
data.value = JSON.parse(data.value);
}
if (data.textValue) {
if (data.textValue && !data.textValue.startsWith(OPTION_LABEL_PREFIX)) {
data.value = data.textValue;
}
}

View File

@ -21,7 +21,12 @@ public class CustomFieldDao extends CustomField {
private String key;
// 支持输入字符时实时调用 optionMethod 方法查询下拉框数据
// 目前 jira 获取 sprint 字段有使用
private Boolean inputSearch;
private String optionMethod;
// jira 获取 sprint 下拉框选项不全需要检索才能获取这里将当前选项的名称保存
private String optionLabel;
}

View File

@ -10,4 +10,5 @@ public class CustomFieldItemDTO {
private String type;
private String key;
private String customData;
private String optionLabel;
}

View File

@ -18,5 +18,6 @@ import java.io.Serializable;
public class CustomFieldResourceDTO extends CustomFieldTestCase implements Serializable {
private String name;
private String type;
private String optionLabel;
private static final long serialVersionUID = 1L;
}

View File

@ -78,6 +78,7 @@ public class BaseCustomFieldService {
} else {
resource.setValue(JSON.toJSONString(dto.getValue()));
}
resource.setOptionLabel(dto.getOptionLabel());
return resource;
}

View File

@ -1,6 +1,7 @@
package io.metersphere.service;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import io.metersphere.base.domain.CustomField;
import io.metersphere.base.domain.CustomFieldIssues;
import io.metersphere.base.domain.CustomFieldIssuesExample;
@ -94,12 +95,15 @@ public class CustomFieldIssuesService extends CustomFieldResourceService {
continue;
}
List<String> fieldIds = resourceFieldMap.get(resourceId);
for (CustomFieldResourceDTO CustomFieldResourceDTO : list) {
CustomFieldResourceDTO.setResourceId(resourceId);
if (CollectionUtils.isEmpty(fieldIds) || !fieldIds.contains(CustomFieldResourceDTO.getFieldId())) {
addList.add(CustomFieldResourceDTO);
for (CustomFieldResourceDTO customFieldResourceDTO : list) {
customFieldResourceDTO.setResourceId(resourceId);
if (StringUtils.isNotBlank(customFieldResourceDTO.getOptionLabel())) {
customFieldResourceDTO.setTextValue("optionLabel:" + customFieldResourceDTO.getOptionLabel());
}
if (CollectionUtils.isEmpty(fieldIds) || !fieldIds.contains(customFieldResourceDTO.getFieldId())) {
addList.add(customFieldResourceDTO);
} else {
updateList.add(CustomFieldResourceDTO);
updateList.add(customFieldResourceDTO);
}
}
}