@antscorp/antsomi-ui 1.3.5-beta.352 → 1.3.5-beta.354
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/molecules/EditorTab/EditorTab.d.ts +4 -1
- package/es/components/molecules/EditorTab/EditorTab.js +51 -68
- package/es/components/molecules/EditorTab/styled.js +10 -3
- package/es/components/molecules/SelectAccount/AccountChip.d.ts +13 -0
- package/es/components/molecules/SelectAccount/AccountChip.js +31 -0
- package/es/components/molecules/SelectAccount/AccountList.d.ts +4 -0
- package/es/components/molecules/SelectAccount/AccountList.js +47 -0
- package/es/components/molecules/SelectAccount/ButtonAdd.d.ts +3 -0
- package/es/components/molecules/SelectAccount/ButtonAdd.js +29 -0
- package/es/components/molecules/SelectAccount/ButtonViewAll.d.ts +3 -0
- package/es/components/molecules/SelectAccount/ButtonViewAll.js +37 -0
- package/es/components/molecules/SelectAccount/Content.d.ts +2 -0
- package/es/components/molecules/SelectAccount/Content.js +40 -0
- package/es/components/molecules/SelectAccount/context/SelectAccountContext.d.ts +4 -0
- package/es/components/molecules/SelectAccount/context/SelectAccountContext.js +51 -0
- package/es/components/molecules/SelectAccount/context/index.d.ts +1 -0
- package/es/components/molecules/SelectAccount/context/index.js +1 -0
- package/es/components/molecules/SelectAccount/context/reducer.d.ts +3 -0
- package/es/components/molecules/SelectAccount/context/reducer.js +95 -0
- package/es/components/molecules/SelectAccount/hook/index.d.ts +1 -0
- package/es/components/molecules/SelectAccount/hook/index.js +1 -0
- package/es/components/molecules/SelectAccount/hook/useGetAbstractUsers.d.ts +11 -0
- package/es/components/molecules/SelectAccount/hook/useGetAbstractUsers.js +9 -0
- package/es/components/molecules/SelectAccount/index.d.ts +4 -0
- package/es/components/molecules/SelectAccount/index.js +21 -0
- package/es/components/molecules/SelectAccount/styled.d.ts +23 -0
- package/es/components/molecules/SelectAccount/styled.js +164 -0
- package/es/components/molecules/SelectAccount/type.d.ts +79 -0
- package/es/components/molecules/SelectAccount/type.js +1 -0
- package/es/components/molecules/index.d.ts +1 -0
- package/es/components/molecules/index.js +1 -0
- package/es/components/template/Layout/Layout.js +11 -8
- package/es/components/template/Layout/stores/index.js +2 -2
- package/es/constants/queries.d.ts +1 -0
- package/es/constants/queries.js +2 -0
- package/es/constants/variables.d.ts +3 -0
- package/es/constants/variables.js +4 -0
- package/es/providers/ConfigProvider/GlobalStyle.js +20 -6
- package/es/services/Abstract/index.d.ts +15 -0
- package/es/services/Abstract/index.js +45 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ModalFuncProps } from 'antd';
|
|
2
3
|
interface EditorTabItem {
|
|
3
4
|
showIcon?: boolean;
|
|
4
5
|
showDropdown?: boolean;
|
|
@@ -14,13 +15,15 @@ interface EditorTabProps {
|
|
|
14
15
|
showArrow?: boolean;
|
|
15
16
|
showDropdown?: boolean;
|
|
16
17
|
editNameOnConfigure?: boolean;
|
|
18
|
+
newTabText?: string;
|
|
17
19
|
showComposeNewQuery?: boolean;
|
|
18
20
|
className?: string;
|
|
19
21
|
leftBlockClassName?: string;
|
|
20
22
|
tabItemClassName?: string;
|
|
21
23
|
listTab?: EditorTabItem[];
|
|
22
24
|
activeId?: string;
|
|
23
|
-
|
|
25
|
+
confirmOnRemoveTab?: boolean;
|
|
26
|
+
modalFuncProps?: ModalFuncProps;
|
|
24
27
|
onActiveTab: (id: string) => void;
|
|
25
28
|
onCloseTab: (tab: EditorTabItem, index: number, newTabs: EditorTabItem[]) => void;
|
|
26
29
|
onConfigure: (id: string) => void;
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
// Lib
|
|
2
|
-
import React, {
|
|
11
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
12
|
import classnames from 'classnames';
|
|
4
13
|
// Components
|
|
5
14
|
import Icon from '@antscorp/icons/main';
|
|
6
|
-
import { Button, Typography, Dropdown, ContentEditable } from '@antscorp/antsomi-ui/es/components';
|
|
15
|
+
import { Button, Typography, Dropdown, ContentEditable, Modal, } from '@antscorp/antsomi-ui/es/components';
|
|
7
16
|
// Styles
|
|
8
17
|
import { EditorTabStyled } from './styled';
|
|
9
18
|
// Utils
|
|
@@ -11,15 +20,15 @@ import { handleError } from '@antscorp/antsomi-ui/es/utils';
|
|
|
11
20
|
const PATH = 'src/components/EditorTab/index.jsx';
|
|
12
21
|
export const EditorTab = props => {
|
|
13
22
|
var _a;
|
|
14
|
-
const { listTab = [], activeId = '',
|
|
23
|
+
const { listTab = [], activeId = '', showArrow, showDropdown, editNameOnConfigure,
|
|
15
24
|
// disabledScroll,
|
|
16
|
-
onCloseTab, onActiveTab, onAddTab, onConfigure, onSaveName, showComposeNewQuery, className, leftBlockClassName, tabItemClassName, } = props;
|
|
17
|
-
const [activeTabId, setActiveTabId] = useState(
|
|
25
|
+
onCloseTab, onActiveTab, onAddTab, onConfigure, onSaveName, newTabText, showComposeNewQuery, className, leftBlockClassName, tabItemClassName, confirmOnRemoveTab = true, modalFuncProps, } = props;
|
|
26
|
+
const [activeTabId, setActiveTabId] = useState(activeId || ((_a = listTab === null || listTab === void 0 ? void 0 : listTab[0]) === null || _a === void 0 ? void 0 : _a.id));
|
|
18
27
|
const [arrTabs, setArrTabs] = useState(listTab || []);
|
|
19
28
|
const [isEditable, setIsEditable] = useState();
|
|
29
|
+
const [modal, contextModal] = Modal.useModal();
|
|
20
30
|
// Ref
|
|
21
31
|
const leftBlockRef = useRef(null);
|
|
22
|
-
const activeTabIdx = useMemo(() => arrTabs.findIndex(tab => tab.id === activeId), [activeId, arrTabs]);
|
|
23
32
|
useEffect(() => {
|
|
24
33
|
if (listTab.length - arrTabs.length === 1) {
|
|
25
34
|
setActiveTabId(listTab[listTab.length - 1].id);
|
|
@@ -27,58 +36,46 @@ export const EditorTab = props => {
|
|
|
27
36
|
setArrTabs(listTab);
|
|
28
37
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
38
|
}, [listTab]);
|
|
30
|
-
// useEffect(() => {
|
|
31
|
-
// if (onActiveTab) onActiveTab(activeTabId);
|
|
32
|
-
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
-
// }, [activeTabId]);
|
|
34
39
|
useEffect(() => {
|
|
35
|
-
|
|
40
|
+
var _a;
|
|
41
|
+
const tabEl = (_a = leftBlockRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.tab-item.active');
|
|
36
42
|
if (tabEl) {
|
|
37
|
-
tabEl.scrollIntoView({ block: '
|
|
43
|
+
tabEl.scrollIntoView({ block: 'nearest', inline: 'center', behavior: 'smooth' });
|
|
38
44
|
}
|
|
39
45
|
}, [activeTabId]);
|
|
40
46
|
useEffect(() => {
|
|
41
|
-
// if (activeId && activeTabId !== activeId) {
|
|
42
|
-
// setActiveTabId(activeId);
|
|
43
|
-
// }
|
|
44
47
|
setActiveTabId(prev => (activeId && prev !== activeId ? activeId : prev));
|
|
45
48
|
}, [activeId]);
|
|
46
49
|
const handleAddNew = () => {
|
|
47
50
|
onAddTab();
|
|
48
51
|
};
|
|
49
|
-
const
|
|
52
|
+
const modalConfirmAsync = useCallback(() => modal.confirm(Object.assign({ title: 'Remove this tab', content: 'Removing this tab will delete it permanently. Are you sure you want to perform this action?', okText: 'Confirm', icon: React.createElement("span", { style: { display: 'none' } }), className: 'editor-tab__modal-confirm' }, modalFuncProps)), [modalFuncProps, modal]);
|
|
53
|
+
const handleActiveTab = useCallback((tabId) => {
|
|
54
|
+
setActiveTabId(tabId);
|
|
55
|
+
if (onActiveTab)
|
|
56
|
+
onActiveTab(tabId);
|
|
57
|
+
}, [onActiveTab]);
|
|
58
|
+
const handleCloseTab = (e, tab, idx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
59
|
e.stopPropagation();
|
|
51
60
|
if (arrTabs.length < 2) {
|
|
52
61
|
return;
|
|
53
62
|
}
|
|
63
|
+
const isConfirm = confirmOnRemoveTab ? yield modalConfirmAsync() : true;
|
|
64
|
+
if (!isConfirm)
|
|
65
|
+
return;
|
|
54
66
|
if (activeTabId === tab.id) {
|
|
55
67
|
if (idx === arrTabs.length - 1) {
|
|
56
|
-
|
|
57
|
-
if (onActiveTab)
|
|
58
|
-
onActiveTab(arrTabs[idx - 1].id);
|
|
68
|
+
handleActiveTab(arrTabs[idx - 1].id);
|
|
59
69
|
}
|
|
60
70
|
else if (arrTabs.length > 1) {
|
|
61
|
-
|
|
62
|
-
if (onActiveTab)
|
|
63
|
-
onActiveTab(arrTabs[idx - 1].id);
|
|
71
|
+
handleActiveTab(arrTabs[idx + 1].id);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
|
-
const newTabs =
|
|
67
|
-
newTabs.splice(idx, 1);
|
|
74
|
+
const newTabs = arrTabs.filter(item => item.id !== tab.id);
|
|
68
75
|
onCloseTab(tab, idx, newTabs);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// onCloseTab(tab, idx, newTabs);
|
|
73
|
-
// return newTabs;
|
|
74
|
-
// });
|
|
75
|
-
};
|
|
76
|
-
const handleActiveTab = tab => {
|
|
77
|
-
setActiveTabId(tab.id);
|
|
78
|
-
if (onActiveTab)
|
|
79
|
-
onActiveTab(tab.id);
|
|
80
|
-
};
|
|
81
|
-
const onWheelLeftBlock = event => {
|
|
76
|
+
setArrTabs(newTabs);
|
|
77
|
+
});
|
|
78
|
+
const onWheelLeftBlock = useCallback(event => {
|
|
82
79
|
try {
|
|
83
80
|
if (!event.deltaY) {
|
|
84
81
|
return;
|
|
@@ -92,42 +89,33 @@ export const EditorTab = props => {
|
|
|
92
89
|
args: {},
|
|
93
90
|
});
|
|
94
91
|
}
|
|
95
|
-
};
|
|
96
|
-
const onClickArrow = (direction = 'left') => {
|
|
92
|
+
}, []);
|
|
93
|
+
const onClickArrow = useCallback((direction = 'left') => {
|
|
97
94
|
const idx = arrTabs.findIndex(tab => tab.id === activeTabId);
|
|
98
95
|
if (idx !== -1) {
|
|
99
96
|
switch (direction) {
|
|
100
97
|
case 'left':
|
|
101
|
-
if (idx
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
setActiveTabId(arrTabs[idx - 1].id);
|
|
105
|
-
if (onActiveTab)
|
|
106
|
-
onActiveTab(arrTabs[idx - 1].id);
|
|
98
|
+
if (idx !== 0)
|
|
99
|
+
handleActiveTab(arrTabs[idx - 1].id);
|
|
107
100
|
break;
|
|
108
101
|
case 'right':
|
|
109
|
-
if (idx
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
setActiveTabId(arrTabs[idx + 1].id);
|
|
113
|
-
if (onActiveTab)
|
|
114
|
-
onActiveTab(arrTabs[idx + 1].id);
|
|
102
|
+
if (idx !== arrTabs.length - 1)
|
|
103
|
+
handleActiveTab(arrTabs[idx + 1].id);
|
|
115
104
|
break;
|
|
116
105
|
default:
|
|
117
106
|
break;
|
|
118
107
|
}
|
|
119
108
|
}
|
|
120
|
-
};
|
|
109
|
+
}, [activeTabId, arrTabs, handleActiveTab]);
|
|
121
110
|
return (React.createElement(EditorTabStyled, { className: className || '' },
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}), onClick: () => onClickArrow('left') },
|
|
111
|
+
contextModal,
|
|
112
|
+
showArrow && (React.createElement("div", { className: "navigate-button", onClick: () => onClickArrow('left') },
|
|
125
113
|
React.createElement(Icon, { type: "icon-ants-angle-left" }))),
|
|
126
114
|
React.createElement("div", { ref: leftBlockRef, className: classnames('left-block', leftBlockClassName), onWheel: onWheelLeftBlock }, arrTabs && arrTabs.length
|
|
127
115
|
? arrTabs.map((tab, idx) => {
|
|
128
116
|
const { showIcon = true, closeable = true } = tab;
|
|
129
117
|
// const { showIcon = true, showDropdown = true, closeable = true } = tab;
|
|
130
|
-
return (React.createElement("div", { key: tab.id,
|
|
118
|
+
return (React.createElement("div", { key: tab.id, onClick: () => handleActiveTab(tab.id), className: classnames('tab-item', tabItemClassName, {
|
|
131
119
|
active: tab.id === activeTabId,
|
|
132
120
|
}) },
|
|
133
121
|
showIcon &&
|
|
@@ -141,7 +129,7 @@ export const EditorTab = props => {
|
|
|
141
129
|
{ label: 'Configure', key: 'configure', style: { minWidth: '135px' } },
|
|
142
130
|
{ label: 'Remove', key: 'remove', style: { minWidth: '135px' } },
|
|
143
131
|
],
|
|
144
|
-
onClick: ({ key, domEvent })
|
|
132
|
+
onClick: (_a) => __awaiter(void 0, [_a], void 0, function* ({ key, domEvent }) {
|
|
145
133
|
switch (key) {
|
|
146
134
|
case 'configure':
|
|
147
135
|
if (editNameOnConfigure)
|
|
@@ -149,24 +137,19 @@ export const EditorTab = props => {
|
|
|
149
137
|
onConfigure === null || onConfigure === void 0 ? void 0 : onConfigure(tab.id);
|
|
150
138
|
break;
|
|
151
139
|
case 'remove':
|
|
152
|
-
handleCloseTab(domEvent, tab, idx);
|
|
140
|
+
yield handleCloseTab(domEvent, tab, idx);
|
|
153
141
|
break;
|
|
154
142
|
default:
|
|
155
143
|
break;
|
|
156
144
|
}
|
|
157
|
-
},
|
|
145
|
+
}),
|
|
158
146
|
}, placement: "bottomRight", trigger: ['click'], destroyPopupOnHide: true },
|
|
159
|
-
React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-three-dot-vertical", overlayStyle: { fontSize: 12 } }),
|
|
160
|
-
// icon={<Icon type="icon-ants-angle-left" overlayStyle={{ fontSize: 12 }} />}
|
|
161
|
-
// style={{ transform: 'rotate(-90deg)' }}
|
|
162
|
-
size: "small" }))) : closeable ? (React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-remove-slim", onClick: e => handleCloseTab(e, tab, idx), overlayStyle: { fontSize: 12 } }), size: "small" })) : null));
|
|
147
|
+
React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-three-dot-vertical", overlayStyle: { fontSize: 12 } }), size: "small" }))) : closeable ? (React.createElement(Button, { onClick: e => handleCloseTab(e, tab, idx), icon: React.createElement(Icon, { type: "icon-ants-remove-slim", overlayStyle: { fontSize: 12 } }), size: "small" })) : null));
|
|
163
148
|
})
|
|
164
149
|
: null),
|
|
165
|
-
showArrow && (React.createElement("div", { className:
|
|
166
|
-
'--disabled': activeTabIdx === arrTabs.length - 1,
|
|
167
|
-
}), onClick: () => onClickArrow('right') },
|
|
150
|
+
showArrow && (React.createElement("div", { className: "navigate-button", onClick: () => onClickArrow('right') },
|
|
168
151
|
React.createElement(Icon, { type: "icon-ants-angle-right" }))),
|
|
169
|
-
showComposeNewQuery
|
|
152
|
+
showComposeNewQuery || newTabText ? (React.createElement(Button, { onClick: handleAddNew, className: "new-query-button" },
|
|
170
153
|
React.createElement(Icon, { type: "icon-ants-add-square" }),
|
|
171
|
-
|
|
154
|
+
newTabText || 'New query')) : null));
|
|
172
155
|
};
|
|
@@ -115,6 +115,13 @@ export const EditorTabStyled = styled.div `
|
|
|
115
115
|
border: none;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
&:has(.left-block > div:last-child.active) .navigate-button:last-child,
|
|
119
|
+
&:has(.left-block > div:first-child.active) .navigate-button:first-child {
|
|
120
|
+
cursor: not-allowed;
|
|
121
|
+
pointer-events: none;
|
|
122
|
+
opacity: 0.5;
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
.navigate-button {
|
|
119
126
|
/* Structure Block */
|
|
120
127
|
flex-shrink: 0;
|
|
@@ -130,14 +137,14 @@ export const EditorTabStyled = styled.div `
|
|
|
130
137
|
|
|
131
138
|
cursor: pointer;
|
|
132
139
|
|
|
133
|
-
|
|
140
|
+
&:last-child {
|
|
134
141
|
border-right: 1px solid #e0e0e0;
|
|
135
142
|
}
|
|
136
143
|
|
|
137
|
-
&.--disabled {
|
|
144
|
+
/* &.--disabled {
|
|
138
145
|
cursor: not-allowed;
|
|
139
146
|
pointer-events: none;
|
|
140
147
|
opacity: 0.7;
|
|
141
|
-
}
|
|
148
|
+
} */
|
|
142
149
|
}
|
|
143
150
|
`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type AccountChipProps = {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
user: any;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
isViewMode?: boolean;
|
|
8
|
+
isError?: boolean;
|
|
9
|
+
errorMsg?: string;
|
|
10
|
+
onRemove?: (item: any) => void;
|
|
11
|
+
};
|
|
12
|
+
declare const AccountChip: React.FC<AccountChipProps>;
|
|
13
|
+
export default AccountChip;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
// Context
|
|
4
|
+
import { SelectAccountContext } from './context';
|
|
5
|
+
// Components
|
|
6
|
+
import { AccountChipWrapper } from './styled';
|
|
7
|
+
import Icon from '@antscorp/icons';
|
|
8
|
+
import { Tooltip } from '../../atoms';
|
|
9
|
+
const AccountChip = props => {
|
|
10
|
+
const { user, label, value, disabled, isViewMode, isError, errorMsg, onRemove } = props;
|
|
11
|
+
const { state } = useContext(SelectAccountContext);
|
|
12
|
+
const { disabledAccount, userIdKey } = state;
|
|
13
|
+
const handleRemove = () => {
|
|
14
|
+
if (typeof onRemove === 'function') {
|
|
15
|
+
onRemove({ value, user });
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const isDisabled = disabled || (state === null || state === void 0 ? void 0 : state.disabled) || (disabledAccount === null || disabledAccount === void 0 ? void 0 : disabledAccount.includes(user === null || user === void 0 ? void 0 : user[userIdKey]));
|
|
19
|
+
return (React.createElement(Tooltip, { open: isError ? undefined : false, title: errorMsg },
|
|
20
|
+
React.createElement(AccountChipWrapper, { disabled: isDisabled, isError: isError },
|
|
21
|
+
React.createElement("div", { className: "name" }, label),
|
|
22
|
+
!isViewMode && !(state === null || state === void 0 ? void 0 : state.isViewMode) && !isDisabled && (React.createElement("div", { className: "icon-remove", onClick: handleRemove },
|
|
23
|
+
React.createElement(Icon, { type: "icon-ants-remove-slim" }))))));
|
|
24
|
+
};
|
|
25
|
+
AccountChip.defaultProps = {
|
|
26
|
+
disabled: false,
|
|
27
|
+
isViewMode: false,
|
|
28
|
+
isError: false,
|
|
29
|
+
errorMsg: '',
|
|
30
|
+
};
|
|
31
|
+
export default AccountChip;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { useContext, useState } from 'react';
|
|
2
|
+
import { AccountListBody, AccountListContent, AccountListFooter, AccountListTitleGroup, AccountListWrapper, CheckboxStyled, } from './styled';
|
|
3
|
+
import { Button, Icon, Input } from '../../atoms';
|
|
4
|
+
import { Dropdown } from '../Dropdown';
|
|
5
|
+
import { SelectAccountContext } from './context/SelectAccountContext';
|
|
6
|
+
const AccountList = () => {
|
|
7
|
+
const { state, dispatch } = useContext(SelectAccountContext);
|
|
8
|
+
const { usersDisplay, disabledAccount, draftUsersSelected, nameKey, userIdKey, searchText, listAccountGroupDisplay, } = state;
|
|
9
|
+
const [openGroup, setOpenGroup] = useState(true);
|
|
10
|
+
const [openAccount, setOpenAccount] = useState(true);
|
|
11
|
+
const handleCheckbox = userId => {
|
|
12
|
+
dispatch({ type: 'UPDATE_DRAFT_USERS_SELECTED', payload: { userId } });
|
|
13
|
+
};
|
|
14
|
+
const handleCancel = () => {
|
|
15
|
+
dispatch({ type: 'CLOSE_ACCOUNT_LIST' });
|
|
16
|
+
};
|
|
17
|
+
const handleApply = () => {
|
|
18
|
+
dispatch({ type: 'APPLY' });
|
|
19
|
+
};
|
|
20
|
+
const handleSearch = text => {
|
|
21
|
+
dispatch({ type: 'UPDATE_SEARCH_TEXT', payload: text });
|
|
22
|
+
};
|
|
23
|
+
return (React.createElement(AccountListWrapper, null,
|
|
24
|
+
React.createElement(AccountListBody, null,
|
|
25
|
+
React.createElement(Input, { value: searchText, placeholder: "Search", suffix: React.createElement(Icon, { type: "icon-ants-search-2" }), onAfterChange: value => handleSearch(value), debounce: 500 }),
|
|
26
|
+
(state === null || state === void 0 ? void 0 : state.type) === 'group' ? (React.createElement(React.Fragment, null,
|
|
27
|
+
React.createElement(Dropdown, { open: openGroup, getPopupContainer: () => document.getElementById('account-group-list') || document.body, overlayStyle: { position: 'initial' }, trigger: ['click'], dropdownRender: () => (React.createElement(AccountListContent, null, listAccountGroupDisplay === null || listAccountGroupDisplay === void 0 ? void 0 : listAccountGroupDisplay.map((item, idx) => (React.createElement(CheckboxStyled, { key: item === null || item === void 0 ? void 0 : item[state === null || state === void 0 ? void 0 : state.groupIdKey], disabled: disabledAccount === null || disabledAccount === void 0 ? void 0 : disabledAccount.includes(item === null || item === void 0 ? void 0 : item[state === null || state === void 0 ? void 0 : state.groupIdKey]), defaultChecked: draftUsersSelected.includes(item === null || item === void 0 ? void 0 : item[state === null || state === void 0 ? void 0 : state.groupIdKey]), onChange: () => handleCheckbox(item === null || item === void 0 ? void 0 : item[state === null || state === void 0 ? void 0 : state.groupIdKey]) }, item === null || item === void 0 ? void 0 : item[state === null || state === void 0 ? void 0 : state.groupNameKey]))))) },
|
|
28
|
+
React.createElement(AccountListTitleGroup, { onClick: () => setOpenGroup(!openGroup) },
|
|
29
|
+
React.createElement("div", null, "Account Group"),
|
|
30
|
+
React.createElement(Icon, { type: "icon-ants-expand-more", size: 20, style: {
|
|
31
|
+
transform: openGroup ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
32
|
+
transition: '0.3s',
|
|
33
|
+
} }))),
|
|
34
|
+
React.createElement("div", { id: "account-group-list" }),
|
|
35
|
+
React.createElement(Dropdown, { open: openAccount, getPopupContainer: () => document.getElementById('account-list') || document.body, overlayStyle: { position: 'initial' }, trigger: ['click'], dropdownRender: () => (React.createElement(AccountListContent, null, usersDisplay === null || usersDisplay === void 0 ? void 0 : usersDisplay.map(item => (React.createElement(CheckboxStyled, { key: item === null || item === void 0 ? void 0 : item[userIdKey], disabled: disabledAccount === null || disabledAccount === void 0 ? void 0 : disabledAccount.includes(item === null || item === void 0 ? void 0 : item[userIdKey]), defaultChecked: draftUsersSelected.includes(item === null || item === void 0 ? void 0 : item[userIdKey]), onChange: () => handleCheckbox(item === null || item === void 0 ? void 0 : item[userIdKey]) }, item === null || item === void 0 ? void 0 : item[nameKey]))))) },
|
|
36
|
+
React.createElement(AccountListTitleGroup, { onClick: () => setOpenAccount(!openAccount) },
|
|
37
|
+
React.createElement("div", null, "Account"),
|
|
38
|
+
React.createElement(Icon, { type: "icon-ants-expand-more", size: 20, style: {
|
|
39
|
+
transform: openAccount ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
40
|
+
transition: '0.3s',
|
|
41
|
+
} }))),
|
|
42
|
+
React.createElement("div", { id: "account-list" }))) : (React.createElement(AccountListContent, { style: { marginTop: 15 } }, usersDisplay === null || usersDisplay === void 0 ? void 0 : usersDisplay.map(item => (React.createElement(CheckboxStyled, { key: item === null || item === void 0 ? void 0 : item[userIdKey], disabled: disabledAccount === null || disabledAccount === void 0 ? void 0 : disabledAccount.includes(item === null || item === void 0 ? void 0 : item[userIdKey]), defaultChecked: draftUsersSelected.includes(item === null || item === void 0 ? void 0 : item[userIdKey]), onChange: () => handleCheckbox(item === null || item === void 0 ? void 0 : item[userIdKey]) }, item === null || item === void 0 ? void 0 : item[nameKey])))))),
|
|
43
|
+
React.createElement(AccountListFooter, null,
|
|
44
|
+
React.createElement(Button, { onClick: () => handleCancel() }, "Cancel"),
|
|
45
|
+
React.createElement(Button, { type: "primary", onClick: () => handleApply() }, "Apply"))));
|
|
46
|
+
};
|
|
47
|
+
export default AccountList;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
// Context
|
|
4
|
+
import { SelectAccountContext } from './context';
|
|
5
|
+
// Components
|
|
6
|
+
import { ButtonAddStyled } from './styled';
|
|
7
|
+
import { Icon, Popover } from '../../atoms';
|
|
8
|
+
import AccountList from './AccountList';
|
|
9
|
+
const ButtonAdd = () => {
|
|
10
|
+
const { state, dispatch } = useContext(SelectAccountContext);
|
|
11
|
+
const handleClose = visible => {
|
|
12
|
+
if (!visible) {
|
|
13
|
+
dispatch({ type: 'CLOSE_ACCOUNT_LIST' });
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const handleAfterClose = visible => {
|
|
17
|
+
if (!visible) {
|
|
18
|
+
dispatch({ type: 'UPDATE_SEARCH_TEXT', payload: '' });
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return (React.createElement(Popover, { open: state.openAccountList, content: React.createElement(AccountList, null), trigger: "click", arrow: false, overlayInnerStyle: { padding: 0 }, destroyTooltipOnHide: true, onOpenChange: handleClose, afterOpenChange: handleAfterClose },
|
|
22
|
+
React.createElement(ButtonAddStyled, { loading: !state.isInitDone, onClick: () => state.openAccountList
|
|
23
|
+
? dispatch({ type: 'CLOSE_ACCOUNT_LIST' })
|
|
24
|
+
: dispatch({ type: 'OPEN_ACCOUNT_LIST' }) },
|
|
25
|
+
React.createElement("div", { className: "icon" },
|
|
26
|
+
React.createElement(Icon, { type: "icon-ants-add", size: 10 })),
|
|
27
|
+
React.createElement("div", { className: "name" }, "Add account"))));
|
|
28
|
+
};
|
|
29
|
+
export default ButtonAdd;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
// Context
|
|
4
|
+
import { SelectAccountContext } from './context';
|
|
5
|
+
// Components
|
|
6
|
+
import { ButtonViewAllStyled, ViewAllWrapper } from './styled';
|
|
7
|
+
import { Popover } from '../../atoms';
|
|
8
|
+
import AccountChip from './AccountChip';
|
|
9
|
+
const ButtonViewAll = () => {
|
|
10
|
+
const { state, dispatch } = useContext(SelectAccountContext);
|
|
11
|
+
const { usersSelected, nameKey, userIdKey, users } = state;
|
|
12
|
+
const handleRemove = ({ userId, index }) => {
|
|
13
|
+
dispatch({ type: 'REMOVE_USER', payload: { userId, index } });
|
|
14
|
+
};
|
|
15
|
+
const contentViewAll = () => (React.createElement(ViewAllWrapper, null, state.type === 'group'
|
|
16
|
+
? usersSelected === null || usersSelected === void 0 ? void 0 : usersSelected.map((id, index) => {
|
|
17
|
+
if (index < (state === null || state === void 0 ? void 0 : state.limitShow))
|
|
18
|
+
return null;
|
|
19
|
+
const group = state.listAccountGroup.find(u => (u === null || u === void 0 ? void 0 : u[state === null || state === void 0 ? void 0 : state.groupIdKey]) === id);
|
|
20
|
+
if (!group) {
|
|
21
|
+
const user = users.find(u => (u === null || u === void 0 ? void 0 : u[userIdKey]) === id);
|
|
22
|
+
if (!user)
|
|
23
|
+
return null;
|
|
24
|
+
return (React.createElement(AccountChip, { key: user === null || user === void 0 ? void 0 : user[userIdKey], user: user, value: user === null || user === void 0 ? void 0 : user[userIdKey], label: user === null || user === void 0 ? void 0 : user[nameKey], onRemove: () => handleRemove({ userId: user === null || user === void 0 ? void 0 : user[userIdKey], index }) }));
|
|
25
|
+
}
|
|
26
|
+
return (React.createElement(AccountChip, { key: group === null || group === void 0 ? void 0 : group[state.groupIdKey], user: group, value: group === null || group === void 0 ? void 0 : group[state.groupIdKey], label: group === null || group === void 0 ? void 0 : group[state === null || state === void 0 ? void 0 : state.groupNameKey], onRemove: () => handleRemove({ userId: group === null || group === void 0 ? void 0 : group[state.groupIdKey], index }) }));
|
|
27
|
+
})
|
|
28
|
+
: usersSelected === null || usersSelected === void 0 ? void 0 : usersSelected.map((id, index) => {
|
|
29
|
+
if (index < (state === null || state === void 0 ? void 0 : state.limitShow))
|
|
30
|
+
return null;
|
|
31
|
+
const user = users.find(u => (u === null || u === void 0 ? void 0 : u[userIdKey]) === id);
|
|
32
|
+
return (React.createElement(AccountChip, { key: user === null || user === void 0 ? void 0 : user[userIdKey], user: user, value: user === null || user === void 0 ? void 0 : user[userIdKey], label: user === null || user === void 0 ? void 0 : user[nameKey], onRemove: () => handleRemove({ userId: user === null || user === void 0 ? void 0 : user[userIdKey], index }) }));
|
|
33
|
+
})));
|
|
34
|
+
return (React.createElement(Popover, { content: () => contentViewAll(), trigger: "click", arrow: false, overlayInnerStyle: { padding: 0 }, destroyTooltipOnHide: true },
|
|
35
|
+
React.createElement(ButtonViewAllStyled, { type: "text" }, "View all")));
|
|
36
|
+
};
|
|
37
|
+
export default ButtonViewAll;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
// Context
|
|
4
|
+
import { SelectAccountContext } from './context';
|
|
5
|
+
// Components
|
|
6
|
+
import { Wrapper } from './styled';
|
|
7
|
+
import AccountChip from './AccountChip';
|
|
8
|
+
import ButtonAdd from './ButtonAdd';
|
|
9
|
+
import ButtonViewAll from './ButtonViewAll';
|
|
10
|
+
export const Content = () => {
|
|
11
|
+
var _a;
|
|
12
|
+
const { state, dispatch } = useContext(SelectAccountContext);
|
|
13
|
+
const { usersSelected, nameKey, userIdKey, users, disabled } = state;
|
|
14
|
+
const handleRemove = ({ userId, index }) => {
|
|
15
|
+
dispatch({ type: 'REMOVE_USER', payload: { userId, index } });
|
|
16
|
+
};
|
|
17
|
+
return (React.createElement(Wrapper, { disabled: !!disabled },
|
|
18
|
+
state.type === 'group'
|
|
19
|
+
? usersSelected === null || usersSelected === void 0 ? void 0 : usersSelected.map((id, index) => {
|
|
20
|
+
var _a;
|
|
21
|
+
if (index >= (state === null || state === void 0 ? void 0 : state.limitShow))
|
|
22
|
+
return null;
|
|
23
|
+
const group = (_a = state === null || state === void 0 ? void 0 : state.listAccountGroup) === null || _a === void 0 ? void 0 : _a.find(u => (u === null || u === void 0 ? void 0 : u[state === null || state === void 0 ? void 0 : state.groupIdKey]) === id);
|
|
24
|
+
if (!group) {
|
|
25
|
+
const user = users.find(u => (u === null || u === void 0 ? void 0 : u[userIdKey]) === id);
|
|
26
|
+
if (!user)
|
|
27
|
+
return null;
|
|
28
|
+
return (React.createElement(AccountChip, { key: user === null || user === void 0 ? void 0 : user[userIdKey], user: user, value: user === null || user === void 0 ? void 0 : user[userIdKey], label: user === null || user === void 0 ? void 0 : user[nameKey], onRemove: () => handleRemove({ userId: user === null || user === void 0 ? void 0 : user[userIdKey], index }) }));
|
|
29
|
+
}
|
|
30
|
+
return (React.createElement(AccountChip, { key: group === null || group === void 0 ? void 0 : group[state.groupIdKey], user: group, value: group === null || group === void 0 ? void 0 : group[state.groupIdKey], label: group === null || group === void 0 ? void 0 : group[state === null || state === void 0 ? void 0 : state.groupNameKey], onRemove: () => handleRemove({ userId: group === null || group === void 0 ? void 0 : group[state.groupIdKey], index }) }));
|
|
31
|
+
})
|
|
32
|
+
: usersSelected === null || usersSelected === void 0 ? void 0 : usersSelected.map((id, index) => {
|
|
33
|
+
if (index >= (state === null || state === void 0 ? void 0 : state.limitShow))
|
|
34
|
+
return null;
|
|
35
|
+
const user = users.find(u => (u === null || u === void 0 ? void 0 : u[userIdKey]) === id);
|
|
36
|
+
return (React.createElement(AccountChip, { key: user === null || user === void 0 ? void 0 : user[userIdKey], user: user, value: user === null || user === void 0 ? void 0 : user[userIdKey], label: user === null || user === void 0 ? void 0 : user[nameKey], onRemove: () => handleRemove({ userId: user === null || user === void 0 ? void 0 : user[userIdKey], index }) }));
|
|
37
|
+
}),
|
|
38
|
+
((_a = state === null || state === void 0 ? void 0 : state.usersSelected) === null || _a === void 0 ? void 0 : _a.length) > (state === null || state === void 0 ? void 0 : state.limitShow) && React.createElement(ButtonViewAll, null),
|
|
39
|
+
!(state === null || state === void 0 ? void 0 : state.isViewMode) && React.createElement(ButtonAdd, null)));
|
|
40
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
// Libraries
|
|
13
|
+
import React, { createContext, useEffect, useMemo, useReducer } from 'react';
|
|
14
|
+
import { uniq } from 'lodash';
|
|
15
|
+
// Reducer
|
|
16
|
+
import { initialState, reducer } from './reducer';
|
|
17
|
+
// Hooks
|
|
18
|
+
import { useGetAbstractUsers } from '../hook';
|
|
19
|
+
const initialContext = {
|
|
20
|
+
state: initialState,
|
|
21
|
+
dispatch: () => { },
|
|
22
|
+
};
|
|
23
|
+
export const SelectAccountContext = createContext(initialContext);
|
|
24
|
+
export const SelectAccountProvider = props => {
|
|
25
|
+
const { children, initData } = props, rest = __rest(props, ["children", "initData"]);
|
|
26
|
+
const [state, dispatch] = useReducer(reducer, Object.assign(Object.assign(Object.assign({}, initialState), rest), { usersSelected: [...(uniq(initData) || [])] }));
|
|
27
|
+
const contextValue = useMemo(() => ({ state, dispatch }), [state, dispatch]);
|
|
28
|
+
const { usersSelected, isInitDone, onChange } = state;
|
|
29
|
+
// Fetch users
|
|
30
|
+
const { isLoading, data } = useGetAbstractUsers({
|
|
31
|
+
queryFn: state.serviceAccounts,
|
|
32
|
+
params: state.paramsFetchUsers,
|
|
33
|
+
search: state.searchType === 'server' ? state.searchText : '',
|
|
34
|
+
});
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
dispatch({ type: 'INIT' });
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!isLoading) {
|
|
40
|
+
dispatch({ type: 'UPDATE_USERS', payload: (data === null || data === void 0 ? void 0 : data[state === null || state === void 0 ? void 0 : state.dataAccountsKey]) || [] });
|
|
41
|
+
dispatch({ type: 'UPDATE_USERS_DISPLAY', payload: (data === null || data === void 0 ? void 0 : data[state === null || state === void 0 ? void 0 : state.dataAccountsKey]) || [] });
|
|
42
|
+
}
|
|
43
|
+
}, [data]);
|
|
44
|
+
// Callback OnChange
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (isInitDone && typeof onChange === 'function') {
|
|
47
|
+
onChange(usersSelected);
|
|
48
|
+
}
|
|
49
|
+
}, [usersSelected]);
|
|
50
|
+
return (React.createElement(SelectAccountContext.Provider, { value: contextValue }, children));
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SelectAccountContext';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SelectAccountContext';
|