@dhis2-ui/transfer 9.11.0 → 9.11.1-beta.2
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/build/cjs/__e2e__/{add_remove-highlighted-options.stories.e2e.js → add_remove-highlighted-options.e2e.stories.js} +2 -13
- package/build/cjs/__e2e__/common/options.js +2 -3
- package/build/cjs/__e2e__/common/stateful-decorator.js +3 -8
- package/build/cjs/__e2e__/{disabled-transfer-buttons.stories.e2e.js → disabled-transfer-buttons.e2e.stories.js} +4 -20
- package/build/cjs/__e2e__/{disabled-transfer-options.stories.e2e.js → disabled-transfer-options.e2e.stories.js} +4 -12
- package/build/cjs/__e2e__/{display-order.stories.e2e.js → display-order.e2e.stories.js} +2 -13
- package/build/cjs/__e2e__/{filter-options-list.stories.e2e.js → filter-options-list.e2e.stories.js} +3 -24
- package/build/cjs/__e2e__/{highlight-range-of-options.stories.e2e.js → highlight-range-of-options.e2e.stories.js} +2 -15
- package/build/cjs/__e2e__/{loading_lists.stories.e2e.js → loading_lists.e2e.stories.js} +2 -16
- package/build/cjs/__e2e__/{notify_at_end_of_list.stories.e2e.js → notify_at_end_of_list.e2e.stories.js} +2 -17
- package/build/cjs/__e2e__/{reorder-with-buttons.stories.e2e.js → reorder-with-buttons.e2e.stories.js} +2 -11
- package/build/cjs/__e2e__/{set_unset-highlighted-option.stories.e2e.js → set_unset-highlighted-option.e2e.stories.js} +2 -13
- package/build/cjs/__e2e__/{transferring-items.stories.e2e.js → transferring-items.e2e.stories.js} +2 -13
- package/build/cjs/__tests__/common.test.js +0 -1
- package/build/cjs/__tests__/helper/add-all-selectable-source-options.test.js +0 -1
- package/build/cjs/__tests__/helper/add-individual-source-options.test.js +0 -1
- package/build/cjs/__tests__/helper/default-filter-callback.test.js +0 -1
- package/build/cjs/__tests__/helper/is-reorder-down-disabled.test.js +0 -1
- package/build/cjs/__tests__/helper/is-reorder-up-disabled.test.js +0 -1
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-down.test.js +0 -1
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-up.test.js +0 -1
- package/build/cjs/__tests__/helper/remove-all-picked-options.test.js +0 -1
- package/build/cjs/__tests__/helper/remove-individual-picked-options.test.js +0 -1
- package/build/cjs/__tests__/helper/use-highlighted-option/create-toggle-highlighted-option.test.js +2 -9
- package/build/cjs/__tests__/helper/use-highlighted-option/toggle-add.test.js +0 -1
- package/build/cjs/__tests__/helper/use-highlighted-option/toggle-range.test.js +2 -3
- package/build/cjs/__tests__/helper/use-highlighted-option/toggle-replace.test.js +0 -1
- package/build/cjs/__tests__/helper/use-highlighted-option.test.js +1 -5
- package/build/cjs/__tests__/transfer.test.js +1 -5
- package/build/cjs/actions.js +2 -9
- package/build/cjs/add-all.js +2 -9
- package/build/cjs/add-individual.js +2 -9
- package/build/cjs/common/find-option-index.js +0 -3
- package/build/cjs/common/get-mode-by-modifier-key.js +2 -8
- package/build/cjs/common/index.js +0 -6
- package/build/cjs/common/is-option.js +0 -2
- package/build/cjs/common/modes.js +6 -9
- package/build/cjs/common/remove-option.js +0 -6
- package/build/cjs/common/styles.js +3 -8
- package/build/cjs/common/toggle-value.js +0 -4
- package/build/cjs/container.js +2 -8
- package/build/cjs/end-intersection-detector.js +1 -8
- package/build/cjs/features/add_remove-highlighted-options/index.js +0 -1
- package/build/cjs/features/common/index.js +0 -2
- package/build/cjs/features/disabled-transfer-buttons/index.js +0 -1
- package/build/cjs/features/disabled-transfer-options/index.js +0 -2
- package/build/cjs/features/display-order/index.js +6 -5
- package/build/cjs/features/filter-options-list/index.js +6 -8
- package/build/cjs/features/highlight-range-of-options/index.js +8 -5
- package/build/cjs/features/loading_lists/index.js +2 -3
- package/build/cjs/features/notify_at_end_of_list/index.js +1 -2
- package/build/cjs/features/reorder-with-buttons/index.js +3 -3
- package/build/cjs/features/set_unset-highlighted-option/index.js +0 -2
- package/build/cjs/features/transferring-items/index.js +6 -6
- package/build/cjs/filter.js +5 -14
- package/build/cjs/icons.js +17 -35
- package/build/cjs/index.js +0 -2
- package/build/cjs/left-footer.js +2 -10
- package/build/cjs/left-header.js +2 -10
- package/build/cjs/left-side.js +2 -9
- package/build/cjs/options-container.js +9 -20
- package/build/cjs/picked-options.js +2 -10
- package/build/cjs/remove-all.js +2 -9
- package/build/cjs/remove-individual.js +2 -9
- package/build/cjs/reordering-actions.js +7 -16
- package/build/cjs/right-footer.js +2 -10
- package/build/cjs/right-header.js +2 -10
- package/build/cjs/right-side.js +2 -9
- package/build/cjs/source-options.js +2 -10
- package/build/cjs/transfer/add-all-selectable-source-options.js +3 -4
- package/build/cjs/transfer/add-individual-source-options.js +1 -4
- package/build/cjs/transfer/create-double-click-handlers.js +0 -5
- package/build/cjs/transfer/default-filter-callback.js +0 -2
- package/build/cjs/transfer/get-option-click-handlers.js +0 -3
- package/build/cjs/transfer/index.js +0 -26
- package/build/cjs/transfer/is-reorder-down-disabled.js +4 -4
- package/build/cjs/transfer/is-reorder-up-disabled.js +4 -4
- package/build/cjs/transfer/move-highlighted-picked-option-down.js +4 -5
- package/build/cjs/transfer/move-highlighted-picked-option-up.js +4 -5
- package/build/cjs/transfer/remove-all-picked-options.js +0 -2
- package/build/cjs/transfer/remove-individual-picked-options.js +1 -4
- package/build/cjs/transfer/use-filter.js +0 -4
- package/build/cjs/transfer/use-highlighted-options/create-toggle-highlighted-option.js +2 -12
- package/build/cjs/transfer/use-highlighted-options/toggle-add.js +0 -3
- package/build/cjs/transfer/use-highlighted-options/toggle-range.js +3 -8
- package/build/cjs/transfer/use-highlighted-options/toggle-replace.js +0 -4
- package/build/cjs/transfer/use-highlighted-options.js +0 -5
- package/build/cjs/transfer-option.js +4 -16
- package/build/cjs/transfer.js +29 -54
- package/build/cjs/{transfer.stories.js → transfer.prod.stories.js} +83 -103
- package/build/cjs/use-resize-counter.js +0 -4
- package/build/es/__e2e__/common/stateful-decorator.js +1 -2
- package/build/es/__e2e__/{disabled-transfer-buttons.stories.e2e.js → disabled-transfer-buttons.e2e.stories.js} +2 -1
- package/build/es/__e2e__/{disabled-transfer-options.stories.e2e.js → disabled-transfer-options.e2e.stories.js} +2 -1
- package/build/es/__e2e__/{filter-options-list.stories.e2e.js → filter-options-list.e2e.stories.js} +1 -3
- package/build/es/__tests__/helper/use-highlighted-option/create-toggle-highlighted-option.test.js +2 -1
- package/build/es/__tests__/helper/use-highlighted-option/toggle-range.test.js +2 -2
- package/build/es/__tests__/helper/use-highlighted-option.test.js +1 -1
- package/build/es/actions.js +1 -1
- package/build/es/add-all.js +1 -1
- package/build/es/add-individual.js +1 -1
- package/build/es/common/find-option-index.js +1 -1
- package/build/es/common/get-mode-by-modifier-key.js +3 -6
- package/build/es/common/modes.js +5 -4
- package/build/es/common/remove-option.js +1 -4
- package/build/es/common/toggle-value.js +0 -2
- package/build/es/container.js +1 -1
- package/build/es/features/display-order/index.js +6 -3
- package/build/es/features/filter-options-list/index.js +6 -6
- package/build/es/features/highlight-range-of-options/index.js +8 -3
- package/build/es/features/loading_lists/index.js +2 -2
- package/build/es/features/notify_at_end_of_list/index.js +1 -1
- package/build/es/features/reorder-with-buttons/index.js +3 -2
- package/build/es/features/transferring-items/index.js +6 -3
- package/build/es/filter.js +4 -4
- package/build/es/icons.js +16 -16
- package/build/es/left-footer.js +1 -1
- package/build/es/left-header.js +1 -1
- package/build/es/left-side.js +1 -1
- package/build/es/options-container.js +6 -5
- package/build/es/picked-options.js +1 -1
- package/build/es/remove-all.js +1 -1
- package/build/es/remove-individual.js +1 -1
- package/build/es/reordering-actions.js +6 -6
- package/build/es/right-footer.js +1 -1
- package/build/es/right-header.js +1 -1
- package/build/es/right-side.js +1 -1
- package/build/es/source-options.js +1 -1
- package/build/es/transfer/add-all-selectable-source-options.js +3 -2
- package/build/es/transfer/add-individual-source-options.js +1 -2
- package/build/es/transfer/create-double-click-handlers.js +0 -3
- package/build/es/transfer/get-option-click-handlers.js +1 -1
- package/build/es/transfer/is-reorder-down-disabled.js +4 -2
- package/build/es/transfer/is-reorder-up-disabled.js +4 -2
- package/build/es/transfer/move-highlighted-picked-option-down.js +4 -3
- package/build/es/transfer/move-highlighted-picked-option-up.js +4 -3
- package/build/es/transfer/remove-individual-picked-options.js +1 -2
- package/build/es/transfer/use-filter.js +0 -2
- package/build/es/transfer/use-highlighted-options/create-toggle-highlighted-option.js +3 -7
- package/build/es/transfer/use-highlighted-options/toggle-add.js +1 -1
- package/build/es/transfer/use-highlighted-options/toggle-range.js +4 -6
- package/build/es/transfer/use-highlighted-options/toggle-replace.js +0 -2
- package/build/es/transfer/use-highlighted-options.js +1 -2
- package/build/es/transfer-option.js +1 -2
- package/build/es/transfer.js +28 -32
- package/build/es/{transfer.stories.js → transfer.prod.stories.js} +65 -50
- package/build/es/use-resize-counter.js +1 -2
- package/package.json +10 -10
- /package/build/es/__e2e__/{add_remove-highlighted-options.stories.e2e.js → add_remove-highlighted-options.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{display-order.stories.e2e.js → display-order.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{highlight-range-of-options.stories.e2e.js → highlight-range-of-options.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{loading_lists.stories.e2e.js → loading_lists.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{notify_at_end_of_list.stories.e2e.js → notify_at_end_of_list.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{reorder-with-buttons.stories.e2e.js → reorder-with-buttons.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{set_unset-highlighted-option.stories.e2e.js → set_unset-highlighted-option.e2e.stories.js} +0 -0
- /package/build/es/__e2e__/{transferring-items.stories.e2e.js → transferring-items.e2e.stories.js} +0 -0
|
@@ -15,7 +15,6 @@ export const createDoubleClickHandlers = _ref => {
|
|
|
15
15
|
setHighlightedPickedOptions,
|
|
16
16
|
setHighlightedSourceOptions
|
|
17
17
|
} = _ref;
|
|
18
|
-
|
|
19
18
|
const selectSingleOption = _ref2 => {
|
|
20
19
|
let {
|
|
21
20
|
value
|
|
@@ -26,7 +25,6 @@ export const createDoubleClickHandlers = _ref => {
|
|
|
26
25
|
selected: newSelected.slice(-1 * maxSelections)
|
|
27
26
|
});
|
|
28
27
|
};
|
|
29
|
-
|
|
30
28
|
const deselectSingleOption = _ref3 => {
|
|
31
29
|
let {
|
|
32
30
|
value
|
|
@@ -37,7 +35,6 @@ export const createDoubleClickHandlers = _ref => {
|
|
|
37
35
|
selected: newSelected
|
|
38
36
|
});
|
|
39
37
|
};
|
|
40
|
-
|
|
41
38
|
return {
|
|
42
39
|
selectSingleOption,
|
|
43
40
|
deselectSingleOption
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getModeByModifierKey } from '../common/index.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* @param {Object} option
|
|
4
5
|
* @param {Function} selectionHandler
|
|
5
6
|
* @param {Function} toggleHighlightedOption
|
|
6
7
|
* @returns {Object}
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
export const getOptionClickHandlers = (option, selectionHandler, toggleHighlightedOption) => ({
|
|
10
10
|
onClick: (_, event) => {
|
|
11
11
|
const mode = getModeByModifierKey(event);
|
|
@@ -9,8 +9,10 @@ export const isReorderDownDisabled = _ref => {
|
|
|
9
9
|
highlightedPickedOptions,
|
|
10
10
|
selected
|
|
11
11
|
} = _ref;
|
|
12
|
-
return (
|
|
13
|
-
|
|
12
|
+
return (
|
|
13
|
+
// only one item can be moved with the buttons
|
|
14
|
+
highlightedPickedOptions.length !== 1 ||
|
|
15
|
+
// can't move an item down if it's the last one
|
|
14
16
|
selected.indexOf(highlightedPickedOptions[0]) === selected.length - 1
|
|
15
17
|
);
|
|
16
18
|
};
|
|
@@ -9,8 +9,10 @@ export const isReorderUpDisabled = _ref => {
|
|
|
9
9
|
highlightedPickedOptions,
|
|
10
10
|
selected
|
|
11
11
|
} = _ref;
|
|
12
|
-
return (
|
|
13
|
-
|
|
12
|
+
return (
|
|
13
|
+
// only one item can be moved with the buttons
|
|
14
|
+
highlightedPickedOptions.length !== 1 ||
|
|
15
|
+
// can't move an item up if it's the first one
|
|
14
16
|
selected.indexOf(highlightedPickedOptions[0]) === 0
|
|
15
17
|
);
|
|
16
18
|
};
|
|
@@ -11,13 +11,14 @@ export const moveHighlightedPickedOptionDown = _ref => {
|
|
|
11
11
|
highlightedPickedOptions,
|
|
12
12
|
onChange
|
|
13
13
|
} = _ref;
|
|
14
|
-
const optionIndex = selected.findIndex(selectedOption => selectedOption === highlightedPickedOptions[0]);
|
|
14
|
+
const optionIndex = selected.findIndex(selectedOption => selectedOption === highlightedPickedOptions[0]);
|
|
15
15
|
|
|
16
|
+
// Can't move down last or non-existing option
|
|
16
17
|
if (optionIndex === -1 || optionIndex > selected.length - 2) {
|
|
17
18
|
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
+
// swap with next item
|
|
21
22
|
const reordered = [...selected.slice(0, optionIndex), selected[optionIndex + 1], selected[optionIndex], ...selected.slice(optionIndex + 2)];
|
|
22
23
|
onChange({
|
|
23
24
|
selected: reordered
|
|
@@ -11,13 +11,14 @@ export const moveHighlightedPickedOptionUp = _ref => {
|
|
|
11
11
|
highlightedPickedOptions,
|
|
12
12
|
onChange
|
|
13
13
|
} = _ref;
|
|
14
|
-
const optionIndex = selected.findIndex(selectedOption => selectedOption === highlightedPickedOptions[0]);
|
|
14
|
+
const optionIndex = selected.findIndex(selectedOption => selectedOption === highlightedPickedOptions[0]);
|
|
15
15
|
|
|
16
|
+
// Can't move up option at index 0 or non-existing option
|
|
16
17
|
if (optionIndex < 1) {
|
|
17
18
|
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
+
// swap with previous item
|
|
21
22
|
const reordered = [...selected.slice(0, optionIndex - 1), selected[optionIndex], selected[optionIndex - 1], ...selected.slice(optionIndex + 1)];
|
|
22
23
|
onChange({
|
|
23
24
|
selected: reordered
|
|
@@ -15,7 +15,6 @@ export const removeIndividualPickedOptions = _ref => {
|
|
|
15
15
|
selected,
|
|
16
16
|
setHighlightedPickedOptions
|
|
17
17
|
} = _ref;
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* Creates a subset of the highlighted options to reflect a changed
|
|
21
20
|
* filter value in case previously highlighted options are now
|
|
@@ -30,12 +29,12 @@ export const removeIndividualPickedOptions = _ref => {
|
|
|
30
29
|
const filteredHighlightedPickedOptions = filterablePicked ? highlightedPickedOptions.filter(value => pickedOptions.find(filteredOption => filteredOption.value === value)) : highlightedPickedOptions;
|
|
31
30
|
const newSelected = selected.filter(selectedOption => !filteredHighlightedPickedOptions.includes(selectedOption));
|
|
32
31
|
setHighlightedPickedOptions([]);
|
|
32
|
+
|
|
33
33
|
/**
|
|
34
34
|
* as the maximum amount of selected items
|
|
35
35
|
* is already restricted through the selection mechanism,
|
|
36
36
|
* there's no need to handle `maxSelection` here
|
|
37
37
|
*/
|
|
38
|
-
|
|
39
38
|
onChange({
|
|
40
39
|
selected: newSelected
|
|
41
40
|
});
|
|
@@ -2,6 +2,7 @@ import { ADD_MODE, RANGE_MODE } from '../../common/index.js';
|
|
|
2
2
|
import { toggleAdd } from './toggle-add.js';
|
|
3
3
|
import { toggleRange } from './toggle-range.js';
|
|
4
4
|
import { toggleReplace } from './toggle-replace.js';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* @param {Object} args
|
|
7
8
|
* @param {bool} args.disabled
|
|
@@ -13,7 +14,6 @@ import { toggleReplace } from './toggle-replace.js';
|
|
|
13
14
|
* @param {string} args.lastClicked
|
|
14
15
|
* @returns {void}
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
17
|
export const createToggleHighlightedOption = _ref => {
|
|
18
18
|
let {
|
|
19
19
|
disabled,
|
|
@@ -29,13 +29,10 @@ export const createToggleHighlightedOption = _ref => {
|
|
|
29
29
|
option,
|
|
30
30
|
mode
|
|
31
31
|
} = _ref2;
|
|
32
|
-
|
|
33
32
|
if (disabled) {
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
setHighlightedOptions([]);
|
|
38
|
-
|
|
39
36
|
if (mode === ADD_MODE) {
|
|
40
37
|
setLastClicked(option.value);
|
|
41
38
|
return toggleAdd({
|
|
@@ -45,7 +42,6 @@ export const createToggleHighlightedOption = _ref => {
|
|
|
45
42
|
setHighlightedOptions
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
|
-
|
|
49
45
|
if (mode === RANGE_MODE) {
|
|
50
46
|
return toggleRange({
|
|
51
47
|
highlightedOptions,
|
|
@@ -55,9 +51,9 @@ export const createToggleHighlightedOption = _ref => {
|
|
|
55
51
|
lastClicked,
|
|
56
52
|
maxSelections
|
|
57
53
|
});
|
|
58
|
-
}
|
|
59
|
-
|
|
54
|
+
}
|
|
60
55
|
|
|
56
|
+
// REPLACE_MODE
|
|
61
57
|
setLastClicked(option.value);
|
|
62
58
|
return toggleReplace({
|
|
63
59
|
option,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toggleValue } from '../../common/index.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* @param {Object} args
|
|
4
5
|
* @param {number} args.maxSelections
|
|
@@ -7,7 +8,6 @@ import { toggleValue } from '../../common/index.js';
|
|
|
7
8
|
* @param {Function} args.setHighlightedOption
|
|
8
9
|
* @returns {void}
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
export const toggleAdd = _ref => {
|
|
12
12
|
let {
|
|
13
13
|
highlightedOptions,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { findOptionIndex } from '../../common/index.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* @param {Object} args
|
|
4
5
|
* @param {number} args.maxSelections
|
|
@@ -9,7 +10,6 @@ import { findOptionIndex } from '../../common/index.js';
|
|
|
9
10
|
* @param {Function} args.setHighlightedOption
|
|
10
11
|
* @returns {void}
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
13
|
export const toggleRange = _ref => {
|
|
14
14
|
let {
|
|
15
15
|
highlightedOptions,
|
|
@@ -19,14 +19,12 @@ export const toggleRange = _ref => {
|
|
|
19
19
|
lastClicked,
|
|
20
20
|
maxSelections
|
|
21
21
|
} = _ref;
|
|
22
|
-
|
|
23
22
|
if (highlightedOptions.length === 0) {
|
|
24
23
|
setHighlightedOptions([option.value]);
|
|
25
24
|
} else {
|
|
26
25
|
let from, to;
|
|
27
26
|
const clickedOptionIndex = findOptionIndex(options, option);
|
|
28
27
|
const lastClickedSourceOptionWithoutRangeModeIndex = lastClicked ? options.findIndex(curOption => curOption.value === lastClicked) : -1;
|
|
29
|
-
|
|
30
28
|
if (lastClickedSourceOptionWithoutRangeModeIndex !== -1) {
|
|
31
29
|
from = lastClickedSourceOptionWithoutRangeModeIndex;
|
|
32
30
|
to = clickedOptionIndex;
|
|
@@ -37,11 +35,11 @@ export const toggleRange = _ref => {
|
|
|
37
35
|
const firstHighlightedInList = options.findIndex(option => highlightedOptions.find(highlightedOption => highlightedOption === option.value));
|
|
38
36
|
from = firstHighlightedInList;
|
|
39
37
|
to = clickedOptionIndex;
|
|
40
|
-
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// this is so we can also selected
|
|
41
41
|
// a range of options above "from" option.
|
|
42
42
|
// -> Just how slice works ;)
|
|
43
|
-
|
|
44
|
-
|
|
45
43
|
const lower = Math.min(from, to);
|
|
46
44
|
const higher = Math.max(from, to);
|
|
47
45
|
const newHighlightedSourceOptions = options.slice(lower, higher + 1).filter(option => !option.disabled).slice(maxSelections * -1).map(_ref2 => {
|
|
@@ -11,12 +11,10 @@ export const toggleReplace = _ref => {
|
|
|
11
11
|
highlightedOptions,
|
|
12
12
|
setHighlightedOptions
|
|
13
13
|
} = _ref;
|
|
14
|
-
|
|
15
14
|
if (highlightedOptions.length > 1) {
|
|
16
15
|
setHighlightedOptions([option.value]);
|
|
17
16
|
} else {
|
|
18
17
|
const optionIndex = highlightedOptions.findIndex(highlightedOption => highlightedOption === option.value);
|
|
19
|
-
|
|
20
18
|
if (optionIndex === -1) {
|
|
21
19
|
setHighlightedOptions([option.value]);
|
|
22
20
|
} else {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { createToggleHighlightedOption } from './use-highlighted-options/create-toggle-highlighted-option.js';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* @param {Object} args
|
|
5
6
|
* @param {bool} args.disabled
|
|
@@ -7,14 +8,12 @@ import { createToggleHighlightedOption } from './use-highlighted-options/create-
|
|
|
7
8
|
* @param {Object[]} args.options
|
|
8
9
|
* @returns {Object} highlighted options & helpers
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
export const useHighlightedOptions = _ref => {
|
|
12
12
|
let {
|
|
13
13
|
disabled,
|
|
14
14
|
maxSelections,
|
|
15
15
|
options
|
|
16
16
|
} = _ref;
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* These are important so the stored element can be used
|
|
20
19
|
* as range-start when using shift multiple times consecutively
|
|
@@ -22,7 +22,6 @@ export const TransferOption = _ref => {
|
|
|
22
22
|
if (disabled) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
25
|
if (doubleClickTimeout.current) {
|
|
27
26
|
clearTimeout(doubleClickTimeout.current);
|
|
28
27
|
doubleClickTimeout.current = null;
|
|
@@ -47,7 +46,7 @@ export const TransferOption = _ref => {
|
|
|
47
46
|
}, label, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
48
47
|
id: "4216903932",
|
|
49
48
|
dynamic: [colors.grey900, colors.grey200, colors.teal700, colors.white, colors.grey600]
|
|
50
|
-
}, [
|
|
49
|
+
}, [`div.__jsx-style-dynamic-selector{font-size:14px;line-height:16px;padding:4px 8px;color:${colors.grey900};-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}`, `div.__jsx-style-dynamic-selector:hover{background:${colors.grey200};}`, `div.highlighted.__jsx-style-dynamic-selector{background:${colors.teal700};color:${colors.white};}`, `div.disabled.__jsx-style-dynamic-selector{color:${colors.grey600};cursor:not-allowed;}`]));
|
|
51
50
|
};
|
|
52
51
|
TransferOption.defaultProps = {
|
|
53
52
|
dataTest: 'dhis2-uicore-transferoption'
|
package/build/es/transfer.js
CHANGED
|
@@ -15,11 +15,9 @@ import { ReorderingActions } from './reordering-actions.js';
|
|
|
15
15
|
import { RightFooter } from './right-footer.js';
|
|
16
16
|
import { RightHeader } from './right-header.js';
|
|
17
17
|
import { RightSide } from './right-side.js';
|
|
18
|
-
import { TransferOption } from './transfer-option.js';
|
|
19
18
|
import { addAllSelectableSourceOptions, addIndividualSourceOptions, createDoubleClickHandlers, defaultFilterCallback, getOptionClickHandlers, isReorderDownDisabled, isReorderUpDisabled, moveHighlightedPickedOptionDown, moveHighlightedPickedOptionUp, removeAllPickedOptions, removeIndividualPickedOptions, useFilter, useHighlightedOptions } from './transfer/index.js';
|
|
20
|
-
|
|
19
|
+
import { TransferOption } from './transfer-option.js';
|
|
21
20
|
const identity = value => value;
|
|
22
|
-
|
|
23
21
|
export const Transfer = _ref => {
|
|
24
22
|
let {
|
|
25
23
|
options,
|
|
@@ -65,7 +63,6 @@ export const Transfer = _ref => {
|
|
|
65
63
|
onEndReached,
|
|
66
64
|
onEndReachedPicked
|
|
67
65
|
} = _ref;
|
|
68
|
-
|
|
69
66
|
/* Source options search value:
|
|
70
67
|
* Depending on whether the onFilterChange callback has been provided
|
|
71
68
|
* either the internal or external search value is used */
|
|
@@ -80,23 +77,23 @@ export const Transfer = _ref => {
|
|
|
80
77
|
filterable,
|
|
81
78
|
filterCallback
|
|
82
79
|
});
|
|
80
|
+
|
|
83
81
|
/*
|
|
84
82
|
* Actual source options:
|
|
85
83
|
* Extract the not-selected options.
|
|
86
84
|
* Filters options if filterable is true.
|
|
87
85
|
*/
|
|
88
|
-
|
|
89
86
|
const sourceOptions = actualFilterCallback(options.filter(_ref2 => {
|
|
90
87
|
let {
|
|
91
88
|
value
|
|
92
89
|
} = _ref2;
|
|
93
90
|
return !selected.includes(value);
|
|
94
91
|
}), actualFilter);
|
|
92
|
+
|
|
95
93
|
/*
|
|
96
94
|
* Picked options highlighting:
|
|
97
95
|
* These are all the highlighted options on the options side.
|
|
98
96
|
*/
|
|
99
|
-
|
|
100
97
|
const {
|
|
101
98
|
highlightedOptions: highlightedSourceOptions,
|
|
102
99
|
setHighlightedOptions: setHighlightedSourceOptions,
|
|
@@ -106,10 +103,10 @@ export const Transfer = _ref => {
|
|
|
106
103
|
disabled,
|
|
107
104
|
maxSelections
|
|
108
105
|
});
|
|
106
|
+
|
|
109
107
|
/* Picked options search value:
|
|
110
108
|
* Depending on whether the onFilterChangePicked callback has been provided
|
|
111
109
|
* either the internal or external search value is used */
|
|
112
|
-
|
|
113
110
|
const {
|
|
114
111
|
filterValue: actualFilterPicked,
|
|
115
112
|
filter: actualFilterPickedCallback,
|
|
@@ -121,25 +118,26 @@ export const Transfer = _ref => {
|
|
|
121
118
|
externalSearchTerm: searchTermPicked,
|
|
122
119
|
filterCallback: filterCallbackPicked
|
|
123
120
|
});
|
|
121
|
+
|
|
124
122
|
/*
|
|
125
123
|
* Actual picked options:
|
|
126
124
|
* Extract the selected options. Can't use `options.filter`
|
|
127
125
|
* because we need to keep the order of `selected`
|
|
128
126
|
*/
|
|
127
|
+
let pickedOptions = [];
|
|
129
128
|
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
// Only map if selected is an array
|
|
132
130
|
if (Array.isArray(selected)) {
|
|
133
|
-
pickedOptions = actualFilterPickedCallback(selected.map(value => options.find(option => value === option.value))
|
|
131
|
+
pickedOptions = actualFilterPickedCallback(selected.map(value => options.find(option => value === option.value))
|
|
132
|
+
// filter -> in case a selected value has been provided
|
|
134
133
|
// that does not exist as option
|
|
135
134
|
.filter(identity), actualFilterPicked);
|
|
136
135
|
}
|
|
136
|
+
|
|
137
137
|
/*
|
|
138
138
|
* Source options highlighting:
|
|
139
139
|
* These are all the highlighted options on the selected side.
|
|
140
140
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
141
|
const {
|
|
144
142
|
highlightedOptions: highlightedPickedOptions,
|
|
145
143
|
setHighlightedOptions: setHighlightedPickedOptions,
|
|
@@ -149,11 +147,11 @@ export const Transfer = _ref => {
|
|
|
149
147
|
disabled,
|
|
150
148
|
maxSelections
|
|
151
149
|
});
|
|
150
|
+
|
|
152
151
|
/*
|
|
153
152
|
* Source & Picked options:
|
|
154
153
|
* These are the double click handlers for (de-)selection
|
|
155
154
|
*/
|
|
156
|
-
|
|
157
155
|
const {
|
|
158
156
|
selectSingleOption,
|
|
159
157
|
deselectSingleOption
|
|
@@ -164,10 +162,10 @@ export const Transfer = _ref => {
|
|
|
164
162
|
onChange,
|
|
165
163
|
maxSelections
|
|
166
164
|
});
|
|
165
|
+
|
|
167
166
|
/**
|
|
168
167
|
* Disabled button states
|
|
169
168
|
*/
|
|
170
|
-
|
|
171
169
|
const isAddAllDisabled = disabled || sourceOptions.filter(_ref3 => {
|
|
172
170
|
let {
|
|
173
171
|
disabled
|
|
@@ -182,14 +180,14 @@ export const Transfer = _ref => {
|
|
|
182
180
|
className: className,
|
|
183
181
|
height: height
|
|
184
182
|
}, /*#__PURE__*/React.createElement(LeftSide, {
|
|
185
|
-
dataTest:
|
|
183
|
+
dataTest: `${dataTest}-leftside`,
|
|
186
184
|
width: optionsWidth
|
|
187
185
|
}, (leftHeader || filterable) && /*#__PURE__*/React.createElement(LeftHeader, {
|
|
188
|
-
dataTest:
|
|
186
|
+
dataTest: `${dataTest}-leftheader`
|
|
189
187
|
}, leftHeader, filterable && !hideFilterInput && /*#__PURE__*/React.createElement(Filter, {
|
|
190
188
|
label: filterLabel,
|
|
191
189
|
placeholder: filterPlaceholder,
|
|
192
|
-
dataTest:
|
|
190
|
+
dataTest: `${dataTest}-filter`,
|
|
193
191
|
filter: actualFilter,
|
|
194
192
|
onChange: onFilterChange ? onFilterChange : _ref4 => {
|
|
195
193
|
let {
|
|
@@ -198,7 +196,7 @@ export const Transfer = _ref => {
|
|
|
198
196
|
return setInternalFilter(value);
|
|
199
197
|
}
|
|
200
198
|
})), /*#__PURE__*/React.createElement(OptionsContainer, {
|
|
201
|
-
dataTest:
|
|
199
|
+
dataTest: `${dataTest}-sourceoptions`,
|
|
202
200
|
emptyComponent: sourceEmptyPlaceholder,
|
|
203
201
|
getOptionClickHandlers: getOptionClickHandlers,
|
|
204
202
|
highlightedOptions: highlightedSourceOptions,
|
|
@@ -209,12 +207,12 @@ export const Transfer = _ref => {
|
|
|
209
207
|
toggleHighlightedOption: toggleHighlightedSourceOption,
|
|
210
208
|
onEndReached: onEndReached
|
|
211
209
|
}), leftFooter && /*#__PURE__*/React.createElement(LeftFooter, {
|
|
212
|
-
dataTest:
|
|
210
|
+
dataTest: `${dataTest}-leftfooter`
|
|
213
211
|
}, leftFooter)), /*#__PURE__*/React.createElement(Actions, {
|
|
214
|
-
dataTest:
|
|
212
|
+
dataTest: `${dataTest}-actions`
|
|
215
213
|
}, maxSelections === Infinity && /*#__PURE__*/React.createElement(AddAll, {
|
|
216
214
|
label: addAllText,
|
|
217
|
-
dataTest:
|
|
215
|
+
dataTest: `${dataTest}-actions-addall`,
|
|
218
216
|
disabled: isAddAllDisabled,
|
|
219
217
|
onClick: () => addAllSelectableSourceOptions({
|
|
220
218
|
sourceOptions,
|
|
@@ -224,7 +222,7 @@ export const Transfer = _ref => {
|
|
|
224
222
|
})
|
|
225
223
|
}), /*#__PURE__*/React.createElement(AddIndividual, {
|
|
226
224
|
label: addIndividualText,
|
|
227
|
-
dataTest:
|
|
225
|
+
dataTest: `${dataTest}-actions-addindividual`,
|
|
228
226
|
disabled: isAddIndividualDisabled,
|
|
229
227
|
onClick: () => addIndividualSourceOptions({
|
|
230
228
|
filterable,
|
|
@@ -237,7 +235,7 @@ export const Transfer = _ref => {
|
|
|
237
235
|
})
|
|
238
236
|
}), maxSelections === Infinity && /*#__PURE__*/React.createElement(RemoveAll, {
|
|
239
237
|
label: removeAllText,
|
|
240
|
-
dataTest:
|
|
238
|
+
dataTest: `${dataTest}-actions-removeall`,
|
|
241
239
|
disabled: isRemoveAllDisabled,
|
|
242
240
|
onClick: () => removeAllPickedOptions({
|
|
243
241
|
setHighlightedPickedOptions,
|
|
@@ -245,7 +243,7 @@ export const Transfer = _ref => {
|
|
|
245
243
|
})
|
|
246
244
|
}), /*#__PURE__*/React.createElement(RemoveIndividual, {
|
|
247
245
|
label: removeIndividualText,
|
|
248
|
-
dataTest:
|
|
246
|
+
dataTest: `${dataTest}-actions-removeindividual`,
|
|
249
247
|
disabled: isRemoveIndividualDisabled,
|
|
250
248
|
onClick: () => removeIndividualPickedOptions({
|
|
251
249
|
filterablePicked,
|
|
@@ -256,14 +254,14 @@ export const Transfer = _ref => {
|
|
|
256
254
|
setHighlightedPickedOptions
|
|
257
255
|
})
|
|
258
256
|
})), /*#__PURE__*/React.createElement(RightSide, {
|
|
259
|
-
dataTest:
|
|
257
|
+
dataTest: `${dataTest}-rightside`,
|
|
260
258
|
width: selectedWidth
|
|
261
259
|
}, (rightHeader || filterablePicked) && /*#__PURE__*/React.createElement(RightHeader, {
|
|
262
|
-
dataTest:
|
|
260
|
+
dataTest: `${dataTest}-rightheader`
|
|
263
261
|
}, rightHeader, filterablePicked && !hideFilterInputPicked && /*#__PURE__*/React.createElement(Filter, {
|
|
264
262
|
label: filterLabelPicked,
|
|
265
263
|
placeholder: filterPlaceholderPicked,
|
|
266
|
-
dataTest:
|
|
264
|
+
dataTest: `${dataTest}-filter`,
|
|
267
265
|
filter: actualFilterPicked,
|
|
268
266
|
onChange: onFilterChangePicked ? onFilterChangePicked : _ref5 => {
|
|
269
267
|
let {
|
|
@@ -273,7 +271,7 @@ export const Transfer = _ref => {
|
|
|
273
271
|
}
|
|
274
272
|
})), /*#__PURE__*/React.createElement(OptionsContainer, {
|
|
275
273
|
selected: true,
|
|
276
|
-
dataTest:
|
|
274
|
+
dataTest: `${dataTest}-pickedoptions`,
|
|
277
275
|
emptyComponent: selectedEmptyComponent,
|
|
278
276
|
getOptionClickHandlers: getOptionClickHandlers,
|
|
279
277
|
highlightedOptions: highlightedPickedOptions,
|
|
@@ -284,9 +282,9 @@ export const Transfer = _ref => {
|
|
|
284
282
|
toggleHighlightedOption: toggleHighlightedPickedOption,
|
|
285
283
|
onEndReached: onEndReachedPicked
|
|
286
284
|
}), (rightFooter || enableOrderChange) && /*#__PURE__*/React.createElement(RightFooter, {
|
|
287
|
-
dataTest:
|
|
285
|
+
dataTest: `${dataTest}-rightfooter`
|
|
288
286
|
}, enableOrderChange && /*#__PURE__*/React.createElement(ReorderingActions, {
|
|
289
|
-
dataTest:
|
|
287
|
+
dataTest: `${dataTest}-reorderingactions`,
|
|
290
288
|
disabledDown: isReorderDownDisabled({
|
|
291
289
|
highlightedPickedOptions,
|
|
292
290
|
selected
|
|
@@ -309,9 +307,7 @@ export const Transfer = _ref => {
|
|
|
309
307
|
}
|
|
310
308
|
}), rightFooter)));
|
|
311
309
|
};
|
|
312
|
-
|
|
313
310
|
const defaultRenderOption = option => /*#__PURE__*/React.createElement(TransferOption, option);
|
|
314
|
-
|
|
315
311
|
Transfer.defaultProps = {
|
|
316
312
|
dataTest: 'dhis2-uicore-transfer',
|
|
317
313
|
height: '240px',
|