@axinom/mosaic-ui 0.49.0-rc.1 → 0.49.0-rc.10

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.
Files changed (60) hide show
  1. package/dist/components/DynamicDataList/DynamicDataList.d.ts.map +1 -1
  2. package/dist/components/DynamicDataList/DynamicListRow/DynamicListRow.d.ts.map +1 -1
  3. package/dist/components/Explorer/Explorer.d.ts.map +1 -1
  4. package/dist/components/Filters/Filter/Filter.d.ts +2 -1
  5. package/dist/components/Filters/Filter/Filter.d.ts.map +1 -1
  6. package/dist/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.d.ts +2 -0
  7. package/dist/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.d.ts.map +1 -1
  8. package/dist/components/FormStation/FormStationHeader/FormStationHeader.d.ts.map +1 -1
  9. package/dist/components/List/ListRow/ListRow.d.ts.map +1 -1
  10. package/dist/components/PageHeader/PageHeader.d.ts +9 -2
  11. package/dist/components/PageHeader/PageHeader.d.ts.map +1 -1
  12. package/dist/components/PageHeader/PageHeader.model.d.ts +11 -12
  13. package/dist/components/PageHeader/PageHeader.model.d.ts.map +1 -1
  14. package/dist/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroup.d.ts +35 -0
  15. package/dist/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroup.d.ts.map +1 -0
  16. package/dist/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroupsContext.d.ts +7 -0
  17. package/dist/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroupsContext.d.ts.map +1 -0
  18. package/dist/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroupsContextProvider.d.ts +3 -0
  19. package/dist/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroupsContextProvider.d.ts.map +1 -0
  20. package/dist/components/PageHeader/index.d.ts +1 -1
  21. package/dist/components/PageHeader/index.d.ts.map +1 -1
  22. package/dist/index.es.js +4 -4
  23. package/dist/index.es.js.map +1 -1
  24. package/dist/index.js +4 -4
  25. package/dist/index.js.map +1 -1
  26. package/dist/{components/DynamicDataList/helpers/generateId.d.ts → utils/GenerateId.d.ts} +1 -1
  27. package/dist/utils/GenerateId.d.ts.map +1 -0
  28. package/package.json +3 -3
  29. package/src/components/DynamicDataList/DynamicDataList.spec.tsx +2 -1
  30. package/src/components/DynamicDataList/DynamicDataList.tsx +1 -1
  31. package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.spec.tsx +37 -0
  32. package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.tsx +4 -0
  33. package/src/components/Explorer/Explorer.spec.tsx +26 -16
  34. package/src/components/Explorer/Explorer.tsx +47 -28
  35. package/src/components/Explorer/NavigationExplorer/NavigationExplorer.spec.tsx +2 -2
  36. package/src/components/Explorer/SelectionExplorer/SelectionExplorer.spec.tsx +8 -32
  37. package/src/components/Filters/Filter/Filter.tsx +3 -0
  38. package/src/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.spec.tsx +16 -1
  39. package/src/components/Filters/SelectionTypes/FreeTextFilter/FreeTextFilter.tsx +13 -1
  40. package/src/components/FormStation/FormStationHeader/FormStationHeader.tsx +34 -30
  41. package/src/components/List/ListRow/ListRow.scss +0 -1
  42. package/src/components/List/ListRow/ListRow.spec.tsx +35 -0
  43. package/src/components/List/ListRow/ListRow.tsx +5 -1
  44. package/src/components/PageHeader/PageHeader.model.ts +10 -12
  45. package/src/components/PageHeader/PageHeader.scss +7 -3
  46. package/src/components/PageHeader/PageHeader.spec.tsx +28 -86
  47. package/src/components/PageHeader/PageHeader.stories.tsx +32 -7
  48. package/src/components/PageHeader/PageHeader.tsx +50 -77
  49. package/src/components/PageHeader/{PageHeaderBulkActions/PageHeaderBulkActions.scss → PageHeaderActionsGroup/PageHeaderActionsGroup.scss} +21 -21
  50. package/src/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroup.spec.tsx +105 -0
  51. package/src/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroup.tsx +224 -0
  52. package/src/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroupsContext.ts +13 -0
  53. package/src/components/PageHeader/PageHeaderActionsGroup/PageHeaderActionsGroupsContextProvider.tsx +30 -0
  54. package/src/components/PageHeader/index.ts +1 -1
  55. package/dist/components/DynamicDataList/helpers/generateId.d.ts.map +0 -1
  56. package/dist/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.d.ts +0 -22
  57. package/dist/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.d.ts.map +0 -1
  58. package/src/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.spec.tsx +0 -369
  59. package/src/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.tsx +0 -188
  60. /package/src/{components/DynamicDataList/helpers/generateId.ts → utils/GenerateId.ts} +0 -0
