@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.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
- import { Button, Typography, Input, Pane } from '@bigbinary/neetoui';
12
+ import { Button, Typography, 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,
@@ -246,7 +332,6 @@ var RepositoryTile = function RepositoryTile(_ref) {
246
332
 
247
333
  var List = withT(function (_ref) {
248
334
  var t = _ref.t,
249
- isPublicRepoAllowed = _ref.isPublicRepoAllowed,
250
335
  filteredRepositories = _ref.filteredRepositories,
251
336
  repositories = _ref.repositories,
252
337
  isConnecting = _ref.isConnecting,
@@ -254,10 +339,7 @@ var List = withT(function (_ref) {
254
339
  installationUrl = _ref.installationUrl,
255
340
  troubleshootUrl = _ref.troubleshootUrl;
256
341
  return /*#__PURE__*/React.createElement("div", {
257
- className: classNames("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", {
258
- "h-52": isPublicRepoAllowed,
259
- "h-72": !isPublicRepoAllowed
260
- })
342
+ 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"
261
343
  }, isPresent(repositories) ? /*#__PURE__*/React.createElement(Scrollable, {
262
344
  className: "m-0 h-full w-full overflow-y-scroll p-0 shadow-inner"
263
345
  }, isPresent(filteredRepositories) ? filteredRepositories.map(function (repository, index) {
@@ -298,7 +380,6 @@ var NotConnected = withT(function (_ref) {
298
380
  var Private = function Private(_ref) {
299
381
  var isConnected = _ref.isConnected,
300
382
  isConnecting = _ref.isConnecting,
301
- isPublicRepoAllowed = _ref.isPublicRepoAllowed,
302
383
  repositories = _ref.repositories,
303
384
  onConnect = _ref.onConnect,
304
385
  installationUrl = _ref.installationUrl,
@@ -329,6 +410,7 @@ var Private = function Private(_ref) {
329
410
  className: "flex w-full flex-col space-y-6"
330
411
  }, /*#__PURE__*/React.createElement(Search, {
331
412
  onSearch: onSearch,
413
+ unlimitedChars: false,
332
414
  className: "w-full",
333
415
  suffix: /*#__PURE__*/React.createElement(Typography, {
334
416
  style: "body2"
@@ -339,7 +421,6 @@ var Private = function Private(_ref) {
339
421
  filteredRepositories: filteredRepositories,
340
422
  installationUrl: installationUrl,
341
423
  isConnecting: isConnecting,
342
- isPublicRepoAllowed: isPublicRepoAllowed,
343
424
  onConnect: onConnect,
344
425
  repositories: repositories,
345
426
  troubleshootUrl: troubleshootUrl
@@ -352,79 +433,9 @@ var Private = function Private(_ref) {
352
433
  }))));
353
434
  };
354
435
 
355
- var Public = function Public(_ref) {
356
- var isConnecting = _ref.isConnecting,
357
- onConnect = _ref.onConnect;
358
- var _useTranslation = useTranslation(),
359
- t = _useTranslation.t;
360
- var _useState = useState(false),
361
- _useState2 = _slicedToArray(_useState, 2),
362
- isLoading = _useState2[0],
363
- setIsLoading = _useState2[1];
364
- var _useState3 = useState(""),
365
- _useState4 = _slicedToArray(_useState3, 2),
366
- publicRepoUrl = _useState4[0],
367
- setPublicRepoUrl = _useState4[1];
368
- return /*#__PURE__*/React.createElement("div", {
369
- className: "transition-drop-shadow neeto-ui-border-gray-300 neeto-ui-rounded-md border border-solid px-8 py-7 font-sans transition-colors"
370
- }, /*#__PURE__*/React.createElement("div", {
371
- className: "mb-2 pb-5"
372
- }, /*#__PURE__*/React.createElement("div", {
373
- className: "flex justify-between"
374
- }, /*#__PURE__*/React.createElement("div", {
375
- className: "pr-4"
376
- }, /*#__PURE__*/React.createElement(Typography, {
377
- className: "text-lg font-medium",
378
- style: "h2"
379
- }, t("neetoGithub.publicGitRepo")), /*#__PURE__*/React.createElement("div", {
380
- className: "neeto-ui-text-gray-900 mt-2 flex max-w-xl space-x-1 font-sans text-sm font-normal leading-6 antialiased"
381
- }, /*#__PURE__*/React.createElement(Typography, {
382
- style: "body2"
383
- }, t("neetoGithub.publicGitRepoDescription")))))), /*#__PURE__*/React.createElement("div", {
384
- className: "neeto-ui-text-gray-900 font-sans text-sm font-normal leading-6 antialiased"
385
- }, /*#__PURE__*/React.createElement("div", {
386
- className: "flex"
387
- }, /*#__PURE__*/React.createElement("div", {
388
- className: "z-0 flex-1"
389
- }, /*#__PURE__*/React.createElement("div", {
390
- className: "w-full"
391
- }, /*#__PURE__*/React.createElement(Input, {
392
- nakedInput: true,
393
- autocomplete: "false",
394
- className: "relative rounded-b rounded-l rounded-r-none rounded-t border-b border-l border-r-0 border-t border-solid px-2",
395
- placeholder: t("neetoGithub.publicGitRepoPlaceholder"),
396
- size: "large",
397
- spellcheck: "false",
398
- type: "text",
399
- value: publicRepoUrl,
400
- onChange: function onChange(e) {
401
- return setPublicRepoUrl(e.target.value);
402
- }
403
- }))), /*#__PURE__*/React.createElement("div", {
404
- className: "relative"
405
- }, /*#__PURE__*/React.createElement(Button, {
406
- className: "rounded-b rounded-l-none rounded-r rounded-t",
407
- disabled: !isPresent(publicRepoUrl) || isLoading || isConnecting,
408
- loading: isLoading,
409
- size: "large",
410
- style: "primary",
411
- type: "button",
412
- onClick: function onClick() {
413
- return onConnect({
414
- repoType: "public",
415
- repository: {
416
- fullName: publicRepoUrl
417
- },
418
- setIsLoading: setIsLoading
419
- });
420
- }
421
- }, t("neetoGithub.continue"))))));
422
- };
423
-
424
436
  var Repositories = function Repositories(_ref) {
425
437
  var isConnected = _ref.isConnected,
426
438
  isConnecting = _ref.isConnecting,
427
- isPublicRepoAllowed = _ref.isPublicRepoAllowed,
428
439
  repositories = _ref.repositories,
429
440
  onConnect = _ref.onConnect,
430
441
  installationUrl = _ref.installationUrl,
@@ -435,31 +446,51 @@ var Repositories = function Repositories(_ref) {
435
446
  installationUrl: installationUrl,
436
447
  isConnected: isConnected,
437
448
  isConnecting: isConnecting,
438
- isPublicRepoAllowed: isPublicRepoAllowed,
439
449
  onConnect: onConnect,
440
450
  repositories: repositories,
441
451
  troubleshootUrl: troubleshootUrl
442
- }), isPublicRepoAllowed && /*#__PURE__*/React.createElement(Public, {
443
- isConnecting: isConnecting,
444
- onConnect: onConnect
445
452
  }));
446
453
  };
447
454
 
448
455
  var NeetoGithubNanoContainer = function NeetoGithubNanoContainer(_ref) {
449
- var _ref$accounts = _ref.accounts,
450
- accounts = _ref$accounts === void 0 ? [] : _ref$accounts,
456
+ var _ref$isPaneLoading = _ref.isPaneLoading,
457
+ isPaneLoading = _ref$isPaneLoading === void 0 ? false : _ref$isPaneLoading,
458
+ _ref$shouldFetchRepos = _ref.shouldFetchRepositories,
459
+ shouldFetchRepositories = _ref$shouldFetchRepos === void 0 ? true : _ref$shouldFetchRepos,
460
+ _ref$paneAccounts = _ref.paneAccounts,
461
+ paneAccounts = _ref$paneAccounts === void 0 ? [] : _ref$paneAccounts,
451
462
  installationUrl = _ref.installationUrl,
452
463
  isConnected = _ref.isConnected,
453
464
  _ref$isConnecting = _ref.isConnecting,
454
465
  isConnecting = _ref$isConnecting === void 0 ? false : _ref$isConnecting,
455
- _ref$isPublicRepoAllo = _ref.isPublicRepoAllowed,
456
- isPublicRepoAllowed = _ref$isPublicRepoAllo === void 0 ? false : _ref$isPublicRepoAllo,
457
466
  onConnect = _ref.onConnect,
458
- _ref$repositories = _ref.repositories,
459
- repositories = _ref$repositories === void 0 ? [] : _ref$repositories,
467
+ _ref$paneRepositories = _ref.paneRepositories,
468
+ paneRepositories = _ref$paneRepositories === void 0 ? [] : _ref$paneRepositories,
460
469
  troubleshootUrl = _ref.troubleshootUrl,
461
470
  _ref$isPane = _ref.isPane,
462
471
  isPane = _ref$isPane === void 0 ? false : _ref$isPane;
472
+ var _useTranslation = useTranslation(),
473
+ t = _useTranslation.t;
474
+ var _useFetchGithubReposi = useFetchGithubRepositories({
475
+ isConnected: shouldFetchRepositories && globalProps.isGithubIntegrated
476
+ }),
477
+ _useFetchGithubReposi2 = _useFetchGithubReposi.data,
478
+ _useFetchGithubReposi3 = _useFetchGithubReposi2 === void 0 ? {} : _useFetchGithubReposi2,
479
+ _useFetchGithubReposi4 = _useFetchGithubReposi3.repositories,
480
+ containerRepositories = _useFetchGithubReposi4 === void 0 ? [] : _useFetchGithubReposi4,
481
+ _useFetchGithubReposi5 = _useFetchGithubReposi3.accounts,
482
+ containerAccounts = _useFetchGithubReposi5 === void 0 ? [] : _useFetchGithubReposi5,
483
+ isContainerLoading = _useFetchGithubReposi.isLoading;
484
+ var repositories = shouldFetchRepositories ? containerRepositories : paneRepositories;
485
+ var accounts = shouldFetchRepositories ? containerAccounts : paneAccounts;
486
+ var isLoading = shouldFetchRepositories ? isContainerLoading : isPaneLoading;
487
+ if (isLoading) {
488
+ return /*#__PURE__*/React.createElement("div", {
489
+ className: "flex h-96 w-full flex-col items-center"
490
+ }, /*#__PURE__*/React.createElement(PageLoader, {
491
+ text: t("neetoGithub.fetchingRepos")
492
+ }), ";");
493
+ }
463
494
  return /*#__PURE__*/React.createElement("div", {
464
495
  className: classNames("flex w-full flex-col-reverse", {
465
496
  "2xl:flex-row": isPane,
@@ -469,7 +500,6 @@ var NeetoGithubNanoContainer = function NeetoGithubNanoContainer(_ref) {
469
500
  installationUrl: installationUrl,
470
501
  isConnected: isConnected,
471
502
  isConnecting: isConnecting,
472
- isPublicRepoAllowed: isPublicRepoAllowed,
473
503
  onConnect: onConnect,
474
504
  repositories: repositories,
475
505
  troubleshootUrl: troubleshootUrl
@@ -2742,18 +2772,14 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2742
2772
  isConnecting = _ref$isConnecting === void 0 ? false : _ref$isConnecting,
2743
2773
  _ref$isConnected = _ref.isConnected,
2744
2774
  isConnected = _ref$isConnected === void 0 ? false : _ref$isConnected,
2745
- _ref$isPublicRepoAllo = _ref.isPublicRepoAllowed,
2746
- 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
2775
  _ref$installationUrl = _ref.installationUrl,
2752
2776
  installationUrl = _ref$installationUrl === void 0 ? NEW_INSTALLATION_URL : _ref$installationUrl,
2753
2777
  _ref$troubleshootUrl = _ref.troubleshootUrl,
2754
2778
  troubleshootUrl = _ref$troubleshootUrl === void 0 ? TROUBLESHOOT_URL : _ref$troubleshootUrl,
2755
2779
  _ref$onConnect = _ref.onConnect,
2756
2780
  onConnect = _ref$onConnect === void 0 ? noop : _ref$onConnect,
2781
+ _ref$projects = _ref.projects,
2782
+ projects = _ref$projects === void 0 ? [] : _ref$projects,
2757
2783
  _ref$title = _ref.title,
2758
2784
  title = _ref$title === void 0 ? "" : _ref$title,
2759
2785
  _ref$description = _ref.description,
@@ -2761,6 +2787,22 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2761
2787
  var _useTranslation = useTranslation(),
2762
2788
  t = _useTranslation.t;
2763
2789
  var initialFocusRef = useRef(null);
2790
+ var _useFetchGithubReposi = useFetchGithubRepositories({
2791
+ isConnected: isOpen && isConnected
2792
+ }),
2793
+ _useFetchGithubReposi2 = _useFetchGithubReposi.data,
2794
+ _useFetchGithubReposi3 = _useFetchGithubReposi2 === void 0 ? {} : _useFetchGithubReposi2,
2795
+ _useFetchGithubReposi4 = _useFetchGithubReposi3.repositories,
2796
+ repositories = _useFetchGithubReposi4 === void 0 ? [] : _useFetchGithubReposi4,
2797
+ _useFetchGithubReposi5 = _useFetchGithubReposi3.accounts,
2798
+ accounts = _useFetchGithubReposi5 === void 0 ? [] : _useFetchGithubReposi5,
2799
+ isPaneLoading = _useFetchGithubReposi.isLoading;
2800
+ var paneRepositories = repositories.filter(function (repository) {
2801
+ return !findBy({
2802
+ repository: repository.fullName
2803
+ }, projects);
2804
+ });
2805
+ var paneAccounts = isConnected ? accounts : [];
2764
2806
  return /*#__PURE__*/React.createElement(Pane, {
2765
2807
  initialFocusRef: initialFocusRef,
2766
2808
  isOpen: isOpen,
@@ -2773,15 +2815,16 @@ var NeetoGithubNanoPane = function NeetoGithubNanoPane(_ref) {
2773
2815
  className: "mt-4",
2774
2816
  style: "body2"
2775
2817
  }, isPresent(description) ? description : t("neetoGithub.modal.description"))), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(NeetoGithubNanoContainer, {
2776
- accounts: accounts,
2777
2818
  installationUrl: installationUrl,
2778
2819
  isConnected: isConnected,
2779
2820
  isConnecting: isConnecting,
2780
- isPublicRepoAllowed: isPublicRepoAllowed,
2821
+ isPaneLoading: isPaneLoading,
2781
2822
  onConnect: onConnect,
2782
- repositories: repositories,
2823
+ paneAccounts: paneAccounts,
2824
+ paneRepositories: paneRepositories,
2783
2825
  troubleshootUrl: troubleshootUrl,
2784
- isPane: true
2826
+ isPane: true,
2827
+ shouldFetchRepositories: false
2785
2828
  })));
2786
2829
  };
2787
2830