@bigbinary/neeto-github-frontend 1.0.11 → 1.0.14

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/dist/index.cjs.js CHANGED
@@ -4,27 +4,115 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var classNames = require('classnames');
7
+ var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
8
+ var PageLoader = require('@bigbinary/neeto-molecules/PageLoader');
9
+ var reactI18next = require('react-i18next');
10
+ var ramda = require('ramda');
11
+ var reactQuery = require('react-query');
12
+ var axios = require('axios');
13
+ var constants = require('@bigbinary/neeto-commons-frontend/constants');
7
14
  var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
8
15
  var neetoIcons = require('@bigbinary/neeto-icons');
9
16
  var neetoui = require('@bigbinary/neetoui');
10
17
  var misc = require('@bigbinary/neeto-icons/misc');
11
18
  var neetoCist = require('@bigbinary/neeto-cist');
12
19
  var Search = require('@bigbinary/neeto-molecules/Search');
13
- var reactI18next = require('react-i18next');
14
20
  var Scrollable = require('@bigbinary/neeto-molecules/Scrollable');
15
21
  var DateFormat = require('@bigbinary/neeto-molecules/DateFormat');
16
- var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
17
22
  var require$$0 = require('util');
18
23
 
19
24
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
25
 
21
26
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
22
27
  var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
28
+ var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
29
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
23
30
  var Search__default = /*#__PURE__*/_interopDefaultLegacy(Search);
24
31
  var Scrollable__default = /*#__PURE__*/_interopDefaultLegacy(Scrollable);
25
32
  var DateFormat__default = /*#__PURE__*/_interopDefaultLegacy(DateFormat);
26
33
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
27
34
 
