@atlaskit/link-datasource 1.20.0 → 1.22.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/common/utils/adf.js +15 -0
  3. package/dist/cjs/hooks/useDatasourceTableState.js +91 -88
  4. package/dist/cjs/index.js +7 -0
  5. package/dist/cjs/ui/assets-modal/modal/index.js +18 -22
  6. package/dist/cjs/ui/common/error-state/messages.js +20 -0
  7. package/dist/cjs/ui/common/error-state/provider-auth-required-svg.js +449 -0
  8. package/dist/cjs/ui/common/error-state/provider-auth-required.js +96 -0
  9. package/dist/cjs/ui/datasource-table-view/datasourceTableView.js +16 -7
  10. package/dist/cjs/ui/jira-issues-modal/modal/index.js +18 -23
  11. package/dist/es2019/common/utils/adf.js +9 -0
  12. package/dist/es2019/hooks/useDatasourceTableState.js +26 -24
  13. package/dist/es2019/index.js +1 -0
  14. package/dist/es2019/ui/assets-modal/modal/index.js +16 -20
  15. package/dist/es2019/ui/common/error-state/messages.js +20 -0
  16. package/dist/es2019/ui/common/error-state/provider-auth-required-svg.js +442 -0
  17. package/dist/es2019/ui/common/error-state/provider-auth-required.js +62 -0
  18. package/dist/es2019/ui/datasource-table-view/datasourceTableView.js +16 -7
  19. package/dist/es2019/ui/jira-issues-modal/modal/index.js +16 -21
  20. package/dist/esm/common/utils/adf.js +9 -0
  21. package/dist/esm/hooks/useDatasourceTableState.js +91 -88
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/ui/assets-modal/modal/index.js +18 -22
  24. package/dist/esm/ui/common/error-state/messages.js +20 -0
  25. package/dist/esm/ui/common/error-state/provider-auth-required-svg.js +442 -0
  26. package/dist/esm/ui/common/error-state/provider-auth-required.js +85 -0
  27. package/dist/esm/ui/datasource-table-view/datasourceTableView.js +16 -7
  28. package/dist/esm/ui/jira-issues-modal/modal/index.js +18 -23
  29. package/dist/types/common/utils/adf.d.ts +2 -0
  30. package/dist/types/hooks/useDatasourceTableState.d.ts +3 -1
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/ui/assets-modal/types.d.ts +1 -1
  33. package/dist/types/ui/common/error-state/messages.d.ts +20 -0
  34. package/dist/types/ui/common/error-state/provider-auth-required-svg.d.ts +3 -0
  35. package/dist/types/ui/common/error-state/provider-auth-required.d.ts +9 -0
  36. package/dist/types/ui/jira-issues-modal/types.d.ts +1 -20
  37. package/dist/types-ts4.5/common/utils/adf.d.ts +2 -0
  38. package/dist/types-ts4.5/hooks/useDatasourceTableState.d.ts +3 -1
  39. package/dist/types-ts4.5/index.d.ts +1 -0
  40. package/dist/types-ts4.5/ui/assets-modal/types.d.ts +1 -1
  41. package/dist/types-ts4.5/ui/common/error-state/messages.d.ts +20 -0
  42. package/dist/types-ts4.5/ui/common/error-state/provider-auth-required-svg.d.ts +3 -0
  43. package/dist/types-ts4.5/ui/common/error-state/provider-auth-required.d.ts +9 -0
  44. package/dist/types-ts4.5/ui/jira-issues-modal/types.d.ts +1 -20
  45. package/examples-helpers/buildJiraIssuesTable.tsx +34 -6
  46. package/package.json +4 -3
@@ -30,6 +30,7 @@ var _ufoExperiences = require("../../../analytics/ufoExperiences");
30
30
  var _useColumnPickerRenderedFailedUfoExperience = require("../../../analytics/ufoExperiences/hooks/useColumnPickerRenderedFailedUfoExperience");
31
31
  var _useDataRenderedUfoExperience = require("../../../analytics/ufoExperiences/hooks/useDataRenderedUfoExperience");
32
32
  var _utils = require("../../../analytics/utils");
33
+ var _adf = require("../../../common/utils/adf");
33
34
  var _fetchMessagesForLocale = require("../../../common/utils/locale/fetch-messages-for-locale");
