Skip to content

Commit

Permalink
[feature]: Replace character compression algorithm to support Chinese…
Browse files Browse the repository at this point in the history
… and special characters
  • Loading branch information
LZS911 committed Oct 24, 2024
1 parent a971c5b commit 4ffb815
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 297 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"i18next": "^21.8.14",
"json2md": "^2.0.0",
"lodash": "^4.17.21",
"lz-string": "1.5.0",
"moment": "^2.29.4",
"monaco-editor": "^0.34.1",
"nprogress": "^0.2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/shared/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export { default as Download } from './utils/Download';
export { default as LocalStorageWrapper } from './utils/LocalStorageWrapper';
export { default as EventEmitter } from './utils/EventEmitter';
export { default as HighlightCode } from './utils/HighlightCode';
export * as Compression from './utils/Compression';

export * as FormatterSQL from './utils/FormatterSQL';
export * as Common from './utils/Common';
Expand Down
130 changes: 0 additions & 130 deletions packages/shared/lib/utils/Compression.ts

This file was deleted.

156 changes: 0 additions & 156 deletions packages/shared/lib/utils/__tests__/Compression.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import {
WORKFLOW_VERSION_ID_PATH_KEY
} from '../../../../../../../../../data/common';
import { TRANSIT_FROM_CONSTANT } from '@actiontech/shared/lib/data/common';
import { decompressData } from '@actiontech/shared/lib/utils/Compression';
import { decompressFromEncodedURIComponent } from 'lz-string';
import { mockProjectInfo } from '@actiontech/shared/lib/testUtil/mockHook/data';

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useSelector: jest.fn()
}));

jest.mock('@actiontech/shared/lib/utils/Compression', () => ({
...jest.requireActual('@actiontech/shared/lib/utils/Compression'),
decompressData: jest.fn()
jest.mock('lz-string', () => ({
...jest.requireActual('lz-string'),
decompressFromEncodedURIComponent: jest.fn()
}));

describe('test DatabaseSelectionItems', () => {
Expand Down Expand Up @@ -141,12 +141,14 @@ describe('test DatabaseSelectionItems', () => {
const getInstanceSpy = instance.getInstance();
const getInstanceSchemaSpy = instance.getInstanceSchemas();
const handleInstanceNameChangeSpy = jest.fn();
const decompressDataSpy = decompressData as jest.Mock;
const decompressDataSpy = decompressFromEncodedURIComponent as jest.Mock;
const instanceName = 'mysql-1';
const schema = 'dev';
const sql = 'select * form t1 where id = 1';

decompressDataSpy.mockReturnValue({ instanceName, schema, sql });
decompressDataSpy.mockReturnValue(
JSON.stringify({ instanceName, schema, sql })
);
const { result } = renderHook(() => Form.useForm());
const { container } = superRender(
<Form form={result.current[0]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import { useSelector } from 'react-redux';
import { IReduxState } from '../../../../../../../../store';
import useCreationMode from '../../../../../hooks/useCreationMode';
import { useSearchParams } from 'react-router-dom';
import { decompressData } from '@actiontech/shared/lib/utils/Compression';
import { SAME_SQL_MODE_DEFAULT_FIELD_KEY } from '../../../../../../Common/SqlStatementFormController/SqlStatementFormItem/index.data';
import { TRANSIT_FROM_CONSTANT } from '@actiontech/shared/lib/data/common';
import { decompressFromEncodedURIComponent } from 'lz-string';
import { jsonParse } from '@actiontech/shared/lib/utils/Common';

const DatabaseSelectionItem: React.FC<DatabaseSelectionItemProps> = ({
handleInstanceNameChange,
Expand Down Expand Up @@ -120,11 +121,11 @@ const DatabaseSelectionItem: React.FC<DatabaseSelectionItemProps> = ({
// 处理从 cloud_beaver 跳转至创建工单的情况
if (compressionData && from === TRANSIT_FROM_CONSTANT.cloudbeaver) {
try {
const { instanceName, schema, sql } = decompressData<{
const { instanceName, schema, sql } = jsonParse<{
instanceName: string;
schema: string;
sql: string;
}>(compressionData);
}>(decompressFromEncodedURIComponent(compressionData));

form.setFieldsValue({
databaseInfo: [{ instanceName, instanceSchema: schema }],
Expand Down
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ffb815

Please sign in to comment.