@bigbinary/neeto-github-frontend 1.0.11 → 1.0.13

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.js CHANGED
@@ -1,17 +1,103 @@
1
1
  import React, { useState, useRef } from 'react';
2
2
  import classNames from 'classnames';
3
+ import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
4
+ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
5
+ import { Trans, useTranslation } from 'react-i18next';
6
+ import { isNotNil } from 'ramda';
7
+ import { useQuery } from 'react-query';
8
+ import axios from 'axios';
9
+ import { DEFAULT_STALE_TIME } from '@bigbinary/neeto-commons-frontend/constants';
3
10
  import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
4
11
  import { Settings, Plus, Building, User, CannedResponses, Lock } from '@bigbinary/neeto-icons';
5
12
  import { Button, Typography, Input, Pane } from '@bigbinary/neetoui';
6
13
  import { Github } from '@bigbinary/neeto-icons/misc';
7
- import { isPresent, noop } from '@bigbinary/neeto-cist';
14
+ import { isPresent, findBy, noop } from '@bigbinary/neeto-cist';
8
15
  import Search from '@bigbinary/neeto-molecules/Search';
9
- import { Trans, useTranslation } from 'react-i18next';
10
16
  import Scrollable from '@bigbinary/neeto-molecules/Scrollable';
11
17
  import DateFormat from '@bigbinary/neeto-molecules/DateFormat';
12
- import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
13
18
  import require$$0 from 'util';
14
19
 
