Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore]:(DataSourceComparison) Optimize code and ui #484

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
getDetailParams: IGetComparisonStatementV1Params;
genModifiedSqlParams: IGenDatabaseDiffModifySQLsV1Params;
comparisonResult: ObjectDiffResultComparisonResultEnum;
selectedBaselineInstanceType: string;
selectedBaselineInstanceInfo?: SelectedInstanceInfo;
selectComparisonInstanceInfo?: SelectedInstanceInfo;
};

Expand All @@ -44,98 +44,98 @@
modified = 'modified'
}

const ComparisonDetailDrawer: React.FC<Props> = ({
open,
onClose,
getDetailParams,
genModifiedSqlParams,
comparisonResult,
selectedBaselineInstanceType,
selectedBaselineInstanceInfo,
selectComparisonInstanceInfo
}) => {
const { t } = useTranslation();
const [messageApi, messageContextHolder] = message.useMessage();
const { loading: getDetailPending, data: comparisonDetail } = useRequest(
() =>
databaseCompareService
.getComparisonStatementV1(getDetailParams)
.then((res) => res.data.data),
{
ready: open
}
);

const [tableDDLAuditResultActiveKey, setTableDDLAuditResultActiveKey] =
useState<CollapseItemKeyEnum[]>([]);

const [modifiedSqlAuditResultActiveKey, setModifiedSqlAuditResultActiveKey] =
useState<CollapseItemKeyEnum[]>([]);

const {
createWorkflowAction,
createWorkflowPermission,
createWorkflowPending
} = useGenerateModifiedSqlWorkflow(
selectComparisonInstanceInfo?.instanceId ?? '',
selectComparisonInstanceInfo?.instanceName ?? ''
);

const {
loading: generateModifiedSqlPending,
data: modifiedSqlResult,
runAsync: genModifiedSqlAsyncApi
} = useRequest(
() =>
databaseCompareService
.genDatabaseDiffModifySQLsV1(genModifiedSqlParams)
.then((res) => res.data.data),
{
manual: true
}
);

const modifiedSqls = useMemo(() => {
return (
modifiedSqlResult?.[0]?.modify_sqls
?.map((v) => v.sql_statement)
?.join('\n') ?? ''
);
}, [modifiedSqlResult]);

const modifiedSqlAuditResults = useMemo(() => {
return (
modifiedSqlResult?.[0].modify_sqls?.flatMap(
(v) => v.audit_results ?? []
) ?? []
);
}, [modifiedSqlResult]);

const {
auditResultRuleInfo: baselineSqlAuditResultRuleInfo,
loading: getBaselineSqlAuditResultRuleInfoPending
} = useAuditResultRuleInfo(
comparisonDetail?.base_sql?.audit_results ?? [],
selectedBaselineInstanceType,
selectedBaselineInstanceInfo?.instanceType,
tableDDLAuditResultActiveKey.includes(CollapseItemKeyEnum.baseline)
);

Check warning on line 120 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ComparisonTreeNode/ComparisonDetailDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const {
auditResultRuleInfo: comparisonSqlAuditResultRuleInfo,
loading: getComparisonSqlAuditResultRuleInfoPending
} = useAuditResultRuleInfo(
comparisonDetail?.comparison_sql?.audit_results ?? [],
selectedBaselineInstanceType,
selectComparisonInstanceInfo?.instanceType,
tableDDLAuditResultActiveKey.includes(CollapseItemKeyEnum.comparison)
);

Check warning on line 129 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ComparisonTreeNode/ComparisonDetailDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const {
auditResultRuleInfo: modifiedSqlAuditResultRuleInfo,
loading: getModifiedSqlRulePending
} = useAuditResultRuleInfo(
modifiedSqlAuditResults,
selectedBaselineInstanceType,
selectComparisonInstanceInfo?.instanceType,
modifiedSqlAuditResultActiveKey.includes(CollapseItemKeyEnum.modified)
);

Check warning on line 138 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ComparisonTreeNode/ComparisonDetailDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const auditResultCollapseItems: CollapseProps['items'] = useMemo(() => {
const items: CollapseProps['items'] = [];
Expand Down Expand Up @@ -210,26 +210,22 @@
);
};

return (
<BasicDrawer
title={t('dataSourceComparison.entry.comparisonDetail.title')}
open={open}
onClose={onClose}
width={920}
maskClosable
footer={
<EmptyBox if={!!modifiedSqlResult}>
<Space size={12}>
<EmptyBox if={createWorkflowPermission}>
<BasicButton
loading={createWorkflowPending}
type="primary"
onClick={() => {
createWorkflowAction(
modifiedSqls,
modifiedSqlResult?.map((item) => item.schema_name ?? '') ??
[]
);
createWorkflowAction(modifiedSqls);

Check warning on line 228 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ComparisonTreeNode/ComparisonDetailDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}}
>
{t(
Expand Down Expand Up @@ -298,6 +294,7 @@
<Typography.Title level={4}>
{t('dataSourceComparison.entry.comparisonDetail.ddlDiff')}
</Typography.Title>

<SQLRenderer.DiffViewOnlyEditor
originalSql={comparisonDetail?.base_sql?.sql_statement}
modifiedSql={comparisonDetail?.comparison_sql?.sql_statement}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { styled } from '@mui/material/styles';
import { Collapse } from 'antd';

export const ComparisonDetailContentStyleWrapper = styled('div')`
height: 100%;
`;

export const DiffSQLEditorWrapperStyleWrapper = styled('div')`
margin-bottom: 24px;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,116 +24,114 @@
showDifferencesOnly: boolean;
};

const ComparisonTreeNode: React.FC<Props> = ({
comparisonResults,
selectedBaselineInstanceInfo,
selectedComparisonInstanceInfo,
comparisonObjectTreeOnCheck,
comparisonObjectCheckKeys,
showDifferencesOnly
}) => {
const isFirstRenderTreeNode = useRef(true);

const {
assemblingBaselineTreeData,
assemblingComparisonTreeData,
selectedObjectNodeKey,
resetStateAndCloseComparisonDetailDrawer,
comparisonDetailDrawerOpen,
generateGetComparisonDetailParams,
generateModifiedSqlParams,
treeExpandedKeys,
setTreeExpandedKeys
} = useComparisonResultTree(comparisonResults, showDifferencesOnly);

const baselineTreeData = useMemo(() => {
if (!selectedBaselineInstanceInfo) {
return [];
}
return assemblingBaselineTreeData(
selectedBaselineInstanceInfo.instanceName
);
}, [assemblingBaselineTreeData, selectedBaselineInstanceInfo]);

const comparisonTreeData = useMemo(() => {
if (!selectedComparisonInstanceInfo) {
return [];
}
return assemblingComparisonTreeData(
selectedComparisonInstanceInfo.instanceName
);
}, [assemblingComparisonTreeData, selectedComparisonInstanceInfo]);

useEffect(() => {
if (isFirstRenderTreeNode.current) {
setTreeExpandedKeys(generateTreeDefaultExpandedKeys(baselineTreeData));
isFirstRenderTreeNode.current = false;
}
}, [baselineTreeData, setTreeExpandedKeys]);

return (
<ComparisonTreeContainerStyleWrapper>
<ComparisonTreeItemStyleWrapper>
<Tree
expandedKeys={treeExpandedKeys}
onExpand={setTreeExpandedKeys}
switcherIcon={({ expanded }: AntTreeNodeProps) => {
if (expanded) {
return <DownOutlined color="currentColor" />;
}
return <RightOutlined />;
}}
treeData={baselineTreeData}
/>
</ComparisonTreeItemStyleWrapper>
<ComparisonTreeItemStyleWrapper>
<Tree
checkable
expandedKeys={treeExpandedKeys}
onExpand={setTreeExpandedKeys}
checkedKeys={comparisonObjectCheckKeys}
onCheck={(checkedKeys) => {
comparisonObjectTreeOnCheck(checkedKeys as string[]);
}}
switcherIcon={({ expanded }: AntTreeNodeProps) => {
if (expanded) {
return <DownOutlined color="currentColor" />;
}
return <RightOutlined />;
}}
treeData={comparisonTreeData}
/>
</ComparisonTreeItemStyleWrapper>

{!!selectedObjectNodeKey ? (
<ComparisonDetailDrawer
open={comparisonDetailDrawerOpen}
onClose={resetStateAndCloseComparisonDetailDrawer}
comparisonResult={
getComparisonResultByNodeKey(
comparisonResults,
selectedObjectNodeKey
)!
}
selectedBaselineInstanceType={
selectedBaselineInstanceInfo?.instanceType ?? ''
}
selectedBaselineInstanceInfo={selectedBaselineInstanceInfo}
selectComparisonInstanceInfo={selectedComparisonInstanceInfo}
getDetailParams={generateGetComparisonDetailParams(
selectedObjectNodeKey,
selectedBaselineInstanceInfo?.instanceId,
selectedComparisonInstanceInfo?.instanceId,
selectedBaselineInstanceInfo?.schemaName,
selectedComparisonInstanceInfo?.schemaName
)}
genModifiedSqlParams={generateModifiedSqlParams(
selectedObjectNodeKey,
selectedBaselineInstanceInfo?.instanceId,
selectedComparisonInstanceInfo?.instanceId,
selectedBaselineInstanceInfo?.schemaName,
selectedComparisonInstanceInfo?.schemaName
)}
/>

Check warning on line 134 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ComparisonTreeNode/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
) : null}
</ComparisonTreeContainerStyleWrapper>
);

Check warning on line 137 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ComparisonTreeNode/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,103 +32,100 @@
comparisonInstanceInfo?: SelectedInstanceInfo;
};

const ModifiedSqlDrawer: React.FC<Props> = ({
open,
databaseDiffModifiedSqlInfos,
generateModifySqlPending,
instanceType,
onClose,
comparisonInstanceInfo
}) => {
const { t } = useTranslation();

const auditResultMap = useMemo(() => {
return databaseDiffModifiedSqlInfos?.reduce<AuditResultMap>((acc, cur) => {
return {
...acc,
[cur.schema_name!]: cur.modify_sqls?.flatMap(
(v) => v.audit_results ?? []
) as IAuditResult[]
};
}, {});
}, [databaseDiffModifiedSqlInfos]);

const { auditResultRuleInfoMap, loading: getAuditResultsRuleInfoPending } =
useAuditResultMapRuleInfo(auditResultMap, instanceType);

const renderModifiedSqlInfo = (
databaseDiffModifiedSqlInfo: IDatabaseDiffModifySQL
) => {
return (
<ModifiedSqlStyleWrapper key={databaseDiffModifiedSqlInfo.schema_name}>
<Typography.Title level={4}>
{t('dataSourceComparison.entry.comparisonDetail.modifySqlInfo', {
schema: `SCHEMA-${databaseDiffModifiedSqlInfo.schema_name}-`
})}
</Typography.Title>
<SQLRenderer.ViewOnlyEditor
className="sql-audit-report-content"
value={
databaseDiffModifiedSqlInfo?.modify_sqls
?.map((v) => v.sql_statement)
?.join('\n') ?? ''
}
height={300}
/>

<SqlAuditResultCollapseStyleWrapper
items={[
{
key: databaseDiffModifiedSqlInfo.schema_name,
label: t(
'dataSourceComparison.entry.comparisonDetail.modifiedSqlAuditResultTitle'
),
children: (
<AuditResult
results={
auditResultRuleInfoMap[
databaseDiffModifiedSqlInfo.schema_name!
] ?? []
}
/>
)
}
]}
/>
</ModifiedSqlStyleWrapper>
);
};

const {
createWorkflowAction,
createWorkflowPermission,
createWorkflowPending
} = useGenerateModifiedSqlWorkflow(
comparisonInstanceInfo?.instanceId ?? '',
comparisonInstanceInfo?.instanceName ?? ''
);

return (
<BasicDrawer
open={open}
onClose={onClose}
size="large"
title={t('dataSourceComparison.entry.modifiedSqlDrawer.title')}
extra={
<EmptyBox if={createWorkflowPermission}>
<BasicButton
loading={createWorkflowPending}
type="primary"
onClick={() => {
createWorkflowAction(
databaseDiffModifiedSqlInfos
?.map((info) =>
info.modify_sqls?.map((v) => v.sql_statement).join('\n')
)
.join('\n') ?? '',
databaseDiffModifiedSqlInfos?.map(
(info) => info.schema_name!
) ?? []
.join('\n') ?? ''

Check warning on line 128 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ModifiedSqlDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 128 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ModifiedSqlDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
);

Check warning on line 129 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/component/ModifiedSqlDrawer/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,30 @@
} from '@actiontech/shared/lib/global';
import { compressToEncodedURIComponent } from 'lz-string';
import { useEffect } from 'react';
import useInstanceSchema from '../../../../hooks/useInstanceSchema';

const useGenerateModifiedSqlWorkflow = (
instanceId: string,
instanceName: string
) => {
const { projectID, projectName } = useCurrentProject();
const { projectID } = useCurrentProject();

Check warning on line 14 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/hooks/useGenerateModifiedSqlWorkflow.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const {
isHaveServicePermission,
updateUserOperationPermission,
loading: getUserOperationPermissionPending
} = useUserOperationPermission();
const { schemaList, loading: getSchemaListPending } = useInstanceSchema(
projectName,
instanceName
);

const createWorkflowPermission = isHaveServicePermission(
OpPermissionItemOpPermissionTypeEnum.create_workflow,
instanceId
);

const createWorkflowAction = (sql: string, schemaNames: string[]) => {
const createWorkflowAction = (sql: string) => {

Check warning on line 26 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/hooks/useGenerateModifiedSqlWorkflow.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const compressionData = compressToEncodedURIComponent(
JSON.stringify({
sql,
instanceName,
schema: schemaNames.filter((schema) => schemaList.includes(schema))
instanceName
})
);

Check warning on line 32 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/hooks/useGenerateModifiedSqlWorkflow.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
window.open(
`/sqle/project/${projectID}/exec-workflow/create?from=${TRANSIT_FROM_CONSTANT.data_source_comparison}&compression_data=${compressionData}`
);
Expand All @@ -45,12 +39,11 @@
updateUserOperationPermission();
}, [updateUserOperationPermission]);

return {
createWorkflowAction,
createWorkflowPermission,
createWorkflowPending:
getSchemaListPending || getUserOperationPermissionPending
createWorkflowPending: getUserOperationPermissionPending
};

Check warning on line 46 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/hooks/useGenerateModifiedSqlWorkflow.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 47 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/hooks/useGenerateModifiedSqlWorkflow.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

export default useGenerateModifiedSqlWorkflow;
Original file line number Diff line number Diff line change
Expand Up @@ -26,221 +26,214 @@
import ModifiedSqlDrawer from './component/ModifiedSqlDrawer';
import { useState } from 'react';

const ComparisonEntry: React.FC = () => {
const { t } = useTranslation();
const { projectName } = useCurrentProject();
const [messageApi, messageContextHolder] = message.useMessage();

const [form] = Form.useForm<DatabaseComparisonFromFields>();

const [showDifferencesOnly, { toggle: toggleShowDifferencesOnly }] =
useToggle(false);

const baselineInstance = Form.useWatch('baselineInstance', form);
const comparisonInstance = Form.useWatch('comparisonInstance', form);

const [
modifiedSqlDrawerOpen,
{ setTrue: openModifiedSqlDrawer, setFalse: closeOpenModifiedSqlDrawer }
] = useBoolean();

const [checkedObjectNodeKeys, setCheckObjectNodeKeys] = useState<string[]>(
[]
);

const {
parse2DatabaseCompareObject,
getInstanceInfoBySelectedValue,
...otherHookValues
} = useDataSourceSelectorTree();

const {
data: comparisonResults,
run: executeComparisonApi,
loading: executeComparisonPending,
mutate: updateComparisonResult
} = useRequest(
(baseLineValue: string, comparisonValue: string) =>
databaseCompareService
.executeDatabaseComparisonV1({
project_name: projectName,
base_db_object: parse2DatabaseCompareObject(baseLineValue),
comparison_db_object: parse2DatabaseCompareObject(comparisonValue)
})
.then((res) => res.data.data),
{
manual: true
}
);

const {
loading: generateModifySqlPending,
data: databaseDiffModifiedSqlInfos,
run: generateModifiedSqlInfoApi,
mutate: updateModifiedSqlInfos
} = useRequest(
() => {
return databaseCompareService
.genDatabaseDiffModifySQLsV1({
project_name: projectName,
base_instance_id: selectedBaselineInstanceInfo?.instanceId,
comparison_instance_id: selectedComparisonInstanceInfo?.instanceId,
database_schema_objects: (() => {
const parseResults = filteredWithoutSchemaNameNodeKey(
checkedObjectNodeKeys
).map((key) => {
const { comparisonSchemaName, baselineSchemaName } =
parseTreeNodeKey(key, comparisonResults ?? []);
return {
base_schema_name:
selectedBaselineInstanceInfo?.schemaName ??
baselineSchemaName,
comparison_schema_name:
selectedComparisonInstanceInfo?.schemaName ??
comparisonSchemaName,
key
};
});

const groupedResults = parseResults.reduce(
(acc, curr) => {
const key = `${curr.base_schema_name}_${curr.comparison_schema_name}`;
if (!acc[key]) {
acc[key] = {
base_schema_name: curr.base_schema_name!,
comparison_schema_name: curr.comparison_schema_name!,
keys: []
};
}
acc[key].keys.push(curr.key);
return acc;
},
{} as Record<
string,
{
base_schema_name: string;
comparison_schema_name: string;
keys: string[];
}
>
);

return Object.values(groupedResults).map(
({ base_schema_name, comparison_schema_name, keys }) => ({
base_schema_name,
comparison_schema_name,
database_objects: keys.map((key) => {
const parseNodeKeyResult = parseTreeNodeKey(
key,
comparisonResults ?? []
);
return {
object_name: parseNodeKeyResult.objectName,
object_type:
parseNodeKeyResult.objectType as DatabaseObjectObjectTypeEnum
};
})
})
);
})()
})
.then((res) => res.data.data);
},
{
manual: true
}
);

const executeComparison = async () => {
const values = await form.validateFields();
setCheckObjectNodeKeys([]);
executeComparisonApi(values.baselineInstance, values.comparisonInstance);
};

const onCloseModifiedSqlDrawer = () => {
updateModifiedSqlInfos(undefined);
closeOpenModifiedSqlDrawer();
};

const generateModifiedSqlEvent = () => {
const comparisonResultsWithCheckNodeKeys = filteredWithoutSchemaNameNodeKey(
checkedObjectNodeKeys
).map((key) => getComparisonResultByNodeKey(comparisonResults ?? [], key));
if (
comparisonResultsWithCheckNodeKeys.includes(
ObjectDiffResultComparisonResultEnum.same
)
) {
messageApi.error(t('dataSourceComparison.entry.generateSQLErrorTips'));
return;
}

openModifiedSqlDrawer();
generateModifiedSqlInfoApi();
};

const selectedBaselineInstanceInfo =
getInstanceInfoBySelectedValue(baselineInstance);
const selectedComparisonInstanceInfo =
getInstanceInfoBySelectedValue(comparisonInstance);

return (
<ComparisonEntryStyleWrapper>
{messageContextHolder}
<ComparisonSelectorFormStyleWrapper form={form}>
<EnvironmentSelector
{...otherHookValues}
updateComparisonResult={updateComparisonResult}
executeComparisonPending={executeComparisonPending}
/>
</ComparisonSelectorFormStyleWrapper>

<BasicButton
size="large"
className="full-width-element"
type="primary"
onClick={executeComparison}
disabled={executeComparisonPending}
loading={executeComparisonPending}
>
{t('dataSourceComparison.entry.executeComparison')}
</BasicButton>

<EmptyBox
if={!!comparisonResults && !!baselineInstance && !!comparisonInstance}
>
<ComparisonActionStyleWrapper size={12}>
<ToggleButtonStyleWrapper
disabled={executeComparisonPending}
active={showDifferencesOnly}
onClick={() => {
if (!executeComparisonPending) {
toggleShowDifferencesOnly();
}
}}
onClick={toggleShowDifferencesOnly}
>
{t('dataSourceComparison.entry.showDifferencesOnly')}
</ToggleButtonStyleWrapper>

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

{checkedObjectNodeKeys.length === 0 ? (
{filteredWithoutSchemaNameNodeKey(checkedObjectNodeKeys).length ===
0 ? (
<BasicToolTips
title={t('dataSourceComparison.entry.generateSQLDisabledTips')}
>
<BasicButton disabled={true}>
{t('dataSourceComparison.entry.generateSQL')}
</BasicButton>
</BasicToolTips>
) : (
<BasicButton
onClick={generateModifiedSqlEvent}
disabled={executeComparisonPending}
>
<BasicButton onClick={generateModifiedSqlEvent}>
{t('dataSourceComparison.entry.generateSQL')}
</BasicButton>

Check warning on line 236 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
)}
</ComparisonActionStyleWrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,59 @@
return <FolderFilled width={18} height={18} />;
};

export const renderComparisonResultObjectName = (
result: ObjectDiffResultComparisonResultEnum,
objectName: string,
source: 'baseline' | 'comparison'
) => {
if (source === 'baseline') {
if (result === ObjectDiffResultComparisonResultEnum.base_not_exist) {
return null;
}
return <span className="content">{objectName}</span>;
}

if (source === 'comparison') {
if (result === ObjectDiffResultComparisonResultEnum.same) {
return (
<>
<span title={objectName} className="content">
{objectName}
</span>
<CheckCircleFilled />
</>
);
}

if (result === ObjectDiffResultComparisonResultEnum.inconsistent) {
return (
<>
<span title={objectName} className="content">
{objectName}
</span>
<CloseCircleFilled />
</>
);
}

if (result === ObjectDiffResultComparisonResultEnum.base_not_exist) {
return (
<>
<span title={objectName} className="content">
{objectName}
</span>
<CloseCircleFilled />
</>
);
}

if (result === ObjectDiffResultComparisonResultEnum.comparison_not_exist) {
return <CloseCircleFilled />;
return (
<>
<span className="content"></span>
<CloseCircleFilled />
</>
);

Check warning on line 86 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 87 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 87 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 88 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 88 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
};

Check warning on line 89 in packages/sqle/src/page/DataSourceComparison/ComparisonEntry/utils/TreeNode.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,45 +128,26 @@ const DatabaseSelectionItem: React.FC<DatabaseSelectionItemProps> = ({
// 存在即使压缩后的字符长度依旧超出浏览器地址栏的长度限制,导致解压缩失败的场景。
const { instanceName, schema, sql } = jsonParse<{
instanceName: string;
schema: string | string[];
schema?: string;
sql: string;
}>(decompressFromEncodedURIComponent(compressionData));

const schemaNames: string[] = [];
if (Array.isArray(schema)) {
schemaNames.push(...schema);
} else {
schemaNames.push(schema);
}

handleInstanceNameChange?.(instanceName);

if (schemaNames.length === 0) {
form.setFieldsValue({
databaseInfo: [
{
instanceName
}
],
[SAME_SQL_MODE_DEFAULT_FIELD_KEY]: {
form_data: sql
} as SqlStatementFields
});
handleInstanceChange(SAME_SQL_MODE_DEFAULT_FIELD_KEY, instanceName);
} else {
form.setFieldsValue({
databaseInfo: schemaNames.map((item) => ({
form.setFieldsValue({
databaseInfo: [
{
instanceName,
instanceSchema: item
})),
[SAME_SQL_MODE_DEFAULT_FIELD_KEY]: {
form_data: sql
} as SqlStatementFields
});
schemaNames.forEach((item, index) => {
handleInstanceChange(index.toString(), instanceName);
handleInstanceSchemaChange(index.toString(), item);
});
instanceSchema: schema
}
],
[SAME_SQL_MODE_DEFAULT_FIELD_KEY]: {
form_data: sql
} as SqlStatementFields
});
handleInstanceChange(SAME_SQL_MODE_DEFAULT_FIELD_KEY, instanceName);
if (schema) {
handleInstanceSchemaChange(SAME_SQL_MODE_DEFAULT_FIELD_KEY, schema);
}
} catch (error) {
// eslint-disable-next-line no-console
Expand Down
Loading