@@ -0,0 +1,224 @@
1
+ import clsx from 'clsx';
2
+ import React, { useCallback, useEffect, useState } from 'react';
3
+ import { noop } from '../../../helpers/utils';
4
+ import { useExpand } from '../../../hooks/useExpand/useExpand';
5
+ import { uuid } from '../../../utils/GenerateId';
6
+ import { ConfirmationMode } from '../../ConfirmDialog';
7
+ import { IconName } from '../../Icons';
8
+ import {
9
+ PageHeaderAction,
10
+ isPageHeaderJsAction,
11
+ } from '../PageHeaderAction/PageHeaderAction';
12
+ import {
13
+ PageHeaderActionProps,
14
+ PageHeaderActionType,
15
+ } from '../PageHeaderAction/PageHeaderAction.model';
16
+ import classes from './PageHeaderActionsGroup.scss';
17
+ import { PageHeaderActionsGroupContext } from './PageHeaderActionsGroupsContext';
18
+
19
+ export interface PageHeaderActionsGroupProps {
20
+ /** Array of Actions to be rendered (default: []) */
21
+ actions: PageHeaderActionProps[];
22
+ /** Whether group is disabled (default: false) */
23
+ disabled?: boolean;
24
+ /** Whether actions in the group are disabled or not (default: false)*/
25
+ groupActionsDisabled?: boolean;
26
+ /** CSS Class name for additional styles */
27
+ className?: string;
28
+ /** The label of the action. */
29
+ label: string;
30
+ /** Optional built in icon. This prop also accepts an img src. */
31
+ icon?: IconName | string;
32
+ /** Whether group actions are shown by default. (default: false) */
33
+ openActionsGroupOnStart?: boolean;
34
+ /** The number of actions that can be displayed in the group. (default: actions.length) */
35
+ availableActionSpace?: number;
36
+ /**
37
+ * Callback to emit when Group Actions is toggled
38
+ * The expanded state is supplied as an argument
39
+ */
40
+ onActionsGroupToggled?: (expanded: boolean) => void;
41
+ }
42
+
43
+ /**
44
+ * Used to perform group operations from the PageHeader component.
45
+ * @example
46
+ * <PageHeaderActionsGroup>
47
+ * <PageHeaderAction action={action} onActionsGroupToggled={onActionsGroupToggledHandler} />
48
+ * </PageHeaderActionsGroup>
49
+ */
50
+ export const PageHeaderActionsGroup: React.FC<PageHeaderActionsGroupProps> = ({
51
+ actions = [],
52
+ openActionsGroupOnStart = false,
53
+ label,
54
+ icon,
55
+ onActionsGroupToggled = noop,
56
+ groupActionsDisabled = false,
57
+ disabled = false,
58
+ availableActionSpace = actions.length,
59
+ className = '',
60
+ }) => {
61
+ const [uniqueId] = useState<string>(uuid());
62
+ const { isExpanded, toggleExpanded, collapse } = useExpand(
63
+ openActionsGroupOnStart,
64
+ );
65
+
66
+ const { registerCollapse, collapseAll } = React.useContext(
67
+ PageHeaderActionsGroupContext,
68
+ );
69
+
70
+ const customCollapse = useCallback(() => {
71
+ collapse();
72
+ onActionsGroupToggled(false);
73
+ }, [collapse, onActionsGroupToggled]);
74
+
75
+ useEffect(() => {
76
+ registerCollapse(customCollapse, uniqueId);
77
+ }, [customCollapse, registerCollapse, uniqueId]);
78
+
79
+ const {
80
+ isExpanded: isMoreExpanded,
81
+ expand: moreExpanded,
82
+ collapse: moreCollapse,
83
+ toggleExpanded: toggleMoreExpanded,
84
+ } = useExpand();
85
+
86
+ const [isMouseOverMore, setIsMouseOverMore] = useState<boolean>(false);
87
+ const [isConfirmOpen, setIsConfirmOpen] = useState<Record<string, boolean>>(
88
+ {},
89
+ );
90
+
91
+ const onConfirmToggled = (
92
+ isOpen: boolean,
93
+ data: { id: string; mode: ConfirmationMode },
94
+ ): void => {
95
+ setIsConfirmOpen((prevState) => {
96
+ return { ...prevState, [data.id]: isOpen };
97
+ });
98
+ };
99
+
100
+ useEffect(() => {
101
+ const hasConfirm: boolean = Object.values(isConfirmOpen).includes(true);
102
+
103
+ // open drop down
104
+ if (isMouseOverMore) {
105
+ moreExpanded();
106
+ // close drop down if no confirmation is active
107
+ } else if (!isMouseOverMore && !hasConfirm) {
108
+ moreCollapse();
109
+ // keep the drop down open if confirmation is active
110
+ } else if (!isMouseOverMore && hasConfirm) {
111
+ return;
112
+ }
113
+ }, [isConfirmOpen, isMouseOverMore, moreCollapse, moreExpanded]);
114
+
115
+ const actionsSlice =
116
+ availableActionSpace < actions.length
117
+ ? availableActionSpace - 1
118
+ : availableActionSpace;
119
+
120
+ return (
121
+ <div
122
+ className={clsx(
123
+ classes.container,
124
+ 'page-header-group-action-container',
125
+ className,
126
+ )}
127
+ onMouseLeave={() => setIsMouseOverMore(false)}
128
+ >
129
+ <PageHeaderAction
130
+ label={label}
131
+ actionType={
132
+ isExpanded
133
+ ? PageHeaderActionType.Active
134
+ : PageHeaderActionType.Context
135
+ }
136
+ icon={icon}
137
+ onClick={() => {
138
+ if (!isExpanded) {
139
+ collapseAll();
140
+ }
141
+ toggleExpanded();
142
+ onActionsGroupToggled(!isExpanded);
143
+ }}
144
+ disabled={disabled}
145
+ />
146
+ <div
147
+ style={{
148
+ maxWidth: isExpanded
149
+ ? `${Math.min(availableActionSpace, actions.length) * 121}px`
150
+ : `0px`,
151
+ opacity: isExpanded ? 1 : 0,
152
+ }}
153
+ className={classes.actions}
154
+ >
155
+ {actions.slice(0, actionsSlice).map((action, idx) =>
156
+ isPageHeaderJsAction(action) ? (
157
+ <PageHeaderAction
158
+ key={idx}
159
+ {...action}
160
+ disabled={groupActionsDisabled}
161
+ confirmationConfig={{
162
+ ...action.confirmationConfig,
163
+ onConfirmOpen: (isOpen: boolean, args: unknown) => {
164
+ onConfirmToggled(
165
+ isOpen,
166
+ args as { id: string; mode: ConfirmationMode },
167
+ );
168
+ action.confirmationConfig?.onConfirmOpen?.(isOpen, args);
169
+ },
170
+ }}
171
+ />
172
+ ) : (
173
+ <PageHeaderAction key={idx} {...action} />
174
+ ),
175
+ )}
176
+ {actions.length > availableActionSpace && (
177
+ <div onMouseEnter={() => setIsMouseOverMore(true)}>
178
+ <PageHeaderAction
179
+ label="More"
180
+ icon={IconName.Ellipsis}
181
+ actionType={
182
+ isMoreExpanded
183
+ ? PageHeaderActionType.Active
184
+ : PageHeaderActionType.Context
185
+ }
186
+ onClick={() => toggleMoreExpanded()}
187
+ />
188
+ </div>
189
+ )}
190
+ </div>
191
+ {isMoreExpanded && (
192
+ <div className={clsx(classes.dropDownList)}>
193
+ {actions.slice(actionsSlice).map((action, idx) =>
194
+ isPageHeaderJsAction(action) ? (
195
+ <PageHeaderAction
196
+ key={idx}
197
+ {...action}
198
+ disabled={groupActionsDisabled}
199
+ onClick={() => {
200
+ action.onClick();
201
+ moreCollapse();
202
+ setIsMouseOverMore(false);
203
+ }}
204
+ className={clsx(classes.dropDown)}
205
+ confirmationConfig={{
206
+ ...action.confirmationConfig,
207
+ onConfirmOpen: (isOpen, args) => {
208
+ onConfirmToggled(
209
+ isOpen,
210
+ args as { id: string; mode: ConfirmationMode },
211
+ );
212
+ action.confirmationConfig?.onConfirmOpen?.(isOpen, args);
213
+ },
214
+ }}
215
+ />
216
+ ) : (
217
+ <PageHeaderAction key={idx} {...action} />
218
+ ),
219
+ )}
220
+ </div>
221
+ )}
222
+ </div>
223
+ );
224
+ };
@@ -0,0 +1,13 @@
1
+ import { createContext } from 'react';
2
+ import { noop } from '../../../helpers/utils';
3
+
4
+ export interface PageHeaderActionsGroupContextType {
5
+ registerCollapse: (readonly: () => void, uuid: string) => void;
6
+ collapseAll: () => void;
7
+ }
8
+
9
+ export const PageHeaderActionsGroupContext =
10
+ createContext<PageHeaderActionsGroupContextType>({
11
+ registerCollapse: noop,
12
+ collapseAll: noop,
13
+ });
@@ -0,0 +1,30 @@
1
+ import React, { useCallback, useState } from 'react';
2
+ import { PageHeaderActionsGroupContext } from './PageHeaderActionsGroupsContext';
3
+
4
+ type CollapseAction = Record<string, () => void>;
5
+
6
+ export const PageHeaderActionsGroupContextProvider: React.FC = ({
7
+ children,
8
+ }) => {
9
+ const [registeredCollapses, setRegisteredCollapses] =
10
+ useState<CollapseAction>({});
11
+
12
+ const registerCollapse = useCallback(
13
+ (collapse: () => void, uuid: string): void => {
14
+ setRegisteredCollapses((prev) => ({ ...prev, [uuid]: collapse }));
15
+ },
16
+ [],
17
+ );
18
+
19
+ const collapseAll = useCallback(() => {
20
+ Object.values(registeredCollapses).forEach((collapse) => collapse());
21
+ }, [registeredCollapses]);
22
+
23
+ return (
24
+ <PageHeaderActionsGroupContext.Provider
25
+ value={{ registerCollapse, collapseAll }}
26
+ >
27
+ {children}
28
+ </PageHeaderActionsGroupContext.Provider>
29
+ );
30
+ };
@@ -1,5 +1,5 @@
1
1
  export { PageHeader } from './PageHeader';
