@reportportal/ui-kit 0.0.1-alpha.165 → 0.0.1-alpha.167

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/dist/bulkPanel.js CHANGED
@@ -1,92 +1,220 @@
1
- import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
- import { useState as C, useRef as v, useCallback as p, useEffect as N } from "react";
3
- import { createPortal as k } from "react-dom";
4
- import { c as b } from "./bind-06a7ff84.js";
5
- import { Scrollbars as E } from "rc-scrollbars";
6
- import { u as S } from "./useOnClickOutside-8f7d68a1.js";
1
+ import { jsx as n, jsxs as a, Fragment as y } from "react/jsx-runtime";
2
+ import { useState as k, useRef as z, useMemo as P, useCallback as b, useEffect as A } from "react";
3
+ import { createPortal as H } from "react-dom";
4
+ import { c as J } from "./bind-06a7ff84.js";
5
+ import { Scrollbars as Q } from "rc-scrollbars";
6
+ import { u as X } from "./useOnClickOutside-8f7d68a1.js";
7
7
  import "react-dnd";
8
8
  import "react-dnd-html5-backend";
9
- import { K as y } from "./keyCodes-f63c0e11.js";
10
- import { S as w } from "./selection-9124d029.js";
11
- import { Chip as D } from "./chip.js";
12
- import { S as I } from "./chevronDownDropdown-0260bb66.js";
9
+ import { K as Z } from "./keyCodes-f63c0e11.js";
10
+ import { S as ee } from "./selection-9124d029.js";
11
+ import { Chip as ne } from "./chip.js";
12
+ import { B } from "./button-97d9e587.js";
13
+ import { Tooltip as le } from "./tooltip.js";
14
+ import { S as te } from "./chevronDownDropdown-0260bb66.js";
15
+ import { S as ie } from "./warning-537ead32.js";
13
16
  import "./close-4d480ef7.js";
