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

Fix/sqle issue 2791 #520

Merged
merged 2 commits into from
Dec 4, 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
31 changes: 10 additions & 21 deletions packages/base/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { StyledEngineProvider, ThemeProvider } from '@mui/system';
import {
EmptyBox,
HeaderProgress,
LocalStorageWrapper,
SpinIndicator,
useTypedNavigate
} from '@actiontech/shared';
Expand Down Expand Up @@ -46,10 +45,9 @@ import usePermission from '@actiontech/shared/lib/global/usePermission/usePermis
import useFetchPermissionData from './hooks/useFetchPermissionData';
import { useDispatch } from 'react-redux';
import { updateModuleFeatureSupport } from './store/permission';
import { compressToBase64 } from 'lz-string';

import './index.less';
import { ROUTE_PATHS } from '@actiontech/shared/lib/data/routePaths';
import useSyncDmsCloudBeaverChannel from './hooks/useSyncDmsCloudBeaverChannel';
import './index.less';

dayjs.extend(updateLocale);
dayjs.updateLocale('zh-cn', {
Expand All @@ -69,7 +67,13 @@ export const Wrapper: React.FC<{ children: ReactNode }> = ({ children }) => {
return;
}
setInitRenderApp(false);
if (!token && !['/login', '/user/bind'].includes(location.pathname)) {
if (
!token &&
!(
location.pathname === ROUTE_PATHS.BASE.LOGIN.index.path ||
location.pathname === ROUTE_PATHS.BASE.USER_BIND.index.path
)
) {
const currentPath = location.pathname;
const currentSearch = location.search;

Expand Down Expand Up @@ -205,22 +209,7 @@ function App() {
i18n.changeLanguage(currentLanguage);
}, [currentLanguage]);

useEffect(() => {
let sqleEdition;
// #if [ee]
sqleEdition = 'ee';
// #elif [ce]
sqleEdition = 'ce';
// #endif
if (sqleEdition !== LocalStorageWrapper.get('DMS_CB_CHANNEL')) {
LocalStorageWrapper.set(
'DMS_CB_CHANNEL',
compressToBase64(
JSON.stringify({ type: 'sqle_edition', data: sqleEdition })
)
);
}
}, []);
useSyncDmsCloudBeaverChannel();

return (
<Wrapper>
Expand Down
25 changes: 25 additions & 0 deletions packages/base/src/hooks/useSyncDmsCloudBeaverChannel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LocalStorageWrapper } from '@actiontech/shared';
import { StorageKey } from '@actiontech/shared/lib/enum';
import { compressToBase64 } from 'lz-string';
import { useEffect } from 'react';

const useSyncDmsCloudBeaverChannel = () => {
useEffect(() => {
let sqleEdition;
// #if [ee]
sqleEdition = 'ee';
// #elif [ce]
sqleEdition = 'ce';
// #endif
if (sqleEdition !== LocalStorageWrapper.get(StorageKey.DMS_CB_CHANNEL)) {
LocalStorageWrapper.set(
StorageKey.DMS_CB_CHANNEL,
compressToBase64(
JSON.stringify({ type: 'sqle_edition', data: sqleEdition })
)
);
}
}, []);
};

export default useSyncDmsCloudBeaverChannel;
2 changes: 1 addition & 1 deletion packages/base/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import enUS from './en-US';
import { TOptions } from 'i18next';
import { LocalStorageWrapper } from '@actiontech/shared';
import { TemplateKeyPath } from '@actiontech/shared/lib/types/common.type';
import { findDuplicateKeys } from '../utils/findDuplicateKeys';
import { DEFAULT_LANGUAGE } from '@actiontech/shared/lib/locale';
import { findDuplicateKeys } from '@actiontech/shared/lib/utils/Common';

// #if [DEV]
const zh_dupKeys = findDuplicateKeys([
Expand Down
27 changes: 9 additions & 18 deletions packages/base/src/page/UserCenter/Modal/User/UserForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Form, Switch } from 'antd';
import { BasicInput, BasicSelect } from '@actiontech/shared';
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Rule } from 'antd/es/form';
import { nameRule, phoneRule } from '@actiontech/shared/lib/utils/FormRule';
import { phoneRule } from '@actiontech/shared/lib/utils/FormRule';
import EmptyBox from '@actiontech/shared/lib/components/EmptyBox';
import { BasicToolTips } from '@actiontech/shared';
import useOpPermission from '../../../../../hooks/useOpPermission';
Expand All @@ -19,21 +18,6 @@ const UserForm: React.FC<IUserFormProps> = (props) => {
updateOpPermissionList
} = useOpPermission();

const userNameRules = (): Rule[] => {
const baseRules = [
{
required: true,
message: t('common.form.rule.require', {
name: t('dmsUserCenter.user.userForm.username')
})
}
];
if (props.isUpdate) {
return baseRules;
}
return [...baseRules, ...nameRule()];
};

useEffect(() => {
if (props.visible) {
updateOpPermissionList(ListOpPermissionsFilterByTargetEnum.user);
Expand All @@ -46,7 +30,14 @@ const UserForm: React.FC<IUserFormProps> = (props) => {
name="username"
label={t('dmsUserCenter.user.userForm.username')}
validateFirst={true}
rules={userNameRules()}
rules={[
{
required: true,
message: t('common.form.rule.require', {
name: t('dmsUserCenter.user.userForm.username')
})
}
]}
>
<BasicInput
disabled={props.isUpdate}
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configureStore } from '@reduxjs/toolkit';
import { baseStoreData } from './base';
import { SQLEStoreData } from 'sqle/src/store';
import { findDuplicateKeys } from '../utils/findDuplicateKeys';
import { findDuplicateKeys } from '@actiontech/shared/lib/utils/Common';

// #if [DEV]
const dupKeys = findDuplicateKeys([baseStoreData, SQLEStoreData]);
Expand Down
19 changes: 0 additions & 19 deletions packages/base/src/utils/findDuplicateKeys.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/base/src/utils/test/findDuplicateKeys.test.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion packages/shared/lib/enum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export enum StorageKey {
Token = 'TOKEN',
DMS_Project_Catch = 'DMS_Project_Catch',
USER_UID = 'DMS_USER_UID',
SHOW_COMPANY_NOTICE = 'SHOW_COMPANY_NOTICE'
SHOW_COMPANY_NOTICE = 'SHOW_COMPANY_NOTICE',
DMS_CB_CHANNEL = 'DMS_CB_CHANNEL'
}

/**
Expand Down
20 changes: 20 additions & 0 deletions packages/shared/lib/utils/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ export const emailValidate = (email: string): boolean => {
return reg.test(email);
};

export const findDuplicateKeys: (objects: Record<string, any>[]) => string[] = (
objects
) => {
const keys = new Map<string, number>();
const duplicates: string[] = [];

objects.forEach((obj) => {
Object.keys(obj).forEach((key) => {
if (!keys.has(key)) {
keys.set(key, 1);
} else if (keys.get(key) === 1) {
duplicates.push(key);
keys.set(key, keys.get(key)! + 1);
}
});
});

return duplicates;
};

export const integerValidate = (value: string): boolean => {
const reg = /^\d+$/;

Expand Down
46 changes: 45 additions & 1 deletion packages/shared/lib/utils/__tests__/Common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
isFileStreamResponse,
getFileFromUploadChangeEvent,
jsonParse,
translateTimeForRequest
translateTimeForRequest,
findDuplicateKeys
} from '../Common';
import { act } from '@testing-library/react';
import 'blob-polyfill';
Expand Down Expand Up @@ -288,4 +289,47 @@ describe('utils/Common', () => {
value: ''
});
});

describe('utils/findDuplicateKeys', () => {
it('render when obj has same key', () => {
const objA = {
a: '1'
};
const objB = {
a: '2',
b: '1'
};
const result = findDuplicateKeys([objA, objB]);
expect(result.length).toBe(1);
expect(result).toEqual(['a']);
});

it('render more obj when obj has same key', () => {
const objA = {
c: '1',
e: {
a: '2'
}
};
const objB = {
a: '2',
b: '1'
};
const result = findDuplicateKeys([objA, objB]);
expect(result.length).toBe(0);
expect(result).toEqual([]);
});

it('render when obj no same key', () => {
const objA = {
a: '1'
};
const objB = {
b: '2'
};
const result = findDuplicateKeys([objA, objB]);
expect(result.length).toBe(0);
expect(result).toEqual([]);
});
});
});
2 changes: 1 addition & 1 deletion packages/sqle/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
Dictionary,
TemplateKeyPath
} from '@actiontech/shared/lib/types/common.type';
import { findDuplicateKeys } from '../../../base/src/utils/findDuplicateKeys';
import { DEFAULT_LANGUAGE } from '@actiontech/shared/lib/locale';
import { findDuplicateKeys } from '@actiontech/shared/lib/utils/Common';

// #if [DEV]
const zh_dupKeys = findDuplicateKeys([
Expand Down
Loading