From 7426aa5d3da7362b4d87e956b1808671281ed765 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 27 Feb 2023 11:20:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AE=9E=E6=97=B6=E6=A3=80=E7=B4=A2=E7=9A=84?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E5=B9=B3=E5=8F=B0=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=98=BE=E7=A4=BA=E7=9A=84=E6=98=AF=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E5=80=BC=EF=BC=8C=E4=B8=8D=E6=98=AF=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk-parent/frontend/src/utils/custom_field.js | 10 ++++++++++ .../sdk-parent/frontend/src/utils/tableUtils.js | 10 +++++++++- .../java/io/metersphere/dto/CustomFieldDao.java | 5 +++++ .../io/metersphere/dto/CustomFieldItemDTO.java | 1 + .../io/metersphere/dto/CustomFieldResourceDTO.java | 1 + .../service/BaseCustomFieldService.java | 1 + .../service/CustomFieldIssuesService.java | 14 +++++++++----- 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/framework/sdk-parent/frontend/src/utils/custom_field.js b/framework/sdk-parent/frontend/src/utils/custom_field.js index ff7cb718c0..64c1247f11 100644 --- a/framework/sdk-parent/frontend/src/utils/custom_field.js +++ b/framework/sdk-parent/frontend/src/utils/custom_field.js @@ -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); diff --git a/framework/sdk-parent/frontend/src/utils/tableUtils.js b/framework/sdk-parent/frontend/src/utils/tableUtils.js index d7dda93b86..0184593efb 100644 --- a/framework/sdk-parent/frontend/src/utils/tableUtils.js +++ b/framework/sdk-parent/frontend/src/utils/tableUtils.js @@ -478,6 +478,8 @@ export function saveCustomTableWidth(key, fieldKey, colWith) { localStorage.setItem(key + '_WITH', JSON.stringify(fields)); } +export const OPTION_LABEL_PREFIX = "optionLabel:"; + /** * 获取列表的自定义字段的显示值 * @param row @@ -490,6 +492,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++) { @@ -657,7 +665,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; } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldDao.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldDao.java index c2fcf153e5..b2a667fd78 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldDao.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldDao.java @@ -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; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldItemDTO.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldItemDTO.java index 70b5f9357a..bb2fbd4cda 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldItemDTO.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldItemDTO.java @@ -10,4 +10,5 @@ public class CustomFieldItemDTO { private String type; private String key; private String customData; + private String optionLabel; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldResourceDTO.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldResourceDTO.java index 3868869e76..1855bd5269 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldResourceDTO.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/dto/CustomFieldResourceDTO.java @@ -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; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseCustomFieldService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseCustomFieldService.java index 2a5b0cc816..cce32daacb 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseCustomFieldService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseCustomFieldService.java @@ -78,6 +78,7 @@ public class BaseCustomFieldService { } else { resource.setValue(JSON.toJSONString(dto.getValue())); } + resource.setOptionLabel(dto.getOptionLabel()); return resource; } diff --git a/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java index ca7b25bee6..be8811a1de 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java @@ -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 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); } } }