@atlaskit/editor-plugin-card 2.6.2 → 2.6.3
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 +8 -0
- package/dist/cjs/toolbar.js +1 -0
- package/dist/cjs/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js} +15 -65
- package/dist/cjs/ui/EditToolbarButton/index.js +286 -0
- package/dist/cjs/ui/EditToolbarButton/types.js +5 -0
- package/dist/cjs/ui/useFetchDatasourceDataInfo.js +75 -0
- package/dist/es2019/toolbar.js +1 -0
- package/dist/es2019/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js} +14 -67
- package/dist/es2019/ui/EditToolbarButton/index.js +278 -0
- package/dist/es2019/ui/EditToolbarButton/types.js +1 -0
- package/dist/es2019/ui/useFetchDatasourceDataInfo.js +41 -0
- package/dist/esm/toolbar.js +1 -0
- package/dist/esm/ui/EditToolbarButton/EditToolbarButtonPresentation.js +116 -0
- package/dist/esm/ui/{EditToolbarButton.js → EditToolbarButton/index.js} +116 -4
- package/dist/esm/ui/EditToolbarButton/types.js +1 -0
- package/dist/esm/ui/useFetchDatasourceDataInfo.js +67 -0
- package/dist/types/ui/EditToolbarButton/EditToolbarButtonPresentation.d.ts +9 -0
- package/dist/types/ui/EditToolbarButton/index.d.ts +3 -0
- package/dist/types/ui/EditToolbarButton/types.d.ts +29 -0
- package/dist/types/ui/useFetchDatasourceDataInfo.d.ts +10 -0
- package/dist/types-ts4.5/ui/EditToolbarButton/EditToolbarButtonPresentation.d.ts +9 -0
- package/dist/types-ts4.5/ui/EditToolbarButton/index.d.ts +3 -0
- package/dist/types-ts4.5/ui/EditToolbarButton/types.d.ts +29 -0
- package/dist/types-ts4.5/ui/useFetchDatasourceDataInfo.d.ts +10 -0
- package/package.json +4 -1
- package/dist/types/ui/EditToolbarButton.d.ts +0 -18
- package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-card
|
|
2
2
|
|
|
3
|
+
## 2.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#121784](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121784)
|
|
8
|
+
[`a6117088af0ad`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a6117088af0ad) -
|
|
9
|
+
The edit toolbar button is retrieving metadata from /data endpoint for analytics metadata.
|
|
10
|
+
|
|
3
11
|
## 2.6.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -476,6 +476,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
|
|
|
476
476
|
render: function render(editorView) {
|
|
477
477
|
return /*#__PURE__*/_react.default.createElement(_EditToolbarButton.EditToolbarButton, {
|
|
478
478
|
datasourceId: datasourceId,
|
|
479
|
+
node: node,
|
|
479
480
|
key: "edit-toolbar-item",
|
|
480
481
|
url: metadata.url,
|
|
481
482
|
intl: intl,
|
package/dist/cjs/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js}
RENAMED
|
@@ -4,9 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.default = void 0;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
9
|
var _react = require("react");
|
|
11
10
|
var _react2 = require("@emotion/react");
|
|
12
11
|
var _reactIntlNext = require("react-intl-next");
|
|
@@ -16,33 +15,24 @@ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
|
16
15
|
var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
|
|
17
16
|
var _menu = require("@atlaskit/menu");
|
|
18
17
|
var _primitives = require("@atlaskit/primitives");
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var _CardContextProvider = require("./CardContextProvider");
|
|
22
|
-
var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
|
|
23
|
-
var _excluded = ["extensionKey"];
|
|
18
|
+
var _utils = require("../../utils");
|
|
19
|
+
var _EditDatasourceButton = require("../EditDatasourceButton");
|
|
24
20
|
/** @jsx jsx */
|
|
21
|
+
|
|
25
22
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
23
|
+
|
|
26
24
|
var dropdownExpandContainer = (0, _react2.css)({
|
|
27
25
|
margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
|
|
28
26
|
});
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
editorView =
|
|
35
|
-
|
|
36
|
-
onLinkEditClick =
|
|
37
|
-
|
|
38
|
-
var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
|
|
39
|
-
isRegularCardNode: true,
|
|
40
|
-
url: url,
|
|
41
|
-
cardContext: cardContext
|
|
42
|
-
}),
|
|
43
|
-
extensionKey = _useFetchDatasourceIn.extensionKey,
|
|
44
|
-
response = (0, _objectWithoutProperties2.default)(_useFetchDatasourceIn, _excluded);
|
|
45
|
-
var datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
|
|
27
|
+
var EditToolbarButtonPresentation = function EditToolbarButtonPresentation(_ref) {
|
|
28
|
+
var datasourceId = _ref.datasourceId,
|
|
29
|
+
currentAppearance = _ref.currentAppearance,
|
|
30
|
+
editorAnalyticsApi = _ref.editorAnalyticsApi,
|
|
31
|
+
editVariant = _ref.editVariant,
|
|
32
|
+
editorView = _ref.editorView,
|
|
33
|
+
extensionKey = _ref.extensionKey,
|
|
34
|
+
onLinkEditClick = _ref.onLinkEditClick,
|
|
35
|
+
intl = _ref.intl;
|
|
46
36
|
var _useState = (0, _react.useState)(false),
|
|
47
37
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
48
38
|
isOpen = _useState2[0],
|
|
@@ -62,25 +52,6 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
|
|
|
62
52
|
(0, _utils.focusEditorView)(editorView);
|
|
63
53
|
}
|
|
64
54
|
}, [editorView, onLinkEditClick]);
|
|
65
|
-
var editVariant = (0, _react.useMemo)(function () {
|
|
66
|
-
var hasUrl = url !== null && url !== undefined;
|
|
67
|
-
if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
|
|
68
|
-
if (hasUrl) {
|
|
69
|
-
return 'edit-link';
|
|
70
|
-
}
|
|
71
|
-
return 'none';
|
|
72
|
-
}
|
|
73
|
-
if (hasUrl) {
|
|
74
|
-
var _cardContext$store, _urlState$error;
|
|
75
|
-
var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
76
|
-
if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
77
|
-
return 'edit-link';
|
|
78
|
-
}
|
|
79
|
-
return 'edit-dropdown';
|
|
80
|
-
} else {
|
|
81
|
-
return 'edit-datasource';
|
|
82
|
-
}
|
|
83
|
-
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
84
55
|
var onEditDatasource = (0, _react.useCallback)(function () {
|
|
85
56
|
if (editorView && datasourceId) {
|
|
86
57
|
(0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
|
|
@@ -150,25 +121,4 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
|
|
|
150
121
|
return null;
|
|
151
122
|
}
|
|
152
123
|
};
|
|
153
|
-
var
|
|
154
|
-
var currentAppearance = props.currentAppearance,
|
|
155
|
-
datasourceId = props.datasourceId,
|
|
156
|
-
editorAnalyticsApi = props.editorAnalyticsApi,
|
|
157
|
-
editorView = props.editorView,
|
|
158
|
-
intl = props.intl,
|
|
159
|
-
onLinkEditClick = props.onLinkEditClick,
|
|
160
|
-
url = props.url;
|
|
161
|
-
return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref) {
|
|
162
|
-
var cardContext = _ref.cardContext;
|
|
163
|
-
return (0, _react2.jsx)(EditToolbarButtonWithCardContext, {
|
|
164
|
-
datasourceId: datasourceId,
|
|
165
|
-
url: url,
|
|
166
|
-
intl: intl,
|
|
167
|
-
editorAnalyticsApi: editorAnalyticsApi,
|
|
168
|
-
editorView: editorView,
|
|
169
|
-
cardContext: cardContext,
|
|
170
|
-
onLinkEditClick: onLinkEditClick,
|
|
171
|
-
currentAppearance: currentAppearance
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
};
|
|
124
|
+
var _default = exports.default = EditToolbarButtonPresentation;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.EditToolbarButton = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _react2 = require("@emotion/react");
|
|
12
|
+
var _reactIntlNext = require("react-intl-next");
|
|
13
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
15
|
+
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
|
|
16
|
+
var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
|
|
17
|
+
var _menu = require("@atlaskit/menu");
|
|
18
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
19
|
+
var _primitives = require("@atlaskit/primitives");
|
|
20
|
+
var _EditDatasourceButton = require("../../ui/EditDatasourceButton");
|
|
21
|
+
var _utils = require("../../utils");
|
|
22
|
+
var _CardContextProvider = require("../CardContextProvider");
|
|
23
|
+
var _useFetchDatasourceDataInfo = require("../useFetchDatasourceDataInfo");
|
|
24
|
+
var _useFetchDatasourceInfo = require("../useFetchDatasourceInfo");
|
|
25
|
+
var _EditToolbarButtonPresentation = _interopRequireDefault(require("./EditToolbarButtonPresentation"));
|
|
26
|
+
var _excluded = ["extensionKey"];
|
|
27
|
+
/** @jsx jsx */
|
|
28
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
29
|
+
var dropdownExpandContainer = (0, _react2.css)({
|
|
30
|
+
margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
|
|
31
|
+
});
|
|
32
|
+
var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext(props) {
|
|
33
|
+
var _response$datasourceI;
|
|
34
|
+
var cardContext = props.cardContext,
|
|
35
|
+
currentAppearance = props.currentAppearance,
|
|
36
|
+
editorAnalyticsApi = props.editorAnalyticsApi,
|
|
37
|
+
editorView = props.editorView,
|
|
38
|
+
intl = props.intl,
|
|
39
|
+
onLinkEditClick = props.onLinkEditClick,
|
|
40
|
+
url = props.url;
|
|
41
|
+
var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
|
|
42
|
+
isRegularCardNode: true,
|
|
43
|
+
url: url,
|
|
44
|
+
cardContext: cardContext
|
|
45
|
+
}),
|
|
46
|
+
extensionKey = _useFetchDatasourceIn.extensionKey,
|
|
47
|
+
response = (0, _objectWithoutProperties2.default)(_useFetchDatasourceIn, _excluded);
|
|
48
|
+
var datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
|
|
49
|
+
var _useState = (0, _react.useState)(false),
|
|
50
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
51
|
+
isOpen = _useState2[0],
|
|
52
|
+
setIsOpen = _useState2[1];
|
|
53
|
+
var containerRef = (0, _react.useRef)();
|
|
54
|
+
var toggleOpen = function toggleOpen() {
|
|
55
|
+
return setIsOpen(function (open) {
|
|
56
|
+
return !open;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
var onClose = function onClose() {
|
|
60
|
+
return setIsOpen(false);
|
|
61
|
+
};
|
|
62
|
+
var onEditLink = (0, _react.useCallback)(function () {
|
|
63
|
+
if (editorView) {
|
|
64
|
+
onLinkEditClick(editorView.state, editorView.dispatch);
|
|
65
|
+
(0, _utils.focusEditorView)(editorView);
|
|
66
|
+
}
|
|
67
|
+
}, [editorView, onLinkEditClick]);
|
|
68
|
+
var editVariant = (0, _react.useMemo)(function () {
|
|
69
|
+
var hasUrl = url !== null && url !== undefined;
|
|
70
|
+
if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
|
|
71
|
+
if (hasUrl) {
|
|
72
|
+
return 'edit-link';
|
|
73
|
+
}
|
|
74
|
+
return 'none';
|
|
75
|
+
}
|
|
76
|
+
if (hasUrl) {
|
|
77
|
+
var _cardContext$store, _urlState$error;
|
|
78
|
+
var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
79
|
+
if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
80
|
+
return 'edit-link';
|
|
81
|
+
}
|
|
82
|
+
return 'edit-dropdown';
|
|
83
|
+
} else {
|
|
84
|
+
return 'edit-datasource';
|
|
85
|
+
}
|
|
86
|
+
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
87
|
+
var onEditDatasource = (0, _react.useCallback)(function () {
|
|
88
|
+
if (editorView && datasourceId) {
|
|
89
|
+
(0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
|
|
90
|
+
(0, _utils.focusEditorView)(editorView);
|
|
91
|
+
}
|
|
92
|
+
}, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
|
|
93
|
+
switch (editVariant) {
|
|
94
|
+
case 'edit-link':
|
|
95
|
+
{
|
|
96
|
+
return (0, _react2.jsx)(_primitives.Flex, {
|
|
97
|
+
gap: "space.050"
|
|
98
|
+
}, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
|
|
99
|
+
testId: "edit-link",
|
|
100
|
+
onClick: onEditLink
|
|
101
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.linkToolbarMessages.editLink)), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
|
|
102
|
+
}
|
|
103
|
+
case 'edit-datasource':
|
|
104
|
+
{
|
|
105
|
+
return (0, _react2.jsx)(_primitives.Flex, {
|
|
106
|
+
gap: "space.050"
|
|
107
|
+
}, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
|
|
108
|
+
testId: "edit-datasource",
|
|
109
|
+
tooltipContent: intl.formatMessage(_messages.linkToolbarMessages.editDatasourceStandaloneTooltip),
|
|
110
|
+
onClick: onEditDatasource
|
|
111
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.linkToolbarMessages.editDatasourceStandalone)), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
|
|
112
|
+
}
|
|
113
|
+
case 'edit-dropdown':
|
|
114
|
+
{
|
|
115
|
+
var trigger = (0, _react2.jsx)(_primitives.Flex, {
|
|
116
|
+
gap: "space.050"
|
|
117
|
+
}, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
|
|
118
|
+
testId: "edit-dropdown-trigger",
|
|
119
|
+
iconAfter: (0, _react2.jsx)("span", {
|
|
120
|
+
css: dropdownExpandContainer
|
|
121
|
+
}, (0, _react2.jsx)(_chevronDown.default, {
|
|
122
|
+
label: intl.formatMessage(_messages.cardMessages.editDropdownTriggerTitle)
|
|
123
|
+
})),
|
|
124
|
+
onClick: toggleOpen,
|
|
125
|
+
selected: isOpen,
|
|
126
|
+
disabled: false,
|
|
127
|
+
ariaHasPopup: true
|
|
128
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownTriggerTitle)), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
|
|
129
|
+
return (0, _react2.jsx)(_primitives.Flex, {
|
|
130
|
+
ref: containerRef
|
|
131
|
+
}, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
|
|
132
|
+
mountTo: containerRef.current,
|
|
133
|
+
isOpen: isOpen,
|
|
134
|
+
handleClickOutside: onClose,
|
|
135
|
+
handleEscapeKeydown: onClose,
|
|
136
|
+
trigger: trigger,
|
|
137
|
+
scrollableElement: containerRef.current,
|
|
138
|
+
arrowKeyNavigationProviderOptions: {
|
|
139
|
+
type: _uiMenu.ArrowKeyNavigationType.MENU
|
|
140
|
+
}
|
|
141
|
+
}, (0, _react2.jsx)(_menu.ButtonItem, {
|
|
142
|
+
key: "edit.link",
|
|
143
|
+
onClick: onEditLink,
|
|
144
|
+
testId: "edit-dropdown-edit-link-item"
|
|
145
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditLinkTitle)), (0, _react2.jsx)(_menu.ButtonItem, {
|
|
146
|
+
key: "edit.datasource",
|
|
147
|
+
onClick: onEditDatasource,
|
|
148
|
+
testId: "edit-dropdown-edit-datasource-item"
|
|
149
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditDatasourceTitle))));
|
|
150
|
+
}
|
|
151
|
+
case 'none':
|
|
152
|
+
default:
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var EditToolbarButtonWithUrl = function EditToolbarButtonWithUrl(props) {
|
|
157
|
+
var cardContext = props.cardContext,
|
|
158
|
+
currentAppearance = props.currentAppearance,
|
|
159
|
+
editorAnalyticsApi = props.editorAnalyticsApi,
|
|
160
|
+
editorView = props.editorView,
|
|
161
|
+
intl = props.intl,
|
|
162
|
+
onLinkEditClick = props.onLinkEditClick,
|
|
163
|
+
url = props.url;
|
|
164
|
+
var _useFetchDatasourceIn2 = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
|
|
165
|
+
isRegularCardNode: true,
|
|
166
|
+
url: url,
|
|
167
|
+
cardContext: cardContext
|
|
168
|
+
}),
|
|
169
|
+
extensionKey = _useFetchDatasourceIn2.extensionKey,
|
|
170
|
+
datasourceId = _useFetchDatasourceIn2.datasourceId;
|
|
171
|
+
var editVariant = (0, _react.useMemo)(function () {
|
|
172
|
+
var _cardContext$store2, _urlState$error2;
|
|
173
|
+
if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
|
|
174
|
+
return 'edit-link';
|
|
175
|
+
}
|
|
176
|
+
var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store2 = cardContext.store) === null || _cardContext$store2 === void 0 ? void 0 : _cardContext$store2.getState()[url];
|
|
177
|
+
if ((urlState === null || urlState === void 0 || (_urlState$error2 = urlState.error) === null || _urlState$error2 === void 0 ? void 0 : _urlState$error2.kind) === 'fatal') {
|
|
178
|
+
return 'edit-link';
|
|
179
|
+
}
|
|
180
|
+
return 'edit-dropdown';
|
|
181
|
+
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
182
|
+
return (0, _react2.jsx)(_EditToolbarButtonPresentation.default, {
|
|
183
|
+
datasourceId: datasourceId,
|
|
184
|
+
currentAppearance: currentAppearance,
|
|
185
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
186
|
+
editVariant: editVariant,
|
|
187
|
+
editorView: editorView,
|
|
188
|
+
extensionKey: extensionKey,
|
|
189
|
+
onLinkEditClick: onLinkEditClick,
|
|
190
|
+
intl: intl
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
var EditToolbarButtonWithDatasourceId = function EditToolbarButtonWithDatasourceId(props) {
|
|
194
|
+
var currentAppearance = props.currentAppearance,
|
|
195
|
+
editorAnalyticsApi = props.editorAnalyticsApi,
|
|
196
|
+
editorView = props.editorView,
|
|
197
|
+
intl = props.intl,
|
|
198
|
+
onLinkEditClick = props.onLinkEditClick,
|
|
199
|
+
datasourceId = props.datasourceId,
|
|
200
|
+
node = props.node;
|
|
201
|
+
var fetchData = (0, _react.useMemo)(function () {
|
|
202
|
+
try {
|
|
203
|
+
var _attrs$datasource$vie;
|
|
204
|
+
var attrs = node.attrs;
|
|
205
|
+
var parameters = attrs.datasource.parameters;
|
|
206
|
+
var visibleColumnKeys = (_attrs$datasource$vie = attrs.datasource.views[0]) === null || _attrs$datasource$vie === void 0 || (_attrs$datasource$vie = _attrs$datasource$vie.properties) === null || _attrs$datasource$vie === void 0 ? void 0 : _attrs$datasource$vie.columns.map(function (c) {
|
|
207
|
+
return c.key;
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
parameters: parameters,
|
|
211
|
+
visibleColumnKeys: visibleColumnKeys
|
|
212
|
+
};
|
|
213
|
+
} catch (e) {
|
|
214
|
+
// eslint-disable-next-line no-console
|
|
215
|
+
console.error(e);
|
|
216
|
+
}
|
|
217
|
+
}, [node.attrs]);
|
|
218
|
+
var _useFetchDatasourceDa = (0, _useFetchDatasourceDataInfo.useFetchDatasourceDataInfo)({
|
|
219
|
+
datasourceId: datasourceId,
|
|
220
|
+
parameters: fetchData === null || fetchData === void 0 ? void 0 : fetchData.parameters,
|
|
221
|
+
visibleColumnKeys: fetchData === null || fetchData === void 0 ? void 0 : fetchData.visibleColumnKeys
|
|
222
|
+
}),
|
|
223
|
+
extensionKey = _useFetchDatasourceDa.extensionKey;
|
|
224
|
+
var editVariant = (0, _react.useMemo)(function () {
|
|
225
|
+
if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
|
|
226
|
+
return 'none';
|
|
227
|
+
}
|
|
228
|
+
return 'edit-datasource';
|
|
229
|
+
}, [datasourceId]);
|
|
230
|
+
return (0, _react2.jsx)(_EditToolbarButtonPresentation.default, {
|
|
231
|
+
datasourceId: datasourceId,
|
|
232
|
+
currentAppearance: currentAppearance,
|
|
233
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
234
|
+
editVariant: editVariant,
|
|
235
|
+
editorView: editorView,
|
|
236
|
+
extensionKey: extensionKey,
|
|
237
|
+
onLinkEditClick: onLinkEditClick,
|
|
238
|
+
intl: intl
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
var EditToolbarButton = exports.EditToolbarButton = function EditToolbarButton(props) {
|
|
242
|
+
var currentAppearance = props.currentAppearance,
|
|
243
|
+
datasourceId = props.datasourceId,
|
|
244
|
+
editorAnalyticsApi = props.editorAnalyticsApi,
|
|
245
|
+
editorView = props.editorView,
|
|
246
|
+
intl = props.intl,
|
|
247
|
+
onLinkEditClick = props.onLinkEditClick,
|
|
248
|
+
url = props.url;
|
|
249
|
+
return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref) {
|
|
250
|
+
var cardContext = _ref.cardContext;
|
|
251
|
+
if ((0, _platformFeatureFlags.fg)('enable_datasource_nourl_edit_dropdown_datafetch')) {
|
|
252
|
+
if (props.url) {
|
|
253
|
+
return (0, _react2.jsx)(EditToolbarButtonWithUrl, {
|
|
254
|
+
url: props.url,
|
|
255
|
+
intl: intl,
|
|
256
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
257
|
+
editorView: editorView,
|
|
258
|
+
cardContext: cardContext,
|
|
259
|
+
onLinkEditClick: onLinkEditClick,
|
|
260
|
+
currentAppearance: currentAppearance
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (props.datasourceId && props.node) {
|
|
264
|
+
return (0, _react2.jsx)(EditToolbarButtonWithDatasourceId, {
|
|
265
|
+
datasourceId: props.datasourceId,
|
|
266
|
+
node: props.node,
|
|
267
|
+
intl: intl,
|
|
268
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
269
|
+
editorView: editorView,
|
|
270
|
+
onLinkEditClick: onLinkEditClick,
|
|
271
|
+
currentAppearance: currentAppearance
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return (0, _react2.jsx)(EditToolbarButtonWithCardContext, {
|
|
276
|
+
datasourceId: datasourceId,
|
|
277
|
+
url: url,
|
|
278
|
+
intl: intl,
|
|
279
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
280
|
+
editorView: editorView,
|
|
281
|
+
cardContext: cardContext,
|
|
282
|
+
onLinkEditClick: onLinkEditClick,
|
|
283
|
+
currentAppearance: currentAppearance
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useFetchDatasourceDataInfo = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _linkClientExtension = require("@atlaskit/link-client-extension");
|
|
13
|
+
/** @jsx jsx */
|
|
14
|
+
|
|
15
|
+
var useFetchDatasourceDataInfo = exports.useFetchDatasourceDataInfo = function useFetchDatasourceDataInfo(_ref) {
|
|
16
|
+
var datasourceId = _ref.datasourceId,
|
|
17
|
+
parameters = _ref.parameters,
|
|
18
|
+
visibleColumnKeys = _ref.visibleColumnKeys;
|
|
19
|
+
var _useState = (0, _react.useState)(undefined),
|
|
20
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
21
|
+
extensionKey = _useState2[0],
|
|
22
|
+
setExtensionKey = _useState2[1];
|
|
23
|
+
var _useDatasourceClientE = (0, _linkClientExtension.useDatasourceClientExtension)(),
|
|
24
|
+
getDatasourceData = _useDatasourceClientE.getDatasourceData;
|
|
25
|
+
(0, _react.useEffect)(function () {
|
|
26
|
+
var fetchDatasource = /*#__PURE__*/function () {
|
|
27
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
28
|
+
var datasourceDataRequest, _yield$getDatasourceD, meta;
|
|
29
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
30
|
+
while (1) switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_context.prev = 0;
|
|
33
|
+
if (!(!datasourceId || !parameters || !visibleColumnKeys)) {
|
|
34
|
+
_context.next = 3;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return _context.abrupt("return");
|
|
38
|
+
case 3:
|
|
39
|
+
datasourceDataRequest = {
|
|
40
|
+
parameters: parameters,
|
|
41
|
+
pageSize: _linkClientExtension.DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE,
|
|
42
|
+
pageCursor: undefined,
|
|
43
|
+
fields: visibleColumnKeys,
|
|
44
|
+
includeSchema: true
|
|
45
|
+
};
|
|
46
|
+
_context.next = 6;
|
|
47
|
+
return getDatasourceData(datasourceId, datasourceDataRequest, false);
|
|
48
|
+
case 6:
|
|
49
|
+
_yield$getDatasourceD = _context.sent;
|
|
50
|
+
meta = _yield$getDatasourceD.meta;
|
|
51
|
+
setExtensionKey(meta.extensionKey);
|
|
52
|
+
_context.next = 15;
|
|
53
|
+
break;
|
|
54
|
+
case 11:
|
|
55
|
+
_context.prev = 11;
|
|
56
|
+
_context.t0 = _context["catch"](0);
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
console.error(_context.t0);
|
|
59
|
+
setExtensionKey(undefined);
|
|
60
|
+
case 15:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee, null, [[0, 11]]);
|
|
65
|
+
}));
|
|
66
|
+
return function fetchDatasource() {
|
|
67
|
+
return _ref2.apply(this, arguments);
|
|
68
|
+
};
|
|
69
|
+
}();
|
|
70
|
+
void fetchDatasource();
|
|
71
|
+
}, [getDatasourceData, visibleColumnKeys, parameters, datasourceId]);
|
|
72
|
+
return {
|
|
73
|
+
extensionKey: extensionKey
|
|
74
|
+
};
|
|
75
|
+
};
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -464,6 +464,7 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
|
|
|
464
464
|
fallback: [],
|
|
465
465
|
render: editorView => /*#__PURE__*/React.createElement(EditToolbarButton, {
|
|
466
466
|
datasourceId: datasourceId,
|
|
467
|
+
node: node,
|
|
467
468
|
key: "edit-toolbar-item",
|
|
468
469
|
url: metadata.url,
|
|
469
470
|
intl: intl,
|
package/dist/es2019/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
5
5
|
import { css, jsx } from '@emotion/react';
|
|
@@ -10,33 +10,21 @@ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlask
|
|
|
10
10
|
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
11
11
|
import { ButtonItem } from '@atlaskit/menu';
|
|
12
12
|
import { Flex } from '@atlaskit/primitives';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { CardContextProvider } from './CardContextProvider';
|
|
16
|
-
import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
|
|
13
|
+
import { focusEditorView } from '../../utils';
|
|
14
|
+
import { editDatasource } from '../EditDatasourceButton';
|
|
17
15
|
const dropdownExpandContainer = css({
|
|
18
16
|
margin: `0px ${"var(--ds-space-negative-050, -4px)"}`
|
|
19
17
|
});
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = props;
|
|
31
|
-
const {
|
|
32
|
-
extensionKey,
|
|
33
|
-
...response
|
|
34
|
-
} = useFetchDatasourceInfo({
|
|
35
|
-
isRegularCardNode: true,
|
|
36
|
-
url,
|
|
37
|
-
cardContext
|
|
38
|
-
});
|
|
39
|
-
const datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
|
|
18
|
+
const EditToolbarButtonPresentation = ({
|
|
19
|
+
datasourceId,
|
|
20
|
+
currentAppearance,
|
|
21
|
+
editorAnalyticsApi,
|
|
22
|
+
editVariant,
|
|
23
|
+
editorView,
|
|
24
|
+
extensionKey,
|
|
25
|
+
onLinkEditClick,
|
|
26
|
+
intl
|
|
27
|
+
}) => {
|
|
40
28
|
const [isOpen, setIsOpen] = useState(false);
|
|
41
29
|
const containerRef = useRef();
|
|
42
30
|
const toggleOpen = () => setIsOpen(open => !open);
|
|
@@ -47,25 +35,6 @@ const EditToolbarButtonWithCardContext = props => {
|
|
|
47
35
|
focusEditorView(editorView);
|
|
48
36
|
}
|
|
49
37
|
}, [editorView, onLinkEditClick]);
|
|
50
|
-
const editVariant = useMemo(() => {
|
|
51
|
-
const hasUrl = url !== null && url !== undefined;
|
|
52
|
-
if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
|
|
53
|
-
if (hasUrl) {
|
|
54
|
-
return 'edit-link';
|
|
55
|
-
}
|
|
56
|
-
return 'none';
|
|
57
|
-
}
|
|
58
|
-
if (hasUrl) {
|
|
59
|
-
var _cardContext$store, _urlState$error;
|
|
60
|
-
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
61
|
-
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
62
|
-
return 'edit-link';
|
|
63
|
-
}
|
|
64
|
-
return 'edit-dropdown';
|
|
65
|
-
} else {
|
|
66
|
-
return 'edit-datasource';
|
|
67
|
-
}
|
|
68
|
-
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
69
38
|
const onEditDatasource = useCallback(() => {
|
|
70
39
|
if (editorView && datasourceId) {
|
|
71
40
|
editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
|
|
@@ -135,26 +104,4 @@ const EditToolbarButtonWithCardContext = props => {
|
|
|
135
104
|
return null;
|
|
136
105
|
}
|
|
137
106
|
};
|
|
138
|
-
export
|
|
139
|
-
const {
|
|
140
|
-
currentAppearance,
|
|
141
|
-
datasourceId,
|
|
142
|
-
editorAnalyticsApi,
|
|
143
|
-
editorView,
|
|
144
|
-
intl,
|
|
145
|
-
onLinkEditClick,
|
|
146
|
-
url
|
|
147
|
-
} = props;
|
|
148
|
-
return jsx(CardContextProvider, null, ({
|
|
149
|
-
cardContext
|
|
150
|
-
}) => jsx(EditToolbarButtonWithCardContext, {
|
|
151
|
-
datasourceId: datasourceId,
|
|
152
|
-
url: url,
|
|
153
|
-
intl: intl,
|
|
154
|
-
editorAnalyticsApi: editorAnalyticsApi,
|
|
155
|
-
editorView: editorView,
|
|
156
|
-
cardContext: cardContext,
|
|
157
|
-
onLinkEditClick: onLinkEditClick,
|
|
158
|
-
currentAppearance: currentAppearance
|
|
159
|
-
}));
|
|
160
|
-
};
|
|
107
|
+
export default EditToolbarButtonPresentation;
|