@atlaskit/link-datasource 0.28.5 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/link-datasource
2
2
 
3
+ ## 0.29.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`dd0db85e7b7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/dd0db85e7b7) - [ux] Added onInsertPressed method to insert ADF into doc and updated helper test mocks
8
+
3
9
  ## 0.28.5
4
10
 
5
11
  ### Patch Changes
@@ -12,6 +12,7 @@ var _react2 = require("@emotion/react");
12
12
  var _reactIntlNext = require("react-intl-next");
13
13
  var _standardButton = _interopRequireDefault(require("@atlaskit/button/standard-button"));
14
14
  var _modalDialog = _interopRequireWildcard(require("@atlaskit/modal-dialog"));
15
+ var _useAssetsClient2 = require("../../../hooks/useAssetsClient");
15
16
  var _useDatasourceTableState = require("../../../hooks/useDatasourceTableState");
16
17
  var _messages = require("./messages");
17
18
  var _renderAssetsContent = require("./render-assets-content");
@@ -23,13 +24,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
23
24
  var AssetsConfigModal = function AssetsConfigModal(props) {
24
25
  var datasourceId = props.datasourceId,
25
26
  initialParameters = props.parameters,
26
- onCancel = props.onCancel;
27
+ onCancel = props.onCancel,
28
+ onInsert = props.onInsert,
29
+ initialVisibleColumnKeys = props.visibleColumnKeys;
27
30
  var _useState = (0, _react.useState)(initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.aql),
28
31
  _useState2 = (0, _slicedToArray2.default)(_useState, 1),
29
32
  aql = _useState2[0];
30
33
  var _useState3 = (0, _react.useState)(initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId),
31
34
  _useState4 = (0, _slicedToArray2.default)(_useState3, 1),
32
35
  schemaId = _useState4[0];
36
+ var _useState5 = (0, _react.useState)(initialVisibleColumnKeys),
37
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
38
+ visibleColumnKeys = _useState6[0],
39
+ setVisibleColumnKeys = _useState6[1];
40
+ var _useAssetsClient = (0, _useAssetsClient2.useAssetsClient)(),
41
+ workspaceId = _useAssetsClient.workspaceId;
33
42
  var parameters = (0, _react.useMemo)(function () {
34
43
  return {
35
44
  aql: aql || '',
@@ -42,11 +51,59 @@ var AssetsConfigModal = function AssetsConfigModal(props) {
42
51
  parameters: parameters
43
52
  }),
44
53
  status = _useDatasourceTableSt.status,
45
- responseItems = _useDatasourceTableSt.responseItems;
46
- var isDisabled = status === 'rejected' || status === 'loading' || status === 'empty' || status === 'resolved' && !responseItems.length;
54
+ responseItems = _useDatasourceTableSt.responseItems,
55
+ defaultVisibleColumnKeys = _useDatasourceTableSt.defaultVisibleColumnKeys;
56
+ (0, _react.useEffect)(function () {
57
+ var newVisibleColumnKeys = !initialVisibleColumnKeys || (initialVisibleColumnKeys || []).length === 0 ? defaultVisibleColumnKeys : initialVisibleColumnKeys;
58
+ setVisibleColumnKeys(newVisibleColumnKeys);
59
+ }, [initialVisibleColumnKeys, defaultVisibleColumnKeys]);
60
+ var isDisabled = status === 'rejected' || status === 'loading' || status === 'empty' || !aql || !workspaceId || !schemaId;
61
+ var retrieveUrlForSmartCardRender = (0, _react.useCallback)(function () {
62
+ var _data$key, _data$key$data;
63
+ var _responseItems = (0, _slicedToArray2.default)(responseItems, 1),
64
+ data = _responseItems[0];
65
+ // agreement with BE that we will use `key` for rendering smartlink
66
+ return data === null || data === void 0 ? void 0 : (_data$key = data.key) === null || _data$key === void 0 ? void 0 : (_data$key$data = _data$key.data) === null || _data$key$data === void 0 ? void 0 : _data$key$data.url;
67
+ }, [responseItems]);
47
68
  var onInsertPressed = (0, _react.useCallback)(function () {
48
- /* Placeholder for inserting of ADF, to do in FLY-1241 */
49
- }, []);
69
+ if (!aql) {
70
+ return;
71
+ }
72
+ var firstAssetUrl = retrieveUrlForSmartCardRender();
73
+ if (responseItems.length === 1 && firstAssetUrl) {
74
+ onInsert({
75
+ type: 'inlineCard',
76
+ attrs: {
77
+ url: firstAssetUrl
78
+ }
79
+ });
80
+ } else {
81
+ onInsert({
82
+ type: 'blockCard',
83
+ attrs: {
84
+ datasource: {
85
+ id: datasourceId,
86
+ parameters: {
87
+ cloudId: '',
88
+ // TODO FLY-1278: get actual cloudID
89
+ aql: aql,
90
+ schemaId: schemaId
91
+ },
92
+ views: [{
93
+ type: 'table',
94
+ properties: {
95
+ columns: visibleColumnKeys === null || visibleColumnKeys === void 0 ? void 0 : visibleColumnKeys.map(function (key) {
96
+ return {
97
+ key: key
98
+ };
99
+ })
100
+ }
101
+ }]
102
+ }
103
+ }
104
+ });
105
+ }
106
+ }, [aql, datasourceId, onInsert, responseItems.length, retrieveUrlForSmartCardRender, schemaId, visibleColumnKeys]);
50
107
  return (0, _react2.jsx)(_modalDialog.ModalTransition, null, (0, _react2.jsx)(_modalDialog.default, {
51
108
  testId: 'asset-datasource-modal',
52
109
  onClose: onCancel,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-datasource",
3
- "version": "0.28.5",
3
+ "version": "0.29.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,9 +1,10 @@
1
1
  /** @jsx jsx */
2
- import { useCallback, useMemo, useState } from 'react';
2
+ import { useCallback, useEffect, useMemo, useState } from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import { FormattedMessage } from 'react-intl-next';
5
5
  import Button from '@atlaskit/button/standard-button';
6
6
  import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
7
+ import { useAssetsClient } from '../../../hooks/useAssetsClient';
7
8
  import { useDatasourceTableState } from '../../../hooks/useDatasourceTableState';
8
9
  import { modalMessages } from './messages';
9
10
  import { RenderAssetsContent } from './render-assets-content';
@@ -12,10 +13,16 @@ export const AssetsConfigModal = props => {
12
13
  const {
13
14
  datasourceId,
14
15
  parameters: initialParameters,
15
- onCancel
16
+ onCancel,
17
+ onInsert,
18
+ visibleColumnKeys: initialVisibleColumnKeys
16
19
  } = props;
17
20
  const [aql] = useState(initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.aql);
18
21
  const [schemaId] = useState(initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId);
22
+ const [visibleColumnKeys, setVisibleColumnKeys] = useState(initialVisibleColumnKeys);
23
+ const {
24
+ workspaceId
25
+ } = useAssetsClient();
19
26
  const parameters = useMemo(() => ({
20
27
  aql: aql || '',
21
28
  schemaId: schemaId || '',
@@ -23,15 +30,60 @@ export const AssetsConfigModal = props => {
23
30
  }), [aql, schemaId]);
24
31
  const {
25
32
  status,
26
- responseItems
33
+ responseItems,
34
+ defaultVisibleColumnKeys
27
35
  } = useDatasourceTableState({
28
36
  datasourceId,
29
37
  parameters
30
38
  });
31
- const isDisabled = status === 'rejected' || status === 'loading' || status === 'empty' || status === 'resolved' && !responseItems.length;
39
+ useEffect(() => {
40
+ const newVisibleColumnKeys = !initialVisibleColumnKeys || (initialVisibleColumnKeys || []).length === 0 ? defaultVisibleColumnKeys : initialVisibleColumnKeys;
41
+ setVisibleColumnKeys(newVisibleColumnKeys);
42
+ }, [initialVisibleColumnKeys, defaultVisibleColumnKeys]);
43
+ const isDisabled = status === 'rejected' || status === 'loading' || status === 'empty' || !aql || !workspaceId || !schemaId;
44
+ const retrieveUrlForSmartCardRender = useCallback(() => {
45
+ var _data$key, _data$key$data;
46
+ const [data] = responseItems;
47
+ // agreement with BE that we will use `key` for rendering smartlink
48
+ return data === null || data === void 0 ? void 0 : (_data$key = data.key) === null || _data$key === void 0 ? void 0 : (_data$key$data = _data$key.data) === null || _data$key$data === void 0 ? void 0 : _data$key$data.url;
49
+ }, [responseItems]);
32
50
  const onInsertPressed = useCallback(() => {
33
- /* Placeholder for inserting of ADF, to do in FLY-1241 */
34
- }, []);
51
+ if (!aql) {
52
+ return;
53
+ }
54
+ const firstAssetUrl = retrieveUrlForSmartCardRender();
55
+ if (responseItems.length === 1 && firstAssetUrl) {
56
+ onInsert({
57
+ type: 'inlineCard',
58
+ attrs: {
59
+ url: firstAssetUrl
60
+ }
61
+ });
62
+ } else {
63
+ onInsert({
64
+ type: 'blockCard',
65
+ attrs: {
66
+ datasource: {
67
+ id: datasourceId,
68
+ parameters: {
69
+ cloudId: '',
70
+ // TODO FLY-1278: get actual cloudID
71
+ aql: aql,
72
+ schemaId
73
+ },
74
+ views: [{
75
+ type: 'table',
76
+ properties: {
77
+ columns: visibleColumnKeys === null || visibleColumnKeys === void 0 ? void 0 : visibleColumnKeys.map(key => ({
78
+ key
79
+ }))
80
+ }
81
+ }]
82
+ }
83
+ }
84
+ });
85
+ }
86
+ }, [aql, datasourceId, onInsert, responseItems.length, retrieveUrlForSmartCardRender, schemaId, visibleColumnKeys]);
35
87
  return jsx(ModalTransition, null, jsx(Modal, {
36
88
  testId: 'asset-datasource-modal',
37
89
  onClose: onCancel,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-datasource",
3
- "version": "0.28.5",
3
+ "version": "0.29.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,10 +1,11 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
- import { useCallback, useMemo, useState } from 'react';
3
+ import { useCallback, useEffect, useMemo, useState } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
5
  import { FormattedMessage } from 'react-intl-next';
6
6
  import Button from '@atlaskit/button/standard-button';
7
7
  import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
8
+ import { useAssetsClient } from '../../../hooks/useAssetsClient';
8
9
  import { useDatasourceTableState } from '../../../hooks/useDatasourceTableState';
9
10
  import { modalMessages } from './messages';
10
11
  import { RenderAssetsContent } from './render-assets-content';
@@ -12,13 +13,21 @@ import { ModalContentContainer } from './styled';
12
13
  export var AssetsConfigModal = function AssetsConfigModal(props) {
13
14
  var datasourceId = props.datasourceId,
14
15
  initialParameters = props.parameters,
15
- onCancel = props.onCancel;
16
+ onCancel = props.onCancel,
17
+ onInsert = props.onInsert,
18
+ initialVisibleColumnKeys = props.visibleColumnKeys;
16
19
  var _useState = useState(initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.aql),
17
20
  _useState2 = _slicedToArray(_useState, 1),
18
21
  aql = _useState2[0];
19
22
  var _useState3 = useState(initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId),
20
23
  _useState4 = _slicedToArray(_useState3, 1),
21
24
  schemaId = _useState4[0];
25
+ var _useState5 = useState(initialVisibleColumnKeys),
26
+ _useState6 = _slicedToArray(_useState5, 2),
27
+ visibleColumnKeys = _useState6[0],
28
+ setVisibleColumnKeys = _useState6[1];
29
+ var _useAssetsClient = useAssetsClient(),
30
+ workspaceId = _useAssetsClient.workspaceId;
22
31
  var parameters = useMemo(function () {
23
32
  return {
24
33
  aql: aql || '',
@@ -31,11 +40,59 @@ export var AssetsConfigModal = function AssetsConfigModal(props) {
31
40
  parameters: parameters
32
41
  }),
33
42
  status = _useDatasourceTableSt.status,
34
- responseItems = _useDatasourceTableSt.responseItems;
35
- var isDisabled = status === 'rejected' || status === 'loading' || status === 'empty' || status === 'resolved' && !responseItems.length;
43
+ responseItems = _useDatasourceTableSt.responseItems,
44
+ defaultVisibleColumnKeys = _useDatasourceTableSt.defaultVisibleColumnKeys;
45
+ useEffect(function () {
46
+ var newVisibleColumnKeys = !initialVisibleColumnKeys || (initialVisibleColumnKeys || []).length === 0 ? defaultVisibleColumnKeys : initialVisibleColumnKeys;
47
+ setVisibleColumnKeys(newVisibleColumnKeys);
48
+ }, [initialVisibleColumnKeys, defaultVisibleColumnKeys]);
49
+ var isDisabled = status === 'rejected' || status === 'loading' || status === 'empty' || !aql || !workspaceId || !schemaId;
50
+ var retrieveUrlForSmartCardRender = useCallback(function () {
51
+ var _data$key, _data$key$data;
52
+ var _responseItems = _slicedToArray(responseItems, 1),
53
+ data = _responseItems[0];
54
+ // agreement with BE that we will use `key` for rendering smartlink
55
+ return data === null || data === void 0 ? void 0 : (_data$key = data.key) === null || _data$key === void 0 ? void 0 : (_data$key$data = _data$key.data) === null || _data$key$data === void 0 ? void 0 : _data$key$data.url;
56
+ }, [responseItems]);
36
57
  var onInsertPressed = useCallback(function () {
37
- /* Placeholder for inserting of ADF, to do in FLY-1241 */
38
- }, []);
58
+ if (!aql) {
59
+ return;
60
+ }
61
+ var firstAssetUrl = retrieveUrlForSmartCardRender();
62
+ if (responseItems.length === 1 && firstAssetUrl) {
63
+ onInsert({
64
+ type: 'inlineCard',
65
+ attrs: {
66
+ url: firstAssetUrl
67
+ }
68
+ });
69
+ } else {
70
+ onInsert({
71
+ type: 'blockCard',
72
+ attrs: {
73
+ datasource: {
74
+ id: datasourceId,
75
+ parameters: {
76
+ cloudId: '',
77
+ // TODO FLY-1278: get actual cloudID
78
+ aql: aql,
79
+ schemaId: schemaId
80
+ },
81
+ views: [{
82
+ type: 'table',
83
+ properties: {
84
+ columns: visibleColumnKeys === null || visibleColumnKeys === void 0 ? void 0 : visibleColumnKeys.map(function (key) {
85
+ return {
86
+ key: key
87
+ };
88
+ })
89
+ }
90
+ }]
91
+ }
92
+ }
93
+ });
94
+ }
95
+ }, [aql, datasourceId, onInsert, responseItems.length, retrieveUrlForSmartCardRender, schemaId, visibleColumnKeys]);
39
96
  return jsx(ModalTransition, null, jsx(Modal, {
40
97
  testId: 'asset-datasource-modal',
41
98
  onClose: onCancel,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-datasource",
3
- "version": "0.28.5",
3
+ "version": "0.29.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,7 @@
1
1
  import { ObjectSchema } from '../types/assets/types';
2
- export declare const useAssetsClient: (hostname?: string) => {
3
- workspaceId: string | undefined;
4
- objectSchemas: ObjectSchema[] | undefined;
5
- error: Error | undefined;
6
- };
2
+ export interface AssetsClientState {
3
+ workspaceId?: string;
4
+ objectSchemas?: ObjectSchema[];
5
+ error?: Error;
6
+ }
7
+ export declare const useAssetsClient: (hostname?: string) => AssetsClientState;
@@ -1,6 +1,7 @@
1
1
  import { ObjectSchema } from '../types/assets/types';
2
- export declare const useAssetsClient: (hostname?: string) => {
3
- workspaceId: string | undefined;
4
- objectSchemas: ObjectSchema[] | undefined;
5
- error: Error | undefined;
6
- };
2
+ export interface AssetsClientState {
3
+ workspaceId?: string;
4
+ objectSchemas?: ObjectSchema[];
5
+ error?: Error;
6
+ }
7
+ export declare const useAssetsClient: (hostname?: string) => AssetsClientState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/link-datasource",
3
- "version": "0.28.5",
3
+ "version": "0.29.0",
4
4
  "description": "UI Components to support linking platform dataset feature",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -50,7 +50,7 @@
50
50
  "@atlaskit/tag": "^11.5.0",
51
51
  "@atlaskit/textfield": "5.6.3",
52
52
  "@atlaskit/theme": "^12.5.0",
53
- "@atlaskit/tokens": "^1.12.0",
53
+ "@atlaskit/tokens": "^1.13.0",
54
54
  "@atlassianlabs/jql-editor": "^2.0.1",
55
55
  "@atlassianlabs/jql-editor-autocomplete-rest": "^1.1.2",
56
56
  "@babel/runtime": "^7.0.0",
@@ -66,7 +66,7 @@
66
66
  "devDependencies": {
67
67
  "@af/visual-regression": "*",
68
68
  "@atlaskit/link-provider": "^1.6.0",
69
- "@atlaskit/link-test-helpers": "^4.1.0",
69
+ "@atlaskit/link-test-helpers": "^4.2.0",
70
70
  "@atlaskit/ssr": "*",
71
71
  "@atlaskit/visual-regression": "*",
72
72
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",