Skip to content

Commit 560288b

Browse files
authored
Merge pull request #610 from actiontech/fix/sqle-ee-issue-2243
[fix]:(SQLE/DataSourceComparison) disable diff-only button when no differences found and fix SQL parameter generation issue
2 parents bdee4e9 + 8aa2a0a commit 560288b

File tree

4 files changed

+77
-26
lines changed

4 files changed

+77
-26
lines changed

packages/sqle/src/locale/zh-CN/dataSourceComparison.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default {
2020
generateSQLErrorTips:
2121
'当前选中的节点中包含对比结果一致的对象,请修改选择对象后重试!',
2222
generateSQLDisabledTips: '请先选择数据对象',
23+
noDifferencesFound: '当前对比结果暂无差异',
2324
comparisonDetail: {
2425
title: '查看对比详情',
2526
generateSQL: '生成变更SQL',

packages/sqle/src/page/DataSourceComparison/ComparisonEntry/__tests__/index.test.tsx

+34-16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import ComparisonEntry from '..';
1212
import DatabaseComparisonMockService from '../../../../testUtils/mockApi/database_comparison';
1313
import { mockProjectInfo } from '@actiontech/shared/lib/testUtil/mockHook/data';
1414
import { mockUsePermission } from '@actiontech/shared/lib/testUtil/mockHook/mockUsePermission';
15+
import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi';
16+
import { executeDatabaseComparisonMockData } from '../../../../testUtils/mockApi/database_comparison/data';
1517

1618
describe('EnvironmentSelector', () => {
1719
let executeDatabaseComparisonSpy: jest.SpyInstance;
@@ -143,21 +145,13 @@ describe('EnvironmentSelector', () => {
143145
base_schema_name: 'test3',
144146
comparison_schema_name: 'test3',
145147
database_objects: [
146-
{
147-
object_name: undefined,
148-
object_type: 'TABLE'
149-
},
150148
{
151149
object_name: 'task',
152150
object_type: 'TABLE'
153151
},
154152
{
155153
object_name: 'task_copy',
156154
object_type: 'TABLE'
157-
},
158-
{
159-
object_name: undefined,
160-
object_type: undefined
161155
}
162156
]
163157
}
@@ -201,14 +195,6 @@ describe('EnvironmentSelector', () => {
201195
base_schema_name: 'test3',
202196
comparison_schema_name: 'test3',
203197
database_objects: [
204-
{
205-
object_name: undefined,
206-
object_type: undefined
207-
},
208-
{
209-
object_name: undefined,
210-
object_type: 'TABLE'
211-
},
212198
{
213199
object_name: 'task',
214200
object_type: 'TABLE'
@@ -223,4 +209,36 @@ describe('EnvironmentSelector', () => {
223209
project_name: mockProjectInfo.projectName
224210
});
225211
});
212+
213+
it('should disabled showDifferencesOnly button when comparison result is not differences', async () => {
214+
executeDatabaseComparisonSpy.mockImplementation(() =>
215+
createSpySuccessResponse({
216+
data: executeDatabaseComparisonMockData.filter(
217+
(item) => item.comparison_result === 'same'
218+
)
219+
})
220+
);
221+
superRender(<ComparisonEntry />);
222+
223+
await act(async () => jest.advanceTimersByTime(3000));
224+
225+
const baselineInstanceSelect = getBySelector('#baselineInstance');
226+
fireEvent.mouseDown(baselineInstanceSelect);
227+
fireEvent.click(screen.getAllByText('mysql-1(10.186.62.13:33061)')[0]);
228+
229+
const comparisonInstanceSelect = getBySelector('#comparisonInstance');
230+
fireEvent.mouseDown(comparisonInstanceSelect);
231+
fireEvent.click(
232+
screen.getAllByText('xin-test-database(10.186.62.15:33063)')[1]
233+
);
234+
await act(async () => jest.advanceTimersByTime(0));
235+
236+
fireEvent.click(screen.getByText('执行对比'));
237+
await act(async () => jest.advanceTimersByTime(0));
238+
await act(async () => jest.advanceTimersByTime(3000));
239+
240+
fireEvent.mouseEnter(screen.getByText('只看差异'));
241+
242+
await screen.findByText('当前对比结果暂无差异');
243+
});
226244
});

packages/sqle/src/page/DataSourceComparison/ComparisonEntry/index.tsx

+37-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
filterSchemasInDatabase,
1818
filteredWithoutParentNodeKey,
1919
getComparisonResultByNodeKey,
20+
isValidChildNodeKey,
2021
parseTreeNodeKey
2122
} from './utils/TreeNode';
2223
import {
@@ -143,7 +144,9 @@ const ComparisonEntry: React.FC = () => {
143144
keys: []
144145
};
145146
}
146-
acc[key].keys.push(curr.key);
147+
if (isValidChildNodeKey(curr.key)) {
148+
acc[key].keys.push(curr.key);
149+
}
147150
return acc;
148151
},
149152
{} as Record<
@@ -235,6 +238,13 @@ const ComparisonEntry: React.FC = () => {
235238
generateModifiedSqlInfoApi();
236239
}
237240
};
241+
242+
const noDifferencesFound = useMemo(() => {
243+
return filteredComparisonResultsWithoutSame.every(
244+
(item) => item.comparison_result === SchemaObjectComparisonResultEnum.same
245+
);
246+
}, [filteredComparisonResultsWithoutSame]);
247+
238248
return (
239249
<ComparisonEntryStyleWrapper>
240250
{messageContextHolder}
@@ -266,15 +276,32 @@ const ComparisonEntry: React.FC = () => {
266276
}
267277
>
268278
<ComparisonActionStyleWrapper size={12}>
269-
<ToggleButtonStyleWrapper
270-
active={showDifferencesOnly}
271-
onClick={() => {
272-
toggleShowDifferencesOnly();
273-
setCheckedObjectNodeKeys([]);
274-
}}
275-
>
276-
{t('dataSourceComparison.entry.showDifferencesOnly')}
277-
</ToggleButtonStyleWrapper>
279+
{noDifferencesFound ? (
280+
<BasicToolTip
281+
title={t('dataSourceComparison.entry.noDifferencesFound')}
282+
>
283+
<ToggleButtonStyleWrapper
284+
disabled={true}
285+
active={showDifferencesOnly}
286+
onClick={() => {
287+
toggleShowDifferencesOnly();
288+
setCheckedObjectNodeKeys([]);
289+
}}
290+
>
291+
{t('dataSourceComparison.entry.showDifferencesOnly')}
292+
</ToggleButtonStyleWrapper>
293+
</BasicToolTip>
294+
) : (
295+
<ToggleButtonStyleWrapper
296+
active={showDifferencesOnly}
297+
onClick={() => {
298+
toggleShowDifferencesOnly();
299+
setCheckedObjectNodeKeys([]);
300+
}}
301+
>
302+
{t('dataSourceComparison.entry.showDifferencesOnly')}
303+
</ToggleButtonStyleWrapper>
304+
)}
278305

279306
{/* <BasicButton disabled={executeComparisonPending}>
280307
{t('dataSourceComparison.entry.modifyMappings')}

packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export const generateTreeNodeKey = (...args: string[]) => {
9191
return args.join(TREE_NODE_KEY_SEPARATOR);
9292
};
9393

94+
export const isValidChildNodeKey = (key: string) => {
95+
return key.split(TREE_NODE_KEY_SEPARATOR).length === 3;
96+
};
97+
9498
export const parseTreeNodeKey = (
9599
key: string,
96100
comparisonResults: ISchemaObject[]
@@ -109,6 +113,7 @@ export const parseTreeNodeKey = (
109113
}
110114

111115
const [index, objectType, objectName] = key.split(TREE_NODE_KEY_SEPARATOR);
116+
112117
return {
113118
baselineSchemaName: getComparisonResultSchemaName(
114119
comparisonResults[Number(index)],

0 commit comments

Comments
 (0)