@antscorp/antsomi-ui 1.3.5-beta.776 → 1.3.5-beta.777
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/atoms/Tag/Tag.d.ts +10 -1
- package/es/components/atoms/Tag/Tag.js +41 -1
- package/es/components/molecules/AddDynamicContent/components/DisplayFormat/DisplayFormat.d.ts +1 -0
- package/es/components/molecules/Select/styled.d.ts +4 -1
- package/es/components/organism/Login/components/VerifyAccount/styled.d.ts +1 -1
- package/es/components/organism/Login/styled.d.ts +1 -1
- package/es/components/template/TemplateListing/Loadable.d.ts +1 -0
- package/es/constants/variables.d.ts +12 -0
- package/es/constants/variables.js +8 -0
- package/es/utils/attribute.js +40 -3
- package/package.json +1 -1
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TagProps } from 'antd';
|
|
1
3
|
import { TagType } from 'antd/lib';
|
|
2
|
-
export
|
|
4
|
+
export interface TagListProps {
|
|
5
|
+
tags: string[];
|
|
6
|
+
tagProps?: TagProps;
|
|
7
|
+
limit?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const Tag: TagType & {
|
|
10
|
+
List: React.FC<TagListProps>;
|
|
11
|
+
};
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable react/no-array-index-key */
|
|
3
|
+
// Libraries
|
|
4
|
+
import { useMemo, useState } from 'react';
|
|
2
5
|
import { Tag as AntdTag } from 'antd';
|
|
3
6
|
import styled from 'styled-components';
|
|
4
7
|
// Icons
|
|
5
8
|
import { CloseIcon } from '../../icons';
|
|
9
|
+
// Components
|
|
10
|
+
import { Flex } from '../Flex';
|
|
11
|
+
import { Button } from '../Button';
|
|
12
|
+
import { Typography } from '../Typography';
|
|
13
|
+
import { SearchPopover } from '../../molecules';
|
|
6
14
|
// Constants
|
|
7
15
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
16
|
+
import { translate, translations } from '@antscorp/antsomi-ui/es/locales';
|
|
17
|
+
// Utils
|
|
18
|
+
import { searchStringQuery } from '@antscorp/antsomi-ui/es/utils';
|
|
19
|
+
import { Scrollbars } from '../Scrollbars';
|
|
20
|
+
const { Text } = Typography;
|
|
8
21
|
const CloseBtn = styled.div `
|
|
9
22
|
display: flex;
|
|
10
23
|
align-items: center;
|
|
@@ -14,9 +27,36 @@ const CloseBtn = styled.div `
|
|
|
14
27
|
background-color: #fff;
|
|
15
28
|
border-radius: 100%;
|
|
16
29
|
`;
|
|
30
|
+
const AllTagsContainer = styled(Flex) `
|
|
31
|
+
padding: 10px;
|
|
32
|
+
`;
|
|
17
33
|
const OriginTag = props => {
|
|
18
34
|
const { closable = false, closeIcon = (_jsx(CloseBtn, { children: _jsx(CloseIcon, { size: 14, color: globalToken?.colorPrimary }) })), ...restOfProps } = props;
|
|
19
35
|
return _jsx(AntdTag, { ...restOfProps, closable: closable, closeIcon: closable ? closeIcon : null });
|
|
20
36
|
};
|
|
37
|
+
const TagList = props => {
|
|
38
|
+
const { tags, tagProps, limit = 2 } = props;
|
|
39
|
+
const [state, setState] = useState({
|
|
40
|
+
open: false,
|
|
41
|
+
searchValue: '',
|
|
42
|
+
selected: [],
|
|
43
|
+
});
|
|
44
|
+
const { searchValue } = state;
|
|
45
|
+
const filteredTags = useMemo(() => tags.filter(tag => searchStringQuery(tag, searchValue)), [tags, searchValue]);
|
|
46
|
+
const renderTags = () => (_jsx(Flex, { align: "center", children: tags.slice(0, limit).map((tag, index) => (_jsx(OriginTag, { ...tagProps, children: _jsx(Text, { ellipsis: { tooltip: true }, children: tag }) }, index))) }));
|
|
47
|
+
const renderAllTags = () => (_jsx(Scrollbars, { autoHeight: true, autoHeightMax: 300, children: _jsx(AllTagsContainer, { gap: "8px 0px", wrap: "wrap", children: filteredTags.map((tag, index) => (_jsx(OriginTag, { ...tagProps, children: _jsx(Text, { ellipsis: { tooltip: true }, children: tag }) }, index))) }) }));
|
|
48
|
+
const renderShowMoreTags = () => {
|
|
49
|
+
if (tags.length > limit) {
|
|
50
|
+
return (_jsx(SearchPopover, { content: renderAllTags(), overlayInnerStyle: { width: 300 }, inputSearchProps: {
|
|
51
|
+
onAfterChange(value) {
|
|
52
|
+
setState(prev => ({ ...prev, searchValue: value }));
|
|
53
|
+
},
|
|
54
|
+
}, children: _jsx(Button, { type: "text", children: translate(translations.viewAll) }) }));
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
return (_jsxs(Flex, { children: [renderTags(), " ", renderShowMoreTags()] }));
|
|
59
|
+
};
|
|
21
60
|
export const Tag = OriginTag;
|
|
22
61
|
Tag.CheckableTag = AntdTag.CheckableTag;
|
|
62
|
+
Tag.List = TagList;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const StyledTag: import("styled-components").StyledComponent<import("antd/lib").TagType & {
|
|
3
|
+
List: import("react").FC<import("../../atoms/Tag/Tag").TagListProps>;
|
|
4
|
+
}, any, {}, never>;
|
|
2
5
|
export declare const TagCloseBtn: import("styled-components").StyledComponent<"div", any, {
|
|
3
6
|
borderColor?: string | undefined;
|
|
4
7
|
}, never>;
|
|
@@ -9,7 +9,7 @@ export declare const WrapperForm: import("styled-components").StyledComponent<(<
|
|
|
9
9
|
useWatch: typeof import("rc-field-form").useWatch;
|
|
10
10
|
Item: (<Values_1 = any>(props: import("antd").FormItemProps<Values_1>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
|
|
11
11
|
useStatus: () => {
|
|
12
|
-
status?: "" | "warning" | "
|
|
12
|
+
status?: "" | "warning" | "success" | "error" | "validating" | undefined;
|
|
13
13
|
errors: import("react").ReactNode[];
|
|
14
14
|
warnings: import("react").ReactNode[];
|
|
15
15
|
};
|
|
@@ -19,7 +19,7 @@ export declare const StyledForm: import("styled-components").StyledComponent<(<V
|
|
|
19
19
|
useWatch: typeof import("rc-field-form").useWatch;
|
|
20
20
|
Item: (<Values_1 = any>(props: import("antd").FormItemProps<Values_1>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
|
|
21
21
|
useStatus: () => {
|
|
22
|
-
status?: "" | "warning" | "
|
|
22
|
+
status?: "" | "warning" | "success" | "error" | "validating" | undefined;
|
|
23
23
|
errors: import("react").ReactNode[];
|
|
24
24
|
warnings: import("react").ReactNode[];
|
|
25
25
|
};
|
|
@@ -66,3 +66,15 @@ export declare const MAP_BOOLEAN_PROPERTIES: {
|
|
|
66
66
|
label: string;
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
|
+
export declare const DEFAULT_STATUS: {
|
|
70
|
+
ENABLED: number;
|
|
71
|
+
DISABLED: number;
|
|
72
|
+
REMOVED: number;
|
|
73
|
+
ARCHIVED: number;
|
|
74
|
+
};
|
|
75
|
+
export declare const ATTRIBUTE_STATUS: {
|
|
76
|
+
ENABLED: number;
|
|
77
|
+
DISABLED: number;
|
|
78
|
+
REMOVED: number;
|
|
79
|
+
ARCHIVED: number;
|
|
80
|
+
};
|
|
@@ -70,3 +70,11 @@ export const MAP_BOOLEAN_PROPERTIES = {
|
|
|
70
70
|
true: BOOLEAN_PROPERTIES[0],
|
|
71
71
|
false: BOOLEAN_PROPERTIES[1],
|
|
72
72
|
};
|
|
73
|
+
export const DEFAULT_STATUS = {
|
|
74
|
+
ENABLED: 1,
|
|
75
|
+
DISABLED: 2,
|
|
76
|
+
REMOVED: 3,
|
|
77
|
+
ARCHIVED: 4,
|
|
78
|
+
};
|
|
79
|
+
// Attribute Status
|
|
80
|
+
export const ATTRIBUTE_STATUS = DEFAULT_STATUS;
|
package/es/utils/attribute.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Constants
|
|
2
|
-
import { MAP_BOOLEAN_PROPERTIES } from '../constants';
|
|
3
|
+
import { ATTRIBUTE_STATUS, MAP_BOOLEAN_PROPERTIES } from '../constants';
|
|
3
4
|
// Utils
|
|
4
5
|
import { formatAttributeUTCDate } from './date';
|
|
5
6
|
import { getUserLocaleLanguage, safeParseDisplayFormat, safeParseDisplayFormatCurrency, safeParseDisplayFormatNumber, safeParseDisplayFormatPercentage, } from './portal';
|
|
6
7
|
import { safeParseJson } from './common';
|
|
8
|
+
// Components
|
|
9
|
+
import { Tag } from '../components/atoms';
|
|
10
|
+
const { REMOVED, ARCHIVED } = ATTRIBUTE_STATUS;
|
|
7
11
|
/**
|
|
8
12
|
* Format attribute value according to its data type and display format.
|
|
9
13
|
* @param {{ attribute: Attribute, value: any }} args - attribute and its value.
|
|
10
14
|
* @returns {string} Formatted value or '--' if value is empty.
|
|
11
15
|
*/
|
|
12
16
|
export const formatAttributeDisplay = ({ attribute, value, }) => {
|
|
13
|
-
const { dataType } = attribute || {};
|
|
17
|
+
const { dataType, itemPropertyName } = attribute || {};
|
|
14
18
|
const displayFormat = safeParseDisplayFormat(attribute?.displayFormat, {
|
|
15
19
|
dataType,
|
|
16
20
|
});
|
|
@@ -42,8 +46,41 @@ export const formatAttributeDisplay = ({ attribute, value, }) => {
|
|
|
42
46
|
dataValue = safeParseJson(value, '--');
|
|
43
47
|
break;
|
|
44
48
|
}
|
|
45
|
-
|
|
49
|
+
case dataType?.startsWith('array'): {
|
|
50
|
+
const draftValue = Array.isArray(value)
|
|
51
|
+
? value
|
|
52
|
+
.map(item => {
|
|
53
|
+
const isSegment = itemPropertyName.startsWith('segment_ids');
|
|
54
|
+
if (isSegment && typeof item === 'object') {
|
|
55
|
+
const { segmentDisplay, status } = item || {};
|
|
56
|
+
if ([REMOVED, ARCHIVED].includes(status)) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
return segmentDisplay;
|
|
60
|
+
}
|
|
61
|
+
return item;
|
|
62
|
+
})
|
|
63
|
+
?.filter(Boolean)
|
|
64
|
+
: value;
|
|
65
|
+
if (Array.isArray(draftValue) && draftValue.length) {
|
|
66
|
+
dataValue = (_jsx(Tag.List, { tags: draftValue, tagProps: {
|
|
67
|
+
color: '#CAE5FE',
|
|
68
|
+
style: {
|
|
69
|
+
color: 'black',
|
|
70
|
+
},
|
|
71
|
+
}, limit: 2 }));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
dataValue = '--';
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default: {
|
|
79
|
+
if (typeof dataValue === 'object') {
|
|
80
|
+
dataValue = safeParseJson(dataValue, '--');
|
|
81
|
+
}
|
|
46
82
|
break;
|
|
83
|
+
}
|
|
47
84
|
}
|
|
48
85
|
return dataValue || '--';
|
|
49
86
|
};
|