diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c79c0b..4dce176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to the "tswagger" extension will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [Unreleased] + +### Fixed + +- Cannot show the diff content after renaming the interface. + +## [1.1.1] - 2023-12-15 + +### Fixed + +- Cannot rename the interface. + ## [1.1.0] - 2023-12-15 ### Changed diff --git a/webview/src/components/TsResultModal/TsResultModal.tsx b/webview/src/components/TsResultModal/TsResultModal.tsx index 80a2ea2..b69365d 100644 --- a/webview/src/components/TsResultModal/TsResultModal.tsx +++ b/webview/src/components/TsResultModal/TsResultModal.tsx @@ -68,20 +68,24 @@ const TsResultModal: React.FC = (props) => { ), key: groupName, selectable: false, - children: serviceList.map(({ serviceName }, pathIndex) => ({ + children: serviceList.map(({ serviceName }, serviceIndex) => ({ title: ( {serviceName} ), - // 增加 index 作为唯一性 key - // 可能存在相同的 serviceName (如:当后端设置了相同的 operationId) - key: [groupName, serviceName, pathIndex].join(','), + key: [groupName, serviceIndex].join(','), })), }); }); setApiPathTree(newTreeData); - setPathKey(newTreeData?.[0]?.children?.[0]?.key?.toString()); + const firstKey = newTreeData?.[0]?.children?.[0]?.key?.toString(); + if (firstKey === pathKey) { + // 手动触发一下 + handleEditContent(firstKey); + } else { + setPathKey(firstKey); + } }); const handleAftreRenameTs = useMemoizedFn((result: V2TSGenerateResult) => { @@ -106,20 +110,24 @@ const TsResultModal: React.FC = (props) => { } }); - useEffect(() => { - if (!pathKey) { + const handleEditContent = (latestPathKey?: Key) => { + if (!latestPathKey) { return; } - const [groupName, serviceName] = pathKey.toString().split(','); - const originalContent = - originalServiceResult.find((it) => it.groupName === groupName)?.serviceList.find((it) => it.serviceName === serviceName)?.tsDefs ?? ''; - const modifiedContent = _this.latestTsResult.serviceResult - .find((it) => it.groupName === groupName) - ?.serviceList.find((it) => it.serviceName === serviceName)?.tsDefs; + const [groupName, index] = latestPathKey.toString().split(','); + const serviceIndex = Number(index); + const originalContent = originalServiceResult.find((it) => it.groupName === groupName)?.serviceList?.[serviceIndex]?.tsDefs ?? ''; + const modifiedContent = _this.latestTsResult.serviceResult.find((it) => it.groupName === groupName)?.serviceList?.[serviceIndex]?.tsDefs; setEditorContent({ originalContent, modifiedContent, }); + }; + + useEffect(() => { + if (pathKey) { + handleEditContent(pathKey); + } }, [pathKey]); useMount(() => {