@bigbinary/neeto-api-keys-frontend 3.1.7-beta1 → 3.1.7

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.
@@ -2,8 +2,8 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
3
  import { useRef, useMemo, useState, useEffect } from 'react';
4
4
  import { t } from 'i18next';
5
- import { Typography, Badge, DatePicker as DatePicker$1, Sheet, Spinner, Empty, DataTable, Button, Alert } from '@bigbinary/neeto-atoms';
6
- import { isPresent, humanize, isNotPresent, isNotEmpty } from '@bigbinary/neeto-cist';
5
+ import { Button, Typography, Badge, DatePicker as DatePicker$1, Sheet, Avatar, Spinner, Empty, DataTable, Alert } from '@bigbinary/neeto-atoms';
6
+ import { isPresent, humanize, isNotEmpty, isNotPresent } from '@bigbinary/neeto-cist';
7
7
  import { DEFAULT_PAGE_SIZE, PLURAL } from '@bigbinary/neeto-commons-frontend/v2/constants';
8
8
  import { withTitle, useQueryParams, useDebounce } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
9
9
  import { dayjs, dateFormat, getQueryParams } from '@bigbinary/neeto-commons-frontend/v2/utils';
@@ -21,6 +21,7 @@ import { globalProps } from '@bigbinary/neeto-commons-frontend/v2/initializers';
21
21
  import CopyToClipboardButton from '@bigbinary/neeto-molecules/v2/CopyToClipboardButton';
22
22
  import MoreDropdown from '@bigbinary/neeto-molecules/v2/MoreDropdown';
23
23
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
24
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
24
25
  import { KeyRound } from 'lucide-react';
25
26
  import '@bigbinary/neeto-commons-frontend/constants';
26
27
  import '@bigbinary/neeto-commons-frontend/react-utils';
@@ -81,6 +82,9 @@ var MASKED_TOKEN_LENGTH = 20;
81
82
  var isInPast = function isInPast(date) {
82
83
  return dayjs(date).isBefore(dayjs());
83
84
  };
