@atlaskit/editor-plugin-card 1.10.3 → 1.11.1

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.
@@ -1,53 +1,68 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, CONFLUENCE_SEARCH_DATASOURCE_ID, ConfluenceSearchConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
4
3
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
4
  import { hideDatasourceModal } from '../../pm-plugins/actions';
6
5
  import { insertDatasource, updateCardViaDatasource } from '../../pm-plugins/doc';
7
6
  import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
8
7
  export const DatasourceModal = ({
9
8
  view,
10
- modalType,
11
- cardContext
9
+ cardContext,
10
+ datasourceId: defaultDatasourceId,
11
+ componentType: Component
12
12
  }) => {
13
- var _existingNode, _existingNode$attrs, _existingNode2, _existingNode3, _existingNode3$attrs, _existingNode3$attrs$;
13
+ var _existingNode$attrs, _existingNode$attrs2;
14
14
  const {
15
- dispatch,
16
15
  state
17
16
  } = view;
17
+ const existingNode = getExistingNode(state);
18
18
  const {
19
- selection
20
- } = state;
21
- let existingNode;
22
- if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar')) {
23
- // Check if the selection contains a link mark
24
- const $pos = state.doc.resolve(selection.from);
25
- const isLinkMark = $pos.marks().some(mark => mark.type === state.schema.marks.link);
26
-
27
- // When selection is a TextNode and a link Mark is present return that node
28
- if (selection instanceof NodeSelection) {
29
- existingNode = selection.node;
30
- } else if (isLinkMark) {
31
- var _state$doc$nodeAt;
32
- existingNode = (_state$doc$nodeAt = state.doc.nodeAt(selection.from)) !== null && _state$doc$nodeAt !== void 0 ? _state$doc$nodeAt : undefined;
19
+ dispatch,
20
+ state: {
21
+ tr: transaction
33
22
  }
34
- } else {
35
- existingNode = selection instanceof NodeSelection ? selection.node : undefined;
36
- }
37
- const isRegularCardNode = !!(existingNode && !((_existingNode = existingNode) !== null && _existingNode !== void 0 && (_existingNode$attrs = _existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
23
+ } = view;
24
+ const onClose = useCallback(() => {
25
+ dispatch(hideDatasourceModal(transaction));
26
+ }, [dispatch, transaction]);
27
+ const onInsert = useOnInsert(view, existingNode);
28
+ const isRegularCardNode = !!(existingNode && !(existingNode !== null && existingNode !== void 0 && (_existingNode$attrs = existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
29
+ const {
30
+ id: datasourceId = defaultDatasourceId,
31
+ views = [],
32
+ parameters: nodeParameters
33
+ } = (existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.datasource) || {};
34
+ const {
35
+ visibleColumnKeys,
36
+ wrappedColumnKeys,
37
+ columnCustomSizes
38
+ } = resolveColumnsConfig(views);
38
39
  const {
39
40
  parameters,
40
41
  ready
41
42
  } = useFetchDatasourceInfo({
42
43
  isRegularCardNode,
43
- url: (_existingNode2 = existingNode) === null || _existingNode2 === void 0 ? void 0 : _existingNode2.attrs.url,
44
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
44
45
  cardContext,
45
- nodeParameters: (_existingNode3 = existingNode) === null || _existingNode3 === void 0 ? void 0 : (_existingNode3$attrs = _existingNode3.attrs) === null || _existingNode3$attrs === void 0 ? void 0 : (_existingNode3$attrs$ = _existingNode3$attrs.datasource) === null || _existingNode3$attrs$ === void 0 ? void 0 : _existingNode3$attrs$.parameters
46
+ nodeParameters
46
47
  });
47
- const onClose = useCallback(() => {
48
- dispatch(hideDatasourceModal(view.state.tr));
49
- }, [dispatch, view.state.tr]);
50
- const onInsert = useCallback((newAdf, analyticEvent) => {
48
+ if (!ready) {
49
+ return null;
50
+ }
51
+ return /*#__PURE__*/React.createElement(Component, {
52
+ datasourceId: datasourceId,
53
+ viewMode: isRegularCardNode ? 'inline' : 'table' // Want non-datasource cards to open in inline view since they are in table view
54
+ ,
55
+ parameters: parameters,
56
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
57
+ visibleColumnKeys: visibleColumnKeys,
58
+ columnCustomSizes: columnCustomSizes,
59
+ wrappedColumnKeys: wrappedColumnKeys,
60
+ onCancel: onClose,
61
+ onInsert: onInsert
62
+ });
63
+ };
64
+ const useOnInsert = (view, existingNode) => {
65
+ return useCallback((newAdf, analyticEvent) => {
51
66
  if (analyticEvent) {
52
67
  analyticEvent.update(payload => ({
53
68
  ...payload,
@@ -69,116 +84,54 @@ export const DatasourceModal = ({
69
84
  insertDatasource(view.state, newAdf, view, analyticEvent);
70
85
  }
71
86
  }, [existingNode, view]);
72
- if (modalType === 'jira') {
73
- var _existingNode4, _existingNode4$attrs, _tableView$properties, _existingNode5;
74
- if (!ready) {
75
- return null;
76
- }
77
- const {
78
- id: datasourceId = JIRA_LIST_OF_LINKS_DATASOURCE_ID,
79
- views = []
80
- } = ((_existingNode4 = existingNode) === null || _existingNode4 === void 0 ? void 0 : (_existingNode4$attrs = _existingNode4.attrs) === null || _existingNode4$attrs === void 0 ? void 0 : _existingNode4$attrs.datasource) || {};
81
- const [tableView] = views;
82
- const visibleColumnKeys = [];
83
- const wrappedColumnKeys = [];
84
- let columnCustomSizes;
85
- const columns = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns;
86
- if (columns) {
87
- columnCustomSizes = {};
88
- for (const {
89
- key,
90
- width,
91
- isWrapped
92
- } of columns) {
93
- visibleColumnKeys.push(key);
94
- if (width) {
95
- columnCustomSizes[key] = width;
96
- }
97
- if (isWrapped) {
98
- wrappedColumnKeys.push(key);
99
- }
100
- }
101
- }
102
- return /*#__PURE__*/React.createElement("div", {
103
- "data-testid": "jira-config-modal"
104
- }, /*#__PURE__*/React.createElement(JiraIssuesConfigModal, {
105
- datasourceId: datasourceId,
106
- viewMode: isRegularCardNode ? 'inline' : 'table' // Want non-datasource cards to open in inline view since they are in table view
107
- ,
108
- visibleColumnKeys: visibleColumnKeys,
109
- parameters: parameters,
110
- url: (_existingNode5 = existingNode) === null || _existingNode5 === void 0 ? void 0 : _existingNode5.attrs.url,
111
- columnCustomSizes: columnCustomSizes,
112
- wrappedColumnKeys: wrappedColumnKeys,
113
- onCancel: onClose,
114
- onInsert: onInsert
115
- }));
116
- }
117
- if (modalType === 'assets') {
118
- var _existingNode6, _existingNode6$attrs, _tableView$properties2;
119
- const {
120
- id: datasourceId = ASSETS_LIST_OF_LINKS_DATASOURCE_ID,
121
- parameters,
122
- views = []
123
- } = ((_existingNode6 = existingNode) === null || _existingNode6 === void 0 ? void 0 : (_existingNode6$attrs = _existingNode6.attrs) === null || _existingNode6$attrs === void 0 ? void 0 : _existingNode6$attrs.datasource) || {};
124
- const [tableView] = views;
125
- const visibleColumnKeys = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties2 = tableView.properties) === null || _tableView$properties2 === void 0 ? void 0 : _tableView$properties2.columns.map(column => column.key);
126
- return /*#__PURE__*/React.createElement("div", {
127
- "data-testid": "assets-config-modal"
128
- }, /*#__PURE__*/React.createElement(AssetsConfigModal, {
129
- datasourceId: datasourceId,
130
- visibleColumnKeys: visibleColumnKeys,
131
- parameters: parameters,
132
- onCancel: onClose,
133
- onInsert: onInsert
134
- }));
135
- }
87
+ };
88
+ const getExistingNode = state => {
89
+ const {
90
+ selection
91
+ } = state;
92
+ let existingNode;
93
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar')) {
94
+ // Check if the selection contains a link mark
95
+ const isLinkMark = state.doc.resolve(selection.from).marks().some(mark => mark.type === state.schema.marks.link);
136
96
 
137
- // TODO: further refactor in https://product-fabric.atlassian.net/browse/EDM-9637
138
- if (modalType === 'confluence-search') {
139
- var _existingNode7, _existingNode7$attrs, _tableView$properties3, _existingNode8;
140
- if (!ready) {
141
- return null;
97
+ // When selection is a TextNode and a link Mark is present return that node
98
+ if (selection instanceof NodeSelection) {
99
+ existingNode = selection.node;
100
+ } else if (isLinkMark) {
101
+ var _state$doc$nodeAt;
102
+ existingNode = (_state$doc$nodeAt = state.doc.nodeAt(selection.from)) !== null && _state$doc$nodeAt !== void 0 ? _state$doc$nodeAt : undefined;
142
103
  }
143
- const {
144
- id: datasourceId = CONFLUENCE_SEARCH_DATASOURCE_ID,
145
- parameters,
146
- views = []
147
- } = ((_existingNode7 = existingNode) === null || _existingNode7 === void 0 ? void 0 : (_existingNode7$attrs = _existingNode7.attrs) === null || _existingNode7$attrs === void 0 ? void 0 : _existingNode7$attrs.datasource) || {};
148
- const [tableView] = views;
149
- const visibleColumnKeys = [];
150
- const wrappedColumnKeys = [];
151
- let columnCustomSizes;
152
- const columns = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties3 = tableView.properties) === null || _tableView$properties3 === void 0 ? void 0 : _tableView$properties3.columns;
153
- if (columns) {
154
- columnCustomSizes = {};
155
- for (const {
156
- key,
157
- width,
158
- isWrapped
159
- } of columns) {
160
- visibleColumnKeys.push(key);
161
- if (width) {
162
- columnCustomSizes[key] = width;
163
- }
164
- if (isWrapped) {
165
- wrappedColumnKeys.push(key);
166
- }
104
+ } else {
105
+ existingNode = selection instanceof NodeSelection ? selection.node : undefined;
106
+ }
107
+ return existingNode;
108
+ };
109
+ const resolveColumnsConfig = views => {
110
+ var _tableView$properties;
111
+ const [tableView] = views;
112
+ const visibleColumnKeys = [];
113
+ const wrappedColumnKeys = [];
114
+ let columnCustomSizes;
115
+ const columns = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns;
116
+ if (columns) {
117
+ columnCustomSizes = {};
118
+ for (const {
119
+ key,
120
+ width,
121
+ isWrapped
122
+ } of columns) {
123
+ visibleColumnKeys.push(key);
124
+ if (width) {
125
+ columnCustomSizes[key] = width;
126
+ }
127
+ if (isWrapped) {
128
+ wrappedColumnKeys.push(key);
167
129
  }
168
130
  }
169
- return /*#__PURE__*/React.createElement("div", {
170
- "data-testid": "confluence-search-config-modal"
171
- }, /*#__PURE__*/React.createElement(ConfluenceSearchConfigModal, {
172
- datasourceId: datasourceId,
173
- viewMode: isRegularCardNode ? 'inline' : 'table',
174
- visibleColumnKeys: visibleColumnKeys,
175
- parameters: parameters,
176
- url: (_existingNode8 = existingNode) === null || _existingNode8 === void 0 ? void 0 : _existingNode8.attrs.url,
177
- columnCustomSizes: columnCustomSizes,
178
- wrappedColumnKeys: wrappedColumnKeys,
179
- onCancel: onClose,
180
- onInsert: onInsert
181
- }));
182
131
  }
183
- return null; // null for now until we have modal component that handles other datasources
132
+ return {
133
+ visibleColumnKeys,
134
+ wrappedColumnKeys,
135
+ columnCustomSizes
136
+ };
184
137
  };
@@ -5,13 +5,13 @@ import { cardMessages as messages } from '@atlaskit/editor-common/messages';
5
5
  import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
6
6
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
7
7
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
- import TableIcon from '@atlaskit/icon/glyph/table';
9
8
  import { buildDatasourceAdf } from '@atlaskit/link-datasource';
10
9
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
10
  import { Flex } from '@atlaskit/primitives';
12
11
  import { updateCardViaDatasource } from '../pm-plugins/doc';
13
12
  import { pluginKey } from '../pm-plugins/plugin-key';
14
13
  import { CardContextProvider } from './CardContextProvider';
14
+ import { DatasourceIcon } from './DatasourceIcon';
15
15
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
16
16
  var buttonStyles = css({
17
17
  pointerEvents: 'auto'
@@ -89,7 +89,7 @@ var DatasourceAppearanceButtonWithCardContext = function DatasourceAppearanceBut
89
89
  return jsx(Flex, null, jsx(Button, {
90
90
  css: buttonStyles,
91
91
  title: buttonLabel,
92
- icon: jsx(TableIcon, {
92
+ icon: jsx(DatasourceIcon, {
93
93
  label: buttonLabel
94
94
  }),
95
95
  selected: selected,
@@ -0,0 +1,32 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import Icon from '@atlaskit/icon';
4
+ import { Flex, xcss } from '@atlaskit/primitives';
5
+ var IconDatasourceGlyph = function IconDatasourceGlyph(props) {
6
+ return /*#__PURE__*/React.createElement("svg", _extends({
7
+ xmlns: "http://www.w3.org/2000/svg",
8
+ width: "15",
9
+ height: "15",
10
+ viewBox: "0 0 15 15",
11
+ fill: "none"
12
+ }, props), /*#__PURE__*/React.createElement("path", {
13
+ fillRule: "evenodd",
14
+ clipRule: "evenodd",
15
+ d: "M0 2C0 0.89543 0.895431 0 2 0H13C14.1046 0 15 0.895431 15 2V13C15 14.1046 14.1046 15 13 15H2C0.89543 15 0 14.1046 0 13V2ZM5 6C5 5.44772 5.44772 5 6 5L12 5C12.5523 5 13 5.44772 13 6C13 6.55229 12.5523 7 12 7L6 7C5.44772 7 5 6.55228 5 6ZM6 8C5.44772 8 5 8.44771 5 9C5 9.55228 5.44772 10 6 10L12 10C12.5523 10 13 9.55229 13 9C13 8.44772 12.5523 8 12 8L6 8ZM5 12C5 11.4477 5.44772 11 6 11L12 11C12.5523 11 13 11.4477 13 12C13 12.5523 12.5523 13 12 13L6 13C5.44772 13 5 12.5523 5 12ZM3 7C3.55228 7 4 6.55228 4 6C4 5.44772 3.55228 5 3 5C2.44772 5 2 5.44772 2 6C2 6.55228 2.44772 7 3 7ZM5 3C5 2.44772 5.44772 2 6 2L12 2C12.5523 2 13 2.44772 13 3C13 3.55229 12.5523 4 12 4L6 4C5.44772 4 5 3.55228 5 3ZM3 4C3.55228 4 4 3.55228 4 3C4 2.44772 3.55228 2 3 2C2.44772 2 2 2.44772 2 3C2 3.55228 2.44772 4 3 4ZM4 9C4 9.55229 3.55228 10 3 10C2.44772 10 2 9.55229 2 9C2 8.44771 2.44772 8 3 8C3.55228 8 4 8.44771 4 9ZM3 13C3.55228 13 4 12.5523 4 12C4 11.4477 3.55228 11 3 11C2.44772 11 2 11.4477 2 12C2 12.5523 2.44772 13 3 13Z",
16
+ fill: 'currentColor'
17
+ }));
18
+ };
19
+ var wrapperStyles = xcss({
20
+ padding: 'space.050',
21
+ justifyContent: 'center',
22
+ alignItems: 'center',
23
+ width: 'space.300',
24
+ height: 'space.300'
25
+ });
26
+ export var DatasourceIcon = function DatasourceIcon(props) {
27
+ return /*#__PURE__*/React.createElement(Flex, {
28
+ xcss: wrapperStyles
29
+ }, /*#__PURE__*/React.createElement(Icon, _extends({
30
+ glyph: IconDatasourceGlyph
31
+ }, props)));
32
+ };
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, CONFLUENCE_SEARCH_DATASOURCE_ID, ConfluenceSearchConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
3
4
  import { DatasourceErrorBoundary } from '../../datasourceErrorBoundary';
4
5
  import { CardContextProvider } from '../CardContextProvider';
5
6
  import { DatasourceModal } from './index';
@@ -8,19 +9,42 @@ var ModalWithState = function ModalWithState(_ref) {
8
9
  editorView = _ref.editorView;
9
10
  var _useSharedPluginState = useSharedPluginState(api, ['card']),
10
11
  cardState = _useSharedPluginState.cardState;
11
- if (!(cardState !== null && cardState !== void 0 && cardState.showDatasourceModal)) {
12
+ if (!cardState) {
12
13
  return null;
13
14
  }
15
+ var showDatasourceModal = cardState.showDatasourceModal,
16
+ datasourceModalType = cardState.datasourceModalType;
17
+ if (!showDatasourceModal || !datasourceModalType) {
18
+ return null;
19
+ }
20
+ var _modalTypeToComponent = modalTypeToComponentMap[datasourceModalType],
21
+ datasourceId = _modalTypeToComponent.datasourceId,
22
+ componentType = _modalTypeToComponent.componentType;
14
23
  return /*#__PURE__*/React.createElement(DatasourceErrorBoundary, {
15
24
  view: editorView,
16
- datasourceModalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
25
+ datasourceModalType: datasourceModalType
17
26
  }, /*#__PURE__*/React.createElement(CardContextProvider, null, function (_ref2) {
18
27
  var cardContext = _ref2.cardContext;
19
28
  return /*#__PURE__*/React.createElement(DatasourceModal, {
20
29
  view: editorView,
21
- modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType,
22
- cardContext: cardContext
30
+ cardContext: cardContext,
31
+ datasourceId: datasourceId,
32
+ componentType: componentType
23
33
  });
24
34
  }));
25
35
  };
36
+ export var modalTypeToComponentMap = {
37
+ jira: {
38
+ componentType: JiraIssuesConfigModal,
39
+ datasourceId: JIRA_LIST_OF_LINKS_DATASOURCE_ID
40
+ },
41
+ 'confluence-search': {
42
+ componentType: ConfluenceSearchConfigModal,
43
+ datasourceId: CONFLUENCE_SEARCH_DATASOURCE_ID
44
+ },
45
+ assets: {
46
+ componentType: AssetsConfigModal,
47
+ datasourceId: ASSETS_LIST_OF_LINKS_DATASOURCE_ID
48
+ }
49
+ };
26
50
  export default ModalWithState;