@cloud-ru/ds-uikit-product-page-layout 2.3.0 → 2.3.1-preview-93c4db1d.0
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.
|
@@ -10,6 +10,7 @@ const adaptive_1 = require("@cloud-ru/ds-adaptive");
|
|
|
10
10
|
const button_1 = require("@cloud-ru/ds-button");
|
|
11
11
|
const system_1 = require("@cloud-ru/ds-icons/interface/system");
|
|
12
12
|
const list_1 = require("@cloud-ru/ds-list");
|
|
13
|
+
const modal_1 = require("@cloud-ru/ds-modal");
|
|
13
14
|
const tooltip_1 = require("@cloud-ru/ds-tooltip");
|
|
14
15
|
const uikit_product_quota_1 = require("@cloud-ru/ds-uikit-product-quota");
|
|
15
16
|
const utils_1 = require("@cloud-ru/ds-utils");
|
|
@@ -19,22 +20,29 @@ const ActionView_1 = require("./ActionView");
|
|
|
19
20
|
const constants_2 = require("./constants");
|
|
20
21
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
21
22
|
const utils_2 = require("./utils");
|
|
23
|
+
function isOverflowOnly(action) {
|
|
24
|
+
return action.variant === constants_2.BUTTON_TYPE.Kebab || action.variant === constants_2.BUTTON_TYPE.Quota;
|
|
25
|
+
}
|
|
22
26
|
function MobileActionsBase({ items, maxVisibleItems }) {
|
|
23
27
|
const containerRef = (0, react_2.useRef)(null);
|
|
24
28
|
const [isOpen, setIsOpen] = (0, react_2.useState)(false);
|
|
29
|
+
const [openQuotaIndex, setOpenQuotaIndex] = (0, react_2.useState)();
|
|
30
|
+
const activeAction = openQuotaIndex === undefined ? undefined : items[openQuotaIndex];
|
|
31
|
+
const openQuota = activeAction?.variant === constants_2.BUTTON_TYPE.Quota ? activeAction : undefined;
|
|
25
32
|
const availableItems = (0, react_2.useMemo)(() => items.filter(item => !item.hidden), [items]);
|
|
33
|
+
const measurableItems = (0, react_2.useMemo)(() => availableItems.filter(action => action.variant !== constants_2.BUTTON_TYPE.Quota), [availableItems]);
|
|
26
34
|
const { visibleItems, hiddenItems } = (0, utils_1.useDynamicList)({
|
|
27
35
|
parentContainerRef: containerRef,
|
|
28
|
-
items:
|
|
36
|
+
items: measurableItems,
|
|
29
37
|
maxVisibleItems,
|
|
30
38
|
});
|
|
31
39
|
const { t: tQuota } = uikit_product_quota_1.quotaLocale.useTranslations();
|
|
32
40
|
if (!(0, utils_2.hasVisibleActions)(items)) {
|
|
33
41
|
return null;
|
|
34
42
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const droplistItems =
|
|
43
|
+
const overflowItems = availableItems.filter(action => isOverflowOnly(action) || hiddenItems.includes(action));
|
|
44
|
+
const visibleActions = visibleItems.filter(action => !isOverflowOnly(action));
|
|
45
|
+
const droplistItems = overflowItems.reduce((acc, action) => {
|
|
38
46
|
if (action.variant === 'custom') {
|
|
39
47
|
const { asListItem } = action.render();
|
|
40
48
|
acc.push({
|
|
@@ -70,18 +78,14 @@ function MobileActionsBase({ items, maxVisibleItems }) {
|
|
|
70
78
|
break;
|
|
71
79
|
}
|
|
72
80
|
case constants_2.BUTTON_TYPE.Quota: {
|
|
73
|
-
// QuotaWidget самодостаточен (свой триггер + dropdown) — рендерим инлайн как inactive-айтем.
|
|
74
|
-
const quotaWidget = (0, jsx_runtime_1.jsx)(uikit_product_quota_1.QuotaWidget, { ...action, buttonProps: { size: 'm', fullWidth: true } });
|
|
75
81
|
acc.push({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
],
|
|
82
|
+
content: { label: action.buttonProps?.label ?? tQuota('quotas') },
|
|
83
|
+
disabled: action.buttonProps?.disabled,
|
|
84
|
+
onClick: () => {
|
|
85
|
+
setIsOpen(false);
|
|
86
|
+
setOpenQuotaIndex(items.indexOf(action));
|
|
87
|
+
action.onWidgetOpen?.();
|
|
88
|
+
},
|
|
85
89
|
});
|
|
86
90
|
break;
|
|
87
91
|
}
|
|
@@ -124,7 +128,7 @@ function MobileActionsBase({ items, maxVisibleItems }) {
|
|
|
124
128
|
}
|
|
125
129
|
return acc;
|
|
126
130
|
}, []);
|
|
127
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.mobileActionsWrapper, ref: containerRef, "data-test-id": constants_1.TEST_IDS.mobileActions.root, children: [droplistItems.length > 0 && ((0, jsx_runtime_1.jsx)(list_1.Droplist, { size: 'm', open: isOpen, onOpenChange: setIsOpen, items: droplistItems, children: (0, jsx_runtime_1.jsx)(button_1.Button, { className: styles_module_scss_1.default.button, view: button_1.VIEW.Outline, appearance: 'neutral', icon: (0, jsx_runtime_1.jsx)(system_1.KebabSVG, {}), size: 'm', "data-test-id": constants_1.TEST_IDS.mobileActions.trigger }) })),
|
|
131
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.mobileActionsWrapper, ref: containerRef, "data-test-id": constants_1.TEST_IDS.mobileActions.root, children: [droplistItems.length > 0 && ((0, jsx_runtime_1.jsx)(list_1.Droplist, { size: 'm', open: isOpen, onOpenChange: setIsOpen, items: droplistItems, children: (0, jsx_runtime_1.jsx)(button_1.Button, { className: styles_module_scss_1.default.button, view: button_1.VIEW.Outline, appearance: 'neutral', icon: (0, jsx_runtime_1.jsx)(system_1.KebabSVG, {}), size: 'm', "data-test-id": constants_1.TEST_IDS.mobileActions.trigger }) })), openQuota && ((0, jsx_runtime_1.jsxs)(modal_1.ModalCustom, { open: true, onClose: () => setOpenQuotaIndex(undefined), snapPoints: [1], children: [(0, jsx_runtime_1.jsx)(modal_1.ModalCustom.Header, { title: tQuota('quotas'), subtitle: openQuota.projectName }), (0, jsx_runtime_1.jsx)(modal_1.ModalCustom.Body, { content: (0, jsx_runtime_1.jsx)(uikit_product_quota_1.QuotaWidgetContent, { quotas: openQuota.quotas, quotasUrl: openQuota.quotasUrl, projectName: openQuota.projectName, loading: openQuota.loading, error: openQuota.error, onRefresh: openQuota.onRefresh, canEditQuota: openQuota.canEditQuota, onIncreaseQuotaClick: openQuota.onIncreaseQuotaClick, onQuotasUrlClick: openQuota.onQuotasUrlClick, disableSorting: openQuota.disableSorting, skeletonRowCount: openQuota.skeletonRowCount, hideMobileHeader: true }) })] })), visibleActions.map((action, index) => ((0, react_1.createElement)(ActionView_1.ActionView, { ...action, key: index, commonProps: {
|
|
128
132
|
className: styles_module_scss_1.default.button,
|
|
129
133
|
size: 'm',
|
|
130
134
|
fullWidth: true,
|
|
@@ -4,8 +4,9 @@ import { LAYOUT_TYPE, withLayoutType } from '@cloud-ru/ds-adaptive';
|
|
|
4
4
|
import { Button, VIEW } from '@cloud-ru/ds-button';
|
|
5
5
|
import { KebabSVG } from '@cloud-ru/ds-icons/interface/system';
|
|
6
6
|
import { Droplist } from '@cloud-ru/ds-list';
|
|
7
|
+
import { ModalCustom } from '@cloud-ru/ds-modal';
|
|
7
8
|
import { Tooltip } from '@cloud-ru/ds-tooltip';
|
|
8
|
-
import { quotaLocale,
|
|
9
|
+
import { quotaLocale, QuotaWidgetContent } from '@cloud-ru/ds-uikit-product-quota';
|
|
9
10
|
import { useDynamicList } from '@cloud-ru/ds-utils';
|
|
10
11
|
import { useMemo, useRef, useState } from 'react';
|
|
11
12
|
import { TEST_IDS } from '../../constants.js';
|
|
@@ -13,22 +14,29 @@ import { ActionView } from './ActionView.js';
|
|
|
13
14
|
import { BUTTON_TYPE } from './constants.js';
|
|
14
15
|
import styles from './styles.module.css';
|
|
15
16
|
import { hasVisibleActions } from './utils.js';
|
|
17
|
+
function isOverflowOnly(action) {
|
|
18
|
+
return action.variant === BUTTON_TYPE.Kebab || action.variant === BUTTON_TYPE.Quota;
|
|
19
|
+
}
|
|
16
20
|
function MobileActionsBase({ items, maxVisibleItems }) {
|
|
17
21
|
const containerRef = useRef(null);
|
|
18
22
|
const [isOpen, setIsOpen] = useState(false);
|
|
23
|
+
const [openQuotaIndex, setOpenQuotaIndex] = useState();
|
|
24
|
+
const activeAction = openQuotaIndex === undefined ? undefined : items[openQuotaIndex];
|
|
25
|
+
const openQuota = activeAction?.variant === BUTTON_TYPE.Quota ? activeAction : undefined;
|
|
19
26
|
const availableItems = useMemo(() => items.filter(item => !item.hidden), [items]);
|
|
27
|
+
const measurableItems = useMemo(() => availableItems.filter(action => action.variant !== BUTTON_TYPE.Quota), [availableItems]);
|
|
20
28
|
const { visibleItems, hiddenItems } = useDynamicList({
|
|
21
29
|
parentContainerRef: containerRef,
|
|
22
|
-
items:
|
|
30
|
+
items: measurableItems,
|
|
23
31
|
maxVisibleItems,
|
|
24
32
|
});
|
|
25
33
|
const { t: tQuota } = quotaLocale.useTranslations();
|
|
26
34
|
if (!hasVisibleActions(items)) {
|
|
27
35
|
return null;
|
|
28
36
|
}
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const droplistItems =
|
|
37
|
+
const overflowItems = availableItems.filter(action => isOverflowOnly(action) || hiddenItems.includes(action));
|
|
38
|
+
const visibleActions = visibleItems.filter(action => !isOverflowOnly(action));
|
|
39
|
+
const droplistItems = overflowItems.reduce((acc, action) => {
|
|
32
40
|
if (action.variant === 'custom') {
|
|
33
41
|
const { asListItem } = action.render();
|
|
34
42
|
acc.push({
|
|
@@ -64,18 +72,14 @@ function MobileActionsBase({ items, maxVisibleItems }) {
|
|
|
64
72
|
break;
|
|
65
73
|
}
|
|
66
74
|
case BUTTON_TYPE.Quota: {
|
|
67
|
-
// QuotaWidget самодостаточен (свой триггер + dropdown) — рендерим инлайн как inactive-айтем.
|
|
68
|
-
const quotaWidget = _jsx(QuotaWidget, { ...action, buttonProps: { size: 'm', fullWidth: true } });
|
|
69
75
|
acc.push({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
],
|
|
76
|
+
content: { label: action.buttonProps?.label ?? tQuota('quotas') },
|
|
77
|
+
disabled: action.buttonProps?.disabled,
|
|
78
|
+
onClick: () => {
|
|
79
|
+
setIsOpen(false);
|
|
80
|
+
setOpenQuotaIndex(items.indexOf(action));
|
|
81
|
+
action.onWidgetOpen?.();
|
|
82
|
+
},
|
|
79
83
|
});
|
|
80
84
|
break;
|
|
81
85
|
}
|
|
@@ -118,7 +122,7 @@ function MobileActionsBase({ items, maxVisibleItems }) {
|
|
|
118
122
|
}
|
|
119
123
|
return acc;
|
|
120
124
|
}, []);
|
|
121
|
-
return (_jsxs("div", { className: styles.mobileActionsWrapper, ref: containerRef, "data-test-id": TEST_IDS.mobileActions.root, children: [droplistItems.length > 0 && (_jsx(Droplist, { size: 'm', open: isOpen, onOpenChange: setIsOpen, items: droplistItems, children: _jsx(Button, { className: styles.button, view: VIEW.Outline, appearance: 'neutral', icon: _jsx(KebabSVG, {}), size: 'm', "data-test-id": TEST_IDS.mobileActions.trigger }) })),
|
|
125
|
+
return (_jsxs("div", { className: styles.mobileActionsWrapper, ref: containerRef, "data-test-id": TEST_IDS.mobileActions.root, children: [droplistItems.length > 0 && (_jsx(Droplist, { size: 'm', open: isOpen, onOpenChange: setIsOpen, items: droplistItems, children: _jsx(Button, { className: styles.button, view: VIEW.Outline, appearance: 'neutral', icon: _jsx(KebabSVG, {}), size: 'm', "data-test-id": TEST_IDS.mobileActions.trigger }) })), openQuota && (_jsxs(ModalCustom, { open: true, onClose: () => setOpenQuotaIndex(undefined), snapPoints: [1], children: [_jsx(ModalCustom.Header, { title: tQuota('quotas'), subtitle: openQuota.projectName }), _jsx(ModalCustom.Body, { content: _jsx(QuotaWidgetContent, { quotas: openQuota.quotas, quotasUrl: openQuota.quotasUrl, projectName: openQuota.projectName, loading: openQuota.loading, error: openQuota.error, onRefresh: openQuota.onRefresh, canEditQuota: openQuota.canEditQuota, onIncreaseQuotaClick: openQuota.onIncreaseQuotaClick, onQuotasUrlClick: openQuota.onQuotasUrlClick, disableSorting: openQuota.disableSorting, skeletonRowCount: openQuota.skeletonRowCount, hideMobileHeader: true }) })] })), visibleActions.map((action, index) => (_createElement(ActionView, { ...action, key: index, commonProps: {
|
|
122
126
|
className: styles.button,
|
|
123
127
|
size: 'm',
|
|
124
128
|
fullWidth: true,
|