20
+ function _typeof(o) {
21
+ "@babel/helpers - typeof";
22
+
23
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
24
+ return typeof o;
25
+ } : function (o) {
26
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
27
+ }, _typeof(o);
28
+ }
29
+
30
+ function _toPrimitive(input, hint) {
31
+ if (_typeof(input) !== "object" || input === null) return input;
32
+ var prim = input[Symbol.toPrimitive];
33
+ if (prim !== undefined) {
34
+ var res = prim.call(input, hint || "default");
35
+ if (_typeof(res) !== "object") return res;
36
+ throw new TypeError("@@toPrimitive must return a primitive value.");
37
+ }
38
+ return (hint === "string" ? String : Number)(input);
39
+ }
40
+
41
+ function _toPropertyKey(arg) {
42
+ var key = _toPrimitive(arg, "string");
43
+ return _typeof(key) === "symbol" ? key : String(key);
44
+ }
45
+
46
+ function _defineProperty(obj, key, value) {
47
+ key = _toPropertyKey(key);
48
+ if (key in obj) {
49
+ Object.defineProperty(obj, key, {
50
+ value: value,
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true
54
+ });
55
+ } else {
56
+ obj[key] = value;
57
+ }
58
+ return obj;
59
+ }
60
+
61
+ var _globalProps$organiza$1;
62
+ var GITHUB_INTEGRATIONS_BASE_API_URL = "/github_integrations";
63
+ ({
64
+ integrator_id: globalProps === null || globalProps === void 0 || (_globalProps$organiza$1 = globalProps.organization) === null || _globalProps$organiza$1 === void 0 ? void 0 : _globalProps$organiza$1.id,
65
+ integrator_type: "Organization"
66
+ });
67
+ var GITHUB_INTEGRATOR_PARAMS = {
68
+ integratorId: globalProps.organization.id,
69
+ integratorType: "Organization"
70
+ };
71
+
72
+ var baseUrl = "".concat(GITHUB_INTEGRATIONS_BASE_API_URL, "/app_installations");
73
+ var githubAppUrl = function githubAppUrl(id) {
74
+ return "".concat(baseUrl, "/").concat(id);
75
+ };
76
+ var repositories = function repositories() {
77
+ return axios.get("".concat(githubAppUrl(globalProps.githubAppInstallationId), "/repositories"), {
78
+ params: GITHUB_INTEGRATOR_PARAMS
79
+ });
80
+ };
81
+ var githubAccountsApi = {
82
+ repositories: repositories
83
+ };
84
+
85
+ var QUERY_KEYS = {
86
+ GITHUB_REPOSITORIES_LIST: "github-repositories-list"
87
+ };
88
+ var STALE_TIME_CONFIG = {
89
+ staleTime: DEFAULT_STALE_TIME
90
+ };
91
+
92
+ 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; }
93
+ 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; }
94
+ var useFetchGithubRepositories = function useFetchGithubRepositories(_ref) {
95
+ var isConnected = _ref.isConnected;
96
+ return useQuery([QUERY_KEYS.GITHUB_REPOSITORIES_LIST], githubAccountsApi.repositories, _objectSpread(_objectSpread({}, STALE_TIME_CONFIG), {}, {
97
+ enabled: isConnected && isNotNil(globalProps.githubAppInstallationId)
98
+ }));
99
+ };
100
+
15
101
  var Configure = withT(function (_ref) {
16
102
  var t = _ref.t,
17
103
  isConnected = _ref.isConnected,
@@ -446,8 +532,12 @@ var Repositories = function Repositories(_ref) {
446
532
  };
447
533
 
448
534
  var NeetoGithubNanoContainer = function NeetoGithubNanoContainer(_ref) {
449
- var _ref$accounts = _ref.accounts,
450
- accounts = _ref$accounts === void 0 ? [] : _ref$accounts,
535
+ var _ref$isPaneLoading = _ref.isPaneLoading,
536
+ isPaneLoading = _ref$isPaneLoading === void 0 ? false : _ref$isPaneLoading,
537
+ _ref$shouldFetchRepos = _ref.shouldFetchRepositories,
538
+ shouldFetchRepositories = _ref$shouldFetchRepos === void 0 ? true : _ref$shouldFetchRepos,
539
+ _ref$paneAccounts = _ref.paneAccounts,
540
+ paneAccounts = _ref$paneAccounts === void 0 ? [] : _ref$paneAccounts,
451
541
  installationUrl = _ref.installationUrl,
452
542
  isConnected = _ref.isConnected,
453
543
  _ref$isConnecting = _ref.isConnecting,
@@ -455,11 +545,33 @@ var NeetoGithubNanoContainer = function NeetoGithubNanoContainer(_ref) {
455
545
  _ref$isPublicRepoAllo = _ref.isPublicRepoAllowed,
456
546
  isPublicRepoAllowed = _ref$isPublicRepoAllo === void 0 ? false : _ref$isPublicRepoAllo,
457
547
  onConnect = _ref.onConnect,
458
- _ref$repositories = _ref.repositories,
459
- repositories = _ref$repositories === void 0 ? [] : _ref$repositories,
548
+ _ref$paneRepositories = _ref.paneRepositories,
549
+ paneRepositories = _ref$paneRepositories === void 0 ? [] : _ref$paneRepositories,
460
550
  troubleshootUrl = _ref.troubleshootUrl,
461
551
  _ref$isPane = _ref.isPane,
462
552
  isPane = _ref$isPane === void 0 ? false : _ref$isPane;
553
+ var _useTranslation = useTranslation(),
554
+ t = _useTranslation.t;
555
+ var _useFetchGithubReposi = useFetchGithubRepositories({
556
+ isConnected: shouldFetchRepositories && globalProps.isGithubIntegrated
557
+ }),
558
+ _useFetchGithubReposi2 = _useFetchGithubReposi.data,
559
+ _useFetchGithubReposi3 = _useFetchGithubReposi2 === void 0 ? {} : _useFetchGithubReposi2,
560
+ _useFetchGithubReposi4 = _useFetchGithubReposi3.repositories,
561
+ containerRepositories = _useFetchGithubReposi4 === void 0 ? [] : _useFetchGithubReposi4,
562
+ _useFetchGithubReposi5 = _useFetchGithubReposi3.accounts,
563
+ containerAccounts = _useFetchGithubReposi5 === void 0 ? [] : _useFetchGithubReposi5,
564
+ isContainerLoading = _useFetchGithubReposi.isLoading;
565
+ var repositories = shouldFetchRepositories ? containerRepositories : paneRepositories;
566
+ var accounts = shouldFetchRepositories ? containerAccounts : paneAccounts;
567
+ var isLoading = shouldFetchRepositories ? isContainerLoading : isPaneLoading;
568
+ if (isLoading) {
569
+ return /*#__PURE__*/React.createElement("div", {
570
+ className: "flex h-96 w-full flex-col items-center"
571
+ }, /*#__PURE__*/React.createElement(PageLoader, {
572
+ text: t("neetoGithub.fetchingRepos")
573
+ }), ";");
574
+ }
463
575
  return /*#__PURE__*/React.createElement("div", {
464
576
  className: classNames("flex w-full flex-col-reverse", {
465
577
  "2xl:flex-row": isPane,
@@ -2744,16 +2856,14 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2744
2856
  isConnected = _ref$isConnected === void 0 ? false : _ref$isConnected,
2745
2857
  _ref$isPublicRepoAllo = _ref.isPublicRepoAllowed,
2746
2858
  isPublicRepoAllowed = _ref$isPublicRepoAllo === void 0 ? false : _ref$isPublicRepoAllo,
2747
- _ref$repositories = _ref.repositories,
2748
- repositories = _ref$repositories === void 0 ? [] : _ref$repositories,
2749
- _ref$accounts = _ref.accounts,
2750
- accounts = _ref$accounts === void 0 ? [] : _ref$accounts,
2751
2859
  _ref$installationUrl = _ref.installationUrl,
2752
2860
  installationUrl = _ref$installationUrl === void 0 ? NEW_INSTALLATION_URL : _ref$installationUrl,
2753
2861
  _ref$troubleshootUrl = _ref.troubleshootUrl,
2754
2862
  troubleshootUrl = _ref$troubleshootUrl === void 0 ? TROUBLESHOOT_URL : _ref$troubleshootUrl,
2755
2863
  _ref$onConnect = _ref.onConnect,
2756
2864
  onConnect = _ref$onConnect === void 0 ? noop : _ref$onConnect,
2865
+ _ref$projects = _ref.projects,
2866
+ projects = _ref$projects === void 0 ? [] : _ref$projects,
2757
2867
  _ref$title = _ref.title,
2758
2868
  title = _ref$title === void 0 ? "" : _ref$title,
2759
2869
  _ref$description = _ref.description,
@@ -2761,6 +2871,22 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2761
2871
  var _useTranslation = useTranslation(),
2762
2872
  t = _useTranslation.t;
2763
2873
  var initialFocusRef = useRef(null);
2874
+ var _useFetchGithubReposi = useFetchGithubRepositories({
2875
+ isConnected: isOpen && isConnected
2876
+ }),
2877
+ _useFetchGithubReposi2 = _useFetchGithubReposi.data,
2878
+ _useFetchGithubReposi3 = _useFetchGithubReposi2 === void 0 ? {} : _useFetchGithubReposi2,
2879
+ _useFetchGithubReposi4 = _useFetchGithubReposi3.repositories,
2880
+ repositories = _useFetchGithubReposi4 === void 0 ? [] : _useFetchGithubReposi4,
2881
+ _useFetchGithubReposi5 = _useFetchGithubReposi3.accounts,
2882
+ accounts = _useFetchGithubReposi5 === void 0 ? [] : _useFetchGithubReposi5,
2883
+ isPaneLoading = _useFetchGithubReposi.isLoading;
2884
+ var paneRepositories = repositories.filter(function (repository) {
2885
+ return !findBy({
2886
+ repository: repository.fullName
2887
+ }, projects);
2888
+ });
2889
+ var paneAccounts = isConnected ? accounts : [];
2764
2890
  return /*#__PURE__*/React.createElement(Pane, {
2765
2891
  initialFocusRef: initialFocusRef,
2766
2892
  isOpen: isOpen,
@@ -2773,15 +2899,17 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2773
2899
  className: "mt-4",
2774
2900
  style: "body2"
2775
2901
  }, isPresent(description) ? description : t("neetoGithub.modal.description"))), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(NeetoGithubNanoContainer, {
2776
- accounts: accounts,
2777
2902
  installationUrl: installationUrl,
2778
2903
  isConnected: isConnected,
2779
2904
  isConnecting: isConnecting,
2905
+ isPaneLoading: isPaneLoading,
2780
2906
  isPublicRepoAllowed: isPublicRepoAllowed,
2781
2907
  onConnect: onConnect,
2782
- repositories: repositories,
2908
+ paneAccounts: paneAccounts,
2909
+ paneRepositories: paneRepositories,
2783
2910
  troubleshootUrl: troubleshootUrl,
2784
- isPane: true
2911
+ isPane: true,
2912
+ shouldFetchRepositories: false
2785
2913
  })));
2786
2914
  };
2787
2915