@yeeyoon/library 3.7.1 → 3.7.2
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.
@@ -1,86 +1,73 @@
|
|
1
|
-
import
|
1
|
+
import { AutoComplete } from 'antd';
|
2
2
|
import PropTypes from 'prop-types';
|
3
|
-
import {
|
3
|
+
import React, { useEffect, useState } from 'react';
|
4
|
+
import { fetchTenantList } from './service';
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
const { Option } = Select;
|
6
|
+
let defaultTenantName;
|
8
7
|
|
9
8
|
const TenantSelector = (props) => {
|
10
9
|
const {
|
11
10
|
tenantId,
|
12
11
|
tenantIdChangeCb,
|
13
12
|
appId,
|
14
|
-
handleException,
|
15
|
-
shareTenantIdList = [],
|
16
|
-
isSharePlatform = false,
|
13
|
+
// handleException,
|
17
14
|
} = props;
|
18
|
-
const [
|
19
|
-
const [
|
15
|
+
const [options, setOptions] = useState([]);
|
16
|
+
const [value, setValue] = useState('');
|
17
|
+
const [placeholder, setPlaceholder] = useState('');
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
const
|
24
|
-
|
25
|
-
|
19
|
+
const searchTenant = async (value = '', tenantId) => {
|
20
|
+
setValue(value);
|
21
|
+
const resp = await fetchTenantList({
|
22
|
+
applicationId: appId,
|
23
|
+
key: value.trim(),
|
24
|
+
});
|
25
|
+
const { success, data } = resp;
|
26
26
|
if (success) {
|
27
|
-
let
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
let tenantList = [];
|
28
|
+
data.forEach((item) => {
|
29
|
+
if (tenantId && tenantId === item.id) {
|
30
|
+
defaultTenantName = item.name;
|
31
|
+
setValue(item.name);
|
32
|
+
}
|
33
|
+
tenantList.push({
|
34
|
+
label: item.name,
|
35
|
+
value: item.id,
|
32
36
|
});
|
33
|
-
}
|
34
|
-
|
35
|
-
handleException && handleException();
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
const result = tenants.filter((item) => item.id === tenantId);
|
39
|
-
if (result.length) {
|
40
|
-
id = tenantId;
|
41
|
-
name = result[0].name;
|
42
|
-
} else {
|
43
|
-
id = tenants[0].id;
|
44
|
-
name = tenants[0].name;
|
45
|
-
}
|
46
|
-
// if (!isSharePlatform) {
|
47
|
-
// tenants = tenants.filter(
|
48
|
-
// (item) => !shareTenantIdList.includes(item.id)
|
49
|
-
// );
|
50
|
-
// } else {
|
51
|
-
// tenants = tenants.filter((item) => shareTenantIdList.includes(item.id));
|
52
|
-
// }
|
53
|
-
if (isSharePlatform) {
|
54
|
-
tenants = tenants.filter((item) => shareTenantIdList.includes(item.id));
|
55
|
-
}
|
56
|
-
setTenantList(tenants);
|
57
|
-
setCurrentTenantId(id);
|
58
|
-
tenantIdChangeCb && tenantIdChangeCb(id, name);
|
37
|
+
});
|
38
|
+
setOptions(tenantList);
|
59
39
|
}
|
40
|
+
};
|
41
|
+
|
42
|
+
useEffect(async () => {
|
43
|
+
searchTenant('', tenantId);
|
60
44
|
}, []);
|
61
45
|
|
62
46
|
return (
|
63
|
-
<
|
64
|
-
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
65
|
-
showSearch
|
66
|
-
optionFilterProp="children"
|
47
|
+
<AutoComplete
|
67
48
|
bordered={false}
|
68
|
-
|
49
|
+
placeholder={placeholder}
|
50
|
+
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
51
|
+
value={value}
|
69
52
|
style={{ width: '215px' }}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
53
|
+
options={options}
|
54
|
+
onChange={(value) => {
|
55
|
+
searchTenant(value);
|
56
|
+
}}
|
57
|
+
onFocus={() => {
|
58
|
+
setValue('');
|
59
|
+
setPlaceholder(defaultTenantName);
|
60
|
+
}}
|
61
|
+
onBlur={() => {
|
62
|
+
// if (value.trim() === '') {
|
63
|
+
setValue(defaultTenantName);
|
64
|
+
// }
|
65
|
+
}}
|
66
|
+
onSelect={(value, option) => {
|
67
|
+
setValue(option.label);
|
68
|
+
tenantIdChangeCb && tenantIdChangeCb(value, option);
|
74
69
|
}}
|
75
|
-
|
76
|
-
{tenantList.map((item) => {
|
77
|
-
return (
|
78
|
-
<Option value={item.id} key={item.id}>
|
79
|
-
{item.name}
|
80
|
-
</Option>
|
81
|
-
);
|
82
|
-
})}
|
83
|
-
</Select>
|
70
|
+
/>
|
84
71
|
);
|
85
72
|
};
|
86
73
|
|
@@ -89,8 +76,6 @@ TenantSelector.propTypes = {
|
|
89
76
|
appId: PropTypes.string,
|
90
77
|
tenantIdChangeCb: PropTypes.func,
|
91
78
|
handleException: PropTypes.func,
|
92
|
-
shareTenantIdList: PropTypes.array,
|
93
|
-
isSharePlatform: PropTypes.bool,
|
94
79
|
};
|
95
80
|
|
96
81
|
export default TenantSelector;
|
@@ -9,3 +9,14 @@ export async function fetchUserInfo() {
|
|
9
9
|
data: {},
|
10
10
|
});
|
11
11
|
}
|
12
|
+
|
13
|
+
export async function fetchTenantList(params) {
|
14
|
+
return request(`/findOidcUserTenantList`, {
|
15
|
+
prefix: `${API_IAM}/api/oidc/v1/oidcuser`,
|
16
|
+
method: 'post',
|
17
|
+
data: {
|
18
|
+
paging: false,
|
19
|
+
...params,
|
20
|
+
},
|
21
|
+
});
|
22
|
+
}
|