@bigbinary/neeto-api-keys-frontend 1.0.1 → 1.0.2

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,10 +1,9 @@
1
- import React, { createElement, isValidElement, cloneElement, createContext, useContext, useRef, useState, useEffect } from 'react';
1
+ import React, { createElement, isValidElement, cloneElement, createContext, useContext, useState, useRef, useEffect } from 'react';
2
2
  import { DEFAULT_PAGE_INDEX, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
3
3
  import { isPresent, isNotPresent, isNotEmpty } from '@bigbinary/neeto-commons-frontend/pure';
4
- import { useMutationWithInvalidation, withT, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
5
- import Container from '@bigbinary/neeto-molecules/Container';
6
4
  import Header from '@bigbinary/neeto-molecules/Header';
7
5
  import { Dropdown, Typography, Button, Tag, DatePicker as DatePicker$1, Pane, NoData, Table as Table$1, Alert } from '@bigbinary/neetoui';
6
+ import { useMutationWithInvalidation, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
8
7
  import { useQuery } from 'react-query';
9
8
  import axios from 'axios';
10
9
  import { Form as Form$1, Input, Checkbox, ActionBlock } from '@bigbinary/neetoui/formik';
@@ -2337,6 +2336,62 @@ function warnOnce() {
2337
2336
  if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
2338
2337
  warn(...args);
2339
2338
  }
2339
+ const loadedClb = (i18n, cb) => () => {
2340
+ if (i18n.isInitialized) {
2341
+ cb();
2342
+ } else {
2343
+ const initialized = () => {
2344
+ setTimeout(() => {
2345
+ i18n.off('initialized', initialized);
2346
+ }, 0);
2347
+ cb();
2348
+ };
2349
+ i18n.on('initialized', initialized);
2350
+ }
2351
+ };
2352
+ function loadNamespaces(i18n, ns, cb) {
2353
+ i18n.loadNamespaces(ns, loadedClb(i18n, cb));
2354
+ }
2355
+ function loadLanguages(i18n, lng, ns, cb) {
2356
+ if (typeof ns === 'string') ns = [ns];
2357
+ ns.forEach(n => {
2358
+ if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
2359
+ });
2360
+ i18n.loadLanguages(lng, loadedClb(i18n, cb));
2361
+ }
2362
+ function oldI18nextHasLoadedNamespace(ns, i18n) {
2363
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2364
+ const lng = i18n.languages[0];
2365
+ const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
2366
+ const lastLng = i18n.languages[i18n.languages.length - 1];
2367
+ if (lng.toLowerCase() === 'cimode') return true;
2368
+ const loadNotPending = (l, n) => {
2369
+ const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
2370
+ return loadState === -1 || loadState === 2;
2371
+ };
2372
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
2373
+ if (i18n.hasResourceBundle(lng, ns)) return true;
2374
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
2375
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2376
+ return false;
2377
+ }
2378
+ function hasLoadedNamespace(ns, i18n) {
2379
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2380
+ if (!i18n.languages || !i18n.languages.length) {
2381
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
2382
+ return true;
2383
+ }
2384
+ const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
2385
+ if (!isNewerI18next) {
2386
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
2387
+ }
2388
+ return i18n.hasLoadedNamespace(ns, {
2389
+ lng: options.lng,
2390
+ precheck: (i18nInstance, loadNotPending) => {
2391
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
2392
+ }
2393
+ });
2394
+ }
2340
2395
 
2341
2396
  const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
2342
2397
  const htmlEntities = {
@@ -2640,6 +2695,19 @@ const initReactI18next = {
2640
2695
  };
2641
2696
 
2642
2697
  const I18nContext = createContext();
2698
+ class ReportNamespaces {
2699
+ constructor() {
2700
+ this.usedNamespaces = {};
2701
+ }
2702
+ addUsedNamespaces(namespaces) {
2703
+ namespaces.forEach(ns => {
2704
+ if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
2705
+ });
2706
+ }
2707
+ getUsedNamespaces() {
2708
+ return Object.keys(this.usedNamespaces);
2709
+ }
2710
+ }
2643
2711
 
2644
2712
  function Trans(_ref) {
2645
2713
  let {
@@ -2682,6 +2750,112 @@ function Trans(_ref) {
2682
2750
  });
2683
2751
  }
2684
2752
 
2753
+ const usePrevious = (value, ignore) => {
2754
+ const ref = useRef();
2755
+ useEffect(() => {
2756
+ ref.current = ignore ? ref.current : value;
2757
+ }, [value, ignore]);
2758
+ return ref.current;
2759
+ };
2760
+ function useTranslation(ns) {
2761
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2762
+ const {
2763
+ i18n: i18nFromProps
2764
+ } = props;
2765
+ const {
2766
+ i18n: i18nFromContext,
2767
+ defaultNS: defaultNSFromContext
2768
+ } = useContext(I18nContext) || {};
2769
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
2770
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
2771
+ if (!i18n) {
2772
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
2773
+ const notReadyT = (k, optsOrDefaultValue) => {
2774
+ if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
2775
+ if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
2776
+ return Array.isArray(k) ? k[k.length - 1] : k;
2777
+ };
2778
+ const retNotReady = [notReadyT, {}, false];
2779
+ retNotReady.t = notReadyT;
2780
+ retNotReady.i18n = {};
2781
+ retNotReady.ready = false;
2782
+ return retNotReady;
2783
+ }
2784
+ if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
2785
+ const i18nOptions = {
2786
+ ...getDefaults(),
2787
+ ...i18n.options.react,
2788
+ ...props
2789
+ };
2790
+ const {
2791
+ useSuspense,
2792
+ keyPrefix
2793
+ } = i18nOptions;
2794
+ let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
2795
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
2796
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
2797
+ const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
2798
+ function getT() {
2799
+ return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
2800
+ }
2801
+ const [t, setT] = useState(getT);
2802
+ let joinedNS = namespaces.join();
2803
+ if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
2804
+ const previousJoinedNS = usePrevious(joinedNS);
2805
+ const isMounted = useRef(true);
2806
+ useEffect(() => {
2807
+ const {
2808
+ bindI18n,
2809
+ bindI18nStore
2810
+ } = i18nOptions;
2811
+ isMounted.current = true;
2812
+ if (!ready && !useSuspense) {
2813
+ if (props.lng) {
2814
+ loadLanguages(i18n, props.lng, namespaces, () => {
2815
+ if (isMounted.current) setT(getT);
2816
+ });
2817
+ } else {
2818
+ loadNamespaces(i18n, namespaces, () => {
2819
+ if (isMounted.current) setT(getT);
2820
+ });
2821
+ }
2822
+ }
2823
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
2824
+ setT(getT);
2825
+ }
2826
+ function boundReset() {
2827
+ if (isMounted.current) setT(getT);
2828
+ }
2829
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
2830
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
2831
+ return () => {
2832
+ isMounted.current = false;
2833
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
2834
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
2835
+ };
2836
+ }, [i18n, joinedNS]);
2837
+ const isInitial = useRef(true);
2838
+ useEffect(() => {
2839
+ if (isMounted.current && !isInitial.current) {
2840
+ setT(getT);
2841
+ }
2842
+ isInitial.current = false;
2843
+ }, [i18n, keyPrefix]);
2844
+ const ret = [t, i18n, ready];
2845
+ ret.t = t;
2846
+ ret.i18n = i18n;
2847
+ ret.ready = ready;
2848
+ if (ready) return ret;
2849
+ if (!ready && !useSuspense) return ret;
2850
+ throw new Promise(resolve => {
2851
+ if (props.lng) {
2852
+ loadLanguages(i18n, props.lng, namespaces, () => resolve());
2853
+ } else {
2854
+ loadNamespaces(i18n, namespaces, () => resolve());
2855
+ }
2856
+ });
2857
+ }
2858
+
2685
2859
  var common = {
2686
2860
  apiKey_one: "API key",
2687
2861
  apiKey_other: "API keys",
@@ -2915,10 +3089,11 @@ var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
2915
3089
 
2916
3090
  var Menu = Dropdown.Menu,
2917
3091
  MenuItem = Dropdown.MenuItem;
2918
- var ActionDropdown = withT(function (_ref) {
2919
- var t = _ref.t,
2920
- handleEdit = _ref.handleEdit,
3092
+ var ActionDropdown = function ActionDropdown(_ref) {
3093
+ var handleEdit = _ref.handleEdit,
2921
3094
  handleDelete = _ref.handleDelete;
3095
+ var _useTranslation = useTranslation(),
3096
+ t = _useTranslation.t;
2922
3097
  return /*#__PURE__*/React.createElement(Dropdown, {
2923
3098
  buttonStyle: "text",
2924
3099
  icon: MenuHorizontal,
@@ -2929,7 +3104,7 @@ var ActionDropdown = withT(function (_ref) {
2929
3104
  style: "danger",
2930
3105
  onClick: handleDelete
2931
3106
  }, t("buttons.delete"))));
2932
- });
3107
+ };
2933
3108
 
2934
3109
  var isInPast = function isInPast(date) {
2935
3110
  return dayjs(date).isBefore(dayjs());
@@ -3081,14 +3256,15 @@ var VALIDATION_SCHEMA = yup.object({
3081
3256
  });
3082
3257
  var DEFAULT_PAGE_SIZE = 15;
3083
3258
 
3084
- var Form = withT(function (_ref) {
3085
- var t = _ref.t,
3086
- _ref$initialValues = _ref.initialValues,
3259
+ var Form = function Form(_ref) {
3260
+ var _ref$initialValues = _ref.initialValues,
3087
3261
  initialValues = _ref$initialValues === void 0 ? INITIAL_VALUES : _ref$initialValues,
3088
3262
  isSubmitting = _ref.isSubmitting,
3089
3263
  onClose = _ref.onClose,
3090
3264
  onSubmit = _ref.onSubmit,
3091
3265
  initialFocusRef = _ref.initialFocusRef;
3266
+ var _useTranslation = useTranslation(),
3267
+ t = _useTranslation.t;
3092
3268
  return /*#__PURE__*/React.createElement(Form$1, {
3093
3269
  formikProps: {
3094
3270
  validationSchema: VALIDATION_SCHEMA,
@@ -3142,16 +3318,17 @@ var Form = withT(function (_ref) {
3142
3318
  }
3143
3319
  })));
3144
3320
  });
3145
- });
3321
+ };
3146
3322
 
3147
- var Create = withT(function (_ref) {
3148
- var t = _ref.t,
3149
- onClose = _ref.onClose,
3323
+ var Create = function Create(_ref) {
3324
+ var onClose = _ref.onClose,
3150
3325
  isOpen = _ref.isOpen;
3151
3326
  var initialFocusRef = useRef(null);
3152
3327
  var _useCreateApiKey = useCreateApiKey(onClose),
3153
3328
  createApiKey = _useCreateApiKey.mutate,
3154
3329
  isCreating = _useCreateApiKey.isLoading;
3330
+ var _useTranslation = useTranslation(),
3331
+ t = _useTranslation.t;
3155
3332
  return /*#__PURE__*/React.createElement(Pane, {
3156
3333
  initialFocusRef: initialFocusRef,
3157
3334
  onClose: onClose,
@@ -3164,7 +3341,7 @@ var Create = withT(function (_ref) {
3164
3341
  isSubmitting: isCreating,
3165
3342
  onSubmit: createApiKey
3166
3343
  }));
3167
- });
3344
+ };
3168
3345
 
3169
3346
  function _typeof(obj) {
3170
3347
  "@babel/helpers - typeof";
@@ -3209,14 +3386,15 @@ function _defineProperty(obj, key, value) {
3209
3386
 
3210
3387
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3211
3388
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3212
- var Update = withT(function (_ref) {
3213
- var t = _ref.t,
3214
- onClose = _ref.onClose,
3389
+ var Update = function Update(_ref) {
3390
+ var onClose = _ref.onClose,
3215
3391
  apiKey = _ref.apiKey;
3216
3392
  var initialFocusRef = useRef(null);
3217
3393
  var _useUpdateApiKey = useUpdateApiKey(onClose),
3218
3394
  updateApiKey = _useUpdateApiKey.mutate,
3219
3395
  isUpdating = _useUpdateApiKey.isLoading;
3396
+ var _useTranslation = useTranslation(),
3397
+ t = _useTranslation.t;
3220
3398
  var handleUpdate = function handleUpdate(values) {
3221
3399
  updateApiKey({
3222
3400
  id: apiKey.id,
@@ -3239,7 +3417,7 @@ var Update = withT(function (_ref) {
3239
3417
  isSubmitting: isUpdating,
3240
3418
  onSubmit: handleUpdate
3241
3419
  }));
3242
- });
3420
+ };
3243
3421
 
3244
3422
  var getPageFromSearchParams = function getPageFromSearchParams() {
3245
3423
  var _getQueryParams = getQueryParams(),
@@ -3293,12 +3471,13 @@ var usePagination = function usePagination(_ref) {
3293
3471
  };
3294
3472
  };
3295
3473
 
3296
- var Table = withT(function (_ref) {
3297
- var t = _ref.t,
3298
- handleDelete = _ref.handleDelete,
3474
+ var Table = function Table(_ref) {
3475
+ var handleDelete = _ref.handleDelete,
3299
3476
  handleEdit = _ref.handleEdit,
3300
3477
  searchTerm = _ref.searchTerm;
3301
3478
  var debouncedSearchTerm = useDebounce(searchTerm);
3479
+ var _useTranslation = useTranslation(),
3480
+ t = _useTranslation.t;
3302
3481
  var _usePagination = usePagination({
3303
3482
  searchTerm: debouncedSearchTerm
3304
3483
  }),
@@ -3347,11 +3526,10 @@ var Table = withT(function (_ref) {
3347
3526
  rowData: apiKeys,
3348
3527
  totalCount: totalCount
3349
3528
  }));
3350
- });
3529
+ };
3351
3530
 
3352
- var ApiKeys = withT(function (_ref) {
3353
- var t = _ref.t,
3354
- _ref$breadcrumbs = _ref.breadcrumbs,
3531
+ var ApiKeys = function ApiKeys(_ref) {
3532
+ var _ref$breadcrumbs = _ref.breadcrumbs,
3355
3533
  breadcrumbs = _ref$breadcrumbs === void 0 ? [] : _ref$breadcrumbs;
3356
3534
  var _useState = useState(""),
3357
3535
  _useState2 = _slicedToArray(_useState, 2),
@@ -3369,12 +3547,16 @@ var ApiKeys = withT(function (_ref) {
3369
3547
  _useState8 = _slicedToArray(_useState7, 2),
3370
3548
  isCreatePaneOpen = _useState8[0],
3371
3549
  setIsCreatePaneOpen = _useState8[1];
3550
+ var _useTranslation = useTranslation(),
3551
+ t = _useTranslation.t;
3372
3552
  var _useDeleteApiKey = useDeleteApiKey(function () {
3373
3553
  return setApiKeyToBeDeleted({});
3374
3554
  }),
3375
3555
  deleteApiKey = _useDeleteApiKey.mutate,
3376
3556
  isDeleting = _useDeleteApiKey.isLoading;
3377
- return /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Header, {
3557
+ return /*#__PURE__*/React.createElement("div", {
3558
+ className: "flex h-full w-full flex-col"
3559
+ }, /*#__PURE__*/React.createElement(Header, {
3378
3560
  breadcrumbs: breadcrumbs,
3379
3561
  title: t("common.apiKey", PLURAL),
3380
3562
  actionBlock: /*#__PURE__*/React.createElement(Button, {
@@ -3426,7 +3608,7 @@ var ApiKeys = withT(function (_ref) {
3426
3608
  return setApiKeyToBeEdited({});
3427
3609
  }
3428
3610
  }));
3429
- });
3611
+ };
3430
3612
 
3431
3613
  export { ApiKeys };
3432
3614
  //# sourceMappingURL=index.js.map