@atlaskit/smart-card 25.3.1 → 25.3.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/CHANGELOG.md +7 -0
- package/dist/cjs/extractors/action/extract-lozenge-action-items.js +25 -0
- package/dist/cjs/state/hooks/use-invoke/index.js +13 -8
- package/dist/cjs/state/hooks/use-invoke/types.js +1 -6
- package/dist/cjs/utils/actions/create-status-update-request.js +21 -0
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/error-boundary/index.js +2 -1
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/index.js +100 -50
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js +13 -2
- package/dist/es2019/extractors/action/extract-lozenge-action-items.js +17 -0
- package/dist/es2019/state/hooks/use-invoke/index.js +15 -6
- package/dist/es2019/state/hooks/use-invoke/types.js +0 -4
- package/dist/es2019/utils/actions/create-status-update-request.js +10 -0
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/error-boundary/index.js +7 -4
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/index.js +47 -23
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js +13 -2
- package/dist/esm/extractors/action/extract-lozenge-action-items.js +18 -0
- package/dist/esm/state/hooks/use-invoke/index.js +13 -8
- package/dist/esm/state/hooks/use-invoke/types.js +0 -4
- package/dist/esm/utils/actions/create-status-update-request.js +13 -0
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/error-boundary/index.js +2 -1
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/index.js +100 -50
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js +13 -2
- package/dist/types/extractors/action/extract-lozenge-action-items.d.ts +4 -0
- package/dist/types/state/hooks/use-invoke/index.d.ts +2 -2
- package/dist/types/state/hooks/use-invoke/types.d.ts +6 -5
- package/dist/types/utils/actions/create-status-update-request.d.ts +4 -0
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/types.d.ts +3 -4
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/types.d.ts +3 -2
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/smart-card
|
|
2
2
|
|
|
3
|
+
## 25.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`fab186f135b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/fab186f135b) - Add load and update functionality to lozenge action
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
3
10
|
## 25.3.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var extractLozengeActionItems = function extractLozengeActionItems(response) {
|
|
8
|
+
var _response$transitions, _response$transitions2;
|
|
9
|
+
var items = (_response$transitions = response === null || response === void 0 ? void 0 : (_response$transitions2 = response.transitions) === null || _response$transitions2 === void 0 ? void 0 : _response$transitions2.map(function (_ref) {
|
|
10
|
+
var _ref2;
|
|
11
|
+
var appearance = _ref.appearance,
|
|
12
|
+
id = _ref.id,
|
|
13
|
+
name = _ref.name;
|
|
14
|
+
return {
|
|
15
|
+
appearance: (_ref2 = appearance) !== null && _ref2 !== void 0 ? _ref2 : 'default',
|
|
16
|
+
id: id,
|
|
17
|
+
text: name
|
|
18
|
+
};
|
|
19
|
+
})) !== null && _response$transitions !== void 0 ? _response$transitions : [];
|
|
20
|
+
return items.sort(function (a, b) {
|
|
21
|
+
return a.appearance.localeCompare(b.appearance) || a.text.localeCompare(b.text);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
var _default = extractLozengeActionItems;
|
|
25
|
+
exports.default = _default;
|
|
@@ -8,30 +8,35 @@ exports.default = void 0;
|
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _react = require("react");
|
|
11
|
+
var _linkClientExtension = require("@atlaskit/link-client-extension");
|
|
12
|
+
var _linkProvider = require("@atlaskit/link-provider");
|
|
11
13
|
var useInvoke = function useInvoke() {
|
|
14
|
+
var _useSmartLinkContext = (0, _linkProvider.useSmartLinkContext)(),
|
|
15
|
+
connections = _useSmartLinkContext.connections;
|
|
16
|
+
var clientExt = (0, _linkClientExtension.useSmartLinkClientExtension)(connections.client);
|
|
12
17
|
return (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
13
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(
|
|
18
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(req, cb) {
|
|
19
|
+
var response;
|
|
14
20
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
15
21
|
while (1) {
|
|
16
22
|
switch (_context.prev = _context.next) {
|
|
17
23
|
case 0:
|
|
18
24
|
_context.next = 2;
|
|
19
|
-
return
|
|
20
|
-
resolve();
|
|
21
|
-
});
|
|
25
|
+
return clientExt.invoke(req);
|
|
22
26
|
case 2:
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
response = _context.sent;
|
|
28
|
+
return _context.abrupt("return", cb ? cb(response) : response);
|
|
29
|
+
case 4:
|
|
25
30
|
case "end":
|
|
26
31
|
return _context.stop();
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
}, _callee);
|
|
30
35
|
}));
|
|
31
|
-
return function (_x) {
|
|
36
|
+
return function (_x, _x2) {
|
|
32
37
|
return _ref.apply(this, arguments);
|
|
33
38
|
};
|
|
34
|
-
}(), []);
|
|
39
|
+
}(), [clientExt]);
|
|
35
40
|
};
|
|
36
41
|
var _default = useInvoke;
|
|
37
42
|
exports.default = _default;
|
|
@@ -3,12 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var InvokeActionName;
|
|
8
|
-
exports.InvokeActionName = InvokeActionName;
|
|
9
|
-
(function (InvokeActionName) {
|
|
10
|
-
InvokeActionName["UpdateAction"] = "UpdateAction";
|
|
11
|
-
})(InvokeActionName || (exports.InvokeActionName = InvokeActionName = {}));
|
|
6
|
+
exports.InvokeActionError = void 0;
|
|
12
7
|
var InvokeActionError;
|
|
13
8
|
exports.InvokeActionError = InvokeActionError;
|
|
14
9
|
(function (InvokeActionError) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
var createStatusUpdateRequest = function createStatusUpdateRequest(request, id) {
|
|
12
|
+
return _objectSpread(_objectSpread({}, request), {}, {
|
|
13
|
+
action: _objectSpread(_objectSpread({}, request.action), {}, {
|
|
14
|
+
payload: {
|
|
15
|
+
newStatusId: id
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var _default = createStatusUpdateRequest;
|
|
21
|
+
exports.default = _default;
|
package/dist/cjs/version.json
CHANGED
|
@@ -14,9 +14,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
14
14
|
var withErrorBoundary = function withErrorBoundary(Component) {
|
|
15
15
|
return function (props) {
|
|
16
16
|
var fallback = (0, _react.useMemo)(function () {
|
|
17
|
+
var _props$testId;
|
|
17
18
|
return /*#__PURE__*/_react.default.createElement(_lozenge.default, {
|
|
18
19
|
appearance: props === null || props === void 0 ? void 0 : props.appearance,
|
|
19
|
-
testId: "".concat(props === null || props === void 0 ? void 0 : props.testId, "-fallback")
|
|
20
|
+
testId: "".concat((_props$testId = props === null || props === void 0 ? void 0 : props.testId) !== null && _props$testId !== void 0 ? _props$testId : 'smart-element-lozenge-action', "-fallback")
|
|
20
21
|
}, props === null || props === void 0 ? void 0 : props.text);
|
|
21
22
|
}, [props === null || props === void 0 ? void 0 : props.appearance, props === null || props === void 0 ? void 0 : props.testId, props === null || props === void 0 ? void 0 : props.text]);
|
|
22
23
|
return /*#__PURE__*/_react.default.createElement(_reactErrorBoundary.ErrorBoundary, {
|
|
@@ -17,13 +17,22 @@ var _lozengeActionItem = _interopRequireDefault(require("./lozenge-action-item")
|
|
|
17
17
|
var _lozengeActionTrigger = _interopRequireDefault(require("./lozenge-action-trigger"));
|
|
18
18
|
var _lozengeActionError = _interopRequireDefault(require("./lozenge-action-error"));
|
|
19
19
|
var _errorBoundary = _interopRequireDefault(require("./error-boundary"));
|
|
20
|
+
var _styled = require("./styled");
|
|
20
21
|
var _useInvoke = _interopRequireDefault(require("../../../../../state/hooks/use-invoke"));
|
|
21
22
|
var _types = require("../../../../../state/hooks/use-invoke/types");
|
|
22
|
-
var
|
|
23
|
+
var _extractLozengeActionItems = _interopRequireDefault(require("../../../../../extractors/action/extract-lozenge-action-items"));
|
|
24
|
+
var _createStatusUpdateRequest = _interopRequireDefault(require("../../../../../utils/actions/create-status-update-request"));
|
|
23
25
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
26
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
27
|
/** @jsx jsx */
|
|
26
28
|
|
|
29
|
+
var validateItems = function validateItems() {
|
|
30
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
31
|
+
var text = arguments.length > 1 ? arguments[1] : undefined;
|
|
32
|
+
return items.filter(function (item) {
|
|
33
|
+
return item.text !== text;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
27
36
|
var LozengeAction = function LozengeAction(_ref) {
|
|
28
37
|
var action = _ref.action,
|
|
29
38
|
appearance = _ref.appearance,
|
|
@@ -38,66 +47,69 @@ var LozengeAction = function LozengeAction(_ref) {
|
|
|
38
47
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
39
48
|
isLoading = _useState4[0],
|
|
40
49
|
setIsLoading = _useState4[1];
|
|
41
|
-
var _useState5 = (0, _react2.useState)(),
|
|
50
|
+
var _useState5 = (0, _react2.useState)(false),
|
|
42
51
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
isOpen = _useState6[0],
|
|
53
|
+
setIsOpen = _useState6[1];
|
|
45
54
|
var _useState7 = (0, _react2.useState)(),
|
|
46
55
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
items = _useState8[0],
|
|
57
|
+
setItems = _useState8[1];
|
|
58
|
+
var _useState9 = (0, _react2.useState)(),
|
|
59
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
60
|
+
errorCode = _useState10[0],
|
|
61
|
+
setErrorCode = _useState10[1];
|
|
49
62
|
var invoke = (0, _useInvoke.default)();
|
|
50
|
-
var
|
|
63
|
+
var handleOpenChange = (0, _react2.useCallback)( /*#__PURE__*/function () {
|
|
51
64
|
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(args) {
|
|
52
|
-
var
|
|
65
|
+
var responseItems, validItems;
|
|
53
66
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
54
67
|
while (1) {
|
|
55
68
|
switch (_context.prev = _context.next) {
|
|
56
69
|
case 0:
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
setIsOpen(args.isOpen);
|
|
71
|
+
if (!(args.isOpen && !isLoaded && action !== null && action !== void 0 && action.read)) {
|
|
72
|
+
_context.next = 19;
|
|
59
73
|
break;
|
|
60
74
|
}
|
|
61
|
-
_context.prev =
|
|
75
|
+
_context.prev = 2;
|
|
62
76
|
setIsLoading(true);
|
|
63
|
-
_context.next =
|
|
64
|
-
return invoke(action);
|
|
65
|
-
case
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
_context.t0 = [];
|
|
72
|
-
case 8:
|
|
73
|
-
lozengeItems = _context.t0;
|
|
74
|
-
setItems(lozengeItems);
|
|
77
|
+
_context.next = 6;
|
|
78
|
+
return invoke(action.read, _extractLozengeActionItems.default);
|
|
79
|
+
case 6:
|
|
80
|
+
responseItems = _context.sent;
|
|
81
|
+
validItems = validateItems(responseItems, text);
|
|
82
|
+
setItems(validItems);
|
|
75
83
|
setIsLoaded(true);
|
|
76
|
-
if (
|
|
84
|
+
if ((validItems === null || validItems === void 0 ? void 0 : validItems.length) === 0) {
|
|
77
85
|
setErrorCode(_types.InvokeActionError.NoData);
|
|
78
86
|
}
|
|
79
|
-
_context.next =
|
|
87
|
+
_context.next = 16;
|
|
80
88
|
break;
|
|
81
|
-
case
|
|
82
|
-
_context.prev =
|
|
83
|
-
_context.
|
|
84
|
-
// TODO: EDM-
|
|
89
|
+
case 13:
|
|
90
|
+
_context.prev = 13;
|
|
91
|
+
_context.t0 = _context["catch"](2);
|
|
92
|
+
// TODO: EDM-6261: Error state
|
|
85
93
|
setErrorCode(_types.InvokeActionError.Unknown);
|
|
86
|
-
case
|
|
87
|
-
_context.prev =
|
|
94
|
+
case 16:
|
|
95
|
+
_context.prev = 16;
|
|
88
96
|
setIsLoading(false);
|
|
89
|
-
return _context.finish(
|
|
97
|
+
return _context.finish(16);
|
|
98
|
+
case 19:
|
|
99
|
+
if (!args.isOpen) {
|
|
100
|
+
setErrorCode(undefined);
|
|
101
|
+
}
|
|
90
102
|
case 20:
|
|
91
103
|
case "end":
|
|
92
104
|
return _context.stop();
|
|
93
105
|
}
|
|
94
106
|
}
|
|
95
|
-
}, _callee, null, [[
|
|
107
|
+
}, _callee, null, [[2, 13, 16, 19]]);
|
|
96
108
|
}));
|
|
97
109
|
return function (_x) {
|
|
98
110
|
return _ref2.apply(this, arguments);
|
|
99
111
|
};
|
|
100
|
-
}(), [action, invoke, isLoaded]);
|
|
112
|
+
}(), [action === null || action === void 0 ? void 0 : action.read, invoke, isLoaded, text]);
|
|
101
113
|
var trigger = (0, _react2.useCallback)(function (props) {
|
|
102
114
|
return (0, _react.jsx)(_lozengeActionTrigger.default, (0, _extends2.default)({}, props, {
|
|
103
115
|
appearance: appearance,
|
|
@@ -105,31 +117,69 @@ var LozengeAction = function LozengeAction(_ref) {
|
|
|
105
117
|
text: text
|
|
106
118
|
}));
|
|
107
119
|
}, [appearance, testId, text]);
|
|
120
|
+
var handleItemClick = (0, _react2.useCallback)( /*#__PURE__*/function () {
|
|
121
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(id) {
|
|
122
|
+
var request;
|
|
123
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
124
|
+
while (1) {
|
|
125
|
+
switch (_context2.prev = _context2.next) {
|
|
126
|
+
case 0:
|
|
127
|
+
_context2.prev = 0;
|
|
128
|
+
if (!(action !== null && action !== void 0 && action.update && id)) {
|
|
129
|
+
_context2.next = 8;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
setIsLoading(true);
|
|
133
|
+
request = (0, _createStatusUpdateRequest.default)(action.update, id);
|
|
134
|
+
_context2.next = 6;
|
|
135
|
+
return invoke(request);
|
|
136
|
+
case 6:
|
|
137
|
+
setIsLoading(false);
|
|
138
|
+
setIsOpen(false);
|
|
139
|
+
case 8:
|
|
140
|
+
_context2.next = 14;
|
|
141
|
+
break;
|
|
142
|
+
case 10:
|
|
143
|
+
_context2.prev = 10;
|
|
144
|
+
_context2.t0 = _context2["catch"](0);
|
|
145
|
+
// TODO: EDM-6261: Error state
|
|
146
|
+
setIsLoading(false);
|
|
147
|
+
setErrorCode(_types.InvokeActionError.Unknown);
|
|
148
|
+
case 14:
|
|
149
|
+
case "end":
|
|
150
|
+
return _context2.stop();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}, _callee2, null, [[0, 10]]);
|
|
154
|
+
}));
|
|
155
|
+
return function (_x2) {
|
|
156
|
+
return _ref3.apply(this, arguments);
|
|
157
|
+
};
|
|
158
|
+
}(), [action === null || action === void 0 ? void 0 : action.update, invoke]);
|
|
108
159
|
var dropdownItemGroup = (0, _react2.useMemo)(function () {
|
|
109
|
-
if (items && items.length > 0) {
|
|
110
|
-
return (0, _react.jsx)("span", {
|
|
111
|
-
css: _styled.dropdownItemGroupStyles
|
|
112
|
-
}, (0, _react.jsx)(_dropdownMenu.DropdownItemGroup, null, items.map(function (_ref3, idx) {
|
|
113
|
-
var appearance = _ref3.appearance,
|
|
114
|
-
text = _ref3.text;
|
|
115
|
-
return (0, _react.jsx)(_lozengeActionItem.default, {
|
|
116
|
-
appearance: appearance,
|
|
117
|
-
key: idx,
|
|
118
|
-
testId: "".concat(testId, "-item-").concat(idx),
|
|
119
|
-
text: text
|
|
120
|
-
});
|
|
121
|
-
})));
|
|
122
|
-
}
|
|
123
160
|
if (errorCode) {
|
|
124
161
|
return (0, _react.jsx)(_lozengeActionError.default, {
|
|
125
162
|
errorCode: errorCode,
|
|
126
163
|
testId: testId
|
|
127
164
|
});
|
|
128
165
|
}
|
|
129
|
-
|
|
166
|
+
if (items && items.length > 0) {
|
|
167
|
+
return (0, _react.jsx)("span", {
|
|
168
|
+
css: _styled.dropdownItemGroupStyles,
|
|
169
|
+
"data-testid": "".concat(testId, "-item-group")
|
|
170
|
+
}, (0, _react.jsx)(_dropdownMenu.DropdownItemGroup, null, items.map(function (item, idx) {
|
|
171
|
+
return (0, _react.jsx)(_lozengeActionItem.default, (0, _extends2.default)({}, item, {
|
|
172
|
+
key: idx,
|
|
173
|
+
onClick: handleItemClick,
|
|
174
|
+
testId: "".concat(testId, "-item-").concat(idx)
|
|
175
|
+
}));
|
|
176
|
+
})));
|
|
177
|
+
}
|
|
178
|
+
}, [errorCode, handleItemClick, items, testId]);
|
|
130
179
|
return (0, _react.jsx)(_dropdownMenu.default, {
|
|
131
180
|
isLoading: isLoading,
|
|
132
|
-
|
|
181
|
+
isOpen: isOpen,
|
|
182
|
+
onOpenChange: handleOpenChange,
|
|
133
183
|
testId: testId,
|
|
134
184
|
trigger: trigger
|
|
135
185
|
}, dropdownItemGroup);
|
package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js
CHANGED
|
@@ -13,15 +13,26 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
13
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
14
|
var LozengeActionItem = function LozengeActionItem(_ref) {
|
|
15
15
|
var appearance = _ref.appearance,
|
|
16
|
+
id = _ref.id,
|
|
17
|
+
onClick = _ref.onClick,
|
|
16
18
|
testId = _ref.testId,
|
|
17
19
|
text = _ref.text;
|
|
18
|
-
var
|
|
20
|
+
var handleClick = (0, _react.useCallback)(function (e) {
|
|
21
|
+
// Prevent dropdown to close on select item.
|
|
22
|
+
// We want to show loading screen.
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
if (onClick) {
|
|
25
|
+
onClick(id);
|
|
26
|
+
}
|
|
27
|
+
}, [id, onClick]);
|
|
28
|
+
var handleMouseEnter = (0, _react.useCallback)(function (e) {
|
|
19
29
|
var _e$currentTarget, _e$currentTarget$firs;
|
|
20
30
|
(_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : (_e$currentTarget$firs = _e$currentTarget.firstElementChild) === null || _e$currentTarget$firs === void 0 ? void 0 : _e$currentTarget$firs.focus();
|
|
21
31
|
}, []);
|
|
22
32
|
return /*#__PURE__*/_react.default.createElement("span", {
|
|
23
|
-
onMouseEnter:
|
|
33
|
+
onMouseEnter: handleMouseEnter
|
|
24
34
|
}, /*#__PURE__*/_react.default.createElement(_dropdownMenu.DropdownItem, {
|
|
35
|
+
onClick: handleClick,
|
|
25
36
|
testId: testId
|
|
26
37
|
}, /*#__PURE__*/_react.default.createElement(_lozenge.default, {
|
|
27
38
|
appearance: appearance
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const extractLozengeActionItems = response => {
|
|
2
|
+
var _response$transitions, _response$transitions2;
|
|
3
|
+
const items = (_response$transitions = response === null || response === void 0 ? void 0 : (_response$transitions2 = response.transitions) === null || _response$transitions2 === void 0 ? void 0 : _response$transitions2.map(({
|
|
4
|
+
appearance,
|
|
5
|
+
id,
|
|
6
|
+
name
|
|
7
|
+
}) => {
|
|
8
|
+
var _ref;
|
|
9
|
+
return {
|
|
10
|
+
appearance: (_ref = appearance) !== null && _ref !== void 0 ? _ref : 'default',
|
|
11
|
+
id,
|
|
12
|
+
text: name
|
|
13
|
+
};
|
|
14
|
+
})) !== null && _response$transitions !== void 0 ? _response$transitions : [];
|
|
15
|
+
return items.sort((a, b) => a.appearance.localeCompare(b.appearance) || a.text.localeCompare(b.text));
|
|
16
|
+
};
|
|
17
|
+
export default extractLozengeActionItems;
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
+
import { useSmartLinkClientExtension } from '@atlaskit/link-client-extension';
|
|
3
|
+
import { useSmartLinkContext } from '@atlaskit/link-provider';
|
|
2
4
|
const useInvoke = () => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const {
|
|
6
|
+
connections
|
|
7
|
+
} = useSmartLinkContext();
|
|
8
|
+
const clientExt = useSmartLinkClientExtension(connections.client);
|
|
9
|
+
return useCallback(async (req, cb) => {
|
|
10
|
+
// TODO: EDM-6140: Check cache from store
|
|
11
|
+
|
|
12
|
+
const response = await clientExt.invoke(req);
|
|
13
|
+
|
|
14
|
+
// TODO: EDM-6140: Cache response in store
|
|
15
|
+
|
|
16
|
+
return cb ? cb(response) : response;
|
|
17
|
+
}, [clientExt]);
|
|
9
18
|
};
|
|
10
19
|
export default useInvoke;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export let InvokeActionName;
|
|
2
|
-
(function (InvokeActionName) {
|
|
3
|
-
InvokeActionName["UpdateAction"] = "UpdateAction";
|
|
4
|
-
})(InvokeActionName || (InvokeActionName = {}));
|
|
5
1
|
export let InvokeActionError;
|
|
6
2
|
(function (InvokeActionError) {
|
|
7
3
|
InvokeActionError["NoData"] = "NoData";
|
package/dist/es2019/version.json
CHANGED
package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/error-boundary/index.js
CHANGED
|
@@ -2,10 +2,13 @@ import React, { useMemo } from 'react';
|
|
|
2
2
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
3
3
|
import Lozenge from '@atlaskit/lozenge';
|
|
4
4
|
const withErrorBoundary = Component => props => {
|
|
5
|
-
const fallback = useMemo(() =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const fallback = useMemo(() => {
|
|
6
|
+
var _props$testId;
|
|
7
|
+
return /*#__PURE__*/React.createElement(Lozenge, {
|
|
8
|
+
appearance: props === null || props === void 0 ? void 0 : props.appearance,
|
|
9
|
+
testId: `${(_props$testId = props === null || props === void 0 ? void 0 : props.testId) !== null && _props$testId !== void 0 ? _props$testId : 'smart-element-lozenge-action'}-fallback`
|
|
10
|
+
}, props === null || props === void 0 ? void 0 : props.text);
|
|
11
|
+
}, [props === null || props === void 0 ? void 0 : props.appearance, props === null || props === void 0 ? void 0 : props.testId, props === null || props === void 0 ? void 0 : props.text]);
|
|
9
12
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
10
13
|
fallback: fallback
|
|
11
14
|
}, /*#__PURE__*/React.createElement(Component, props));
|
|
@@ -7,9 +7,14 @@ import LozengeActionItem from './lozenge-action-item';
|
|
|
7
7
|
import LozengeActionTrigger from './lozenge-action-trigger';
|
|
8
8
|
import LozengeActionError from './lozenge-action-error';
|
|
9
9
|
import withErrorBoundary from './error-boundary';
|
|
10
|
+
import { dropdownItemGroupStyles } from './styled';
|
|
10
11
|
import useInvoke from '../../../../../state/hooks/use-invoke';
|
|
11
12
|
import { InvokeActionError } from '../../../../../state/hooks/use-invoke/types';
|
|
12
|
-
import
|
|
13
|
+
import extractLozengeActionItems from '../../../../../extractors/action/extract-lozenge-action-items';
|
|
14
|
+
import createStatusUpdateRequest from '../../../../../utils/actions/create-status-update-request';
|
|
15
|
+
const validateItems = (items = [], text) => {
|
|
16
|
+
return items.filter(item => item.text !== text);
|
|
17
|
+
};
|
|
13
18
|
const LozengeAction = ({
|
|
14
19
|
action,
|
|
15
20
|
appearance,
|
|
@@ -18,56 +23,75 @@ const LozengeAction = ({
|
|
|
18
23
|
}) => {
|
|
19
24
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
20
25
|
const [isLoading, setIsLoading] = useState(false);
|
|
26
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
21
27
|
const [items, setItems] = useState();
|
|
22
28
|
const [errorCode, setErrorCode] = useState();
|
|
23
29
|
const invoke = useInvoke();
|
|
24
|
-
const
|
|
25
|
-
|
|
30
|
+
const handleOpenChange = useCallback(async args => {
|
|
31
|
+
setIsOpen(args.isOpen);
|
|
32
|
+
if (args.isOpen && !isLoaded && action !== null && action !== void 0 && action.read) {
|
|
26
33
|
try {
|
|
27
34
|
setIsLoading(true);
|
|
28
|
-
const
|
|
29
|
-
|
|
35
|
+
const responseItems = await invoke(action.read, extractLozengeActionItems);
|
|
36
|
+
const validItems = validateItems(responseItems, text);
|
|
37
|
+
setItems(validItems);
|
|
30
38
|
setIsLoaded(true);
|
|
31
|
-
if (
|
|
39
|
+
if ((validItems === null || validItems === void 0 ? void 0 : validItems.length) === 0) {
|
|
32
40
|
setErrorCode(InvokeActionError.NoData);
|
|
33
41
|
}
|
|
34
42
|
} catch (err) {
|
|
35
|
-
// TODO: EDM-
|
|
43
|
+
// TODO: EDM-6261: Error state
|
|
36
44
|
setErrorCode(InvokeActionError.Unknown);
|
|
37
45
|
} finally {
|
|
38
46
|
setIsLoading(false);
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
|
-
|
|
49
|
+
if (!args.isOpen) {
|
|
50
|
+
setErrorCode(undefined);
|
|
51
|
+
}
|
|
52
|
+
}, [action === null || action === void 0 ? void 0 : action.read, invoke, isLoaded, text]);
|
|
42
53
|
const trigger = useCallback(props => jsx(LozengeActionTrigger, _extends({}, props, {
|
|
43
54
|
appearance: appearance,
|
|
44
55
|
testId: testId,
|
|
45
56
|
text: text
|
|
46
57
|
})), [appearance, testId, text]);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const handleItemClick = useCallback(async id => {
|
|
59
|
+
try {
|
|
60
|
+
if (action !== null && action !== void 0 && action.update && id) {
|
|
61
|
+
setIsLoading(true);
|
|
62
|
+
const request = createStatusUpdateRequest(action.update, id);
|
|
63
|
+
await invoke(request);
|
|
64
|
+
setIsLoading(false);
|
|
65
|
+
setIsOpen(false);
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
// TODO: EDM-6261: Error state
|
|
69
|
+
setIsLoading(false);
|
|
70
|
+
setErrorCode(InvokeActionError.Unknown);
|
|
60
71
|
}
|
|
72
|
+
}, [action === null || action === void 0 ? void 0 : action.update, invoke]);
|
|
73
|
+
const dropdownItemGroup = useMemo(() => {
|
|
61
74
|
if (errorCode) {
|
|
62
75
|
return jsx(LozengeActionError, {
|
|
63
76
|
errorCode: errorCode,
|
|
64
77
|
testId: testId
|
|
65
78
|
});
|
|
66
79
|
}
|
|
67
|
-
|
|
80
|
+
if (items && items.length > 0) {
|
|
81
|
+
return jsx("span", {
|
|
82
|
+
css: dropdownItemGroupStyles,
|
|
83
|
+
"data-testid": `${testId}-item-group`
|
|
84
|
+
}, jsx(DropdownItemGroup, null, items.map((item, idx) => jsx(LozengeActionItem, _extends({}, item, {
|
|
85
|
+
key: idx,
|
|
86
|
+
onClick: handleItemClick,
|
|
87
|
+
testId: `${testId}-item-${idx}`
|
|
88
|
+
})))));
|
|
89
|
+
}
|
|
90
|
+
}, [errorCode, handleItemClick, items, testId]);
|
|
68
91
|
return jsx(DropdownMenu, {
|
|
69
92
|
isLoading: isLoading,
|
|
70
|
-
|
|
93
|
+
isOpen: isOpen,
|
|
94
|
+
onOpenChange: handleOpenChange,
|
|
71
95
|
testId: testId,
|
|
72
96
|
trigger: trigger
|
|
73
97
|
}, dropdownItemGroup);
|
package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js
CHANGED
|
@@ -3,16 +3,27 @@ import { DropdownItem } from '@atlaskit/dropdown-menu';
|
|
|
3
3
|
import Lozenge from '@atlaskit/lozenge';
|
|
4
4
|
const LozengeActionItem = ({
|
|
5
5
|
appearance,
|
|
6
|
+
id,
|
|
7
|
+
onClick,
|
|
6
8
|
testId,
|
|
7
9
|
text
|
|
8
10
|
}) => {
|
|
9
|
-
const
|
|
11
|
+
const handleClick = useCallback(e => {
|
|
12
|
+
// Prevent dropdown to close on select item.
|
|
13
|
+
// We want to show loading screen.
|
|
14
|
+
e.stopPropagation();
|
|
15
|
+
if (onClick) {
|
|
16
|
+
onClick(id);
|
|
17
|
+
}
|
|
18
|
+
}, [id, onClick]);
|
|
19
|
+
const handleMouseEnter = useCallback(e => {
|
|
10
20
|
var _e$currentTarget, _e$currentTarget$firs;
|
|
11
21
|
(_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : (_e$currentTarget$firs = _e$currentTarget.firstElementChild) === null || _e$currentTarget$firs === void 0 ? void 0 : _e$currentTarget$firs.focus();
|
|
12
22
|
}, []);
|
|
13
23
|
return /*#__PURE__*/React.createElement("span", {
|
|
14
|
-
onMouseEnter:
|
|
24
|
+
onMouseEnter: handleMouseEnter
|
|
15
25
|
}, /*#__PURE__*/React.createElement(DropdownItem, {
|
|
26
|
+
onClick: handleClick,
|
|
16
27
|
testId: testId
|
|
17
28
|
}, /*#__PURE__*/React.createElement(Lozenge, {
|
|
18
29
|
appearance: appearance
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var extractLozengeActionItems = function extractLozengeActionItems(response) {
|
|
2
|
+
var _response$transitions, _response$transitions2;
|
|
3
|
+
var items = (_response$transitions = response === null || response === void 0 ? void 0 : (_response$transitions2 = response.transitions) === null || _response$transitions2 === void 0 ? void 0 : _response$transitions2.map(function (_ref) {
|
|
4
|
+
var _ref2;
|
|
5
|
+
var appearance = _ref.appearance,
|
|
6
|
+
id = _ref.id,
|
|
7
|
+
name = _ref.name;
|
|
8
|
+
return {
|
|
9
|
+
appearance: (_ref2 = appearance) !== null && _ref2 !== void 0 ? _ref2 : 'default',
|
|
10
|
+
id: id,
|
|
11
|
+
text: name
|
|
12
|
+
};
|
|
13
|
+
})) !== null && _response$transitions !== void 0 ? _response$transitions : [];
|
|
14
|
+
return items.sort(function (a, b) {
|
|
15
|
+
return a.appearance.localeCompare(b.appearance) || a.text.localeCompare(b.text);
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
export default extractLozengeActionItems;
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
|
+
import { useSmartLinkClientExtension } from '@atlaskit/link-client-extension';
|
|
5
|
+
import { useSmartLinkContext } from '@atlaskit/link-provider';
|
|
4
6
|
var useInvoke = function useInvoke() {
|
|
7
|
+
var _useSmartLinkContext = useSmartLinkContext(),
|
|
8
|
+
connections = _useSmartLinkContext.connections;
|
|
9
|
+
var clientExt = useSmartLinkClientExtension(connections.client);
|
|
5
10
|
return useCallback( /*#__PURE__*/function () {
|
|
6
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(
|
|
11
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(req, cb) {
|
|
12
|
+
var response;
|
|
7
13
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
8
14
|
while (1) {
|
|
9
15
|
switch (_context.prev = _context.next) {
|
|
10
16
|
case 0:
|
|
11
17
|
_context.next = 2;
|
|
12
|
-
return
|
|
13
|
-
resolve();
|
|
14
|
-
});
|
|
18
|
+
return clientExt.invoke(req);
|
|
15
19
|
case 2:
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
response = _context.sent;
|
|
21
|
+
return _context.abrupt("return", cb ? cb(response) : response);
|
|
22
|
+
case 4:
|
|
18
23
|
case "end":
|
|
19
24
|
return _context.stop();
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
}, _callee);
|
|
23
28
|
}));
|
|
24
|
-
return function (_x) {
|
|
29
|
+
return function (_x, _x2) {
|
|
25
30
|
return _ref.apply(this, arguments);
|
|
26
31
|
};
|
|
27
|
-
}(), []);
|
|
32
|
+
}(), [clientExt]);
|
|
28
33
|
};
|
|
29
34
|
export default useInvoke;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export var InvokeActionName;
|
|
2
|
-
(function (InvokeActionName) {
|
|
3
|
-
InvokeActionName["UpdateAction"] = "UpdateAction";
|
|
4
|
-
})(InvokeActionName || (InvokeActionName = {}));
|
|
5
1
|
export var InvokeActionError;
|
|
6
2
|
(function (InvokeActionError) {
|
|
7
3
|
InvokeActionError["NoData"] = "NoData";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
var createStatusUpdateRequest = function createStatusUpdateRequest(request, id) {
|
|
5
|
+
return _objectSpread(_objectSpread({}, request), {}, {
|
|
6
|
+
action: _objectSpread(_objectSpread({}, request.action), {}, {
|
|
7
|
+
payload: {
|
|
8
|
+
newStatusId: id
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export default createStatusUpdateRequest;
|
package/dist/esm/version.json
CHANGED
|
@@ -4,9 +4,10 @@ import Lozenge from '@atlaskit/lozenge';
|
|
|
4
4
|
var withErrorBoundary = function withErrorBoundary(Component) {
|
|
5
5
|
return function (props) {
|
|
6
6
|
var fallback = useMemo(function () {
|
|
7
|
+
var _props$testId;
|
|
7
8
|
return /*#__PURE__*/React.createElement(Lozenge, {
|
|
8
9
|
appearance: props === null || props === void 0 ? void 0 : props.appearance,
|
|
9
|
-
testId: "".concat(props === null || props === void 0 ? void 0 : props.testId, "-fallback")
|
|
10
|
+
testId: "".concat((_props$testId = props === null || props === void 0 ? void 0 : props.testId) !== null && _props$testId !== void 0 ? _props$testId : 'smart-element-lozenge-action', "-fallback")
|
|
10
11
|
}, props === null || props === void 0 ? void 0 : props.text);
|
|
11
12
|
}, [props === null || props === void 0 ? void 0 : props.appearance, props === null || props === void 0 ? void 0 : props.testId, props === null || props === void 0 ? void 0 : props.text]);
|
|
12
13
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
@@ -10,9 +10,18 @@ import LozengeActionItem from './lozenge-action-item';
|
|
|
10
10
|
import LozengeActionTrigger from './lozenge-action-trigger';
|
|
11
11
|
import LozengeActionError from './lozenge-action-error';
|
|
12
12
|
import withErrorBoundary from './error-boundary';
|
|
13
|
+
import { dropdownItemGroupStyles } from './styled';
|
|
13
14
|
import useInvoke from '../../../../../state/hooks/use-invoke';
|
|
14
15
|
import { InvokeActionError } from '../../../../../state/hooks/use-invoke/types';
|
|
15
|
-
import
|
|
16
|
+
import extractLozengeActionItems from '../../../../../extractors/action/extract-lozenge-action-items';
|
|
17
|
+
import createStatusUpdateRequest from '../../../../../utils/actions/create-status-update-request';
|
|
18
|
+
var validateItems = function validateItems() {
|
|
19
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
20
|
+
var text = arguments.length > 1 ? arguments[1] : undefined;
|
|
21
|
+
return items.filter(function (item) {
|
|
22
|
+
return item.text !== text;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
16
25
|
var LozengeAction = function LozengeAction(_ref) {
|
|
17
26
|
var action = _ref.action,
|
|
18
27
|
appearance = _ref.appearance,
|
|
@@ -27,66 +36,69 @@ var LozengeAction = function LozengeAction(_ref) {
|
|
|
27
36
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
37
|
isLoading = _useState4[0],
|
|
29
38
|
setIsLoading = _useState4[1];
|
|
30
|
-
var _useState5 = useState(),
|
|
39
|
+
var _useState5 = useState(false),
|
|
31
40
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
isOpen = _useState6[0],
|
|
42
|
+
setIsOpen = _useState6[1];
|
|
34
43
|
var _useState7 = useState(),
|
|
35
44
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
items = _useState8[0],
|
|
46
|
+
setItems = _useState8[1];
|
|
47
|
+
var _useState9 = useState(),
|
|
48
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
49
|
+
errorCode = _useState10[0],
|
|
50
|
+
setErrorCode = _useState10[1];
|
|
38
51
|
var invoke = useInvoke();
|
|
39
|
-
var
|
|
52
|
+
var handleOpenChange = useCallback( /*#__PURE__*/function () {
|
|
40
53
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(args) {
|
|
41
|
-
var
|
|
54
|
+
var responseItems, validItems;
|
|
42
55
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
43
56
|
while (1) {
|
|
44
57
|
switch (_context.prev = _context.next) {
|
|
45
58
|
case 0:
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
setIsOpen(args.isOpen);
|
|
60
|
+
if (!(args.isOpen && !isLoaded && action !== null && action !== void 0 && action.read)) {
|
|
61
|
+
_context.next = 19;
|
|
48
62
|
break;
|
|
49
63
|
}
|
|
50
|
-
_context.prev =
|
|
64
|
+
_context.prev = 2;
|
|
51
65
|
setIsLoading(true);
|
|
52
|
-
_context.next =
|
|
53
|
-
return invoke(action);
|
|
54
|
-
case
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
_context.t0 = [];
|
|
61
|
-
case 8:
|
|
62
|
-
lozengeItems = _context.t0;
|
|
63
|
-
setItems(lozengeItems);
|
|
66
|
+
_context.next = 6;
|
|
67
|
+
return invoke(action.read, extractLozengeActionItems);
|
|
68
|
+
case 6:
|
|
69
|
+
responseItems = _context.sent;
|
|
70
|
+
validItems = validateItems(responseItems, text);
|
|
71
|
+
setItems(validItems);
|
|
64
72
|
setIsLoaded(true);
|
|
65
|
-
if (
|
|
73
|
+
if ((validItems === null || validItems === void 0 ? void 0 : validItems.length) === 0) {
|
|
66
74
|
setErrorCode(InvokeActionError.NoData);
|
|
67
75
|
}
|
|
68
|
-
_context.next =
|
|
76
|
+
_context.next = 16;
|
|
69
77
|
break;
|
|
70
|
-
case
|
|
71
|
-
_context.prev =
|
|
72
|
-
_context.
|
|
73
|
-
// TODO: EDM-
|
|
78
|
+
case 13:
|
|
79
|
+
_context.prev = 13;
|
|
80
|
+
_context.t0 = _context["catch"](2);
|
|
81
|
+
// TODO: EDM-6261: Error state
|
|
74
82
|
setErrorCode(InvokeActionError.Unknown);
|
|
75
|
-
case
|
|
76
|
-
_context.prev =
|
|
83
|
+
case 16:
|
|
84
|
+
_context.prev = 16;
|
|
77
85
|
setIsLoading(false);
|
|
78
|
-
return _context.finish(
|
|
86
|
+
return _context.finish(16);
|
|
87
|
+
case 19:
|
|
88
|
+
if (!args.isOpen) {
|
|
89
|
+
setErrorCode(undefined);
|
|
90
|
+
}
|
|
79
91
|
case 20:
|
|
80
92
|
case "end":
|
|
81
93
|
return _context.stop();
|
|
82
94
|
}
|
|
83
95
|
}
|
|
84
|
-
}, _callee, null, [[
|
|
96
|
+
}, _callee, null, [[2, 13, 16, 19]]);
|
|
85
97
|
}));
|
|
86
98
|
return function (_x) {
|
|
87
99
|
return _ref2.apply(this, arguments);
|
|
88
100
|
};
|
|
89
|
-
}(), [action, invoke, isLoaded]);
|
|
101
|
+
}(), [action === null || action === void 0 ? void 0 : action.read, invoke, isLoaded, text]);
|
|
90
102
|
var trigger = useCallback(function (props) {
|
|
91
103
|
return jsx(LozengeActionTrigger, _extends({}, props, {
|
|
92
104
|
appearance: appearance,
|
|
@@ -94,31 +106,69 @@ var LozengeAction = function LozengeAction(_ref) {
|
|
|
94
106
|
text: text
|
|
95
107
|
}));
|
|
96
108
|
}, [appearance, testId, text]);
|
|
109
|
+
var handleItemClick = useCallback( /*#__PURE__*/function () {
|
|
110
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id) {
|
|
111
|
+
var request;
|
|
112
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
113
|
+
while (1) {
|
|
114
|
+
switch (_context2.prev = _context2.next) {
|
|
115
|
+
case 0:
|
|
116
|
+
_context2.prev = 0;
|
|
117
|
+
if (!(action !== null && action !== void 0 && action.update && id)) {
|
|
118
|
+
_context2.next = 8;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
setIsLoading(true);
|
|
122
|
+
request = createStatusUpdateRequest(action.update, id);
|
|
123
|
+
_context2.next = 6;
|
|
124
|
+
return invoke(request);
|
|
125
|
+
case 6:
|
|
126
|
+
setIsLoading(false);
|
|
127
|
+
setIsOpen(false);
|
|
128
|
+
case 8:
|
|
129
|
+
_context2.next = 14;
|
|
130
|
+
break;
|
|
131
|
+
case 10:
|
|
132
|
+
_context2.prev = 10;
|
|
133
|
+
_context2.t0 = _context2["catch"](0);
|
|
134
|
+
// TODO: EDM-6261: Error state
|
|
135
|
+
setIsLoading(false);
|
|
136
|
+
setErrorCode(InvokeActionError.Unknown);
|
|
137
|
+
case 14:
|
|
138
|
+
case "end":
|
|
139
|
+
return _context2.stop();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}, _callee2, null, [[0, 10]]);
|
|
143
|
+
}));
|
|
144
|
+
return function (_x2) {
|
|
145
|
+
return _ref3.apply(this, arguments);
|
|
146
|
+
};
|
|
147
|
+
}(), [action === null || action === void 0 ? void 0 : action.update, invoke]);
|
|
97
148
|
var dropdownItemGroup = useMemo(function () {
|
|
98
|
-
if (items && items.length > 0) {
|
|
99
|
-
return jsx("span", {
|
|
100
|
-
css: dropdownItemGroupStyles
|
|
101
|
-
}, jsx(DropdownItemGroup, null, items.map(function (_ref3, idx) {
|
|
102
|
-
var appearance = _ref3.appearance,
|
|
103
|
-
text = _ref3.text;
|
|
104
|
-
return jsx(LozengeActionItem, {
|
|
105
|
-
appearance: appearance,
|
|
106
|
-
key: idx,
|
|
107
|
-
testId: "".concat(testId, "-item-").concat(idx),
|
|
108
|
-
text: text
|
|
109
|
-
});
|
|
110
|
-
})));
|
|
111
|
-
}
|
|
112
149
|
if (errorCode) {
|
|
113
150
|
return jsx(LozengeActionError, {
|
|
114
151
|
errorCode: errorCode,
|
|
115
152
|
testId: testId
|
|
116
153
|
});
|
|
117
154
|
}
|
|
118
|
-
|
|
155
|
+
if (items && items.length > 0) {
|
|
156
|
+
return jsx("span", {
|
|
157
|
+
css: dropdownItemGroupStyles,
|
|
158
|
+
"data-testid": "".concat(testId, "-item-group")
|
|
159
|
+
}, jsx(DropdownItemGroup, null, items.map(function (item, idx) {
|
|
160
|
+
return jsx(LozengeActionItem, _extends({}, item, {
|
|
161
|
+
key: idx,
|
|
162
|
+
onClick: handleItemClick,
|
|
163
|
+
testId: "".concat(testId, "-item-").concat(idx)
|
|
164
|
+
}));
|
|
165
|
+
})));
|
|
166
|
+
}
|
|
167
|
+
}, [errorCode, handleItemClick, items, testId]);
|
|
119
168
|
return jsx(DropdownMenu, {
|
|
120
169
|
isLoading: isLoading,
|
|
121
|
-
|
|
170
|
+
isOpen: isOpen,
|
|
171
|
+
onOpenChange: handleOpenChange,
|
|
122
172
|
testId: testId,
|
|
123
173
|
trigger: trigger
|
|
124
174
|
}, dropdownItemGroup);
|
package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js
CHANGED
|
@@ -3,15 +3,26 @@ import { DropdownItem } from '@atlaskit/dropdown-menu';
|
|
|
3
3
|
import Lozenge from '@atlaskit/lozenge';
|
|
4
4
|
var LozengeActionItem = function LozengeActionItem(_ref) {
|
|
5
5
|
var appearance = _ref.appearance,
|
|
6
|
+
id = _ref.id,
|
|
7
|
+
onClick = _ref.onClick,
|
|
6
8
|
testId = _ref.testId,
|
|
7
9
|
text = _ref.text;
|
|
8
|
-
var
|
|
10
|
+
var handleClick = useCallback(function (e) {
|
|
11
|
+
// Prevent dropdown to close on select item.
|
|
12
|
+
// We want to show loading screen.
|
|
13
|
+
e.stopPropagation();
|
|
14
|
+
if (onClick) {
|
|
15
|
+
onClick(id);
|
|
16
|
+
}
|
|
17
|
+
}, [id, onClick]);
|
|
18
|
+
var handleMouseEnter = useCallback(function (e) {
|
|
9
19
|
var _e$currentTarget, _e$currentTarget$firs;
|
|
10
20
|
(_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : (_e$currentTarget$firs = _e$currentTarget.firstElementChild) === null || _e$currentTarget$firs === void 0 ? void 0 : _e$currentTarget$firs.focus();
|
|
11
21
|
}, []);
|
|
12
22
|
return /*#__PURE__*/React.createElement("span", {
|
|
13
|
-
onMouseEnter:
|
|
23
|
+
onMouseEnter: handleMouseEnter
|
|
14
24
|
}, /*#__PURE__*/React.createElement(DropdownItem, {
|
|
25
|
+
onClick: handleClick,
|
|
15
26
|
testId: testId
|
|
16
27
|
}, /*#__PURE__*/React.createElement(Lozenge, {
|
|
17
28
|
appearance: appearance
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GetStatusTransitionsInvokeResponse } from '@atlaskit/linking-types/smart-link-actions';
|
|
2
|
+
import { LozengeItem } from '../../view/FlexibleCard/components/common/lozenge-action/types';
|
|
3
|
+
declare const extractLozengeActionItems: (response: GetStatusTransitionsInvokeResponse) => LozengeItem[];
|
|
4
|
+
export default extractLozengeActionItems;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const useInvoke: () =>
|
|
1
|
+
import type { InvokeRequest } from '@atlaskit/linking-types/smart-link-actions';
|
|
2
|
+
declare const useInvoke: () => (req: InvokeRequest, cb?: Function | undefined) => Promise<any>;
|
|
3
3
|
export default useInvoke;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
UpdateAction = "UpdateAction"
|
|
3
|
-
}
|
|
1
|
+
import type { InvokeRequest } from '@atlaskit/linking-types/smart-link-actions';
|
|
4
2
|
export declare enum InvokeActionError {
|
|
5
3
|
NoData = "NoData",
|
|
6
4
|
Unknown = "Unknown"
|
|
7
5
|
}
|
|
8
|
-
export declare type
|
|
9
|
-
|
|
6
|
+
export declare type InvokeActions = {
|
|
7
|
+
create?: InvokeRequest;
|
|
8
|
+
read?: InvokeRequest;
|
|
9
|
+
update?: InvokeRequest;
|
|
10
|
+
delete?: InvokeRequest;
|
|
10
11
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InvokeRequest } from '@atlaskit/linking-types/smart-link-actions';
|
|
2
|
+
import { StatusUpdateActionPayload } from '@atlaskit/linking-types/smart-link-actions';
|
|
3
|
+
declare const createStatusUpdateRequest: (request: InvokeRequest, id: string) => InvokeRequest<StatusUpdateActionPayload>;
|
|
4
|
+
export default createStatusUpdateRequest;
|
package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare type LozengeActionItemProps = {
|
|
3
|
-
|
|
1
|
+
import { LozengeItem } from '../types';
|
|
2
|
+
export declare type LozengeActionItemProps = LozengeItem & {
|
|
3
|
+
onClick?: (id: string) => void;
|
|
4
4
|
testId?: string;
|
|
5
|
-
text: string;
|
|
6
5
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ThemeAppearance } from '@atlaskit/lozenge';
|
|
2
|
-
import type {
|
|
2
|
+
import type { InvokeActions } from '../../../../../state/hooks/use-invoke/types';
|
|
3
3
|
export declare type LozengeItem = {
|
|
4
4
|
appearance?: ThemeAppearance;
|
|
5
|
+
id: string;
|
|
5
6
|
text: string;
|
|
6
7
|
};
|
|
7
8
|
export declare type LozengeActionProps = {
|
|
8
|
-
action?:
|
|
9
|
+
action?: InvokeActions;
|
|
9
10
|
appearance?: ThemeAppearance;
|
|
10
11
|
testId?: string;
|
|
11
12
|
text: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/smart-card",
|
|
3
|
-
"version": "25.3.
|
|
3
|
+
"version": "25.3.2",
|
|
4
4
|
"description": "Smart card component",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
"@atlaskit/icon-object": "^6.2.0",
|
|
34
34
|
"@atlaskit/icon-priority": "^6.3.0",
|
|
35
35
|
"@atlaskit/in-product-testing": "^0.1.0",
|
|
36
|
+
"@atlaskit/link-client-extension": "^0.3.0",
|
|
36
37
|
"@atlaskit/linking-common": "^2.4.0",
|
|
37
|
-
"@atlaskit/
|
|
38
|
+
"@atlaskit/linking-types": "^0.3.0",
|
|
39
|
+
"@atlaskit/logo": "^13.12.0",
|
|
38
40
|
"@atlaskit/lozenge": "^11.3.0",
|
|
39
41
|
"@atlaskit/media-common": "^4.0.0",
|
|
40
42
|
"@atlaskit/modal-dialog": "^12.4.0",
|
|
@@ -98,6 +100,7 @@
|
|
|
98
100
|
"@types/react-loadable": "^5.4.1",
|
|
99
101
|
"abortcontroller-polyfill": "^1.1.9",
|
|
100
102
|
"brace": "^0.11.1",
|
|
103
|
+
"fetch-mock": "^8.0.0",
|
|
101
104
|
"jest-emotion": "^10.0.32",
|
|
102
105
|
"jest-extended": "^0.11.2",
|
|
103
106
|
"jsdom": "^16.2.2",
|