34
35
  var _useDatasourceTableState = require("../../../hooks/useDatasourceTableState");
35
36
  var _en = _interopRequireDefault(require("../../../i18n/en"));
@@ -418,31 +419,25 @@ var PlainJiraIssuesConfigModal = exports.PlainJiraIssuesConfigModal = function P
418
419
  }
419
420
  }, consumerEvent);
420
421
  } else {
421
- onInsert({
422
- type: 'blockCard',
423
- attrs: {
424
- url: upToDateJqlUrl,
425
- datasource: {
426
- id: datasourceId,
427
- parameters: {
428
- cloudId: cloudId,
429
- jql: upToDateJql // TODO support non JQL type
430
- },
422
+ onInsert((0, _adf.buildDatasourceAdf)({
423
+ id: datasourceId,
424
+ parameters: {
425
+ cloudId: cloudId,
426
+ jql: upToDateJql // TODO support non JQL type
427
+ },
431
428
 
432
- views: [{
433
- type: 'table',
434
- properties: {
435
- columns: visibleColumnKeys === null || visibleColumnKeys === void 0 ? void 0 : visibleColumnKeys.map(function (key) {
436
- return {
437
- key: key,
438
- width: columnCustomSizes === null || columnCustomSizes === void 0 ? void 0 : columnCustomSizes[key]
439
- };
440
- })
441
- }
442
- }]
429
+ views: [{
430
+ type: 'table',
431
+ properties: {
432
+ columns: (visibleColumnKeys || []).map(function (key) {
433
+ return {
434
+ key: key,
435
+ width: columnCustomSizes === null || columnCustomSizes === void 0 ? void 0 : columnCustomSizes[key]
436
+ };
437
+ })
443
438
  }
444
- }
445
- }, consumerEvent);
439
+ }]
440
+ }, upToDateJqlUrl), consumerEvent);
446
441
  }
447
442
  }, [isParametersSet, jql, selectedJiraSite, analyticsPayload, totalCount, visibleColumnKeys, currentViewMode, retrieveUrlForSmartCardRender, onInsert, datasourceId, cloudId, columnCustomSizes, searchBarJql, responseItems]);
