@antscorp/antsomi-ui 1.3.5-beta.310 → 1.3.5-beta.312
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/assets/css/main.scss +19 -1
- package/es/components/atoms/Input/Input.d.ts +2 -1
- package/es/components/atoms/Input/Input.js +6 -2
- package/es/components/atoms/Scrollbars/Scrollbars.js +3 -3
- package/es/components/molecules/HeaderV2/HeaderV2.js +7 -3
- package/es/components/molecules/SearchPopover/SearchPopover.d.ts +8 -0
- package/es/components/molecules/SearchPopover/SearchPopover.js +24 -0
- package/es/components/molecules/SearchPopover/index.d.ts +1 -0
- package/es/components/molecules/SearchPopover/index.js +1 -0
- package/es/components/molecules/SearchPopover/styles.scss +29 -0
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +3 -0
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.js +16 -0
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.d.ts +2 -0
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2698 -0
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +8 -0
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +25 -0
- package/es/components/molecules/VirtualizedMenu/components/Item/index.d.ts +1 -0
- package/es/components/molecules/VirtualizedMenu/components/Item/index.js +1 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +3 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +95 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.d.ts +1 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +1 -0
- package/es/components/molecules/VirtualizedMenu/components/index.d.ts +2 -0
- package/es/components/molecules/VirtualizedMenu/components/index.js +2 -0
- package/es/components/molecules/VirtualizedMenu/config.d.ts +12 -0
- package/es/components/molecules/VirtualizedMenu/config.js +12 -0
- package/es/components/molecules/VirtualizedMenu/index.d.ts +2 -0
- package/es/components/molecules/VirtualizedMenu/index.js +1 -0
- package/es/components/molecules/VirtualizedMenu/styled.d.ts +4 -0
- package/es/components/molecules/VirtualizedMenu/styled.js +64 -0
- package/es/components/molecules/VirtualizedMenu/types.d.ts +30 -0
- package/es/components/molecules/VirtualizedMenu/types.js +1 -0
- package/es/components/molecules/VirtualizedMenu/utils.d.ts +16 -0
- package/es/components/molecules/VirtualizedMenu/utils.js +17 -0
- package/es/components/molecules/index.d.ts +4 -0
- package/es/components/molecules/index.js +2 -0
- package/es/components/organism/LeftMenu/components/HomeMenu/useHomeMenu.js +12 -10
- package/es/constants/theme.js +3 -1
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +1 -0
- package/es/hooks/useCustomRouter.d.ts +33 -0
- package/es/hooks/useCustomRouter.js +62 -0
- package/es/queries/LeftMenu/index.js +2 -1
- package/package.json +5 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import { ItemType, VirtualizedMenuProps } from '../../types';
|
|
3
|
+
type ItemProps = Partial<{
|
|
4
|
+
item: ItemType;
|
|
5
|
+
expandIcon: VirtualizedMenuProps['expandIcon'];
|
|
6
|
+
}> & ComponentProps<'div'>;
|
|
7
|
+
export declare const Item: React.MemoExoticComponent<(props: ItemProps) => React.JSX.Element>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import { Typography } from '../../../../atoms/Typography';
|
|
3
|
+
import { Icon } from '../../../../atoms/Icon';
|
|
4
|
+
import { MenuItemRoot } from '../../styled';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
export const Item = memo((props) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const { className, style, item, expandIcon, onClick } = props;
|
|
9
|
+
const handleOnClick = (e) => {
|
|
10
|
+
if (!onClick || (item === null || item === void 0 ? void 0 : item.disabled))
|
|
11
|
+
return;
|
|
12
|
+
onClick(e);
|
|
13
|
+
};
|
|
14
|
+
const renderLabel = () => {
|
|
15
|
+
if (typeof (item === null || item === void 0 ? void 0 : item.label) === 'string') {
|
|
16
|
+
return React.createElement(Typography.Text, { ellipsis: { tooltip: true } }, item.label);
|
|
17
|
+
}
|
|
18
|
+
return item === null || item === void 0 ? void 0 : item.label;
|
|
19
|
+
};
|
|
20
|
+
return (React.createElement(MenuItemRoot, { className: clsx({
|
|
21
|
+
'item-disabled': item === null || item === void 0 ? void 0 : item.disabled,
|
|
22
|
+
}, className), style: style, onClick: handleOnClick },
|
|
23
|
+
React.createElement("div", { className: "item-label" }, renderLabel()),
|
|
24
|
+
!!((_a = item === null || item === void 0 ? void 0 : item.children) === null || _a === void 0 ? void 0 : _a.length) && (React.createElement("div", { className: "sub-menu-arrow" }, expandIcon || React.createElement(Icon, { type: "icon-ants-expand-more" })))));
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Item } from './Item';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Item } from './Item';
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
import React, { forwardRef, useCallback, useMemo, useState } from 'react';
|
|
13
|
+
import { clsx } from 'clsx';
|
|
14
|
+
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
15
|
+
import { VirtualizedMenuContainer } from '../../styled';
|
|
16
|
+
import { INLINE_INDENT, INLINE_PADDING, ITEM_SIZE, ITEM_SPACING, MODE } from '../../config';
|
|
17
|
+
import { getFlattenItems } from '../../utils';
|
|
18
|
+
import { Item } from '../Item';
|
|
19
|
+
import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
|
|
20
|
+
const innerElementType = forwardRef((_a, ref) => {
|
|
21
|
+
var { style } = _a, rest = __rest(_a, ["style"]);
|
|
22
|
+
return React.createElement("div", Object.assign({ ref: ref, style: style }, rest));
|
|
23
|
+
});
|
|
24
|
+
export const MenuInline = (props) => {
|
|
25
|
+
const { width, height, items = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, openKeys: openKeysProp = [], onClick, className, } = props;
|
|
26
|
+
const [openKeys, setOpenKeys] = useState(new Set());
|
|
27
|
+
const [selectedKeys, setSelectedKeys] = useState(new Set());
|
|
28
|
+
useDeepCompareEffect(() => {
|
|
29
|
+
if (!openKeysProp)
|
|
30
|
+
return;
|
|
31
|
+
setOpenKeys(new Set(openKeysProp));
|
|
32
|
+
}, [openKeysProp]);
|
|
33
|
+
const flattenItems = useMemo(() => {
|
|
34
|
+
const result = getFlattenItems({ items });
|
|
35
|
+
return result.filter(item => {
|
|
36
|
+
const isRootItem = item.level === 1;
|
|
37
|
+
const isParentExpand = item.parent && openKeys.has(String(item.parent.key));
|
|
38
|
+
return isRootItem || isParentExpand;
|
|
39
|
+
});
|
|
40
|
+
}, [items, openKeys]);
|
|
41
|
+
const handleCollapseItem = useCallback((item) => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (!((_a = item.children) === null || _a === void 0 ? void 0 : _a.length))
|
|
44
|
+
return;
|
|
45
|
+
const newOpenKeys = new Set(openKeys);
|
|
46
|
+
newOpenKeys.delete(item.key);
|
|
47
|
+
if (item.children) {
|
|
48
|
+
getFlattenItems({ items: item.children }).forEach(childrenItem => {
|
|
49
|
+
const childrenKey = childrenItem.key;
|
|
50
|
+
if (newOpenKeys.has(childrenKey)) {
|
|
51
|
+
newOpenKeys.delete(childrenKey);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
setOpenKeys(newOpenKeys);
|
|
56
|
+
}, [openKeys]);
|
|
57
|
+
const handleExpandItem = useCallback((item) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!((_a = item.children) === null || _a === void 0 ? void 0 : _a.length))
|
|
60
|
+
return;
|
|
61
|
+
const itemKey = item.key;
|
|
62
|
+
const newOpenKeys = new Set(openKeys);
|
|
63
|
+
newOpenKeys.add(itemKey);
|
|
64
|
+
setOpenKeys(newOpenKeys);
|
|
65
|
+
}, [openKeys]);
|
|
66
|
+
const handleClickItem = useCallback((item, idx) => () => {
|
|
67
|
+
var _a;
|
|
68
|
+
const { key } = item;
|
|
69
|
+
const isOpen = openKeys.has(key);
|
|
70
|
+
const hasChilren = !!((_a = item.children) === null || _a === void 0 ? void 0 : _a.length);
|
|
71
|
+
if (hasChilren && isOpen) {
|
|
72
|
+
handleCollapseItem(item);
|
|
73
|
+
}
|
|
74
|
+
if (hasChilren && !isOpen) {
|
|
75
|
+
handleExpandItem(item);
|
|
76
|
+
}
|
|
77
|
+
if (!hasChilren && !selectedKeys.has(key)) {
|
|
78
|
+
setSelectedKeys(new Set([item.key]));
|
|
79
|
+
}
|
|
80
|
+
if (onClick) {
|
|
81
|
+
onClick({ item, pathKey: flattenItems[idx].pathKey });
|
|
82
|
+
}
|
|
83
|
+
}, [flattenItems, handleCollapseItem, handleExpandItem, onClick, openKeys, selectedKeys]);
|
|
84
|
+
const renderItem = useCallback((args) => {
|
|
85
|
+
const { index, style } = args;
|
|
86
|
+
const item = flattenItems[index];
|
|
87
|
+
const indentSize = ((item.level || 0) - 1) * inlineIndent;
|
|
88
|
+
const itemStyle = Object.assign(Object.assign({}, style), { paddingLeft: indentSize + inlinePadding, paddingRight: inlinePadding, marginTop: itemSpacing, marginBottom: itemSpacing });
|
|
89
|
+
return (React.createElement(Item, { className: clsx({
|
|
90
|
+
'item-selected': selectedKeys.has(item.key),
|
|
91
|
+
}, item.className), onClick: handleClickItem(item, index), style: itemStyle, item: item }));
|
|
92
|
+
}, [flattenItems, handleClickItem, inlinePadding, inlineIndent, itemSpacing, selectedKeys]);
|
|
93
|
+
// console.log('render');
|
|
94
|
+
return (React.createElement(AutoSizer, null, autoSize => (React.createElement(VirtualizedMenuContainer, { className: clsx(`menu-${MODE.Inline}`, className), itemSize: () => itemSize + itemSpacing, itemCount: flattenItems.length, height: height || autoSize.scaledHeight, width: width || autoSize.scaledWidth, innerElementType: innerElementType, useIsScrolling: true }, renderItem))));
|
|
95
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MenuInline } from './MenuInline';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MenuInline } from './MenuInline';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const MODE: {
|
|
2
|
+
readonly Inline: "inline";
|
|
3
|
+
};
|
|
4
|
+
export declare const ACTION_TYPES: {
|
|
5
|
+
readonly init: "init";
|
|
6
|
+
readonly reset: "reset";
|
|
7
|
+
readonly toggleExpand: "toggleExpand";
|
|
8
|
+
};
|
|
9
|
+
export declare const INLINE_PADDING = 10;
|
|
10
|
+
export declare const INLINE_INDENT = 10;
|
|
11
|
+
export declare const ITEM_SPACING: number;
|
|
12
|
+
export declare const ITEM_SIZE: number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var _a, _b, _c, _d, _e;
|
|
2
|
+
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
3
|
+
export const MODE = { Inline: 'inline' };
|
|
4
|
+
export const ACTION_TYPES = {
|
|
5
|
+
init: 'init',
|
|
6
|
+
reset: 'reset',
|
|
7
|
+
toggleExpand: 'toggleExpand',
|
|
8
|
+
};
|
|
9
|
+
export const INLINE_PADDING = 10;
|
|
10
|
+
export const INLINE_INDENT = 10;
|
|
11
|
+
export const ITEM_SPACING = parseFloat(((_c = (_b = (_a = THEME.components) === null || _a === void 0 ? void 0 : _a.Menu) === null || _b === void 0 ? void 0 : _b.itemMarginBlock) === null || _c === void 0 ? void 0 : _c.toString()) || '10');
|
|
12
|
+
export const ITEM_SIZE = ((_e = (_d = THEME.components) === null || _d === void 0 ? void 0 : _d.Menu) === null || _e === void 0 ? void 0 : _e.itemHeight) || 35;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VirtualizedMenu } from './VirtualizedMenu';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { VariableSizeList as List } from 'react-window';
|
|
2
|
+
export declare const MenuItemWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const MenuItemRoot: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
+
export declare const VirtualizedMenuContainer: import("styled-components").StyledComponent<typeof List, any, {}, never>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { VariableSizeList as List } from 'react-window';
|
|
4
|
+
import { THEME, globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
5
|
+
export const MenuItemWrapper = styled.div `
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
display: flex;
|
|
9
|
+
gap: 8px;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
padding: 5px;
|
|
12
|
+
align-items: center;
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
|
|
15
|
+
.icon-expand {
|
|
16
|
+
font-size: 14px;
|
|
17
|
+
flex-shirnk: 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.title-wrapper {
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
text-overflow: ellipsis;
|
|
23
|
+
white-space: nowrap;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
export const MenuItemRoot = styled.div `
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
border-radius: ${(_b = (_a = THEME.components) === null || _a === void 0 ? void 0 : _a.Menu) === null || _b === void 0 ? void 0 : _b.itemBorderRadius}px;
|
|
32
|
+
|
|
33
|
+
> .item-label {
|
|
34
|
+
flex: 1;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
> .sub-menu-arrow {
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.item-disabled {
|
|
45
|
+
color: ${(_d = (_c = THEME.components) === null || _c === void 0 ? void 0 : _c.Menu) === null || _d === void 0 ? void 0 : _d.itemDisabledColor};
|
|
46
|
+
cursor: not-allowed;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&.item-selected {
|
|
50
|
+
background-color: ${(_f = (_e = THEME.components) === null || _e === void 0 ? void 0 : _e.Menu) === null || _f === void 0 ? void 0 : _f.itemActiveBg};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&:hover:not(.item-disabled, .item-selected) {
|
|
54
|
+
background-color: ${(_h = (_g = THEME.components) === null || _g === void 0 ? void 0 : _g.Menu) === null || _h === void 0 ? void 0 : _h.itemHoverBg};
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
export const VirtualizedMenuContainer = styled(List) `
|
|
58
|
+
font-size: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.fontSize}px;
|
|
59
|
+
overflow: hidden !important;
|
|
60
|
+
|
|
61
|
+
&:hover {
|
|
62
|
+
overflow: auto !important;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
2
|
+
import { MODE } from './config';
|
|
3
|
+
export type ItemType = {
|
|
4
|
+
key: string;
|
|
5
|
+
} & Partial<{
|
|
6
|
+
scrollingLabel: string;
|
|
7
|
+
label: ReactNode;
|
|
8
|
+
children: ItemType[];
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}> & Pick<ComponentPropsWithoutRef<'div'>, 'className'>;
|
|
11
|
+
export type VirtualizedMenuProps = Partial<{
|
|
12
|
+
items: ItemType[];
|
|
13
|
+
mode: (typeof MODE)[keyof typeof MODE];
|
|
14
|
+
expandIcon: ReactNode;
|
|
15
|
+
height: number;
|
|
16
|
+
width: number;
|
|
17
|
+
inlineIndent: number;
|
|
18
|
+
inlinePadding: number;
|
|
19
|
+
itemSpacing: number;
|
|
20
|
+
itemSize: number;
|
|
21
|
+
openKeys: string[];
|
|
22
|
+
selectedKeys: string[];
|
|
23
|
+
onClick: (args: {
|
|
24
|
+
item: ItemType;
|
|
25
|
+
pathKey: PathKey;
|
|
26
|
+
}) => void;
|
|
27
|
+
className: string;
|
|
28
|
+
}>;
|
|
29
|
+
export type PathKey = (string | number)[];
|
|
30
|
+
export type MenuInlineProps = Omit<VirtualizedMenuProps, 'mode'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ItemType, PathKey } from './types';
|
|
3
|
+
export declare const getFlattenItems: (args: {
|
|
4
|
+
items: ItemType[];
|
|
5
|
+
}) => ({
|
|
6
|
+
key: string;
|
|
7
|
+
} & Partial<{
|
|
8
|
+
scrollingLabel: string;
|
|
9
|
+
label: import("react").ReactNode;
|
|
10
|
+
children: ItemType[];
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
}> & Pick<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "className"> & {
|
|
13
|
+
level: number;
|
|
14
|
+
pathKey: PathKey;
|
|
15
|
+
parent: ItemType | null;
|
|
16
|
+
})[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const getFlattenItems = (args) => {
|
|
2
|
+
const { items } = args;
|
|
3
|
+
const result = [];
|
|
4
|
+
function recursively(items, level, pathKey, parent) {
|
|
5
|
+
items.forEach((item, idx) => {
|
|
6
|
+
const currentPathKey = [...pathKey, idx, item.key.toString()];
|
|
7
|
+
result.push(Object.assign(Object.assign({}, item), { level, pathKey: currentPathKey, parent }));
|
|
8
|
+
if (item.children && item.children.length > 0) {
|
|
9
|
+
recursively(item.children, level + 1, currentPathKey, item);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (items.length) {
|
|
14
|
+
recursively(items, 1, [], null);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
@@ -47,6 +47,8 @@ export * from './SelectEventAttribute';
|
|
|
47
47
|
export * from './DatePickerV2';
|
|
48
48
|
export { ModalSelect } from './ModalSelect';
|
|
49
49
|
export { EditableName } from './EditableName';
|
|
50
|
+
export { VirtualizedMenu } from './VirtualizedMenu';
|
|
51
|
+
export { SearchPopover } from './SearchPopover';
|
|
50
52
|
export * from './EmptyData';
|
|
51
53
|
export * from './PreviewModal';
|
|
52
54
|
export * from './Drawer';
|
|
@@ -68,3 +70,5 @@ export type { ModalSelectProps } from './ModalSelect';
|
|
|
68
70
|
export type { ImageResizeHandle } from './ImageEditor';
|
|
69
71
|
export type { EditableNameHandle } from './EditableName';
|
|
70
72
|
export type { AccountListingHandle, AccountSelectionProps } from './AccountSelection';
|
|
73
|
+
export type { VirtualizedMenuProps } from './VirtualizedMenu';
|
|
74
|
+
export type { SearchPopoverProps } from './SearchPopover';
|
|
@@ -47,6 +47,8 @@ export * from './SelectEventAttribute';
|
|
|
47
47
|
export * from './DatePickerV2';
|
|
48
48
|
export { ModalSelect } from './ModalSelect';
|
|
49
49
|
export { EditableName } from './EditableName';
|
|
50
|
+
export { VirtualizedMenu } from './VirtualizedMenu';
|
|
51
|
+
export { SearchPopover } from './SearchPopover';
|
|
50
52
|
export * from './EmptyData';
|
|
51
53
|
export * from './PreviewModal';
|
|
52
54
|
export * from './Drawer';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import { useHistory } from 'react-router-dom';
|
|
3
|
+
// import { useHistory } from 'react-router-dom';
|
|
4
4
|
// Constants
|
|
5
5
|
import { CONFIG_OPTIONS } from './constants';
|
|
6
6
|
import { HOME_REPORT_ROUTES, HOME_ROUTE } from '../../constants';
|
|
@@ -9,9 +9,11 @@ import { getGeneratePath, getMenuItem } from '../../utils';
|
|
|
9
9
|
// Types
|
|
10
10
|
import { useLeftMenuStore } from '../../stores';
|
|
11
11
|
import { useLayoutStore } from '@antscorp/antsomi-ui/es/components/template';
|
|
12
|
+
import { useCustomRouter } from '@antscorp/antsomi-ui/es/hooks';
|
|
12
13
|
export const useHomeMenu = () => {
|
|
13
14
|
const { pathname, search } = window.location;
|
|
14
|
-
const history = useHistory();
|
|
15
|
+
// const history = useHistory();
|
|
16
|
+
const { navigate, replace } = useCustomRouter();
|
|
15
17
|
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
16
18
|
const auth = useLeftMenuStore(store => { var _a; return (_a = store.state.appConfig) === null || _a === void 0 ? void 0 : _a.auth; });
|
|
17
19
|
const onClickCreateDashboard = useLayoutStore(store => store.state.leftMenu.onClickCreateDashboard);
|
|
@@ -21,9 +23,9 @@ export const useHomeMenu = () => {
|
|
|
21
23
|
switch (optionKey) {
|
|
22
24
|
case CONFIG_OPTIONS.CONFIGURE.key: {
|
|
23
25
|
const newPathName = getGeneratePath(HOME_REPORT_ROUTES.DETAIL, Object.assign(Object.assign({}, auth), { dashboardId: menuItemKey }));
|
|
24
|
-
|
|
26
|
+
navigate(newPathName);
|
|
25
27
|
urlParams.set('type', HOME_REPORT_ROUTES.CONFIGURE);
|
|
26
|
-
|
|
28
|
+
replace({ search: urlParams.toString() });
|
|
27
29
|
break;
|
|
28
30
|
}
|
|
29
31
|
case CONFIG_OPTIONS.REMOVE.key:
|
|
@@ -31,7 +33,7 @@ export const useHomeMenu = () => {
|
|
|
31
33
|
default:
|
|
32
34
|
break;
|
|
33
35
|
}
|
|
34
|
-
}, [auth,
|
|
36
|
+
}, [auth, navigate, replace, urlParams]);
|
|
35
37
|
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(appMenuItem => {
|
|
36
38
|
var _a;
|
|
37
39
|
return getMenuItem(Object.assign(Object.assign({}, appMenuItem), { children: (_a = appMenuItem === null || appMenuItem === void 0 ? void 0 : appMenuItem.children) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), { options: Object.values(CONFIG_OPTIONS), optionCallback: onOptionCallback }))) }));
|
|
@@ -41,17 +43,17 @@ export const useHomeMenu = () => {
|
|
|
41
43
|
onClickCreateDashboard(e);
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
|
-
|
|
46
|
+
navigate(getGeneratePath(HOME_ROUTE, auth));
|
|
45
47
|
urlParams.set('type', HOME_REPORT_ROUTES.CREATE);
|
|
46
|
-
|
|
48
|
+
replace({ search: urlParams.toString() });
|
|
47
49
|
}
|
|
48
|
-
}, [auth,
|
|
50
|
+
}, [auth, navigate, onClickCreateDashboard, replace, urlParams]);
|
|
49
51
|
const onMenuClick = useCallback((key, _) => {
|
|
50
52
|
const newPathName = getGeneratePath(HOME_REPORT_ROUTES.DETAIL, Object.assign(Object.assign({}, auth), { dashboardId: key }));
|
|
51
53
|
if (newPathName !== pathname) {
|
|
52
|
-
|
|
54
|
+
navigate(newPathName);
|
|
53
55
|
}
|
|
54
|
-
}, [auth, pathname,
|
|
56
|
+
}, [auth, pathname, navigate]);
|
|
55
57
|
return {
|
|
56
58
|
children: customChildren,
|
|
57
59
|
/* Callbacks */
|
package/es/constants/theme.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
1
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
2
2
|
// Types
|
|
3
3
|
import { theme } from 'antd';
|
|
4
4
|
// Variables
|
|
@@ -214,6 +214,8 @@ THEME.components = {
|
|
|
214
214
|
itemMarginBlock: 5,
|
|
215
215
|
itemBorderRadius: 5,
|
|
216
216
|
subMenuItemBg: 'transparent',
|
|
217
|
+
itemDisabledColor: (_1 = THEME.token) === null || _1 === void 0 ? void 0 : _1.colorTextDisabled,
|
|
218
|
+
itemActiveBg: (_2 = THEME.token) === null || _2 === void 0 ? void 0 : _2.blue1_1,
|
|
217
219
|
},
|
|
218
220
|
Form: {},
|
|
219
221
|
};
|
package/es/hooks/index.d.ts
CHANGED
package/es/hooks/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { To } from 'react-router-dom';
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook to handle navigation in React applications supporting both react-router v5 and v6.
|
|
4
|
+
*
|
|
5
|
+
* This hook tries to use `useNavigate` from `react-router-dom` for v6. If it fails, it falls back to
|
|
6
|
+
* `useHistory` for v5.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Object} An object containing the `navigate` and `replace` functions.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Function} return.navigate - Function to navigate to a specified route.
|
|
11
|
+
* @param {string | object} return.navigate.to - The target route path or location object.
|
|
12
|
+
* @param {Object} [return.navigate.options] - Optional navigation options.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Function} return.replace - Function to replace the current route with a specified route.
|
|
15
|
+
* @param {string | object} return.replace.to - The target route path or location object.
|
|
16
|
+
* @param {Object} [return.replace.options] - Optional navigation options.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const { navigate, replace } = useCustomRouter();
|
|
20
|
+
*
|
|
21
|
+
* // Navigate to a route
|
|
22
|
+
* navigate('/home');
|
|
23
|
+
*
|
|
24
|
+
* // Navigate with options
|
|
25
|
+
* navigate('/profile', { state: { userId: 1 } });
|
|
26
|
+
*
|
|
27
|
+
* // Replace current route
|
|
28
|
+
* replace('/login');
|
|
29
|
+
*/
|
|
30
|
+
export declare const useCustomRouter: () => {
|
|
31
|
+
navigate: (to: To, options?: any) => void;
|
|
32
|
+
replace: (to: To, options?: any) => void;
|
|
33
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
3
|
+
// Libraries
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook to handle navigation in React applications supporting both react-router v5 and v6.
|
|
7
|
+
*
|
|
8
|
+
* This hook tries to use `useNavigate` from `react-router-dom` for v6. If it fails, it falls back to
|
|
9
|
+
* `useHistory` for v5.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Object} An object containing the `navigate` and `replace` functions.
|
|
12
|
+
*
|
|
13
|
+
* @returns {Function} return.navigate - Function to navigate to a specified route.
|
|
14
|
+
* @param {string | object} return.navigate.to - The target route path or location object.
|
|
15
|
+
* @param {Object} [return.navigate.options] - Optional navigation options.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function} return.replace - Function to replace the current route with a specified route.
|
|
18
|
+
* @param {string | object} return.replace.to - The target route path or location object.
|
|
19
|
+
* @param {Object} [return.replace.options] - Optional navigation options.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { navigate, replace } = useCustomRouter();
|
|
23
|
+
*
|
|
24
|
+
* // Navigate to a route
|
|
25
|
+
* navigate('/home');
|
|
26
|
+
*
|
|
27
|
+
* // Navigate with options
|
|
28
|
+
* navigate('/profile', { state: { userId: 1 } });
|
|
29
|
+
*
|
|
30
|
+
* // Replace current route
|
|
31
|
+
* replace('/login');
|
|
32
|
+
*/
|
|
33
|
+
export const useCustomRouter = () => {
|
|
34
|
+
try {
|
|
35
|
+
const { useNavigate } = require('react-router-dom');
|
|
36
|
+
const navigateV6 = useNavigate();
|
|
37
|
+
const navigate = useCallback((to, options) => {
|
|
38
|
+
navigateV6(to, options);
|
|
39
|
+
}, [navigateV6]);
|
|
40
|
+
const replace = useCallback((to, options) => {
|
|
41
|
+
navigateV6(to, Object.assign({ replace: true }, options));
|
|
42
|
+
}, [navigateV6]);
|
|
43
|
+
return {
|
|
44
|
+
navigate,
|
|
45
|
+
replace,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const { useHistory } = require('react-router-dom');
|
|
50
|
+
const history = useHistory();
|
|
51
|
+
const navigate = useCallback((to, options) => {
|
|
52
|
+
history.push(to, options);
|
|
53
|
+
}, [history]);
|
|
54
|
+
const replace = useCallback((to, options) => {
|
|
55
|
+
history.replace(to, options);
|
|
56
|
+
}, [history]);
|
|
57
|
+
return {
|
|
58
|
+
navigate,
|
|
59
|
+
replace,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -15,7 +15,8 @@ export const useGetListMenu = (params) => {
|
|
|
15
15
|
};
|
|
16
16
|
export const useGetListMenuPermission = (params) => {
|
|
17
17
|
const { options, args } = params;
|
|
18
|
-
|
|
18
|
+
const { token, accountId, userId } = args.auth;
|
|
19
|
+
return useQuery(Object.assign({ queryKey: [QUERY_KEYS.GET_LIST_MENU_PERMISSION, args.params, token, accountId, userId], queryFn: () => getListMenuPermission(params.args), onSuccess() { } }, options));
|
|
19
20
|
};
|
|
20
21
|
export const useGetDestinationChannel = (params) => {
|
|
21
22
|
const { options, args } = params;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antscorp/antsomi-ui",
|
|
3
|
-
"version": "1.3.5-beta.
|
|
3
|
+
"version": "1.3.5-beta.312",
|
|
4
4
|
"description": "An enterprise-class UI design language and React UI library.",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"dist/*",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"@types/react-custom-scrollbars": "^4.0.13",
|
|
82
82
|
"@types/react-frame-component": "^4.1.6",
|
|
83
83
|
"@types/react-router-dom": "^5.3.3",
|
|
84
|
+
"@types/react-window": "^1.8.8",
|
|
84
85
|
"ace-builds": "1.4.14",
|
|
85
86
|
"animate.css": "^4.1.1",
|
|
86
87
|
"antd": "5.12.6",
|
|
@@ -114,6 +115,8 @@
|
|
|
114
115
|
"react-markdown": "^8.0.7",
|
|
115
116
|
"react-resizable": "^3.0.5",
|
|
116
117
|
"react-syntax-highlighter": "^15.5.0",
|
|
118
|
+
"react-virtualized-auto-sizer": "^1.0.24",
|
|
119
|
+
"react-window": "^1.8.10",
|
|
117
120
|
"rehype-highlight": "^6.0.0",
|
|
118
121
|
"remark-gfm": "^3.0.1",
|
|
119
122
|
"socket.io-client": "^4.7.5",
|
|
@@ -208,7 +211,7 @@
|
|
|
208
211
|
"react-dom": "18.2.0",
|
|
209
212
|
"react-fast-compare": "^3.2.1",
|
|
210
213
|
"react-i18next": "11.16.7",
|
|
211
|
-
"react-router-dom": "5.1.0",
|
|
214
|
+
"react-router-dom": "5.1.0 || 6.14.2",
|
|
212
215
|
"sass": "^1.60.0",
|
|
213
216
|
"sass-loader": "^13.2.2",
|
|
214
217
|
"storybook": "8.0.5",
|