@dhis2-ui/transfer 10.13.1 → 10.14.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.
- package/build/cjs/__e2e__/reorder-with-buttons.e2e.stories.js +15 -4
- package/build/cjs/__tests__/helper/default-filter-callback.test.js +6 -0
- package/build/cjs/__tests__/helper/is-reorder-down-disabled.test.js +50 -11
- package/build/cjs/__tests__/helper/is-reorder-up-disabled.test.js +50 -11
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-down.test.js +65 -11
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-to-bottom.test.js +85 -0
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-to-top.test.js +85 -0
- package/build/cjs/__tests__/helper/move-highlighted-picked-option-up.test.js +65 -11
- package/build/cjs/__tests__/reordering-actions.test.js +104 -0
- package/build/cjs/features/reorder-with-buttons/index.js +70 -2
- package/build/cjs/features/reorder-with-buttons.feature +97 -5
- package/build/cjs/icons.js +53 -13
- package/build/cjs/locales/en/translations.json +7 -0
- package/build/cjs/locales/index.js +21 -0
- package/build/cjs/reordering-actions.js +93 -27
- package/build/cjs/transfer/default-filter-callback.js +17 -6
- package/build/cjs/transfer/get-highlighted-picked-indices.js +34 -0
- package/build/cjs/transfer/index.js +33 -0
- package/build/cjs/transfer/is-reorder-down-disabled.js +19 -8
- package/build/cjs/transfer/is-reorder-up-disabled.js +18 -8
- package/build/cjs/transfer/move-highlighted-picked-option-down.js +23 -6
- package/build/cjs/transfer/move-highlighted-picked-option-to-bottom.js +45 -0
- package/build/cjs/transfer/move-highlighted-picked-option-to-top.js +44 -0
- package/build/cjs/transfer/move-highlighted-picked-option-up.js +21 -6
- package/build/cjs/transfer.js +58 -6
- package/build/cjs/transfer.prod.stories.js +89 -19
- package/build/es/__e2e__/reorder-with-buttons.e2e.stories.js +14 -2
- package/build/es/__tests__/helper/default-filter-callback.test.js +6 -0
- package/build/es/__tests__/helper/is-reorder-down-disabled.test.js +50 -11
- package/build/es/__tests__/helper/is-reorder-up-disabled.test.js +50 -11
- package/build/es/__tests__/helper/move-highlighted-picked-option-down.test.js +65 -11
- package/build/es/__tests__/helper/move-highlighted-picked-option-to-bottom.test.js +83 -0
- package/build/es/__tests__/helper/move-highlighted-picked-option-to-top.test.js +83 -0
- package/build/es/__tests__/helper/move-highlighted-picked-option-up.test.js +65 -11
- package/build/es/__tests__/reordering-actions.test.js +101 -0
- package/build/es/features/reorder-with-buttons/index.js +70 -2
- package/build/es/features/reorder-with-buttons.feature +97 -5
- package/build/es/icons.js +51 -13
- package/build/es/locales/en/translations.json +7 -0
- package/build/es/locales/index.js +13 -0
- package/build/es/reordering-actions.js +94 -28
- package/build/es/transfer/default-filter-callback.js +17 -6
- package/build/es/transfer/get-highlighted-picked-indices.js +27 -0
- package/build/es/transfer/index.js +3 -0
- package/build/es/transfer/is-reorder-down-disabled.js +20 -8
- package/build/es/transfer/is-reorder-up-disabled.js +19 -8
- package/build/es/transfer/move-highlighted-picked-option-down.js +24 -6
- package/build/es/transfer/move-highlighted-picked-option-to-bottom.js +39 -0
- package/build/es/transfer/move-highlighted-picked-option-to-top.js +38 -0
- package/build/es/transfer/move-highlighted-picked-option-up.js +22 -6
- package/build/es/transfer.js +60 -8
- package/build/es/transfer.prod.stories.js +88 -18
- package/package.json +9 -7
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getHighlightedPickedIndices = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the indices, in ascending order, of `highlightedPickedOptions`
|
|
9
|
+
* within `selected`. Values in `highlightedPickedOptions` that don't appear
|
|
10
|
+
* in `selected` are ignored, so callers can pass a potentially stale
|
|
11
|
+
* highlight list without filtering first.
|
|
12
|
+
*
|
|
13
|
+
* Runs in O(n) over `selected` via a Set lookup.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} args
|
|
16
|
+
* @param {string[]} args.selected
|
|
17
|
+
* @param {string[]} args.highlightedPickedOptions
|
|
18
|
+
* @returns {number[]}
|
|
19
|
+
*/
|
|
20
|
+
const getHighlightedPickedIndices = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
selected,
|
|
23
|
+
highlightedPickedOptions
|
|
24
|
+
} = _ref;
|
|
25
|
+
const highlightedSet = new Set(highlightedPickedOptions);
|
|
26
|
+
const indices = [];
|
|
27
|
+
selected.forEach((value, index) => {
|
|
28
|
+
if (highlightedSet.has(value)) {
|
|
29
|
+
indices.push(index);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return indices;
|
|
33
|
+
};
|
|
34
|
+
exports.getHighlightedPickedIndices = getHighlightedPickedIndices;
|
|
@@ -47,6 +47,17 @@ Object.keys(_defaultFilterCallback).forEach(function (key) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
51
|
+
Object.keys(_getHighlightedPickedIndices).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _getHighlightedPickedIndices[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _getHighlightedPickedIndices[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
50
61
|
var _getOptionClickHandlers = require("./get-option-click-handlers.js");
|
|
51
62
|
Object.keys(_getOptionClickHandlers).forEach(function (key) {
|
|
52
63
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -91,6 +102,28 @@ Object.keys(_moveHighlightedPickedOptionDown).forEach(function (key) {
|
|
|
91
102
|
}
|
|
92
103
|
});
|
|
93
104
|
});
|
|
105
|
+
var _moveHighlightedPickedOptionToBottom = require("./move-highlighted-picked-option-to-bottom.js");
|
|
106
|
+
Object.keys(_moveHighlightedPickedOptionToBottom).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _moveHighlightedPickedOptionToBottom[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _moveHighlightedPickedOptionToBottom[key];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
var _moveHighlightedPickedOptionToTop = require("./move-highlighted-picked-option-to-top.js");
|
|
117
|
+
Object.keys(_moveHighlightedPickedOptionToTop).forEach(function (key) {
|
|
118
|
+
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (key in exports && exports[key] === _moveHighlightedPickedOptionToTop[key]) return;
|
|
120
|
+
Object.defineProperty(exports, key, {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _moveHighlightedPickedOptionToTop[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
94
127
|
var _moveHighlightedPickedOptionUp = require("./move-highlighted-picked-option-up.js");
|
|
95
128
|
Object.keys(_moveHighlightedPickedOptionUp).forEach(function (key) {
|
|
96
129
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -4,22 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isReorderDownDisabled = void 0;
|
|
7
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
7
8
|
/**
|
|
8
9
|
* @param {Object} args
|
|
9
|
-
* @param {string} args.highlightedPickedOptions
|
|
10
|
+
* @param {string[]} args.highlightedPickedOptions
|
|
10
11
|
* @param {string[]} args.selected
|
|
12
|
+
* @param {boolean} [args.filterActivePicked] reorder is disabled while a filter is applied to the picked side
|
|
11
13
|
* @returns {bool}
|
|
12
14
|
*/
|
|
13
15
|
const isReorderDownDisabled = _ref => {
|
|
14
16
|
let {
|
|
15
17
|
highlightedPickedOptions,
|
|
16
|
-
selected
|
|
18
|
+
selected,
|
|
19
|
+
filterActivePicked = false
|
|
17
20
|
} = _ref;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
selected
|
|
23
|
-
|
|
21
|
+
if (filterActivePicked) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const indices = (0, _getHighlightedPickedIndices.getHighlightedPickedIndices)({
|
|
25
|
+
selected,
|
|
26
|
+
highlightedPickedOptions
|
|
27
|
+
});
|
|
28
|
+
if (indices.length === 0) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const lastIndex = selected.length - 1;
|
|
32
|
+
|
|
33
|
+
// Flush to the bottom: indices are [len-n, ..., len-1]
|
|
34
|
+
return indices.every((index, i) => index === lastIndex - (indices.length - 1 - i));
|
|
24
35
|
};
|
|
25
36
|
exports.isReorderDownDisabled = isReorderDownDisabled;
|
|
@@ -4,22 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isReorderUpDisabled = void 0;
|
|
7
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
7
8
|
/**
|
|
8
9
|
* @param {Object} args
|
|
9
|
-
* @param {string} args.highlightedPickedOptions
|
|
10
|
+
* @param {string[]} args.highlightedPickedOptions
|
|
10
11
|
* @param {string[]} args.selected
|
|
12
|
+
* @param {boolean} [args.filterActivePicked] reorder is disabled while a filter is applied to the picked side
|
|
11
13
|
* @returns {bool}
|
|
12
14
|
*/
|
|
13
15
|
const isReorderUpDisabled = _ref => {
|
|
14
16
|
let {
|
|
15
17
|
highlightedPickedOptions,
|
|
16
|
-
selected
|
|
18
|
+
selected,
|
|
19
|
+
filterActivePicked = false
|
|
17
20
|
} = _ref;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
selected
|
|
23
|
-
|
|
21
|
+
if (filterActivePicked) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const indices = (0, _getHighlightedPickedIndices.getHighlightedPickedIndices)({
|
|
25
|
+
selected,
|
|
26
|
+
highlightedPickedOptions
|
|
27
|
+
});
|
|
28
|
+
if (indices.length === 0) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Flush to the top: indices are [0, 1, ..., n-1]
|
|
33
|
+
return indices.every((index, i) => index === i);
|
|
24
34
|
};
|
|
25
35
|
exports.isReorderUpDisabled = isReorderUpDisabled;
|
|
@@ -4,7 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.moveHighlightedPickedOptionDown = void 0;
|
|
7
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
7
8
|
/**
|
|
9
|
+
* Moves the highlighted picked options down by one slot as a group.
|
|
10
|
+
* If the selection is non-contiguous, the group collapses into a contiguous
|
|
11
|
+
* block (preserving relative order) with its bottom edge landing at
|
|
12
|
+
* `min(selected.length - 1, bottommostHighlightedIndex + 1)`.
|
|
13
|
+
*
|
|
8
14
|
* @param {Object} args
|
|
9
15
|
* @param {string[]} args.selected
|
|
10
16
|
* @param {string[]} args.highlightedPickedOptions
|
|
@@ -17,15 +23,26 @@ const moveHighlightedPickedOptionDown = _ref => {
|
|
|
17
23
|
highlightedPickedOptions,
|
|
18
24
|
onChange
|
|
19
25
|
} = _ref;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const indices = (0, _getHighlightedPickedIndices.getHighlightedPickedIndices)({
|
|
27
|
+
selected,
|
|
28
|
+
highlightedPickedOptions
|
|
29
|
+
});
|
|
30
|
+
if (indices.length === 0) {
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
33
|
+
const lastIndex = selected.length - 1;
|
|
26
34
|
|
|
27
|
-
//
|
|
28
|
-
|
|
35
|
+
// Already flush to the bottom — nothing to do
|
|
36
|
+
if (indices.every((index, i) => index === lastIndex - (indices.length - 1 - i))) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const indexSet = new Set(indices);
|
|
40
|
+
const highlightedBlock = indices.map(index => selected[index]);
|
|
41
|
+
const remaining = selected.filter((_, index) => !indexSet.has(index));
|
|
42
|
+
const bottommost = indices.at(-1);
|
|
43
|
+
const targetBottom = Math.min(lastIndex, bottommost + 1);
|
|
44
|
+
const insertPos = targetBottom - (indices.length - 1);
|
|
45
|
+
const reordered = [...remaining.slice(0, insertPos), ...highlightedBlock, ...remaining.slice(insertPos)];
|
|
29
46
|
onChange({
|
|
30
47
|
selected: reordered
|
|
31
48
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moveHighlightedPickedOptionToBottom = void 0;
|
|
7
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
8
|
+
/**
|
|
9
|
+
* Moves the highlighted picked options to the very bottom of the list as a
|
|
10
|
+
* single contiguous block, preserving their relative order. Non-contiguous
|
|
11
|
+
* selections are collapsed.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} args
|
|
14
|
+
* @param {string[]} args.selected
|
|
15
|
+
* @param {string[]} args.highlightedPickedOptions
|
|
16
|
+
* @param {Function} args.onChange
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*/
|
|
19
|
+
const moveHighlightedPickedOptionToBottom = _ref => {
|
|
20
|
+
let {
|
|
21
|
+
selected,
|
|
22
|
+
highlightedPickedOptions,
|
|
23
|
+
onChange
|
|
24
|
+
} = _ref;
|
|
25
|
+
const indices = (0, _getHighlightedPickedIndices.getHighlightedPickedIndices)({
|
|
26
|
+
selected,
|
|
27
|
+
highlightedPickedOptions
|
|
28
|
+
});
|
|
29
|
+
if (indices.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const lastIndex = selected.length - 1;
|
|
33
|
+
|
|
34
|
+
// Already a contiguous block flush to the bottom — nothing to do
|
|
35
|
+
if (indices.every((index, i) => index === lastIndex - (indices.length - 1 - i))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const indexSet = new Set(indices);
|
|
39
|
+
const highlightedBlock = indices.map(index => selected[index]);
|
|
40
|
+
const remaining = selected.filter((_, index) => !indexSet.has(index));
|
|
41
|
+
onChange({
|
|
42
|
+
selected: [...remaining, ...highlightedBlock]
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
exports.moveHighlightedPickedOptionToBottom = moveHighlightedPickedOptionToBottom;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moveHighlightedPickedOptionToTop = void 0;
|
|
7
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
8
|
+
/**
|
|
9
|
+
* Moves the highlighted picked options to the very top of the list as a
|
|
10
|
+
* single contiguous block, preserving their relative order. Non-contiguous
|
|
11
|
+
* selections are collapsed.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} args
|
|
14
|
+
* @param {string[]} args.selected
|
|
15
|
+
* @param {string[]} args.highlightedPickedOptions
|
|
16
|
+
* @param {Function} args.onChange
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*/
|
|
19
|
+
const moveHighlightedPickedOptionToTop = _ref => {
|
|
20
|
+
let {
|
|
21
|
+
selected,
|
|
22
|
+
highlightedPickedOptions,
|
|
23
|
+
onChange
|
|
24
|
+
} = _ref;
|
|
25
|
+
const indices = (0, _getHighlightedPickedIndices.getHighlightedPickedIndices)({
|
|
26
|
+
selected,
|
|
27
|
+
highlightedPickedOptions
|
|
28
|
+
});
|
|
29
|
+
if (indices.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Already a contiguous block flush to the top — nothing to do
|
|
34
|
+
if (indices.every((index, i) => index === i)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const indexSet = new Set(indices);
|
|
38
|
+
const highlightedBlock = indices.map(index => selected[index]);
|
|
39
|
+
const remaining = selected.filter((_, index) => !indexSet.has(index));
|
|
40
|
+
onChange({
|
|
41
|
+
selected: [...highlightedBlock, ...remaining]
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.moveHighlightedPickedOptionToTop = moveHighlightedPickedOptionToTop;
|
|
@@ -4,7 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.moveHighlightedPickedOptionUp = void 0;
|
|
7
|
+
var _getHighlightedPickedIndices = require("./get-highlighted-picked-indices.js");
|
|
7
8
|
/**
|
|
9
|
+
* Moves the highlighted picked options up by one slot as a group.
|
|
10
|
+
* If the selection is non-contiguous, the group collapses into a contiguous
|
|
11
|
+
* block (preserving relative order) with its top edge landing at
|
|
12
|
+
* `max(0, topmostHighlightedIndex - 1)`.
|
|
13
|
+
*
|
|
8
14
|
* @param {Object} args
|
|
9
15
|
* @param {string[]} args.selected
|
|
10
16
|
* @param {string[]} args.highlightedPickedOptions
|
|
@@ -17,15 +23,24 @@ const moveHighlightedPickedOptionUp = _ref => {
|
|
|
17
23
|
highlightedPickedOptions,
|
|
18
24
|
onChange
|
|
19
25
|
} = _ref;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const indices = (0, _getHighlightedPickedIndices.getHighlightedPickedIndices)({
|
|
27
|
+
selected,
|
|
28
|
+
highlightedPickedOptions
|
|
29
|
+
});
|
|
30
|
+
if (indices.length === 0) {
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
//
|
|
28
|
-
|
|
34
|
+
// Already flush to the top — nothing to do
|
|
35
|
+
if (indices.every((index, i) => index === i)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const indexSet = new Set(indices);
|
|
39
|
+
const highlightedBlock = indices.map(index => selected[index]);
|
|
40
|
+
const remaining = selected.filter((_, index) => !indexSet.has(index));
|
|
41
|
+
const topmost = indices[0];
|
|
42
|
+
const insertPos = Math.max(0, topmost - 1);
|
|
43
|
+
const reordered = [...remaining.slice(0, insertPos), ...highlightedBlock, ...remaining.slice(insertPos)];
|
|
29
44
|
onChange({
|
|
30
45
|
selected: reordered
|
|
31
46
|
});
|
package/build/cjs/transfer.js
CHANGED
|
@@ -130,6 +130,7 @@ const Transfer = _ref => {
|
|
|
130
130
|
externalSearchTerm: searchTermPicked,
|
|
131
131
|
filterCallback: filterCallbackPicked
|
|
132
132
|
});
|
|
133
|
+
const filterActivePicked = Boolean(actualFilterPicked);
|
|
133
134
|
|
|
134
135
|
/*
|
|
135
136
|
* Actual picked options:
|
|
@@ -174,6 +175,26 @@ const Transfer = _ref => {
|
|
|
174
175
|
maxSelections
|
|
175
176
|
});
|
|
176
177
|
|
|
178
|
+
/*
|
|
179
|
+
* Reorder scroll-into-view:
|
|
180
|
+
* After a reorder move, scroll the moved block so the leading edge
|
|
181
|
+
* (top on Up, bottom on Down) is visible inside the picked-side
|
|
182
|
+
* scroll container. `block: 'nearest'` means no scroll when the
|
|
183
|
+
* element is already fully in view.
|
|
184
|
+
*/
|
|
185
|
+
const reorderScrollTargetRef = (0, _react.useRef)(null);
|
|
186
|
+
(0, _react.useEffect)(() => {
|
|
187
|
+
const target = reorderScrollTargetRef.current;
|
|
188
|
+
if (target == null) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
reorderScrollTargetRef.current = null;
|
|
192
|
+
const element = document.querySelector(`[data-test="${dataTest}-pickedoptions"] [data-value="${CSS.escape(target)}"]`);
|
|
193
|
+
element === null || element === void 0 ? void 0 : element.scrollIntoView({
|
|
194
|
+
block: 'nearest'
|
|
195
|
+
});
|
|
196
|
+
}, [selected, dataTest]);
|
|
197
|
+
|
|
177
198
|
/**
|
|
178
199
|
* Disabled button states
|
|
179
200
|
*/
|
|
@@ -310,25 +331,56 @@ const Transfer = _ref => {
|
|
|
310
331
|
dataTest: `${dataTest}-rightfooter`
|
|
311
332
|
}, enableOrderChange && /*#__PURE__*/_react.default.createElement(_reorderingActions.ReorderingActions, {
|
|
312
333
|
dataTest: `${dataTest}-reorderingactions`,
|
|
334
|
+
filterActive: filterActivePicked,
|
|
313
335
|
disabledDown: (0, _index.isReorderDownDisabled)({
|
|
314
336
|
highlightedPickedOptions,
|
|
315
|
-
selected
|
|
337
|
+
selected,
|
|
338
|
+
filterActivePicked
|
|
316
339
|
}),
|
|
317
340
|
disabledUp: (0, _index.isReorderUpDisabled)({
|
|
318
341
|
highlightedPickedOptions,
|
|
319
|
-
selected
|
|
320
|
-
}),
|
|
321
|
-
onChangeUp: () => (0, _index.moveHighlightedPickedOptionUp)({
|
|
322
342
|
selected,
|
|
323
|
-
|
|
324
|
-
onChange
|
|
343
|
+
filterActivePicked
|
|
325
344
|
}),
|
|
345
|
+
onChangeUp: () => {
|
|
346
|
+
var _selected$find;
|
|
347
|
+
const highlightedSet = new Set(highlightedPickedOptions);
|
|
348
|
+
reorderScrollTargetRef.current = (_selected$find = selected.find(value => highlightedSet.has(value))) !== null && _selected$find !== void 0 ? _selected$find : null;
|
|
349
|
+
(0, _index.moveHighlightedPickedOptionUp)({
|
|
350
|
+
selected,
|
|
351
|
+
highlightedPickedOptions,
|
|
352
|
+
onChange
|
|
353
|
+
});
|
|
354
|
+
},
|
|
326
355
|
onChangeDown: () => {
|
|
356
|
+
var _selected$findLast;
|
|
357
|
+
const highlightedSet = new Set(highlightedPickedOptions);
|
|
358
|
+
reorderScrollTargetRef.current = (_selected$findLast = selected.findLast(value => highlightedSet.has(value))) !== null && _selected$findLast !== void 0 ? _selected$findLast : null;
|
|
327
359
|
(0, _index.moveHighlightedPickedOptionDown)({
|
|
328
360
|
selected,
|
|
329
361
|
highlightedPickedOptions,
|
|
330
362
|
onChange
|
|
331
363
|
});
|
|
364
|
+
},
|
|
365
|
+
onChangeToTop: () => {
|
|
366
|
+
var _selected$find2;
|
|
367
|
+
const highlightedSet = new Set(highlightedPickedOptions);
|
|
368
|
+
reorderScrollTargetRef.current = (_selected$find2 = selected.find(value => highlightedSet.has(value))) !== null && _selected$find2 !== void 0 ? _selected$find2 : null;
|
|
369
|
+
(0, _index.moveHighlightedPickedOptionToTop)({
|
|
370
|
+
selected,
|
|
371
|
+
highlightedPickedOptions,
|
|
372
|
+
onChange
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
onChangeToBottom: () => {
|
|
376
|
+
var _selected$findLast2;
|
|
377
|
+
const highlightedSet = new Set(highlightedPickedOptions);
|
|
378
|
+
reorderScrollTargetRef.current = (_selected$findLast2 = selected.findLast(value => highlightedSet.has(value))) !== null && _selected$findLast2 !== void 0 ? _selected$findLast2 : null;
|
|
379
|
+
(0, _index.moveHighlightedPickedOptionToBottom)({
|
|
380
|
+
selected,
|
|
381
|
+
highlightedPickedOptions,
|
|
382
|
+
onChange
|
|
383
|
+
});
|
|
332
384
|
}
|
|
333
385
|
}), rightFooter)));
|
|
334
386
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.SourceEmptyPlaceholder = exports.SingleSelection = exports.Reordering = exports.RTL = exports.PickedEmptyComponent = exports.OptionsFooter = exports.Multiple = exports.LoadingSource = exports.LoadingPicked = exports.InfiniteLoading = exports.IndividualCustomOption = exports.IncreasedOptionsHeight = exports.Header = exports.FilteredPlaceholder = exports.FilteredPicked = exports.Filtered = exports.DifferentWidths = exports.CustomListOptions = exports.CustomFilteringWithoutFilterInput = exports.CustomFilteringWithFilterInput = exports.CustomButtonText = void 0;
|
|
6
|
+
exports.default = exports.SourceEmptyPlaceholder = exports.SingleSelection = exports.ReorderingWithRightFooterContent = exports.ReorderingWithPickedFilter = exports.ReorderingWithCustomOptions = exports.Reordering = exports.RTL = exports.PickedEmptyComponent = exports.OptionsFooter = exports.Multiple = exports.LoadingSource = exports.LoadingPicked = exports.InfiniteLoading = exports.IndividualCustomOption = exports.IncreasedOptionsHeight = exports.Header = exports.FilteredPlaceholder = exports.FilteredPicked = exports.Filtered = exports.DifferentWidths = exports.CustomListOptions = exports.CustomFilteringWithoutFilterInput = exports.CustomFilteringWithFilterInput = exports.CustomButtonText = void 0;
|
|
7
7
|
var _select = require("@dhis2-ui/select");
|
|
8
8
|
var _tab = require("@dhis2-ui/tab");
|
|
9
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
@@ -312,14 +312,84 @@ PickedEmptyComponent.args = {
|
|
|
312
312
|
const Reordering = exports.Reordering = StatefulTemplate.bind({});
|
|
313
313
|
Reordering.args = {
|
|
314
314
|
enableOrderChange: true,
|
|
315
|
-
options: options.slice(0,
|
|
316
|
-
initiallySelected: options.slice(0,
|
|
315
|
+
options: options.slice(0, 20),
|
|
316
|
+
initiallySelected: options.slice(0, 8).map(_ref6 => {
|
|
317
317
|
let {
|
|
318
318
|
value
|
|
319
319
|
} = _ref6;
|
|
320
320
|
return value;
|
|
321
321
|
})
|
|
322
322
|
};
|
|
323
|
+
const ReorderingWithPickedFilter = exports.ReorderingWithPickedFilter = StatefulTemplate.bind({});
|
|
324
|
+
ReorderingWithPickedFilter.storyName = 'Reordering with picked filter';
|
|
325
|
+
ReorderingWithPickedFilter.args = {
|
|
326
|
+
enableOrderChange: true,
|
|
327
|
+
filterablePicked: true,
|
|
328
|
+
filterPlaceholderPicked: 'Search picked options',
|
|
329
|
+
options: options.slice(0, 20),
|
|
330
|
+
initiallySelected: options.slice(0, 8).map(_ref7 => {
|
|
331
|
+
let {
|
|
332
|
+
value
|
|
333
|
+
} = _ref7;
|
|
334
|
+
return value;
|
|
335
|
+
})
|
|
336
|
+
};
|
|
337
|
+
const ReorderingWithRightFooterTemplate = _ref8 => {
|
|
338
|
+
let {
|
|
339
|
+
initiallySelected = [],
|
|
340
|
+
...args
|
|
341
|
+
} = _ref8;
|
|
342
|
+
const [selected, setSelected] = (0, _react.useState)(initiallySelected);
|
|
343
|
+
const onChange = payload => setSelected(payload.selected);
|
|
344
|
+
return /*#__PURE__*/_react.default.createElement(_transfer.Transfer, _extends({}, args, {
|
|
345
|
+
selected: selected,
|
|
346
|
+
onChange: onChange,
|
|
347
|
+
rightFooter: /*#__PURE__*/_react.default.createElement("span", {
|
|
348
|
+
style: {
|
|
349
|
+
padding: '0 8px'
|
|
350
|
+
}
|
|
351
|
+
}, "Right footer content")
|
|
352
|
+
}));
|
|
353
|
+
};
|
|
354
|
+
ReorderingWithRightFooterTemplate.propTypes = {
|
|
355
|
+
initiallySelected: _propTypes.default.array
|
|
356
|
+
};
|
|
357
|
+
const ReorderingWithRightFooterContent = exports.ReorderingWithRightFooterContent = ReorderingWithRightFooterTemplate.bind({});
|
|
358
|
+
ReorderingWithRightFooterContent.storyName = 'Reordering with right footer content';
|
|
359
|
+
ReorderingWithRightFooterContent.args = {
|
|
360
|
+
enableOrderChange: true,
|
|
361
|
+
options: options.slice(0, 20),
|
|
362
|
+
initiallySelected: options.slice(0, 8).map(_ref9 => {
|
|
363
|
+
let {
|
|
364
|
+
value
|
|
365
|
+
} = _ref9;
|
|
366
|
+
return value;
|
|
367
|
+
})
|
|
368
|
+
};
|
|
369
|
+
const ReorderingWithCustomOptions = exports.ReorderingWithCustomOptions = StatefulTemplateCustomRenderOption.bind({});
|
|
370
|
+
ReorderingWithCustomOptions.storyName = 'Reordering with custom options';
|
|
371
|
+
ReorderingWithCustomOptions.args = {
|
|
372
|
+
enableOrderChange: true,
|
|
373
|
+
options: options.slice(0, 20),
|
|
374
|
+
initiallySelected: options.slice(0, 8).map(_ref10 => {
|
|
375
|
+
let {
|
|
376
|
+
value
|
|
377
|
+
} = _ref10;
|
|
378
|
+
return value;
|
|
379
|
+
}),
|
|
380
|
+
renderOption: option => {
|
|
381
|
+
if (option.value === options[0].value) {
|
|
382
|
+
return renderOption(option);
|
|
383
|
+
}
|
|
384
|
+
if (option.value === options[2].value) {
|
|
385
|
+
return renderOption(option);
|
|
386
|
+
}
|
|
387
|
+
if (option.value === options[5].value) {
|
|
388
|
+
return renderOption(option);
|
|
389
|
+
}
|
|
390
|
+
return /*#__PURE__*/_react.default.createElement(_transferOption.TransferOption, option);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
323
393
|
const IncreasedOptionsHeight = exports.IncreasedOptionsHeight = StatefulTemplate.bind({});
|
|
324
394
|
IncreasedOptionsHeight.args = {
|
|
325
395
|
maxSelections: Infinity,
|
|
@@ -343,13 +413,13 @@ const createCustomFilteringInHeader = hideFilterInput => {
|
|
|
343
413
|
year: index < 5 ? '2020' : '2019'
|
|
344
414
|
}));
|
|
345
415
|
const allOptions = [...relativePeriods, ...fixedPeriods];
|
|
346
|
-
const Header =
|
|
416
|
+
const Header = _ref11 => {
|
|
347
417
|
let {
|
|
348
418
|
onClick,
|
|
349
419
|
relativePeriod,
|
|
350
420
|
selectedYear,
|
|
351
421
|
onSelectedYearChange
|
|
352
|
-
} =
|
|
422
|
+
} = _ref11;
|
|
353
423
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_tab.TabBar, null, /*#__PURE__*/_react.default.createElement(_tab.Tab, {
|
|
354
424
|
selected: relativePeriod,
|
|
355
425
|
onClick: () => onClick({
|
|
@@ -389,26 +459,26 @@ const createCustomFilteringInHeader = hideFilterInput => {
|
|
|
389
459
|
if (filter === '') {
|
|
390
460
|
return optionsWithPeriod;
|
|
391
461
|
}
|
|
392
|
-
return optionsWithPeriod.filter(
|
|
462
|
+
return optionsWithPeriod.filter(_ref12 => {
|
|
393
463
|
let {
|
|
394
464
|
label
|
|
395
|
-
} =
|
|
465
|
+
} = _ref12;
|
|
396
466
|
return label.indexOf(filter) !== -1;
|
|
397
467
|
});
|
|
398
468
|
};
|
|
399
469
|
const header = /*#__PURE__*/_react.default.createElement(Header, {
|
|
400
470
|
relativePeriod: relativePeriod,
|
|
401
471
|
selectedYear: year,
|
|
402
|
-
onSelectedYearChange:
|
|
472
|
+
onSelectedYearChange: _ref13 => {
|
|
403
473
|
let {
|
|
404
474
|
selected
|
|
405
|
-
} =
|
|
475
|
+
} = _ref13;
|
|
406
476
|
return setYear(selected);
|
|
407
477
|
},
|
|
408
|
-
onClick:
|
|
478
|
+
onClick: _ref14 => {
|
|
409
479
|
let {
|
|
410
480
|
relativePeriod: newRelativePeriod
|
|
411
|
-
} =
|
|
481
|
+
} = _ref14;
|
|
412
482
|
return setRelativePeriod(newRelativePeriod);
|
|
413
483
|
}
|
|
414
484
|
});
|
|
@@ -420,10 +490,10 @@ const createCustomFilteringInHeader = hideFilterInput => {
|
|
|
420
490
|
filterCallback: filterCallback,
|
|
421
491
|
leftHeader: header,
|
|
422
492
|
rightHeader: /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("b", null, "Selected Periods")),
|
|
423
|
-
onFilterChange:
|
|
493
|
+
onFilterChange: _ref15 => {
|
|
424
494
|
let {
|
|
425
495
|
value
|
|
426
|
-
} =
|
|
496
|
+
} = _ref15;
|
|
427
497
|
return setFilter(value);
|
|
428
498
|
},
|
|
429
499
|
height: "400px",
|
|
@@ -431,11 +501,11 @@ const createCustomFilteringInHeader = hideFilterInput => {
|
|
|
431
501
|
filterPlaceholder: "Search"
|
|
432
502
|
}));
|
|
433
503
|
};
|
|
434
|
-
return
|
|
504
|
+
return _ref16 => {
|
|
435
505
|
let {
|
|
436
506
|
initiallySelected,
|
|
437
507
|
...args
|
|
438
|
-
} =
|
|
508
|
+
} = _ref16;
|
|
439
509
|
const [selected, setSelected] = (0, _react.useState)(initiallySelected);
|
|
440
510
|
const onChange = payload => setSelected(payload.selected);
|
|
441
511
|
return /*#__PURE__*/_react.default.createElement(CustomTransfer, _extends({}, args, {
|
|
@@ -469,10 +539,10 @@ const InfiniteLoading = args => {
|
|
|
469
539
|
// selected options
|
|
470
540
|
const [selected] = (0, _react.useState)(
|
|
471
541
|
// Last 4 options preselected
|
|
472
|
-
preSelectedOptions.map(
|
|
542
|
+
preSelectedOptions.map(_ref17 => {
|
|
473
543
|
let {
|
|
474
544
|
value
|
|
475
|
-
} =
|
|
545
|
+
} = _ref17;
|
|
476
546
|
return value;
|
|
477
547
|
}));
|
|
478
548
|
const selectedOptionsLookup = (0, _react.useMemo)(() => preSelectedOptions.reduce((lookup, option) => {
|
|
@@ -514,10 +584,10 @@ const LoadingPicked = exports.LoadingPicked = StatefulTemplate.bind({});
|
|
|
514
584
|
LoadingPicked.args = {
|
|
515
585
|
loadingPicked: true,
|
|
516
586
|
options: options.slice(0, 3),
|
|
517
|
-
initiallySelected: options.slice(0, 2).map(
|
|
587
|
+
initiallySelected: options.slice(0, 2).map(_ref18 => {
|
|
518
588
|
let {
|
|
519
589
|
value
|
|
520
|
-
} =
|
|
590
|
+
} = _ref18;
|
|
521
591
|
return value;
|
|
522
592
|
})
|
|
523
593
|
};
|
|
@@ -5,7 +5,7 @@ import { statefulDecorator } from './common/stateful-decorator.js';
|
|
|
5
5
|
export default {
|
|
6
6
|
title: 'Transfer Reorder Buttons'
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const renderReorderTransfer = (_, _ref) => {
|
|
9
9
|
let {
|
|
10
10
|
selected,
|
|
11
11
|
onChange
|
|
@@ -17,13 +17,25 @@ export const HasSomeSelected = (_, _ref) => {
|
|
|
17
17
|
options: options
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
|
+
export const HasSomeSelected = renderReorderTransfer.bind({});
|
|
20
21
|
HasSomeSelected.story = {
|
|
21
22
|
decorators: [statefulDecorator({
|
|
22
|
-
initialState: options.slice(0,
|
|
23
|
+
initialState: options.slice(0, 8).map(_ref2 => {
|
|
23
24
|
let {
|
|
24
25
|
value
|
|
25
26
|
} = _ref2;
|
|
26
27
|
return value;
|
|
27
28
|
})
|
|
28
29
|
})]
|
|
30
|
+
};
|
|
31
|
+
export const HasThreeSelected = renderReorderTransfer.bind({});
|
|
32
|
+
HasThreeSelected.story = {
|
|
33
|
+
decorators: [statefulDecorator({
|
|
34
|
+
initialState: options.slice(0, 3).map(_ref3 => {
|
|
35
|
+
let {
|
|
36
|
+
value
|
|
37
|
+
} = _ref3;
|
|
38
|
+
return value;
|
|
39
|
+
})
|
|
40
|
+
})]
|
|
29
41
|
};
|