Skip to content

Commit

Permalink
fix: cannot show the diff content after renaming the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchardxyz committed Dec 17, 2023
1 parent 373cdc7 commit 6094e66
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 21 additions & 13 deletions webview/src/components/TsResultModal/TsResultModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,24 @@ const TsResultModal: React.FC<TsResultModalProps> = (props) => {
),
key: groupName,
selectable: false,
children: serviceList.map(({ serviceName }, pathIndex) => ({
children: serviceList.map(({ serviceName }, serviceIndex) => ({
title: (
<Text ellipsis={{ tooltip: true }} style={{ fontSize: 14, maxWidth: 180, letterSpacing: 1 }}>
{serviceName}
</Text>
),
// 增加 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) => {
Expand All @@ -106,20 +110,24 @@ const TsResultModal: React.FC<TsResultModalProps> = (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(() => {
Expand Down

0 comments on commit 6094e66

Please sign in to comment.