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

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

View File

@ -1,6 +1,7 @@
import i18n from "../i18n"; import i18n from "../i18n";
import {getCurrentProjectID, getCurrentUser} from "../utils/token"; import {getCurrentProjectID, getCurrentUser} from "../utils/token";
import { SYSTEM_FIELD_NAME_MAP } from "../utils/table-constants"; import { SYSTEM_FIELD_NAME_MAP } from "../utils/table-constants";
import {OPTION_LABEL_PREFIX} from "../utils/tableUtils";
function setDefaultValue(item, value) { function setDefaultValue(item, value) {
item.defaultValue = value; item.defaultValue = value;
@ -84,6 +85,15 @@ export function parseCustomField(data, template, rules, oldFields) {
} else { } else {
setDefaultValue(item, customField.value); 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; item.isEdit = true;
} catch (e) { } catch (e) {
console.error("JSON parse custom field value error.", e); console.error("JSON parse custom field value error.", e);

View File

@ -478,6 +478,8 @@ export function saveCustomTableWidth(key, fieldKey, colWith) {
localStorage.setItem(key + '_WITH', JSON.stringify(fields)); localStorage.setItem(key + '_WITH', JSON.stringify(fields));
} }
export const OPTION_LABEL_PREFIX = "optionLabel:";
/** /**
* 获取列表的自定义字段的显示值 * 获取列表的自定义字段的显示值
* @param row * @param row
@ -490,6 +492,12 @@ export function getCustomFieldValue(row, field, members) {
for (let i = 0; i < row.fields.length; i++) { for (let i = 0; i < row.fields.length; i++) {
let item = row.fields[i]; let item = row.fields[i];
if (item.id === field.id) { 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 (!item.value) return '';
if (field.type === 'member') { if (field.type === 'member') {
for (let j = 0; j < members.length; j++) { for (let j = 0; j < members.length; j++) {
@ -657,7 +665,7 @@ export function parseCustomFilesForItem(data) {
if (data.value) { if (data.value) {
data.value = JSON.parse(data.value); data.value = JSON.parse(data.value);
} }
if (data.textValue) { if (data.textValue && !data.textValue.startsWith(OPTION_LABEL_PREFIX)) {
data.value = data.textValue; data.value = data.textValue;
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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