448
443
  var handleViewModeChange = function handleViewModeChange(selectedMode) {
@@ -0,0 +1,9 @@
1
+ export const buildDatasourceAdf = (datasource, url) => {
2
+ return {
3
+ type: 'blockCard',
4
+ attrs: {
5
+ url,
6
+ datasource
7
+ }
8
+ };
9
+ };
@@ -16,12 +16,14 @@ export const useDatasourceTableState = ({
16
16
  } = useErrorLogger();
17
17
  const idFieldCount = 1;
18
18
  const keyFieldCount = 1;
19
+ const [initialEmptyArray] = useState([]);
19
20
  const [defaultVisibleColumnKeys, setDefaultVisibleColumnKeys] = useState([]);
20
21
  const [lastRequestedFieldKeys, setLastRequestedFieldKeys] = useState([]);
21
22
  const [fullSchema, setFullSchema] = useState({
22
23
  properties: []
23
24
  });
24
25
  const [status, setStatus] = useState('empty');
26
+ const [authDetails, setAuthDetails] = useState([]);
25
27
  const [responseItems, setResponseItems] = useState([]);
26
28
  const [hasNextPage, setHasNextPage] = useState(true);
27
29
  const [nextCursor, setNextCursor] = useState(undefined);
@@ -41,7 +43,8 @@ export const useDatasourceTableState = ({
41
43
  try {
42
44
  const {
43
45
  meta: {
44
- access
46
+ access,
47
+ auth
45
48
  },
46
49
  data: {
47
50
  schema
@@ -49,12 +52,9 @@ export const useDatasourceTableState = ({
49
52
  } = await getDatasourceDetails(datasourceId, {
50
53
  parameters
51
54
  });
52
- if (access === 'unauthorized') {
53
- setStatus('unauthorized');
54
- return;
55
- }
56
- if (access === 'forbidden') {
57
- setStatus('forbidden');
55
+ if (access === 'unauthorized' || access === 'forbidden') {
56
+ setStatus(access);
57
+ setAuthDetails(auth || initialEmptyArray);
58
58
  return;
59
59
  }
60
60
  const isColumnNotPresentInCurrentColumnsList = col => !columns.find(column => column.key === col.key);
@@ -73,7 +73,7 @@ export const useDatasourceTableState = ({
73
73
  }
74
74
  setStatus('rejected');
75
75
  }
76
- }, [captureError, columns, datasourceId, getDatasourceDetails, parameters]);
76
+ }, [captureError, columns, datasourceId, getDatasourceDetails, parameters, initialEmptyArray]);
77
77
  const applySchemaProperties = useCallback((schema, fieldKeys) => {
78
78
  let {
79
79
  properties,
@@ -131,7 +131,8 @@ export const useDatasourceTableState = ({
131
131
  meta: {
132
132
  access,
133
133
  destinationObjectTypes,
134
- extensionKey
134
+ extensionKey,
135
+ auth
135
136
  },
136
137
  data: {
137
138
  items,
@@ -140,12 +141,9 @@ export const useDatasourceTableState = ({
140
141
  schema
141
142
  }
142
143
  } = await getDatasourceData(datasourceId, datasourceDataRequest, shouldForceRequest);
143
- if (access === 'unauthorized') {
144
- setStatus('unauthorized');
145
- return;
146
- }
147
- if (access === 'forbidden') {
148
- setStatus('forbidden');
144
+ if (access === 'unauthorized' || access === 'forbidden') {
145
+ setStatus(access);
146
+ setAuthDetails(auth || initialEmptyArray);
149
147
  return;
150
148
  }
151
149
  setExtensionKey(extensionKey);
@@ -192,23 +190,26 @@ export const useDatasourceTableState = ({
192
190
  }
193
191
  setStatus('rejected');
194
192
  }
195
- }, [captureError, parameters, fieldKeys, nextCursor, getDatasourceData, datasourceId, responseItems, applySchemaProperties, fireEvent, fullSchema]);
193
+ }, [captureError, parameters, fieldKeys, nextCursor, getDatasourceData, datasourceId, responseItems, applySchemaProperties, fireEvent, fullSchema, initialEmptyArray]);
196
194
  const reset = useCallback(options => {
197
- setStatus('empty');
198
- setResponseItems([]);
195
+ setResponseItems(initialEmptyArray);
199
196
  setHasNextPage(true);
200
197
  setNextCursor(undefined);
201
198
  setTotalCount(undefined);
202
- setLastRequestedFieldKeys([]);
199
+ setLastRequestedFieldKeys(initialEmptyArray);
200
+ setAuthDetails(initialEmptyArray);
203
201
  setFullSchema({
204
- properties: []
202
+ properties: initialEmptyArray
205
203
  });
206
204
  setShouldForceRequest((options === null || options === void 0 ? void 0 : options.shouldForceRequest) || false);
207
205
  if (options !== null && options !== void 0 && options.shouldResetColumns) {
208
- setColumns([]);
209
- setDefaultVisibleColumnKeys([]);
206
+ setColumns(initialEmptyArray);
207
+ setDefaultVisibleColumnKeys(initialEmptyArray);
210
208
  }
211
- }, []);
209
+
210
+ // setting the status earlier is triggering useEffects without all reset state values, hence placing this as the last state reset item
211
+ setStatus('empty');
212
+ }, [initialEmptyArray]);
212
213
 
213
214
  // this takes care of requesting /data initially
214
215
  useEffect(() => {
@@ -255,6 +256,7 @@ export const useDatasourceTableState = ({
255
256
  defaultVisibleColumnKeys,
256
257
  totalCount,
257
258
  extensionKey,
258
- destinationObjectTypes
259
+ destinationObjectTypes,
260
+ authDetails
259
261
  };
260
262
  };
@@ -2,6 +2,7 @@ export { default as JiraIssuesConfigModal } from './ui/jira-issues-modal';
2
2
  export { default as AssetsConfigModal } from './ui/assets-modal';
3
3
  export { default as DatasourceTableView } from './ui/datasource-table-view';
4
4
  export { default as JSMAssetsConfigModal } from './ui/assets-modal';
5
+ export { buildDatasourceAdf } from './common/utils/adf';
5
6
  export { JIRA_LIST_OF_LINKS_DATASOURCE_ID } from './ui/jira-issues-modal';
6
7
  export { ASSETS_LIST_OF_LINKS_DATASOURCE_ID } from './ui/assets-modal';
7
8
  export { LazyLoadedDatasourceRenderFailedAnalyticsWrapper } from './analytics/wrappers/render-failed';
@@ -14,6 +14,7 @@ import { DatasourceAction, DatasourceDisplay, DatasourceSearchMethod } from '../
14
14
  import { startUfoExperience } from '../../../analytics/ufoExperiences';
15
15
  import { useColumnPickerRenderedFailedUfoExperience } from '../../../analytics/ufoExperiences/hooks/useColumnPickerRenderedFailedUfoExperience';
16
16
  import { useDataRenderedUfoExperience } from '../../../analytics/ufoExperiences/hooks/useDataRenderedUfoExperience';
17
+ import { buildDatasourceAdf } from '../../../common/utils/adf';
17
18
  import { fetchMessagesForLocale } from '../../../common/utils/locale/fetch-messages-for-locale';
18
19
  import { useAssetsClient } from '../../../hooks/useAssetsClient';
19
20
  import { useDatasourceTableState } from '../../../hooks/useDatasourceTableState';
@@ -227,27 +228,22 @@ const PlainAssetsConfigModal = props => {
227
228
  }
228
229
  }, consumerEvent);
229
230
  } else {
230
- onInsert({
231
- type: 'blockCard',
232
- attrs: {
233
- datasource: {
234
- id: datasourceId,
235
- parameters: {
236
- workspaceId,
237
- aql,
238
- schemaId
239
- },
240
- views: [{
241
- type: 'table',
242
- properties: {
243
- columns: visibleColumnKeys === null || visibleColumnKeys === void 0 ? void 0 : visibleColumnKeys.map(key => ({
244
- key
245
- }))
246
- }
247
- }]
231
+ onInsert(buildDatasourceAdf({
232
+ id: datasourceId,
233
+ parameters: {
234
+ workspaceId,
235
+ aql,
236
+ schemaId
237
+ },
238
+ views: [{
239
+ type: 'table',
240
+ properties: {
241
+ columns: (visibleColumnKeys !== null && visibleColumnKeys !== void 0 ? visibleColumnKeys : []).map(key => ({
242
+ key
243
+ }))
248
244
  }
249
- }
250
- }, consumerEvent);
245
+ }]
246
+ }), consumerEvent);
251
247
  }
252
248
  }, [aql, schemaId, workspaceId, analyticsPayload, totalCount, retrieveUrlForSmartCardRender, responseItems.length, onInsert, datasourceId, visibleColumnKeys]);
253
249
  const onCancelClick = useCallback((e, analyticEvent) => {
@@ -54,5 +54,25 @@ export const loadingErrorMessages = defineMessages({
54
54
  id: 'linkDataSource.jira-issues.no.jira.sites.access.description',
55
55
  description: 'Description that shows in the modal when user has no access to any Jira sites',
56
56
  defaultMessage: 'To request access, contact your admin.'
57
+ },
58
+ authScreenHeaderText: {
59
+ id: 'linkDataSource.datasource.table.authScreenHeaderText',
60
+ defaultMessage: 'Connect your account',
61
+ description: 'Header text to be displayed in the auth screen UI.'
62
+ },
63
+ authScreenDescriptionText: {
64
+ id: 'linkDataSource.datasource.table.authScreenDescriptionText',
65
+ defaultMessage: 'Connect your account to collaborate on work across Atlassian products.',
66
+ description: 'Description text to be displayed in the auth screen UI.'
67
+ },
68
+ learnMoreAboutSmartLinks: {
69
+ id: 'linkDataSource.datasource.table.learnMoreAboutSmartLinks',
70
+ defaultMessage: 'Learn more about Smart Links.',
71
+ description: 'An anchor link to redirect user to a page about Smart Links.'
72
+ },
73
+ authConnectButtonText: {
74
+ id: 'linkDataSource.datasource.table.authConnectButtonText',
75
+ defaultMessage: 'Connect',
76
+ description: 'Label for the authentication button.'
57
77
  }
58
78
  });