14
- import "./button-97d9e587.js";
15
- const K = "_expanded_lggoe_1", O = "_header_lggoe_27", P = {
16
- "bulk-panel": "_bulk-panel_lggoe_1",
17
- expanded: K,
18
- "panel-content": "_panel-content_lggoe_11",
19
- header: O,
20
- "selection-info": "_selection-info_lggoe_37",
21
- "expand-icon": "_expand-icon_lggoe_52",
22
- "items-section": "_items-section_lggoe_64",
23
- "items-header": "_items-header_lggoe_75",
24
- "items-scroll": "_items-scroll_lggoe_84",
25
- "items-list": "_items-list_lggoe_89"
26
- }, l = b.bind(P), T = {
17
+ import "@floating-ui/react";
18
+ import "./floatingUi-41f8c7b5.js";
19
+ const se = "_expanded_ue1t9_6", ae = "_header_ue1t9_32", oe = "_tabs_ue1t9_119", ce = "_tab_ue1t9_119", re = "_active_ue1t9_146", de = "_item_ue1t9_99", me = {
20
+ "bulk-panel": "_bulk-panel_ue1t9_1",
21
+ expanded: se,
22
+ "panel-content": "_panel-content_ue1t9_16",
23
+ header: ae,
24
+ "header-actions": "_header-actions_ue1t9_43",
25
+ "warning-icon": "_warning-icon_ue1t9_49",
26
+ "info-message-container": "_info-message-container_ue1t9_58",
27
+ "buttons-container": "_buttons-container_ue1t9_66",
28
+ "selection-info": "_selection-info_ue1t9_72",
29
+ "expand-icon": "_expand-icon_ue1t9_87",
30
+ "items-section": "_items-section_ue1t9_99",
31
+ "items-header": "_items-header_ue1t9_110",
32
+ tabs: oe,
33
+ tab: ce,
34
+ "tab-count": "_tab-count_ue1t9_142",
35
+ active: re,
36
+ "items-scroll": "_items-scroll_ue1t9_162",
37
+ "items-list": "_items-list_ue1t9_167",
38
+ item: de,
39
+ "tooltip-wrapper": "_tooltip-wrapper_ue1t9_179"
40
+ }, l = J.bind(me), pe = {
27
41
  selected: "selected",
28
42
  clearSelection: "Clear selection",
29
- selectedItems: "Selected items"
30
- }, M = ({
31
- items: o,
32
- onRemoveItem: _,
33
- onClearSelection: h,
34
- className: g,
35
- captions: f,
36
- portalRoot: c
43
+ selectedItems: "Selected items",
44
+ eligibleTab: "Eligible Items",
45
+ ineligibleTab: "Ineligible Items",
46
+ ineligibleInfoMessage: (i) => /* @__PURE__ */ a(y, { children: [
47
+ "You have ",
48
+ /* @__PURE__ */ n("b", { children: i }),
49
+ " ineligible items"
50
+ ] }),
51
+ cancelButton: (i) => `Cancel "${i}"`,
52
+ proceedButton: (i) => `Proceed with ${i} Eligible Items`
53
+ }, p = {
54
+ ELIGIBLE: "eligible",
55
+ INELIGIBLE: "ineligible"
56
+ }, Ge = ({
57
+ items: i,
58
+ actions: D = [],
59
+ captions: K,
60
+ infoMessage: x,
61
+ className: M,
62
+ portalRoot: f,
63
+ onRemoveItem: w,
64
+ onClearSelection: O
37
65
  }) => {
38
- const t = { ...T, ...f }, [n, d] = C(!1), r = v(null), a = p(() => {
39
- d(!1);
40
- }, []), u = p(() => {
41
- d((s) => !s);
42
- }, []);
43
- if (N(() => {
44
- if (!n)
66
+ const c = { ...pe, ...K }, [o, _] = k(!1), [I, v] = k(p.INELIGIBLE), [t, C] = k(null), S = z(null), r = t !== null, { eligibleItems: u, ineligibleItems: h } = P(() => {
67
+ var g;
68
+ if (!t)
69
+ return { eligibleItems: [], ineligibleItems: [] };
70
+ const e = ((g = t.onValidate) == null ? void 0 : g.call(t, i)) ?? [], s = new Set(e.map((L) => L.id));
71
+ return { eligibleItems: i.filter((L) => !s.has(L.id)), ineligibleItems: e };
72
+ }, [i, t]), d = u.length, m = h.length, $ = r && d > 0, T = r && m > 0 ? c.ineligibleInfoMessage(m) : null, V = P(() => r ? m === 0 ? u : d === 0 ? h : I === p.ELIGIBLE ? u : h : i, [
73
+ r,
74
+ i,
75
+ u,
76
+ h,
77
+ I,
78
+ m,
79
+ d
80
+ ]), j = b(
81
+ (e) => {
82
+ var N, g;
83
+ (N = e.onClick) == null || N.call(e), (((g = e.onValidate) == null ? void 0 : g.call(e, i)) ?? []).length === 0 ? e.onProceed(i, !0) : (C(e), v(p.INELIGIBLE), _(!0));
84
+ },
85
+ [i]
86
+ ), F = b(() => {
87
+ const e = t == null ? void 0 : t.onCancel;
88
+ C(null), _(!1), e == null || e();
89
+ }, [t]), W = b(() => {
90
+ t == null || t.onProceed(u), C(null), _(!1);
91
+ }, [t, u]), E = b(() => {
92
+ _(!1);
93
+ }, []), Y = b(() => {
94
+ _((e) => !e);
95
+ }, []), R = b(
96
+ (e) => {
97
+ w(e);
98
+ },
99
+ [w]
100
+ );
101
+ if (A(() => {
102
+ if (!o)
45
103
  return;
46
- const s = (x) => {
47
- x.keyCode === y.ESCAPE_KEY_CODE && a();
104
+ const e = (s) => {
105
+ s.keyCode === Z.ESCAPE_KEY_CODE && E();
48
106
  };
49
- return document.addEventListener("keydown", s, !1), () => document.removeEventListener("keydown", s, !1);
50
- }, [n, a]), S(r, n ? a : void 0), o.length === 0)
107
+ return document.addEventListener("keydown", e, !1), () => document.removeEventListener("keydown", e, !1);
108
+ }, [o, E]), X(S, o ? E : void 0), i.length === 0)
51
109
  return null;
52
- const m = /* @__PURE__ */ e(
110
+ const U = (e) => h.some((s) => s.id === e.id), q = (e) => {
111
+ const s = /* @__PURE__ */ n(
112
+ ne,
113
+ {
114
+ onRemove: () => R(e.id),
115
+ variant: U(e) && r ? "error" : "default",
116
+ children: e.label ?? e.name
117
+ },
118
+ e.id
119
+ );
120
+ return /* @__PURE__ */ n("div", { className: l("item"), children: e.tooltipContent ? /* @__PURE__ */ n(
121
+ le,
122
+ {
123
+ wrapperClassName: l("tooltip-wrapper"),
124
+ content: e.tooltipContent,
125
+ placement: "top",
126
+ width: 270,
127
+ portalRoot: f,
128
+ children: s
129
+ },
130
+ e.id
131
+ ) : s }, e.id);
132
+ }, G = /* @__PURE__ */ n(
53
133
  "div",
54
134
  {
55
- className: l("bulk-panel", { expanded: n }, g),
135
+ className: l("bulk-panel", { expanded: o }, M),
56
136
  role: "region",
57
137
  "aria-label": "Bulk actions panel",
58
- children: /* @__PURE__ */ i("div", { className: l("panel-content", { expanded: n }), ref: r, children: [
59
- /* @__PURE__ */ e("div", { className: l("header"), children: /* @__PURE__ */ i("div", { className: l("selection-info"), children: [
60
- /* @__PURE__ */ e(
61
- "button",
62
- {
63
- onClick: u,
64
- "aria-label": n ? "Collapse panel" : "Expand panel",
65
- "aria-expanded": n,
66
- children: /* @__PURE__ */ e("span", { className: l("expand-icon", { expanded: n }), children: /* @__PURE__ */ e(I, {}) })
67
- }
68
- ),
69
- /* @__PURE__ */ e(
70
- w,
71
- {
72
- selectedCount: o.length,
73
- onClearSelection: h,
74
- captions: {
75
- selected: t.selected,
76
- buttonCaption: t.clearSelection
138
+ children: /* @__PURE__ */ a("div", { className: l("panel-content", { expanded: o }), ref: S, children: [
139
+ /* @__PURE__ */ a("div", { className: l("header"), children: [
140
+ /* @__PURE__ */ a("div", { className: l("selection-info"), children: [
141
+ /* @__PURE__ */ n(
142
+ "button",
143
+ {
144
+ onClick: Y,
145
+ "aria-label": o ? "Collapse panel" : "Expand panel",
146
+ "aria-expanded": o,
147
+ children: /* @__PURE__ */ n("span", { className: l("expand-icon", { expanded: o }), children: /* @__PURE__ */ n(te, {}) })
148
+ }
149
+ ),
150
+ /* @__PURE__ */ n(
151
+ ee,
152
+ {
153
+ selectedCount: i.length,
154
+ onClearSelection: O,
155
+ captions: {
156
+ selected: c.selected,
157
+ buttonCaption: c.clearSelection
158
+ }
159
+ }
160
+ )
161
+ ] }),
162
+ /* @__PURE__ */ a("div", { className: l("header-actions"), children: [
163
+ (T || x) && /* @__PURE__ */ a("div", { className: l("info-message-container"), children: [
164
+ /* @__PURE__ */ n("i", { className: l("warning-icon"), children: /* @__PURE__ */ n(ie, {}) }),
165
+ /* @__PURE__ */ n("div", { className: l("info-message"), children: T || x })
166
+ ] }),
167
+ /* @__PURE__ */ n("div", { className: l("buttons-container"), children: r ? /* @__PURE__ */ a(y, { children: [
168
+ /* @__PURE__ */ n(B, { variant: "ghost", onClick: F, children: c.cancelButton((t == null ? void 0 : t.label) ?? "") }),
169
+ $ && /* @__PURE__ */ n(B, { variant: "primary", onClick: W, children: c.proceedButton(d) })
170
+ ] }) : D.map((e, s) => /* @__PURE__ */ n(
171
+ B,
172
+ {
173
+ variant: e.variant,
174
+ onClick: () => j(e),
175
+ disabled: e.disabled,
176
+ children: e.label
177
+ },
178
+ `${e.label}-${s}`
179
+ )) })
180
+ ] })
181
+ ] }),
182
+ /* @__PURE__ */ a("div", { className: l("items-section"), children: [
183
+ /* @__PURE__ */ n("div", { className: l("items-header"), children: r ? /* @__PURE__ */ a("div", { className: l("tabs"), children: [
184
+ m > 0 && /* @__PURE__ */ a(
185
+ "button",
186
+ {
187
+ className: l("tab", {
188
+ active: I === p.INELIGIBLE || d === 0
189
+ }),
190
+ onClick: () => v(p.INELIGIBLE),
191
+ children: [
192
+ c.ineligibleTab,
193
+ /* @__PURE__ */ n("span", { className: l("tab-count"), children: m })
194
+ ]
195
+ }
196
+ ),
197
+ d > 0 && /* @__PURE__ */ a(
198
+ "button",
199
+ {
200
+ className: l("tab", {
201
+ active: I === p.ELIGIBLE || m === 0
202
+ }),
203
+ onClick: () => v(p.ELIGIBLE),
204
+ children: [
205
+ c.eligibleTab,
206
+ /* @__PURE__ */ n("span", { className: l("tab-count"), children: d })
207
+ ]
77
208
  }
78
- }
79
- )
80
- ] }) }),
81
- /* @__PURE__ */ i("div", { className: l("items-section"), children: [
82
- /* @__PURE__ */ e("div", { className: l("items-header"), children: t.selectedItems }),
83
- /* @__PURE__ */ e("div", { className: l("items-scroll"), children: /* @__PURE__ */ e(E, { hideTracksWhenNotNeeded: !0, children: /* @__PURE__ */ e("div", { className: l("items-list"), children: o.map((s) => /* @__PURE__ */ e(D, { onRemove: () => _(s.id), children: s.label }, s.id)) }) }) })
209
+ )
210
+ ] }) : c.selectedItems }),
211
+ /* @__PURE__ */ n("div", { className: l("items-scroll"), children: /* @__PURE__ */ n(Q, { hideTracksWhenNotNeeded: !0, children: /* @__PURE__ */ n("div", { className: l("items-list"), children: V.map((e) => q(e)) }) }) })
84
212
  ] })
85
213
  ] })
86
214
  }
87
215
  );
88
- return n && c ? k(m, c) : m;
216
+ return o && f ? H(G, f) : G;
89
217
  };
90
218
  export {
91
- M as BulkPanel
219
+ Ge as BulkPanel
92
220
  };
@@ -1,3 +1,3 @@
1
1
  import { BulkPanelProps } from './types';
2
2
 
3
- export declare const BulkPanel: ({ items, onRemoveItem, onClearSelection, className, captions: captionsProp, portalRoot, }: BulkPanelProps) => import("react/jsx-runtime").JSX.Element | null;
3
+ export declare const BulkPanel: ({ items, actions, captions: captionsProp, infoMessage, className, portalRoot, onRemoveItem, onClearSelection, }: BulkPanelProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,2 +1,2 @@
1
1
  export { BulkPanel } from './bulkPanel';
2
- export type { BulkPanelProps, BulkPanelItem } from './types';
2
+ export type { BulkPanelProps, BulkPanelItem, BulkPanelAction, BulkPanelCaptions } from './types';
@@ -1,16 +1,46 @@
1
+ import { ReactNode } from 'react';
2
+ import { ButtonProps } from '../button';
3
+
1
4
  export interface BulkPanelItem {
2
5
  id: string | number;
6
+ label?: string;
7
+ name?: string;
8
+ tooltipContent?: ReactNode;
9
+ }
10
+ export interface BulkPanelAction {
3
11
  label: string;
12
+ variant?: ButtonProps['variant'];
13
+ disabled?: boolean;
14
+ onClick?: () => void;
15
+ /**
16
+ * Called to validate items. May be called multiple times if items change.
17
+ * Should return INELIGIBLE items array.
18
+ * If not provided or returns empty array - all items are eligible and onProceed is called immediately.
19
+ */
20
+ onValidate?: (items: BulkPanelItem[]) => BulkPanelItem[];
21
+ /**
22
+ * @param direct - true if all items were eligible and proceed was called directly, false if called via Proceed button
23
+ */
24
+ onProceed: (eligibleItems: BulkPanelItem[], direct?: boolean) => void;
25
+ onCancel?: () => void;
26
+ }
27
+ export interface BulkPanelCaptions {
28
+ selected?: string;
29
+ clearSelection?: string;
30
+ selectedItems?: string;
31
+ eligibleTab?: string;
32
+ ineligibleTab?: string;
33
+ ineligibleInfoMessage?: (ineligibleCount: number) => ReactNode | string;
34
+ cancelButton?: (actionLabel: string) => ReactNode | string;
35
+ proceedButton?: (eligibleCount: number) => ReactNode | string;
4
36
  }
5
37
  export interface BulkPanelProps {
6
- className?: string;
7
38
  items: BulkPanelItem[];
8
- captions?: {
9
- selected?: string;
10
- clearSelection?: string;
11
- selectedItems?: string;
12
- };
39
+ actions?: BulkPanelAction[];
40
+ captions?: BulkPanelCaptions;
41
+ infoMessage?: ReactNode;
42
+ className?: string;
43
+ portalRoot?: Element;
13
44
  onRemoveItem: (id: string | number) => void;
14
45
  onClearSelection: () => void;
15
- portalRoot?: Element;
16
46
  }