Skip to content

Commit 2d5c8cf

Browse files
committed
[fix]: Username supports non leading and trailing spaces
1 parent 39d512a commit 2d5c8cf

File tree

16 files changed

+68
-25
lines changed

16 files changed

+68
-25
lines changed

packages/base/src/hooks/useMemberTips/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const useMemberTips = () => {
3535
key={member.user_id}
3636
value={member.user_id ?? ''}
3737
label={member.user_name}
38+
className="select-option-whitespace-pre"
3839
>
3940
{member.user_name}
4041
</Select.Option>
@@ -47,7 +48,9 @@ const useMemberTips = () => {
4748
label: (
4849
<Space>
4950
<CustomAvatar noTips size="small" name={member.user_name} />
50-
<Typography.Text>{member.user_name}</Typography.Text>
51+
<Typography.Text className="whitespace-pre">
52+
{member.user_name}
53+
</Typography.Text>
5154
</Space>
5255
),
5356
value: member.user_id

packages/base/src/hooks/useUsername/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ const useUsername = () => {
3232
const generateUsernameSelectOption = React.useCallback(() => {
3333
return usernameList.map((user) => {
3434
return (
35-
<Select.Option key={user.uid} value={user.uid ?? ''} label={user.name}>
35+
<Select.Option
36+
key={user.uid}
37+
value={user.uid ?? ''}
38+
label={user.name}
39+
className="select-option-whitespace-pre"
40+
>
3641
{user.name}
3742
</Select.Option>
3843
);

packages/base/src/locale/zh-CN/dmsUserCenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
},
2020
userForm: {
2121
username: '用户名',
22-
usernameNoSpaces: '用户名不支持空格',
22+
usernameNoSpaces: '用户名不支持首尾空格',
2323
needUpdatePassWord: '是否需要更新密码',
2424
passwordConfirm: '确认密码',
2525
passwordConfirmPlaceholder: '请保持两次密码输入一致',

packages/base/src/page/Account/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const Account: React.FC = () => {
4747
{t('dmsUserCenter.user.userForm.username')}
4848
</LabelContent>
4949
}
50-
descNode={!!userInfo?.name ? userInfo?.name : '-'}
50+
descNode={
51+
<span className="whitespace-pre">
52+
{!!userInfo?.name ? userInfo?.name : '-'}
53+
</span>
54+
}
5155
fieldVisible={false}
5256
needEditButton={false}
5357
/>

packages/base/src/page/Member/List/column.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const MemberListColumns: ActiontechTableColumn<IListMember> = [
1515
dataIndex: 'user',
1616
title: t('common.username'),
1717
width: '10%',
18+
className: 'whitespace-pre',
1819
render: (user) => {
1920
return user?.name ?? '-';
2021
}
@@ -116,7 +117,7 @@ export const MemberGroupListColumns: ActiontechTableColumn<IListMemberGroup> = [
116117
return null;
117118
}
118119
return (
119-
<Typography.Text ellipsis={true}>
120+
<Typography.Text ellipsis={true} className="whitespace-pre">
120121
{users.map((v) => v.name).join('、')}
121122
</Typography.Text>
122123
);

packages/base/src/page/Nav/SideMenu/UserMenu/components/UserNavigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ const UserNavigate: React.FC<Props> = ({
219219
placement: 'topRight'
220220
}}
221221
items={menus}
222-
header={username}
222+
header={<span className="whitespace-pre">{username}</span>}
223223
>
224224
<CustomAvatarStyleWrapper className="action-avatar">
225225
{username?.[0]?.toUpperCase()}

packages/base/src/page/UserCenter/Drawer/User/UserForm/index.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IUserFormProps } from './index.type';
22
import { Form, Switch } from 'antd';
3+
import type { Rule } from 'antd/es/form';
34
import { BasicInput, BasicSelect, EmptyBox } from '@actiontech/dms-kit';
45
import React, { useEffect } from 'react';
56
import { useTranslation } from 'react-i18next';
@@ -14,6 +15,27 @@ const UserForm: React.FC<IUserFormProps> = (props) => {
1415
opPermissionOptions,
1516
updateOpPermissionList
1617
} = useOpPermission();
18+
19+
const getUsernameRules = (): Rule[] => {
20+
const rules: Rule[] = [
21+
{
22+
required: true,
23+
message: t('common.form.rule.require', {
24+
name: t('dmsUserCenter.user.userForm.username')
25+
})
26+
}
27+
];
28+
29+
if (!props.isUpdate) {
30+
rules.push({
31+
pattern: /^\S(.*\S)?$/,
32+
message: t('dmsUserCenter.user.userForm.usernameNoSpaces')
33+
});
34+
}
35+
36+
return rules;
37+
};
38+
1739
useEffect(() => {
1840
if (props.visible) {
1941
updateOpPermissionList(ListOpPermissionsFilterByTargetEnum.user);
@@ -25,18 +47,7 @@ const UserForm: React.FC<IUserFormProps> = (props) => {
2547
name="username"
2648
label={t('dmsUserCenter.user.userForm.username')}
2749
validateFirst={true}
28-
rules={[
29-
{
30-
required: true,
31-
message: t('common.form.rule.require', {
32-
name: t('dmsUserCenter.user.userForm.username')
33-
})
34-
},
35-
{
36-
pattern: /^\S*$/,
37-
message: t('dmsUserCenter.user.userForm.usernameNoSpaces')
38-
}
39-
]}
50+
rules={getUsernameRules()}
4051
>
4152
<BasicInput
4253
disabled={props.isUpdate}

packages/base/src/page/UserCenter/components/UserList/column.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const UserListColumns: () => ActiontechTableColumn = () => [
2525
},
2626
{
2727
dataIndex: 'name',
28-
title: () => t('common.username')
28+
title: () => t('common.username'),
29+
className: 'whitespace-pre'
2930
},
3031
{
3132
dataIndex: 'email',

packages/dms-kit/docs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ nav:
2626
- **Demo 示例规范化**
2727
- 添加必要的注释说明,特别是复杂配置和特殊处理
2828
- 代码保持简洁,移除冗余配置
29+
30+
## 1.0.3
31+
32+
- ConfigItem组件descNode类型由string改为React.ReactNode
33+
- CustomAvatar中Tooltip title改动,用于适配用户名的空格展示
34+
- CustomSelect样式变更,用于适配用户名的空格展示
35+
- BasicSelect样式变更,用于适配用户名的空格展示

packages/dms-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@actiontech/dms-kit",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "DMS Kit - React UI Components Library",
55
"main": "lib/index.js",
66
"module": "es/index.js",

0 commit comments

Comments
 (0)