85
+ var isExpired = function isExpired(expiresAt) {
86
+ return isPresent(expiresAt) && isInPast(expiresAt);
87
+ };
84
88
  var partlyHideToken = function partlyHideToken(key) {
85
89
  var prefixMatch = key.match(/^([A-Z]+-)/);
86
90
  if (prefixMatch) {
@@ -114,6 +118,7 @@ var getMenuItems = function getMenuItems(_ref) {
114
118
  var buildColumnData = function buildColumnData(_ref2) {
115
119
  var handleDelete = _ref2.handleDelete,
116
120
  handleEdit = _ref2.handleEdit,
121
+ handleView = _ref2.handleView,
117
122
  isZapierAvailable = _ref2.isZapierAvailable;
118
123
  var columns = [{
119
124
  id: "label",
@@ -127,11 +132,14 @@ var buildColumnData = function buildColumnData(_ref2) {
127
132
  var apiKey = row.original;
128
133
  return /*#__PURE__*/jsxs("div", {
129
134
  className: "flex items-center justify-between gap-x-3",
130
- children: [/*#__PURE__*/jsx(Typography, {
131
- className: "min-w-0 flex-1 truncate",
135
+ children: [/*#__PURE__*/jsx(Button, {
136
+ className: "min-w-0 shrink justify-start text-left [&>span]:min-w-0 [&>span>span]:truncate",
132
137
  "data-testid": "api-keys-label-field",
133
138
  title: label,
134
- variant: "body2",
139
+ variant: "link",
140
+ onClick: function onClick() {
141
+ return handleView(apiKey);
142
+ },
135
143
  children: label
136
144
  }), /*#__PURE__*/jsx(MoreDropdown, {
137
145
  menuItems: getMenuItems({
@@ -192,7 +200,7 @@ var buildColumnData = function buildColumnData(_ref2) {
192
200
  cell: function cell(_ref6) {
193
201
  var row = _ref6.row;
194
202
  var expiresAt = row.original.expiresAt;
195
- return isPresent(expiresAt) && isInPast(expiresAt) ? /*#__PURE__*/jsx(Badge, {
203
+ return isExpired(expiresAt) ? /*#__PURE__*/jsx(Badge, {
196
204
  variant: "amber",
197
205
  children: t("neetoApiKeys.tags.expired")
198
206
  }) : /*#__PURE__*/jsx(Badge, {
@@ -342,9 +350,9 @@ var getExpirationDate = function getExpirationDate(type) {
342
350
  }
343
351
  };
344
352
 
345
- function ownKeys$3(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; }
346
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
347
- var Item = RadioGroup.Item;
353
+ function ownKeys$4(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; }
354
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
355
+ var Item$1 = RadioGroup.Item;
348
356
  var Form = function Form(_ref) {
349
357
  var _ref$initialValues = _ref.initialValues,
350
358
  initialValues = _ref$initialValues === void 0 ? INITIAL_VALUES : _ref$initialValues,
@@ -358,7 +366,7 @@ var Form = function Form(_ref) {
358
366
  isZapierAvailable = _ref$isZapierAvailabl === void 0 ? false : _ref$isZapierAvailabl;
359
367
  var _useTranslation = useTranslation(),
360
368
  t = _useTranslation.t;
361
- var formInitialValues = _objectSpread$3(_objectSpread$3({}, initialValues), {}, {
369
+ var formInitialValues = _objectSpread$4(_objectSpread$4({}, initialValues), {}, {
362
370
  expirationType: getInitialExpirationType({
363
371
  isEdit: isEdit,
364
372
  values: initialValues
@@ -400,11 +408,11 @@ var Form = function Form(_ref) {
400
408
  label: t("neetoApiKeys.common.type"),
401
409
  name: "type",
402
410
  orientation: "vertical",
403
- children: [/*#__PURE__*/jsx(Item, {
411
+ children: [/*#__PURE__*/jsx(Item$1, {
404
412
  label: t("neetoApiKeys.common.general"),
405
413
  name: "type",
406
414
  value: API_KEY_TYPES.GENERAL
407
- }), /*#__PURE__*/jsx(Item, {
415
+ }), /*#__PURE__*/jsx(Item$1, {
408
416
  label: t("neetoApiKeys.common.zapier"),
409
417
  name: "type",
410
418
  value: API_KEY_TYPES.ZAPIER
@@ -433,27 +441,27 @@ var Form = function Form(_ref) {
433
441
  type: expirationType
434
442
  });
435
443
  },
436
- children: [/*#__PURE__*/jsx(Item, {
444
+ children: [/*#__PURE__*/jsx(Item$1, {
437
445
  name: "expirationType",
438
446
  value: EXPIRATION_OPTIONS.SEVEN_DAYS,
439
447
  label: t("neetoApiKeys.fields.expirationOptions.sevenDays")
440
- }), /*#__PURE__*/jsx(Item, {
448
+ }), /*#__PURE__*/jsx(Item$1, {
441
449
  name: "expirationType",
442
450
  value: EXPIRATION_OPTIONS.THIRTY_DAYS,
443
451
  label: t("neetoApiKeys.fields.expirationOptions.thirtyDays")
444
- }), /*#__PURE__*/jsx(Item, {
452
+ }), /*#__PURE__*/jsx(Item$1, {
445
453
  name: "expirationType",
446
454
  value: EXPIRATION_OPTIONS.NINETY_DAYS,
447
455
  label: t("neetoApiKeys.fields.expirationOptions.ninetyDays")
448
- }), /*#__PURE__*/jsx(Item, {
456
+ }), /*#__PURE__*/jsx(Item$1, {
449
457
  name: "expirationType",
450
458
  value: EXPIRATION_OPTIONS.ONE_YEAR,
451
459
  label: t("neetoApiKeys.fields.expirationOptions.oneYear")
452
- }), /*#__PURE__*/jsx(Item, {
460
+ }), /*#__PURE__*/jsx(Item$1, {
453
461
  label: t("neetoApiKeys.fields.expirationOptions.never"),
454
462
  name: "expirationType",
455
463
  value: EXPIRATION_OPTIONS.NEVER
456
- }), /*#__PURE__*/jsx(Item, {
464
+ }), /*#__PURE__*/jsx(Item$1, {
457
465
  name: "expirationType",
458
466
  value: EXPIRATION_OPTIONS.CUSTOM,
459
467
  label: t("neetoApiKeys.fields.expirationOptions.custom")
@@ -520,6 +528,147 @@ var Create = function Create(_ref) {
520
528
  });
521
529
  };
522
530
 
531
+ var _excluded = ["label", "children"];
532
+ function ownKeys$3(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; }
533
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
534
+ var Item = function Item(_ref) {
535
+ var label = _ref.label,
536
+ children = _ref.children,
537
+ otherProps = _objectWithoutProperties(_ref, _excluded);
538
+ return /*#__PURE__*/jsxs("div", _objectSpread$3(_objectSpread$3({
539
+ className: "space-y-1"
540
+ }, otherProps), {}, {
541
+ children: [/*#__PURE__*/jsx(Typography, {
542
+ color: "muted",
543
+ variant: "body3",
544
+ weight: "medium",
545
+ children: label
546
+ }), /*#__PURE__*/jsx("div", {
547
+ className: "min-w-0",
548
+ children: children
549
+ })]
550
+ }));
551
+ };
552
+
553
+ var Details = function Details(_ref) {
554
+ var apiKey = _ref.apiKey,
555
+ _ref$isZapierAvailabl = _ref.isZapierAvailable,
556
+ isZapierAvailable = _ref$isZapierAvailabl === void 0 ? false : _ref$isZapierAvailabl,
557
+ onClose = _ref.onClose,
558
+ _onEdit = _ref.onEdit,
559
+ _onDelete = _ref.onDelete;
560
+ var _useTranslation = useTranslation(),
561
+ t = _useTranslation.t;
562
+ var label = apiKey.label,
563
+ token = apiKey.token,
564
+ notes = apiKey.notes,
565
+ type = apiKey.type,
566
+ expiresAt = apiKey.expiresAt,
567
+ createdAt = apiKey.createdAt,
568
+ creator = apiKey.creator;
569
+ return /*#__PURE__*/jsxs(Sheet, {
570
+ onClose: onClose,
571
+ isOpen: isNotEmpty(apiKey),
572
+ children: [/*#__PURE__*/jsx(Sheet.Header, {
573
+ children: /*#__PURE__*/jsxs("div", {
574
+ className: "flex items-center gap-x-2",
575
+ children: [/*#__PURE__*/jsx(Sheet.Title, {
576
+ className: "min-w-0 break-words",
577
+ "data-testid": "api-key-details-title",
578
+ children: label
579
+ }), /*#__PURE__*/jsx(MoreDropdown, {
580
+ menuItems: getMenuItems({
581
+ onEdit: function onEdit() {
582
+ return _onEdit(apiKey);
583
+ },
584
+ onDelete: function onDelete() {
585
+ return _onDelete(apiKey);
586
+ },
587
+ isEditVisible: type === API_KEY_TYPES.GENERAL
588
+ })
589
+ })]
590
+ })
591
+ }), /*#__PURE__*/jsx(Sheet.Body, {
592
+ children: /*#__PURE__*/jsxs("div", {
593
+ className: "w-full space-y-6",
594
+ children: [/*#__PURE__*/jsx(Item, {
595
+ label: t("neetoApiKeys.table.headers.token"),
596
+ children: /*#__PURE__*/jsxs("div", {
597
+ className: "flex items-center gap-x-3",
598
+ children: [/*#__PURE__*/jsx(Typography, {
599
+ className: "min-w-0 truncate",
600
+ "data-testid": "api-key-details-token",
601
+ variant: "body2",
602
+ children: isPresent(token) && partlyHideToken(token)
603
+ }), /*#__PURE__*/jsx(CopyToClipboardButton, {
604
+ value: token
605
+ })]
606
+ })
607
+ }), isZapierAvailable && /*#__PURE__*/jsx(Item, {
608
+ label: t("neetoApiKeys.table.headers.type"),
609
+ children: /*#__PURE__*/jsx(Typography, {
610
+ variant: "body2",
611
+ children: humanize(type !== null && type !== void 0 ? type : "")
612
+ })
613
+ }), /*#__PURE__*/jsx(Item, {
614
+ label: t("neetoApiKeys.table.headers.status"),
615
+ children: isExpired(expiresAt) ? /*#__PURE__*/jsx(Badge, {
616
+ variant: "amber",
617
+ children: t("neetoApiKeys.tags.expired")
618
+ }) : /*#__PURE__*/jsx(Badge, {
619
+ variant: "green",
620
+ children: t("neetoApiKeys.tags.active")
621
+ })
622
+ }), isPresent(notes) && /*#__PURE__*/jsx(Item, {
623
+ label: t("neetoApiKeys.table.headers.notes"),
624
+ children: /*#__PURE__*/jsx(Typography, {
625
+ className: "whitespace-pre-wrap break-words",
626
+ "data-testid": "api-key-details-notes",
627
+ variant: "body2",
628
+ children: notes
629
+ })
630
+ }), /*#__PURE__*/jsx(Item, {
631
+ label: t("neetoApiKeys.table.headers.expiresAt"),
632
+ children: /*#__PURE__*/jsx(Typography, {
633
+ "data-testid": "api-key-details-expires-at",
634
+ variant: "body2",
635
+ children: isPresent(expiresAt) ? formatExpiry(expiresAt) : t("neetoApiKeys.common.never")
636
+ })
637
+ }), /*#__PURE__*/jsx(Item, {
638
+ label: t("neetoApiKeys.table.headers.createdAt"),
639
+ children: /*#__PURE__*/jsx(Typography, {
640
+ "data-testid": "api-key-details-created-at",
641
+ variant: "body2",
642
+ children: isPresent(createdAt) && dateFormat.dateTime(createdAt)
643
+ })
644
+ }), /*#__PURE__*/jsx(Item, {
645
+ label: t("neetoApiKeys.fields.createdBy"),
646
+ children: isPresent(creator) ? /*#__PURE__*/jsxs("div", {
647
+ className: "flex items-center gap-x-2",
648
+ "data-testid": "api-key-details-created-by",
649
+ children: [/*#__PURE__*/jsx(Avatar, {
650
+ size: "sm",
651
+ user: {
652
+ name: creator.name,
653
+ imageUrl: creator.profileImageUrl
654
+ }
655
+ }), /*#__PURE__*/jsx(Typography, {
656
+ className: "min-w-0 truncate",
657
+ variant: "body2",
658
+ children: creator.name
659
+ })]
660
+ }) : /*#__PURE__*/jsx(Typography, {
661
+ color: "muted",
662
+ "data-testid": "api-key-details-created-by",
663
+ variant: "body2",
664
+ children: t("neetoApiKeys.common.notAvailable")
665
+ })
666
+ })]
667
+ })
668
+ })]
669
+ });
670
+ };
671
+
523
672
  function ownKeys$2(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; }
524
673
  function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
525
674
  var Update = function Update(_ref) {
@@ -574,6 +723,7 @@ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t
574
723
  var Table = function Table(_ref) {
575
724
  var handleDelete = _ref.handleDelete,
576
725
  handleEdit = _ref.handleEdit,
726
+ handleView = _ref.handleView,
577
727
  currentPage = _ref.currentPage,
578
728
  setIsCreatePaneOpen = _ref.setIsCreatePaneOpen,
579
729
  _ref$noDataProps = _ref.noDataProps,
@@ -589,9 +739,10 @@ var Table = function Table(_ref) {
589
739
  return buildColumnData({
590
740
  handleDelete: handleDelete,
591
741
  handleEdit: handleEdit,
742
+ handleView: handleView,
592
743
  isZapierAvailable: isZapierAvailable
593
744
  });
594
- }, [handleDelete, handleEdit, isZapierAvailable]);
745
+ }, [handleDelete, handleEdit, handleView, isZapierAvailable]);
595
746
  if (isLoading) {
596
747
  return /*#__PURE__*/jsx("div", {
597
748
  className: "flex h-full w-full items-center justify-center",
@@ -629,8 +780,8 @@ var Table = function Table(_ref) {
629
780
  children: /*#__PURE__*/jsx(DataTable, {
630
781
  columns: columns,
631
782
  currentPage: currentPage,
632
- data: (data === null || data === void 0 ? void 0 : data.apiKeys) || [],
633
783
  enableColumnFreeze: true,
784
+ data: (data === null || data === void 0 ? void 0 : data.apiKeys) || [],
634
785
  loading: isFetching,
635
786
  pageSize: DEFAULT_PAGE_SIZE,
636
787
  totalCount: data === null || data === void 0 ? void 0 : data.totalCount
@@ -656,10 +807,14 @@ var ApiKeys = function ApiKeys(_ref) {
656
807
  _useState4 = _slicedToArray(_useState3, 2),
657
808
  apiKeyToBeEdited = _useState4[0],
658
809
  setApiKeyToBeEdited = _useState4[1];
659
- var _useState5 = useState(false),
810
+ var _useState5 = useState({}),
660
811
  _useState6 = _slicedToArray(_useState5, 2),
661
- isCreatePaneOpen = _useState6[0],
662
- setIsCreatePaneOpen = _useState6[1];
812
+ apiKeyToBeViewed = _useState6[0],
813
+ setApiKeyToBeViewed = _useState6[1];
814
+ var _useState7 = useState(false),
815
+ _useState8 = _slicedToArray(_useState7, 2),
816
+ isCreatePaneOpen = _useState8[0],
817
+ setIsCreatePaneOpen = _useState8[1];
663
818
  var _useTranslation = useTranslation(),
664
819
  t = _useTranslation.t;
665
820
  var _useQueryParams = useQueryParams(),
@@ -700,6 +855,14 @@ var ApiKeys = function ApiKeys(_ref) {
700
855
  var showFilters = isPresent(debouncedSearchTerm) || (data === null || data === void 0 ? void 0 : data.totalCount) > 0;
701
856
  var _data$isZapierAvailab = data.isZapierAvailable,
702
857
  isZapierAvailable = _data$isZapierAvailab === void 0 ? false : _data$isZapierAvailab;
858
+ var handleEditFromDetails = function handleEditFromDetails(apiKey) {
859
+ setApiKeyToBeViewed({});
860
+ setApiKeyToBeEdited(apiKey);
861
+ };
862
+ var handleDeleteFromDetails = function handleDeleteFromDetails(apiKey) {
863
+ setApiKeyToBeViewed({});
864
+ setApiKeyToBeDeleted(apiKey);
865
+ };
703
866
  return /*#__PURE__*/jsxs("div", {
704
867
  className: "flex h-full w-full flex-col",
705
868
  children: [/*#__PURE__*/jsx(Header, _objectSpread({
@@ -748,7 +911,8 @@ var ApiKeys = function ApiKeys(_ref) {
748
911
  noDataProps: noDataProps,
749
912
  setIsCreatePaneOpen: setIsCreatePaneOpen,
750
913
  handleDelete: setApiKeyToBeDeleted,
751
- handleEdit: setApiKeyToBeEdited
914
+ handleEdit: setApiKeyToBeEdited,
915
+ handleView: setApiKeyToBeViewed
752
916
  }), /*#__PURE__*/jsx(Alert, {
753
917
  isOpen: isNotEmpty(apiKeyToBeDeleted),
754
918
  isSubmitting: isDeleting,
@@ -781,6 +945,14 @@ var ApiKeys = function ApiKeys(_ref) {
781
945
  onClose: function onClose() {
782
946
  return setIsCreatePaneOpen(false);
783
947
  }
948
+ }), /*#__PURE__*/jsx(Details, {
949
+ isZapierAvailable: isZapierAvailable,
950
+ apiKey: apiKeyToBeViewed,
951
+ onClose: function onClose() {
952
+ return setApiKeyToBeViewed({});
953
+ },
954
+ onDelete: handleDeleteFromDetails,
955
+ onEdit: handleEditFromDetails
784
956
  }), /*#__PURE__*/jsx(Update, {
785
957
  helpDocUrl: helpDocUrl,
786
958
  apiKey: apiKeyToBeEdited,