2
- export { PageHeaderProps } from './PageHeader.model';
2
+ export { PageHeaderActionItemProps, PageHeaderProps } from './PageHeader.model';
3
3
  export {
4
4
  PageHeaderAction,
5
5
  PageHeaderActionProps,
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateId.d.ts","sourceRoot":"","sources":["../../../../src/components/DynamicDataList/helpers/generateId.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,IAAI,QAAO,MAKvB,CAAC"}
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- import { PageHeaderProps } from '../PageHeader.model';
3
- import { PageHeaderActionProps } from '../PageHeaderAction/PageHeaderAction.model';
4
- export interface PageHeaderBulkActionsProps extends Pick<PageHeaderProps, 'openBulkActionsOnStart' | 'onBulkActionsToggled'> {
5
- /** Array of Actions to be rendered (default: []) */
6
- actions?: PageHeaderActionProps[];
7
- /** Number of available slots actions can use in the PageHeader */
8
- availableActionSpace: number;
9
- /** Whether or not bulk actions are disabled (default: false)*/
10
- bulkActionsDisabled?: boolean;
11
- /** CSS Class name for additional styles */
12
- className?: string;
13
- }
14
- /**
15
- * Used to perform bulk operations from the PageHeader component.
16
- * @example
17
- * <PageHeaderBulkActions>
18
- * <PageHeaderAction action={action} onBulkActionsToggled={onBulkActionsToggledHandler} />
19
- * </PageHeaderBulkActions>
20
- */
21
- export declare const PageHeaderBulkActions: React.FC<PageHeaderBulkActionsProps>;
22
- //# sourceMappingURL=PageHeaderBulkActions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PageHeaderBulkActions.d.ts","sourceRoot":"","sources":["../../../../src/components/PageHeader/PageHeaderBulkActions/PageHeaderBulkActions.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAKtD,OAAO,EACL,qBAAqB,EAEtB,MAAM,4CAA4C,CAAC;AAGpD,MAAM,WAAW,0BACf,SAAQ,IAAI,CACV,eAAe,EACf,wBAAwB,GAAG,sBAAsB,CAClD;IACD,oDAAoD;IACpD,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAClC,kEAAkE;IAClE,oBAAoB,EAAE,MAAM,CAAC;IAC7B,+DAA+D;IAC/D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAoJtE,CAAC"}
@@ -1,369 +0,0 @@
1
- import { mount, shallow } from 'enzyme';
2
- import React from 'react';
3
- import { act } from 'react-dom/test-utils';
4
- import { noop } from '../../../helpers/utils';
5
- import { PageHeaderAction } from '../PageHeaderAction/PageHeaderAction';
6
- import {
7
- PageHeaderActionProps,
8
- PageHeaderActionType,
9
- } from '../PageHeaderAction/PageHeaderAction.model';
10
- import {
11
- PageHeaderBulkActions,
12
- PageHeaderBulkActionsProps,
13
- } from './PageHeaderBulkActions';
14
-
15
- const defaultActions: PageHeaderActionProps[] = [
16
- {
17
- label: 'Bulk Action 1',
18
- onClick: noop,
19
- },
20
- {
21
- label: 'Bulk Action 2',
22
- onClick: noop,
23
- },
24
- {
25
- label: 'Bulk Action 3',
26
- onClick: noop,
27
- },
28
- ];
29
-
30
- const defaultProps: PageHeaderBulkActionsProps = {
31
- availableActionSpace: 0,
32
- actions: defaultActions,
33
- };
34
-
35
- describe('PageHeaderBulkActions', () => {
36
- it('renders the component without crashing', () => {
37
- const wrapper = shallow(<PageHeaderBulkActions {...defaultProps} />);
38
- expect(wrapper).toBeTruthy();
39
- });
40
-
41
- it(`renders only 'Bulk Actions' by default`, () => {
42
- const wrapper = mount(<PageHeaderBulkActions {...defaultProps} />);
43
- const actions = wrapper.find(PageHeaderAction);
44
- expect(actions).toHaveLength(1);
45
- });
46
-
47
- it(`'Bulk Actions' has the 'Context' actionType when closed and 'Active' actionType when open`, () => {
48
- const wrapper = mount(
49
- <PageHeaderBulkActions
50
- {...defaultProps}
51
- availableActionSpace={defaultActions.length}
52
- />,
53
- );
54
- const bulkActionsToggle = wrapper.find(PageHeaderAction).first();
55
- let action = wrapper.find(PageHeaderAction);
56
-
57
- expect(action.prop('actionType')).toBe(PageHeaderActionType.Context);
58
-
59
- bulkActionsToggle.simulate('click');
60
- action = wrapper.find(PageHeaderAction).first();
61
-
62
- expect(action.prop('actionType')).toBe(PageHeaderActionType.Active);
63
- });
64
-
65
- it(`renders all actions when 'Bulk Actions' is selected and there is enough available action slots`, () => {
66
- const wrapper = mount(
67
- <PageHeaderBulkActions
68
- {...defaultProps}
69
- availableActionSpace={defaultActions.length}
70
- />,
71
- );
72
- const bulkActionsToggle = wrapper.find(PageHeaderAction).first();
73
- let actions = wrapper.find(PageHeaderAction);
74
- const bulkActionCount = 1;
75
- expect(actions).toHaveLength(1);
76
- bulkActionsToggle.simulate('click');
77
- actions = wrapper.find(PageHeaderAction);
78
- expect(actions).toHaveLength(bulkActionCount + defaultActions.length);
79
- });
80
-
81
- it(`'Bulk Actions' hides all actions when actions are shown`, () => {
82
- const wrapper = mount(
83
- <PageHeaderBulkActions
84
- {...defaultProps}
85
- availableActionSpace={defaultActions.length}
86
- openBulkActionsOnStart={true}
87
- />,
88
- );
89
- const bulkActionsToggle = wrapper.find(PageHeaderAction).first();
90
- let actions = wrapper.find(PageHeaderAction);
91
- const bulkActionCount = 1;
92
- expect(actions).toHaveLength(bulkActionCount + defaultActions.length);
93
- bulkActionsToggle.simulate('click');
94
- actions = wrapper.find(PageHeaderAction);
95
- expect(actions).toHaveLength(1);
96
- });
97
-
98
- it(`raises onBulkActionsToggled`, () => {
99
- const bulkActionSpy = jest.fn();
100
- const wrapper = mount(
101
- <PageHeaderBulkActions
102
- {...defaultProps}
103
- onBulkActionsToggled={bulkActionSpy}
104
- />,
105
- );
106
- const bulkActionsToggle = wrapper.find(PageHeaderAction).first();
107
- bulkActionsToggle.simulate('click');
108
- expect(bulkActionSpy).toHaveBeenCalledTimes(1);
109
- expect(bulkActionSpy).toHaveBeenCalledWith(true);
110
- });
111
-
112
- it(`renders 'Bulk Actions' and 'More Actions' if openBulkActionsOnStart is set to true and there isn't enough available space`, () => {
113
- const wrapper = mount(
114
- <PageHeaderBulkActions {...defaultProps} openBulkActionsOnStart={true} />,
115
- );
116
- const bulkActionCount = 1;
117
- const moreActionCount = 1;
118
- const actions = wrapper.find(PageHeaderAction);
119
- expect(actions).toHaveLength(bulkActionCount + moreActionCount);
120
- });
121
-
122
- it(`renders the dropdown list when 'More' actions are available on mouse enter and closes on mouse leave`, () => {
123
- const wrapper = mount(
124
- <PageHeaderBulkActions {...defaultProps} openBulkActionsOnStart={true} />,
125
- );
126
- const moreActionsToggle = wrapper.find('.hasMore');
127
-
128
- let dropDownActions = wrapper.find('.dropDownList');
129
- expect(dropDownActions.exists()).toBe(false);
130
-
131
- act(() => {
132
- // @ts-expect-error We don't pass event args
133
- moreActionsToggle.prop('onMouseEnter')();
134
- });
135
-
136
- wrapper.update();
137
-
138
- dropDownActions = wrapper.find('.dropDownList');
139
-
140
- expect(dropDownActions.exists()).toBe(true);
141
-
142
- act(() => {
143
- // @ts-expect-error We don't pass event args
144
- moreActionsToggle.prop('onMouseLeave')();
145
- });
146
-
147
- wrapper.update();
148
-
149
- dropDownActions = wrapper.find('.dropDownList');
150
-
151
- expect(dropDownActions.exists()).toBe(false);
152
- });
153
-
154
- it(`'More' action has the 'Context' actionType when closed and the 'Active' actionType when open`, () => {
155
- const wrapper = mount(
156
- <PageHeaderBulkActions {...defaultProps} openBulkActionsOnStart={true} />,
157
- );
158
- const moreActionsToggle = wrapper.find('.hasMore');
159
- let action = wrapper.find(PageHeaderAction).last();
160
-
161
- expect(action.prop('actionType')).toBe(PageHeaderActionType.Context);
162
-
163
- act(() => {
164
- // @ts-expect-error We don't pass event args
165
- moreActionsToggle.prop('onMouseEnter')();
166
- });
167
-
168
- wrapper.update();
169
-
170
- action = wrapper.find(PageHeaderAction).at(1);
171
-
172
- expect(action.prop('actionType')).toBe(PageHeaderActionType.Active);
173
- });
174
-
175
- it(`renders actions, that don't fit in the PageHeader, in the drop down list`, () => {
176
- const [mockAction1, mockAction2, mockAction3] = defaultActions;
177
- const wrapper = mount(
178
- <PageHeaderBulkActions {...defaultProps} openBulkActionsOnStart={true} />,
179
- );
180
- const moreActionsToggle = wrapper.find('.hasMore');
181
-
182
- act(() => {
183
- // @ts-expect-error We don't pass event args
184
- moreActionsToggle.prop('onMouseEnter')();
185
- });
186
-
187
- wrapper.update();
188
-
189
- const dropDownActions = wrapper.find('.dropDownList');
190
- const action1 = dropDownActions.childAt(0);
191
- const action2 = dropDownActions.childAt(1);
192
- const action3 = dropDownActions.childAt(2);
193
-
194
- expect(dropDownActions.children()).toHaveLength(defaultActions.length);
195
- expect(action1.text()).toBe(mockAction1.label);
196
- expect(action2.text()).toBe(mockAction2.label);
197
- expect(action3.text()).toBe(mockAction3.label);
198
- });
199
-
200
- it(`splits actions between the PageHeader and dropdown list when theres not enough space for all`, () => {
201
- const [mockAction1, mockAction2, mockAction3] = defaultActions;
202
- const wrapper = mount(
203
- <PageHeaderBulkActions
204
- {...defaultProps}
205
- openBulkActionsOnStart={true}
206
- availableActionSpace={2}
207
- />,
208
- );
209
- const moreActionsToggle = wrapper.find('.hasMore');
210
-
211
- act(() => {
212
- // @ts-expect-error We don't pass event args
213
- moreActionsToggle.prop('onMouseEnter')();
214
- });
215
-
216
- wrapper.update();
217
-
218
- const pageHeaderActions = wrapper.find('.container').first();
219
- const action1 = pageHeaderActions.find('.container:not(.hasMore)').at(1);
220
- const action2 = pageHeaderActions.find('.container:not(.hasMore)').at(2);
221
- let action3 = pageHeaderActions.find('.container:not(.hasMore)').at(3);
222
-
223
- expect(action1.text()).toBe(mockAction1.label);
224
- expect(action2.text()).toBe(mockAction2.label);
225
- expect(action3.text()).not.toBe(mockAction3.label);
226
-
227
- const dropDownActions = wrapper.find('.dropDownList');
228
- action3 = dropDownActions.childAt(0);
229
-
230
- expect(dropDownActions.children()).toHaveLength(1);
231
- expect(action3.text()).toBe(mockAction3.label);
232
- });
233
-
234
- it(`raises onClick for actions in the page header available space and drop down list`, () => {
235
- const pageHeaderSpy = jest.fn();
236
- const dropDownListSpy = jest.fn();
237
- const actionsWithSpies: PageHeaderActionProps[] = [
238
- {
239
- label: 'Bulk Action 1',
240
- onClick: pageHeaderSpy,
241
- },
242
- {
243
- label: 'Bulk Action 2',
244
- onClick: dropDownListSpy,
245
- },
246
- ];
247
-
248
- const wrapper = mount(
249
- <PageHeaderBulkActions
250
- {...defaultProps}
251
- actions={actionsWithSpies}
252
- openBulkActionsOnStart={true}
253
- availableActionSpace={1}
254
- />,
255
- );
256
- const moreActionsToggle = wrapper.find('.hasMore');
257
-
258
- act(() => {
259
- // @ts-expect-error We don't pass event args
260
- moreActionsToggle.prop('onMouseEnter')();
261
- });
262
-
263
- wrapper.update();
264
-
265
- const pageHeaderActions = wrapper.find('.container').first();
266
- const action1 = pageHeaderActions.find('.container:not(.hasMore)').at(1);
267
-
268
- action1.simulate('click');
269
-
270
- expect(pageHeaderSpy).toHaveBeenCalledTimes(1);
271
-
272
- const dropDownActions = wrapper.find('.dropDownList');
273
- const action2 = dropDownActions.childAt(0);
274
-
275
- action2.simulate('click');
276
-
277
- expect(dropDownListSpy).toHaveBeenCalledTimes(1);
278
- });
279
-
280
- it(`closes drop down list after clicking an action`, () => {
281
- const dropDownListSpy = jest.fn();
282
- const actionsWithSpies: PageHeaderActionProps[] = [
283
- {
284
- label: 'Bulk Action 1',
285
- onClick: dropDownListSpy,
286
- },
287
- ];
288
-
289
- const wrapper = mount(
290
- <PageHeaderBulkActions
291
- {...defaultProps}
292
- actions={actionsWithSpies}
293
- openBulkActionsOnStart={true}
294
- availableActionSpace={0}
295
- />,
296
- );
297
- const moreActionsToggle = wrapper.find('.hasMore');
298
- let dropDownActions = wrapper.find('.dropDownList');
299
-
300
- expect(dropDownActions.exists()).toBe(false);
301
-
302
- act(() => {
303
- // @ts-expect-error We don't pass event args
304
- moreActionsToggle.prop('onMouseEnter')();
305
- });
306
-
307
- wrapper.update();
308
-
309
- dropDownActions = wrapper.find('.dropDownList');
310
- expect(dropDownActions.exists()).toBe(true);
311
-
312
- const action = dropDownActions.childAt(0);
313
-
314
- action.simulate('click');
315
-
316
- dropDownActions = wrapper.find('.dropDownList');
317
-
318
- expect(dropDownActions.exists()).toBe(false);
319
- });
320
-
321
- it(`disables actions if 'isBulkActionsDisabled' prop is true`, () => {
322
- const pageHeaderSpy = jest.fn();
323
- const dropDownListSpy = jest.fn();
324
- const actionsWithSpies: PageHeaderActionProps[] = [
325
- {
326
- label: 'Bulk Action 1',
327
- onClick: pageHeaderSpy,
328
- },
329
- {
330
- label: 'Bulk Action 2',
331
- onClick: dropDownListSpy,
332
- },
333
- ];
334
-
335
- const wrapper = mount(
336
- <PageHeaderBulkActions
337
- {...defaultProps}
338
- actions={actionsWithSpies}
339
- openBulkActionsOnStart={true}
340
- availableActionSpace={1}
341
- bulkActionsDisabled={true}
342
- />,
343
- );
344
- const moreActionsToggle = wrapper.find('.hasMore');
345
-
346
- act(() => {
347
- // @ts-expect-error We don't pass event args
348
- moreActionsToggle.prop('onMouseEnter')();
349
- });
350
-
351
- wrapper.update();
352
-
353
- const pageHeaderActions = wrapper.find('.container').first();
354
- const action1 = pageHeaderActions.find('.container:not(.hasMore)').at(1);
355
-
356
- action1.simulate('click');
357
-
358
- expect(action1.prop('disabled')).toBe(true);
359
- expect(pageHeaderSpy).not.toHaveBeenCalled();
360
-
361
- const dropDownActions = wrapper.find('.dropDownList');
362
- const action2 = dropDownActions.childAt(0);
363
-
364
- action2.simulate('click');
365
-
366
- expect(action2.prop('disabled')).toBe(true);
367
- expect(dropDownListSpy).not.toHaveBeenCalled();
368
- });
369
- });