Skip to content

Commit 467fade

Browse files
authored
fix(filterrules): support i18n (#625)
* fix(filterrules): support i18n * test(filterrules): fix unit test
1 parent 44fb69f commit 467fade

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

src/filterRules/__tests__/filterRules.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const MyInput = ({ rowValues: { input }, rowKey, onChange }: IComponentProps<IRo
1010
<Input value={input} onChange={(e) => onChange?.(rowKey, { input: e.target.value })} />
1111
);
1212

13+
jest.mock('remark-gfm', () => () => {});
1314
describe('FilterRules', () => {
1415
test('should support FilterRules success render', () => {
1516
const wrapper = render(

src/filterRules/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ export enum ROW_PERMISSION_RELATION {
1111
AND = 1,
1212
OR = 2,
1313
}
14-
export const ROW_PERMISSION_RELATION_TEXT = {
15-
[ROW_PERMISSION_RELATION.AND]: '且',
16-
[ROW_PERMISSION_RELATION.OR]: '或',
17-
};
1814

1915
export interface IComponentProps<T> {
2016
rowKey: string; // 当前节点的唯一标识

src/filterRules/ruleController/index.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ import { MinusCircleOutlined, PlusCircleOutlined } from '@dtinsight/react-icons'
33
import { InternalNamePath } from 'antd/lib/form/interface';
44
import classnames from 'classnames';
55

6-
import {
7-
IComponentProps,
8-
IFilterValue,
9-
ROW_PERMISSION_RELATION,
10-
ROW_PERMISSION_RELATION_TEXT,
11-
} from '..';
6+
import useLocale from '../../locale/useLocale';
7+
import { IComponentProps, IFilterValue, ROW_PERMISSION_RELATION } from '..';
128
import './index.scss';
139

1410
interface IProps<T> {
@@ -46,6 +42,13 @@ export const RulesController = <T,>(props: IProps<T>) => {
4642
onChangeRowValues,
4743
} = props;
4844

45+
const locale = useLocale('FilterRules');
46+
47+
const ROW_PERMISSION_RELATION_TEXT = {
48+
[ROW_PERMISSION_RELATION.AND]: locale.and,
49+
[ROW_PERMISSION_RELATION.OR]: locale.or,
50+
};
51+
4952
const isCondition = (item: IFilterValue<T>) =>
5053
item?.type &&
5154
[ROW_PERMISSION_RELATION.AND, ROW_PERMISSION_RELATION.OR].includes(item?.type);

src/locale/en-US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const localeValues: Locale = {
2727
},
2828
FilterRules: {
2929
message: 'Must have one data item',
30+
and: 'And',
31+
or: 'Or',
3032
},
3133
Fullscreen: {
3234
exitFull: 'Exit Full Screen',

src/locale/useLocale.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface Locale {
2121
};
2222
FilterRules: {
2323
message: string;
24+
and: string;
25+
or: string;
2426
};
2527
Fullscreen: { exitFull: string; full: string };
2628
GlobalLoading: { loading: string };

src/locale/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const localeValues: Locale = {
2828
},
2929
FilterRules: {
3030
message: '必须有一条数据',
31+
and: '且',
32+
or: '或',
3133
},
3234
Fullscreen: {
3335
exitFull: '退出全屏',

0 commit comments

Comments
 (0)