35
+ function _typeof(o) {
36
+ "@babel/helpers - typeof";
37
+
38
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
39
+ return typeof o;
40
+ } : function (o) {
41
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
42
+ }, _typeof(o);
43
+ }
44
+
45
+ function _toPrimitive(input, hint) {
46
+ if (_typeof(input) !== "object" || input === null) return input;
47
+ var prim = input[Symbol.toPrimitive];
48
+ if (prim !== undefined) {
49
+ var res = prim.call(input, hint || "default");
50
+ if (_typeof(res) !== "object") return res;
51
+ throw new TypeError("@@toPrimitive must return a primitive value.");
52
+ }
53
+ return (hint === "string" ? String : Number)(input);
54
+ }
55
+
56
+ function _toPropertyKey(arg) {
57
+ var key = _toPrimitive(arg, "string");
58
+ return _typeof(key) === "symbol" ? key : String(key);
59
+ }
60
+
61
+ function _defineProperty(obj, key, value) {
62
+ key = _toPropertyKey(key);
63
+ if (key in obj) {
64
+ Object.defineProperty(obj, key, {
65
+ value: value,
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true
69
+ });
70
+ } else {
71
+ obj[key] = value;
72
+ }
73
+ return obj;
74
+ }
75
+
76
+ var _globalProps$organiza$1;
77
+ var GITHUB_INTEGRATIONS_BASE_API_URL = "/github_integrations";
78
+ ({
79
+ integrator_id: initializers.globalProps === null || initializers.globalProps === void 0 || (_globalProps$organiza$1 = initializers.globalProps.organization) === null || _globalProps$organiza$1 === void 0 ? void 0 : _globalProps$organiza$1.id,
80
+ integrator_type: "Organization"
81
+ });
82
+ var GITHUB_INTEGRATOR_PARAMS = {
83
+ integratorId: initializers.globalProps.organization.id,
84
+ integratorType: "Organization"
85
+ };
86
+
87
+ var baseUrl = "".concat(GITHUB_INTEGRATIONS_BASE_API_URL, "/app_installations");
88
+ var githubAppUrl = function githubAppUrl(id) {
89
+ return "".concat(baseUrl, "/").concat(id);
90
+ };
91
+ var repositories = function repositories() {
92
+ return axios__default["default"].get("".concat(githubAppUrl(initializers.globalProps.githubAppInstallationId), "/repositories"), {
93
+ params: GITHUB_INTEGRATOR_PARAMS
94
+ });
95
+ };
96
+ var githubAccountsApi = {
97
+ repositories: repositories
98
+ };
99
+
100
+ var QUERY_KEYS = {
101
+ GITHUB_REPOSITORIES_LIST: "github-repositories-list"
102
+ };
103
+ var STALE_TIME_CONFIG = {
104
+ staleTime: constants.DEFAULT_STALE_TIME
105
+ };
106
+
107
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
108
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
109
+ var useFetchGithubRepositories = function useFetchGithubRepositories(_ref) {
110
+ var isConnected = _ref.isConnected;
111
+ return reactQuery.useQuery([QUERY_KEYS.GITHUB_REPOSITORIES_LIST], githubAccountsApi.repositories, _objectSpread(_objectSpread({}, STALE_TIME_CONFIG), {}, {
112
+ enabled: isConnected && ramda.isNotNil(initializers.globalProps.githubAppInstallationId)
113
+ }));
114
+ };
115
+
28
116
  var Configure = reactUtils.withT(function (_ref) {
29
117
  var t = _ref.t,
30
118
  isConnected = _ref.isConnected,
@@ -259,7 +347,6 @@ var RepositoryTile = function RepositoryTile(_ref) {
259
347
 
260
348
  var List = reactUtils.withT(function (_ref) {
261
349
  var t = _ref.t,
262
- isPublicRepoAllowed = _ref.isPublicRepoAllowed,
263
350
  filteredRepositories = _ref.filteredRepositories,
264
351
  repositories = _ref.repositories,
265
352
  isConnecting = _ref.isConnecting,
@@ -267,10 +354,7 @@ var List = reactUtils.withT(function (_ref) {
267
354
  installationUrl = _ref.installationUrl,
268
355
  troubleshootUrl = _ref.troubleshootUrl;
269
356
  return /*#__PURE__*/React__default["default"].createElement("div", {
270
- className: classNames__default["default"]("neeto-ui-border-gray-300 neeto-ui-rounded-md m-0 flex flex-col items-center justify-center border border-solid p-0 2xl:h-96", {
271
- "h-52": isPublicRepoAllowed,
272
- "h-72": !isPublicRepoAllowed
273
- })
357
+ className: "neeto-ui-border-gray-300 h-72 neeto-ui-rounded-md m-0 flex flex-col items-center justify-center border border-solid p-0 2xl:h-96"
274
358
  }, neetoCist.isPresent(repositories) ? /*#__PURE__*/React__default["default"].createElement(Scrollable__default["default"], {
275
359
  className: "m-0 h-full w-full overflow-y-scroll p-0 shadow-inner"
276
360
  }, neetoCist.isPresent(filteredRepositories) ? filteredRepositories.map(function (repository, index) {
@@ -311,7 +395,6 @@ var NotConnected = reactUtils.withT(function (_ref) {
311
395
  var Private = function Private(_ref) {
312
396
  var isConnected = _ref.isConnected,
313
397
  isConnecting = _ref.isConnecting,
314
- isPublicRepoAllowed = _ref.isPublicRepoAllowed,
315
398
  repositories = _ref.repositories,
316
399
  onConnect = _ref.onConnect,
317
400
  installationUrl = _ref.installationUrl,
@@ -342,6 +425,7 @@ var Private = function Private(_ref) {
342
425
  className: "flex w-full flex-col space-y-6"
343
426
  }, /*#__PURE__*/React__default["default"].createElement(Search__default["default"], {
344
427
  onSearch: onSearch,
428
+ unlimitedChars: false,
345
429
  className: "w-full",
346
430
  suffix: /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
347
431
  style: "body2"
@@ -352,7 +436,6 @@ var Private = function Private(_ref) {
352
436
  filteredRepositories: filteredRepositories,
353
437
  installationUrl: installationUrl,
354
438
  isConnecting: isConnecting,
355
- isPublicRepoAllowed: isPublicRepoAllowed,
356
439
  onConnect: onConnect,
357
440
  repositories: repositories,
358
441
  troubleshootUrl: troubleshootUrl
@@ -365,79 +448,9 @@ var Private = function Private(_ref) {
365
448
  }))));
366
449
  };
367
450
 
368
- var Public = function Public(_ref) {
369
- var isConnecting = _ref.isConnecting,
370
- onConnect = _ref.onConnect;
371
- var _useTranslation = reactI18next.useTranslation(),
372
- t = _useTranslation.t;
373
- var _useState = React.useState(false),
374
- _useState2 = _slicedToArray(_useState, 2),
375
- isLoading = _useState2[0],
376
- setIsLoading = _useState2[1];
377
- var _useState3 = React.useState(""),
378
- _useState4 = _slicedToArray(_useState3, 2),
379
- publicRepoUrl = _useState4[0],
380
- setPublicRepoUrl = _useState4[1];
381
- return /*#__PURE__*/React__default["default"].createElement("div", {
382
- className: "transition-drop-shadow neeto-ui-border-gray-300 neeto-ui-rounded-md border border-solid px-8 py-7 font-sans transition-colors"
383
- }, /*#__PURE__*/React__default["default"].createElement("div", {
384
- className: "mb-2 pb-5"
385
- }, /*#__PURE__*/React__default["default"].createElement("div", {
386
- className: "flex justify-between"
387
- }, /*#__PURE__*/React__default["default"].createElement("div", {
388
- className: "pr-4"
389
- }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
390
- className: "text-lg font-medium",
391
- style: "h2"
392
- }, t("neetoGithub.publicGitRepo")), /*#__PURE__*/React__default["default"].createElement("div", {
393
- className: "neeto-ui-text-gray-900 mt-2 flex max-w-xl space-x-1 font-sans text-sm font-normal leading-6 antialiased"
394
- }, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
395
- style: "body2"
396
- }, t("neetoGithub.publicGitRepoDescription")))))), /*#__PURE__*/React__default["default"].createElement("div", {
397
- className: "neeto-ui-text-gray-900 font-sans text-sm font-normal leading-6 antialiased"
398
- }, /*#__PURE__*/React__default["default"].createElement("div", {
399
- className: "flex"
400
- }, /*#__PURE__*/React__default["default"].createElement("div", {
401
- className: "z-0 flex-1"
402
- }, /*#__PURE__*/React__default["default"].createElement("div", {
403
- className: "w-full"
404
- }, /*#__PURE__*/React__default["default"].createElement(neetoui.Input, {
405
- nakedInput: true,
406
- autocomplete: "false",
407
- className: "relative rounded-b rounded-l rounded-r-none rounded-t border-b border-l border-r-0 border-t border-solid px-2",
408
- placeholder: t("neetoGithub.publicGitRepoPlaceholder"),
409
- size: "large",
410
- spellcheck: "false",
411
- type: "text",
412
- value: publicRepoUrl,
413
- onChange: function onChange(e) {
414
- return setPublicRepoUrl(e.target.value);
415
- }
416
- }))), /*#__PURE__*/React__default["default"].createElement("div", {
417
- className: "relative"
418
- }, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
419
- className: "rounded-b rounded-l-none rounded-r rounded-t",
420
- disabled: !neetoCist.isPresent(publicRepoUrl) || isLoading || isConnecting,
421
- loading: isLoading,
422
- size: "large",
423
- style: "primary",
424
- type: "button",
425
- onClick: function onClick() {
426
- return onConnect({
427
- repoType: "public",
428
- repository: {
429
- fullName: publicRepoUrl
430
- },
431
- setIsLoading: setIsLoading
432
- });
433
- }
434
- }, t("neetoGithub.continue"))))));
435
- };
436
-
437
451
  var Repositories = function Repositories(_ref) {
438
452
  var isConnected = _ref.isConnected,
439
453
  isConnecting = _ref.isConnecting,
440
- isPublicRepoAllowed = _ref.isPublicRepoAllowed,
441
454
  repositories = _ref.repositories,
442
455
  onConnect = _ref.onConnect,
443
456
  installationUrl = _ref.installationUrl,
@@ -448,31 +461,51 @@ var Repositories = function Repositories(_ref) {
448
461
  installationUrl: installationUrl,
449
462
  isConnected: isConnected,
450
463
  isConnecting: isConnecting,
451
- isPublicRepoAllowed: isPublicRepoAllowed,
452
464
  onConnect: onConnect,
453
465
  repositories: repositories,
454
466
  troubleshootUrl: troubleshootUrl
455
- }), isPublicRepoAllowed && /*#__PURE__*/React__default["default"].createElement(Public, {
456
- isConnecting: isConnecting,
457
- onConnect: onConnect
458
467
  }));
459
468
  };
460
469
 
461
470
  var NeetoGithubNanoContainer = function NeetoGithubNanoContainer(_ref) {
462
- var _ref$accounts = _ref.accounts,
463
- accounts = _ref$accounts === void 0 ? [] : _ref$accounts,
471
+ var _ref$isPaneLoading = _ref.isPaneLoading,
472
+ isPaneLoading = _ref$isPaneLoading === void 0 ? false : _ref$isPaneLoading,
473
+ _ref$shouldFetchRepos = _ref.shouldFetchRepositories,
474
+ shouldFetchRepositories = _ref$shouldFetchRepos === void 0 ? true : _ref$shouldFetchRepos,
475
+ _ref$paneAccounts = _ref.paneAccounts,
476
+ paneAccounts = _ref$paneAccounts === void 0 ? [] : _ref$paneAccounts,
464
477
  installationUrl = _ref.installationUrl,
465
478
  isConnected = _ref.isConnected,
466
479
  _ref$isConnecting = _ref.isConnecting,
467
480
  isConnecting = _ref$isConnecting === void 0 ? false : _ref$isConnecting,
468
- _ref$isPublicRepoAllo = _ref.isPublicRepoAllowed,
469
- isPublicRepoAllowed = _ref$isPublicRepoAllo === void 0 ? false : _ref$isPublicRepoAllo,
470
481
  onConnect = _ref.onConnect,
471
- _ref$repositories = _ref.repositories,
472
- repositories = _ref$repositories === void 0 ? [] : _ref$repositories,
482
+ _ref$paneRepositories = _ref.paneRepositories,
483
+ paneRepositories = _ref$paneRepositories === void 0 ? [] : _ref$paneRepositories,
473
484
  troubleshootUrl = _ref.troubleshootUrl,
474
485
  _ref$isPane = _ref.isPane,
475
486
  isPane = _ref$isPane === void 0 ? false : _ref$isPane;
487
+ var _useTranslation = reactI18next.useTranslation(),
488
+ t = _useTranslation.t;
489
+ var _useFetchGithubReposi = useFetchGithubRepositories({
490
+ isConnected: shouldFetchRepositories && initializers.globalProps.isGithubIntegrated
491
+ }),
492
+ _useFetchGithubReposi2 = _useFetchGithubReposi.data,
493
+ _useFetchGithubReposi3 = _useFetchGithubReposi2 === void 0 ? {} : _useFetchGithubReposi2,
494
+ _useFetchGithubReposi4 = _useFetchGithubReposi3.repositories,
495
+ containerRepositories = _useFetchGithubReposi4 === void 0 ? [] : _useFetchGithubReposi4,
496
+ _useFetchGithubReposi5 = _useFetchGithubReposi3.accounts,
497
+ containerAccounts = _useFetchGithubReposi5 === void 0 ? [] : _useFetchGithubReposi5,
498
+ isContainerLoading = _useFetchGithubReposi.isLoading;
499
+ var repositories = shouldFetchRepositories ? containerRepositories : paneRepositories;
500
+ var accounts = shouldFetchRepositories ? containerAccounts : paneAccounts;
501
+ var isLoading = shouldFetchRepositories ? isContainerLoading : isPaneLoading;
502
+ if (isLoading) {
503
+ return /*#__PURE__*/React__default["default"].createElement("div", {
504
+ className: "flex h-96 w-full flex-col items-center"
505
+ }, /*#__PURE__*/React__default["default"].createElement(PageLoader__default["default"], {
506
+ text: t("neetoGithub.fetchingRepos")
507
+ }), ";");
508
+ }
476
509
  return /*#__PURE__*/React__default["default"].createElement("div", {
477
510
  className: classNames__default["default"]("flex w-full flex-col-reverse", {
478
511
  "2xl:flex-row": isPane,
@@ -482,7 +515,6 @@ var NeetoGithubNanoContainer = function NeetoGithubNanoContainer(_ref) {
482
515
  installationUrl: installationUrl,
483
516
  isConnected: isConnected,
484
517
  isConnecting: isConnecting,
485
- isPublicRepoAllowed: isPublicRepoAllowed,
486
518
  onConnect: onConnect,
487
519
  repositories: repositories,
488
520
  troubleshootUrl: troubleshootUrl
@@ -2755,18 +2787,14 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2755
2787
  isConnecting = _ref$isConnecting === void 0 ? false : _ref$isConnecting,
2756
2788
  _ref$isConnected = _ref.isConnected,
2757
2789
  isConnected = _ref$isConnected === void 0 ? false : _ref$isConnected,
2758
- _ref$isPublicRepoAllo = _ref.isPublicRepoAllowed,
2759
- isPublicRepoAllowed = _ref$isPublicRepoAllo === void 0 ? false : _ref$isPublicRepoAllo,
2760
- _ref$repositories = _ref.repositories,
2761
- repositories = _ref$repositories === void 0 ? [] : _ref$repositories,
2762
- _ref$accounts = _ref.accounts,
2763
- accounts = _ref$accounts === void 0 ? [] : _ref$accounts,
2764
2790
  _ref$installationUrl = _ref.installationUrl,
2765
2791
  installationUrl = _ref$installationUrl === void 0 ? NEW_INSTALLATION_URL : _ref$installationUrl,
2766
2792
  _ref$troubleshootUrl = _ref.troubleshootUrl,
2767
2793
  troubleshootUrl = _ref$troubleshootUrl === void 0 ? TROUBLESHOOT_URL : _ref$troubleshootUrl,
2768
2794
  _ref$onConnect = _ref.onConnect,
2769
2795
  onConnect = _ref$onConnect === void 0 ? neetoCist.noop : _ref$onConnect,
2796
+ _ref$projects = _ref.projects,
2797
+ projects = _ref$projects === void 0 ? [] : _ref$projects,
2770
2798
  _ref$title = _ref.title,
2771
2799
  title = _ref$title === void 0 ? "" : _ref$title,
2772
2800
  _ref$description = _ref.description,
@@ -2774,6 +2802,22 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2774
2802
  var _useTranslation = reactI18next.useTranslation(),
2775
2803
  t = _useTranslation.t;
2776
2804
  var initialFocusRef = React.useRef(null);
2805
+ var _useFetchGithubReposi = useFetchGithubRepositories({
2806
+ isConnected: isOpen && isConnected
2807
+ }),
2808
+ _useFetchGithubReposi2 = _useFetchGithubReposi.data,
2809
+ _useFetchGithubReposi3 = _useFetchGithubReposi2 === void 0 ? {} : _useFetchGithubReposi2,
2810
+ _useFetchGithubReposi4 = _useFetchGithubReposi3.repositories,
2811
+ repositories = _useFetchGithubReposi4 === void 0 ? [] : _useFetchGithubReposi4,
2812
+ _useFetchGithubReposi5 = _useFetchGithubReposi3.accounts,
2813
+ accounts = _useFetchGithubReposi5 === void 0 ? [] : _useFetchGithubReposi5,
2814
+ isPaneLoading = _useFetchGithubReposi.isLoading;
2815
+ var paneRepositories = repositories.filter(function (repository) {
2816
+ return !neetoCist.findBy({
2817
+ repository: repository.fullName
2818
+ }, projects);
2819
+ });
2820
+ var paneAccounts = isConnected ? accounts : [];
2777
2821
  return /*#__PURE__*/React__default["default"].createElement(neetoui.Pane, {
2778
2822
  initialFocusRef: initialFocusRef,
2779
2823
  isOpen: isOpen,
@@ -2786,15 +2830,16 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2786
2830
  className: "mt-4",
2787
2831
  style: "body2"
2788
2832
  }, neetoCist.isPresent(description) ? description : t("neetoGithub.modal.description"))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null, /*#__PURE__*/React__default["default"].createElement(NeetoGithubNanoContainer, {
2789
- accounts: accounts,
2790
2833
  installationUrl: installationUrl,
2791
2834
  isConnected: isConnected,
2792
2835
  isConnecting: isConnecting,
2793
- isPublicRepoAllowed: isPublicRepoAllowed,
2836
+ isPaneLoading: isPaneLoading,
2794
2837
  onConnect: onConnect,
2795
- repositories: repositories,
2838
+ paneAccounts: paneAccounts,
2839
+ paneRepositories: paneRepositories,
2796
2840
  troubleshootUrl: troubleshootUrl,
2797
- isPane: true
2841
+ isPane: true,
2842
+ shouldFetchRepositories: false
2798
2843
  })));
2799
2844
  };
2800
2845