@antscorp/antsomi-ui 1.3.5-beta.561 → 1.3.5-beta.563
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/RequestAccess/RequestAccess.d.ts +1 -1
- package/es/components/molecules/RequestAccess/RequestAccess.js +10 -2
- package/es/components/molecules/RequestAccess/styled.js +7 -0
- package/es/components/organism/LeftMenu/hooks/usePermission.js +2 -1
- package/es/utils/common.d.ts +10 -0
- package/es/utils/common.js +13 -0
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ interface RequestAccessProps {
|
|
|
8
8
|
sentSubTitle?: string;
|
|
9
9
|
requestText?: string;
|
|
10
10
|
switchAccountText?: string;
|
|
11
|
-
onRequest?: (message: string) => Promise<
|
|
11
|
+
onRequest?: (message: string) => Promise<any>;
|
|
12
12
|
onSwitchAccount?: () => void;
|
|
13
13
|
}
|
|
14
14
|
export declare const RequestAccess: React.FC<RequestAccessProps>;
|
|
@@ -5,6 +5,7 @@ import { RequestAccessStyled } from './styled';
|
|
|
5
5
|
// Translate
|
|
6
6
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
7
7
|
import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
|
|
8
|
+
import { BlockIcon } from '../../icons';
|
|
8
9
|
const { t } = i18nInstance;
|
|
9
10
|
export const RequestAccess = props => {
|
|
10
11
|
const { className, placeholder = t(translations.requestAccess.placeholder), deniedTitle = t(translations.requestAccess.deniedTitle), deniedSubTitle = t(translations.requestAccess.deniedSubTitle), sentTitle = t(translations.requestAccess.sentTitle), sentSubTitle = t(translations.requestAccess.sentSubTitle), requestText = t(translations.requestAccess.requestText), switchAccountText = t(translations.requestAccess.switchAccountText), onRequest, onSwitchAccount, } = props;
|
|
@@ -18,10 +19,15 @@ export const RequestAccess = props => {
|
|
|
18
19
|
try {
|
|
19
20
|
setIsLoading(true);
|
|
20
21
|
onRequest(message)
|
|
21
|
-
.then(
|
|
22
|
+
.then(data => {
|
|
23
|
+
if (data) {
|
|
24
|
+
setIsSentRequest(true);
|
|
25
|
+
}
|
|
26
|
+
})
|
|
22
27
|
.finally(() => setIsLoading(false));
|
|
23
28
|
}
|
|
24
29
|
catch (error) {
|
|
30
|
+
// the onRequest(message) callback is called in try (have not call again)
|
|
25
31
|
setIsSentRequest(true);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
@@ -33,7 +39,9 @@ export const RequestAccess = props => {
|
|
|
33
39
|
return (React.createElement(RequestAccessStyled, { className: `antsomi-request-access ${className || ''}` },
|
|
34
40
|
React.createElement(Flex, { vertical: true, gap: 20 },
|
|
35
41
|
React.createElement(Flex, { vertical: true, gap: 5 },
|
|
36
|
-
React.createElement(Typography.Text, { className: "denied-title" }, isSentRequest ? sentTitle :
|
|
42
|
+
React.createElement(Typography.Text, { className: "denied-title" }, isSentRequest ? (sentTitle) : (React.createElement(React.Fragment, null,
|
|
43
|
+
deniedTitle,
|
|
44
|
+
React.createElement(BlockIcon, null)))),
|
|
37
45
|
React.createElement(Typography.Text, { className: "denied-sub-title" }, isSentRequest ? sentSubTitle : deniedSubTitle)),
|
|
38
46
|
!isSentRequest ? (React.createElement(TextArea, { style: { resize: 'none' }, placeholder: placeholder, ref: messageRef })) : null,
|
|
39
47
|
React.createElement(Flex, { className: "action-buttons", gap: 10 },
|
|
@@ -13,10 +13,17 @@ export const RequestAccessStyled = styled.div `
|
|
|
13
13
|
width: 350px;
|
|
14
14
|
|
|
15
15
|
.denied-title {
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
gap: 5px;
|
|
18
|
+
|
|
16
19
|
font-size: 20px;
|
|
17
20
|
line-height: 24px;
|
|
18
21
|
font-weight: 700;
|
|
19
22
|
color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.orange6};
|
|
23
|
+
|
|
24
|
+
& > svg {
|
|
25
|
+
color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw5};
|
|
26
|
+
}
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
.denied-sub-title {
|
|
@@ -11,6 +11,7 @@ import { ENV } from '@antscorp/antsomi-ui/es/config';
|
|
|
11
11
|
// Utils
|
|
12
12
|
import { findLastMatchedItemByUrl, findPathOfActiveItem, flattenMenuArray, getMappingAppChildren, recursivePermissionMenu, } from '../utils';
|
|
13
13
|
import { useCheckUserPermission } from '@antscorp/antsomi-ui/es/queries';
|
|
14
|
+
import { recursiveSortBy } from '@antscorp/antsomi-ui/es/utils';
|
|
14
15
|
const { DEV, SANDBOX, SANDBOX_CDP } = ENV;
|
|
15
16
|
export const usePermission = () => {
|
|
16
17
|
const appConfig = useLeftMenuContext(store => store.appConfig);
|
|
@@ -135,7 +136,7 @@ export const usePermission = () => {
|
|
|
135
136
|
userPermission,
|
|
136
137
|
]);
|
|
137
138
|
const mappingChildrenMenuWithNoPermission = useMemo(() => getMappingAppChildren({
|
|
138
|
-
menuList: (menuList === null || menuList === void 0 ? void 0 : menuList.rows) || [],
|
|
139
|
+
menuList: recursiveSortBy((menuList === null || menuList === void 0 ? void 0 : menuList.rows) || [], 'children', ['level_position']) || [],
|
|
139
140
|
auth,
|
|
140
141
|
dashboardList,
|
|
141
142
|
destinationChannelEntries: destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries,
|
package/es/utils/common.d.ts
CHANGED
|
@@ -137,3 +137,13 @@ export declare function splitTextByNewline(text?: string): string[];
|
|
|
137
137
|
* @returns {any | null} The parsed JSON object if successful, or `null` if the parsing fails or the key does not exist.
|
|
138
138
|
*/
|
|
139
139
|
export declare function parseJSONFromLocalStorage<T = any>(key: string): T | null;
|
|
140
|
+
/**
|
|
141
|
+
* Recursively sorts an array of objects by specified keys and also sorts their nested children arrays.
|
|
142
|
+
*
|
|
143
|
+
* @template T - The type of the objects within the array.
|
|
144
|
+
* @param {T[]} arr - The array of objects to be sorted.
|
|
145
|
+
* @param {keyof T} [childrenKey='children'] - The key used to identify the children array in each object.
|
|
146
|
+
* @param {Array<keyof T>} [sortByKeys=[]] - The keys used to sort the objects.
|
|
147
|
+
* @returns {T[]} - The sorted array with each object’s children arrays also sorted recursively.
|
|
148
|
+
*/
|
|
149
|
+
export declare const recursiveSortBy: <T = any>(arr: T[], childrenKey?: keyof T, sortByKeys?: (keyof T)[]) => T[];
|
package/es/utils/common.js
CHANGED
|
@@ -6,6 +6,7 @@ import uniqid from 'uniqid';
|
|
|
6
6
|
import { MESSAGES, PORTAL_KEYS } from '@antscorp/antsomi-ui/es/services/constants';
|
|
7
7
|
// Utils
|
|
8
8
|
import { handleError } from './handleError';
|
|
9
|
+
import { sortBy } from 'lodash';
|
|
9
10
|
const PATH = 'src/utils/common.ts';
|
|
10
11
|
/**
|
|
11
12
|
* Function to reorder list
|
|
@@ -607,3 +608,15 @@ export function parseJSONFromLocalStorage(key) {
|
|
|
607
608
|
return null;
|
|
608
609
|
}
|
|
609
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* Recursively sorts an array of objects by specified keys and also sorts their nested children arrays.
|
|
613
|
+
*
|
|
614
|
+
* @template T - The type of the objects within the array.
|
|
615
|
+
* @param {T[]} arr - The array of objects to be sorted.
|
|
616
|
+
* @param {keyof T} [childrenKey='children'] - The key used to identify the children array in each object.
|
|
617
|
+
* @param {Array<keyof T>} [sortByKeys=[]] - The keys used to sort the objects.
|
|
618
|
+
* @returns {T[]} - The sorted array with each object’s children arrays also sorted recursively.
|
|
619
|
+
*/
|
|
620
|
+
export const recursiveSortBy = (arr, childrenKey = 'children', sortByKeys = []) => sortBy(arr, [...sortByKeys]).map(item => (Object.assign(Object.assign({}, item), (item[childrenKey] && {
|
|
621
|
+
[childrenKey]: recursiveSortBy(item[childrenKey], childrenKey, sortByKeys),
|
|
622
|
+
}))));
|