@bigbinary/neeto-access-control-frontend 1.3.3 → 1.3.4

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,16 +1,16 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
- import { useRef, useState, createElement } from 'react';
3
+ import { useRef, useState, createElement, Fragment as Fragment$1 } from 'react';
4
4
  import classNames from 'classnames';
5
5
  import { truncate, humanize, isNotEmpty, noop } from '@bigbinary/neeto-cist';
6
6
  import Container from '@bigbinary/neeto-molecules/Container';
7
7
  import Scrollable from '@bigbinary/neeto-molecules/Scrollable';
8
- import Label from '@bigbinary/neetoui/Label';
9
8
  import Spinner from '@bigbinary/neetoui/Spinner';
10
9
  import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
11
10
  import Form from '@bigbinary/neetoui/formik/Form';
12
11
  import Input from '@bigbinary/neetoui/formik/Input';
13
12
  import Radio from '@bigbinary/neetoui/formik/Radio';
13
+ import { prop, pluck, mergeDeepRight, indexBy, values, isEmpty, equals, pick, reject, pipe, trim, mergeLeft, keys } from 'ramda';
14
14
  import { useTranslation, Trans } from 'react-i18next';
15
15
  import { DEFAULT_STALE_TIME, DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/constants';
16
16
  import Delete from '@bigbinary/neeto-icons/Delete';
@@ -22,7 +22,6 @@ import NoData from '@bigbinary/neetoui/NoData';
22
22
  import Pane from '@bigbinary/neetoui/Pane';
23
23
  import Table from '@bigbinary/neetoui/Table';
24
24
  import Typography from '@bigbinary/neetoui/Typography';
25
- import { prop, pluck, mergeDeepRight, indexBy, values, isEmpty, equals, pick, reject, pipe, trim } from 'ramda';
26
25
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
27
26
  import { useQuery } from '@tanstack/react-query';
28
27
  import { useMutationWithInvalidation, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
@@ -35,6 +34,7 @@ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
35
34
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
36
35
  import Tooltip from '@bigbinary/neetoui/Tooltip';
37
36
  import { FieldArray } from 'formik';
37
+ import Label from '@bigbinary/neetoui/Label';
38
38
  import NeetoHeader from '@bigbinary/neeto-molecules/Header';
39
39
  import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
40
40
 
@@ -76,14 +76,14 @@ var QUERY_KEYS = {
76
76
  };
77
77
 
78
78
  var _excluded = ["ownerId", "ownerType"];
79
- 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; }
80
- 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), !0).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; }
79
+ 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; }
80
+ 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), !0).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; }
81
81
  var ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1 = QUERY_KEYS.ACCESS_CONTROL_CONFIGURATION_INVITATIONS;
82
82
  var useListInvitations = function useListInvitations(_ref, options) {
83
83
  var ownerId = _ref.ownerId,
84
84
  ownerType = _ref.ownerType,
85
85
  otherParams = _objectWithoutProperties(_ref, _excluded);
86
- return useQuery(_objectSpread$3({
86
+ return useQuery(_objectSpread$4({
87
87
  queryKey: [ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1, ownerType, ownerId, otherParams],
88
88
  queryFn: function queryFn() {
89
89
  return invitationsApi.list(otherParams);
@@ -100,7 +100,7 @@ var useBulkCreateInvitations = function useBulkCreateInvitations(_ref2, options)
100
100
  configurationId: configurationId,
101
101
  payload: payload
102
102
  });
103
- }, _objectSpread$3({
103
+ }, _objectSpread$4({
104
104
  keysToInvalidate: [[ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1, ownerType, ownerId]]
105
105
  }, options));
106
106
  };
@@ -113,7 +113,7 @@ var useBulkDestroyInvitations = function useBulkDestroyInvitations(_ref3, option
113
113
  configurationId: configurationId,
114
114
  payload: payload
115
115
  });
116
- }, _objectSpread$3({
116
+ }, _objectSpread$4({
117
117
  keysToInvalidate: [[ACCESS_CONTROL_CONFIGURATION_INVITATIONS$1, ownerType, ownerId]]
118
118
  }, options));
119
119
  };
@@ -236,6 +236,8 @@ var renderColumnData = function renderColumnData(_ref2) {
236
236
  }), extraColumnsData);
237
237
  };
238
238
 
239
+ 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; }
240
+ 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), !0).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; }
239
241
  var Invitations$1 = function Invitations(_ref) {
240
242
  var _selectedEmails$;
241
243
  var _ref$extraColumnsData = _ref.extraColumnsData,
@@ -249,6 +251,8 @@ var Invitations$1 = function Invitations(_ref) {
249
251
  onClose = _ref.onClose,
250
252
  _ref$hideAddEmailsFor = _ref.hideAddEmailsForm,
251
253
  hideAddEmailsForm = _ref$hideAddEmailsFor === void 0 ? false : _ref$hideAddEmailsFor,
254
+ _ref$inviteButtonProp = _ref.inviteButtonProps,
255
+ inviteButtonProps = _ref$inviteButtonProp === void 0 ? {} : _ref$inviteButtonProp,
252
256
  _ref$onDestroyInvitat = _ref.onDestroyInvitationsSuccess,
253
257
  onDestroyInvitationsSuccess = _ref$onDestroyInvitat === void 0 ? noop : _ref$onDestroyInvitat;
254
258
  var _useState = useState([]),
@@ -321,8 +325,11 @@ var Invitations$1 = function Invitations(_ref) {
321
325
  children: t("neetoAccessControl.titles.invitations")
322
326
  })
323
327
  }), /*#__PURE__*/jsxs(Pane.Body, {
324
- className: "pt-2",
325
- children: [!hideAddEmailsForm && /*#__PURE__*/jsx(AddEmails, {
328
+ className: "space-y-4 pt-2",
329
+ children: [isNotEmpty(inviteButtonProps) && /*#__PURE__*/jsx("div", {
330
+ className: "flex w-full justify-end",
331
+ children: /*#__PURE__*/jsx(Button$1, _objectSpread$3({}, inviteButtonProps))
332
+ }), !hideAddEmailsForm && /*#__PURE__*/jsx(AddEmails, {
326
333
  configurationId: configurationId,
327
334
  ownerId: ownerId,
328
335
  ownerType: ownerType
@@ -473,27 +480,6 @@ var AUTH = {
473
480
  SESSION: "session",
474
481
  INVITED: "invited"
475
482
  };
476
- var AUTH_OPTIONS = [{
477
- label: t("neetoAccessControl.auth.no"),
478
- value: AUTH.NO,
479
- "data-cy": "access-control-public-access-radio-input"
480
- }, {
481
- label: t("neetoAccessControl.auth.basic"),
482
- value: AUTH.BASIC,
483
- "data-cy": "access-control-password-protected-radio-input"
484
- }, {
485
- label: t("neetoAccessControl.auth.invited"),
486
- value: AUTH.INVITED,
487
- "data-cy": "access-control-only-invited-people-radio-input"
488
- }, {
489
- label: t("neetoAccessControl.auth.email"),
490
- value: AUTH.EMAIL,
491
- "data-cy": "access-control-secure-by-email-patterns-radio-input"
492
- }, {
493
- label: t("neetoAccessControl.auth.session"),
494
- value: AUTH.SESSION,
495
- "data-cy": "access-control-logged-in-members-only-radio-input"
496
- }];
497
483
  var CONFIGURATION_VALIDATION_SCHEMA = yup.object({
498
484
  auth: yup.string().required(t("neetoAccessControl.inputs.validation.authRequired")),
499
485
  password: yup.string().nullable().when("auth", {
@@ -558,6 +544,41 @@ var renderLabelWithViewInvitation = function renderLabelWithViewInvitation(_ref2
558
544
  }
559
545
  });
560
546
  };
547
+ var getAuthOptions = function getAuthOptions(_ref3) {
548
+ var translationContext = _ref3.translationContext,
549
+ t = _ref3.t;
550
+ return [{
551
+ label: t("neetoAccessControl.auth.no", {
552
+ context: translationContext
553
+ }),
554
+ value: AUTH.NO,
555
+ "data-cy": "access-control-public-access-radio-input"
556
+ }, {
557
+ label: t("neetoAccessControl.auth.basic", {
558
+ context: translationContext
559
+ }),
560
+ value: AUTH.BASIC,
561
+ "data-cy": "access-control-password-protected-radio-input"
562
+ }, {
563
+ label: t("neetoAccessControl.auth.invited", {
564
+ context: translationContext
565
+ }),
566
+ value: AUTH.INVITED,
567
+ "data-cy": "access-control-only-invited-people-radio-input"
568
+ }, {
569
+ label: t("neetoAccessControl.auth.email", {
570
+ context: translationContext
571
+ }),
572
+ value: AUTH.EMAIL,
573
+ "data-cy": "access-control-secure-by-email-patterns-radio-input"
574
+ }, {
575
+ label: t("neetoAccessControl.auth.session", {
576
+ context: translationContext
577
+ }),
578
+ value: AUTH.SESSION,
579
+ "data-cy": "access-control-logged-in-members-only-radio-input"
580
+ }];
581
+ };
561
582
 
562
583
  var AllowedKeywords = withT(function (_ref) {
563
584
  var t = _ref.t,
@@ -650,11 +671,18 @@ var Configuration = function Configuration(_ref) {
650
671
  hideAddEmailsFromInvitationPane = _ref$hideAddEmailsFro === void 0 ? false : _ref$hideAddEmailsFro,
651
672
  _ref$onDestroyInvitat = _ref.onDestroyInvitationsSuccess,
652
673
  onDestroyInvitationsSuccess = _ref$onDestroyInvitat === void 0 ? noop : _ref$onDestroyInvitat,
653
- children = _ref.children;
674
+ _ref$inviteButtonProp = _ref.inviteButtonProps,
675
+ inviteButtonProps = _ref$inviteButtonProp === void 0 ? {} : _ref$inviteButtonProp,
676
+ _ref$additionalFields = _ref.additionalFieldsInitialValues,
677
+ additionalFieldsInitialValues = _ref$additionalFields === void 0 ? {} : _ref$additionalFields,
678
+ children = _ref.children,
679
+ fieldsWrapper = _ref.fieldsWrapper,
680
+ translationContext = _ref.translationContext;
654
681
  var _useState = useState(false),
655
682
  _useState2 = _slicedToArray(_useState, 2),
656
- showInviationsPane = _useState2[0],
657
- setShowInviationsPane = _useState2[1];
683
+ showInvitationsPane = _useState2[0],
684
+ setShowInvitationsPane = _useState2[1];
685
+ var FieldsWrapper = fieldsWrapper || Fragment$1;
658
686
  var _useTranslation = useTranslation(),
659
687
  t = _useTranslation.t;
660
688
  var _useShowConfiguration = useShowConfiguration({
@@ -665,7 +693,7 @@ var Configuration = function Configuration(_ref) {
665
693
  configuration = _useShowConfiguration2 === void 0 ? {} : _useShowConfiguration2,
666
694
  isLoading = _useShowConfiguration.isLoading,
667
695
  isFetching = _useShowConfiguration.isFetching;
668
- var configurationInitialValues = buildConfigurationInitialValues(configuration);
696
+ var configurationInitialValues = mergeLeft(buildConfigurationInitialValues(configuration), additionalFieldsInitialValues);
669
697
  var _useUpdateConfigurati = useUpdateConfiguration({
670
698
  ownerId: ownerId,
671
699
  ownerType: ownerType
@@ -683,7 +711,7 @@ var Configuration = function Configuration(_ref) {
683
711
  updateConfiguration = _useUpdateConfigurati.mutate;
684
712
  var handleSubmit = function handleSubmit(values, _ref2) {
685
713
  var setSubmitting = _ref2.setSubmitting;
686
- var payload = buildPayload(values);
714
+ var payload = mergeLeft(buildPayload(values), pick(keys(additionalFieldsInitialValues), values));
687
715
  updateConfiguration(payload, {
688
716
  onSettled: function onSettled() {
689
717
  return setSubmitting(false);
@@ -691,7 +719,7 @@ var Configuration = function Configuration(_ref) {
691
719
  });
692
720
  };
693
721
  var handleShowInvitations = onConfigurationChangedToInviteOnly === noop ? function () {
694
- return setShowInviationsPane(true);
722
+ return setShowInvitationsPane(true);
695
723
  } : onConfigurationChangedToInviteOnly;
696
724
  return /*#__PURE__*/jsxs(Container, {
697
725
  children: [/*#__PURE__*/jsx(Header, {
@@ -713,44 +741,46 @@ var Configuration = function Configuration(_ref) {
713
741
  children: function children(_ref3) {
714
742
  var values = _ref3.values;
715
743
  return /*#__PURE__*/jsxs(Fragment, {
716
- children: [/*#__PURE__*/jsx(Label, {
717
- className: "neeto-ui-text-base",
718
- children: t("neetoAccessControl.inputs.labels.visibility")
719
- }), /*#__PURE__*/jsx(Radio, {
720
- stacked: true,
721
- name: "auth",
722
- children: AUTH_OPTIONS.map(function (props) {
723
- return /*#__PURE__*/createElement(Radio.Item, _objectSpread(_objectSpread({}, props), {}, {
724
- key: props.value,
725
- className: classNames({
726
- "items-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
727
- }),
728
- label: (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED ? renderLabelWithViewInvitation({
729
- onViewInvites: function onViewInvites() {
730
- return setShowInviationsPane(true);
731
- }
732
- }) : props.label,
733
- labelProps: {
744
+ children: [/*#__PURE__*/jsxs(FieldsWrapper, {
745
+ children: [/*#__PURE__*/jsx(Radio, {
746
+ stacked: true,
747
+ name: "auth",
748
+ children: getAuthOptions({
749
+ translationContext: translationContext,
750
+ t: t
751
+ }).map(function (props) {
752
+ return /*#__PURE__*/createElement(Radio.Item, _objectSpread(_objectSpread({}, props), {}, {
753
+ key: props.value,
734
754
  className: classNames({
735
- "flex flex-col items-start justify-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
736
- })
737
- }
738
- }));
739
- })
740
- }), values.auth === AUTH.BASIC && /*#__PURE__*/jsx("div", {
741
- className: "space-y-4 pb-2",
742
- children: /*#__PURE__*/jsx(Input, {
743
- autoFocus: true,
744
- required: true,
745
- unlimitedChars: true,
746
- className: "w-7/12",
747
- label: t("neetoAccessControl.inputs.labels.password"),
748
- name: "password",
749
- placeholder: t("neetoAccessControl.inputs.placeholders.enterPassword")
750
- })
751
- }), values.auth === AUTH.EMAIL && /*#__PURE__*/jsx(AllowedKeywords, {
752
- label: t("neetoAccessControl.inputs.labels.keywords"),
753
- name: "allowedKeywords"
755
+ "items-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
756
+ }),
757
+ label: (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED ? renderLabelWithViewInvitation({
758
+ onViewInvites: function onViewInvites() {
759
+ return setShowInvitationsPane(true);
760
+ }
761
+ }) : props.label,
762
+ labelProps: {
763
+ className: classNames({
764
+ "flex flex-col items-start justify-start": (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === props.value && (configuration === null || configuration === void 0 ? void 0 : configuration.auth) === AUTH.INVITED
765
+ })
766
+ }
767
+ }));
768
+ })
769
+ }), values.auth === AUTH.BASIC && /*#__PURE__*/jsx("div", {
770
+ className: "space-y-4 pb-2",
771
+ children: /*#__PURE__*/jsx(Input, {
772
+ autoFocus: true,
773
+ required: true,
774
+ unlimitedChars: true,
775
+ className: "w-7/12",
776
+ label: t("neetoAccessControl.inputs.labels.password"),
777
+ name: "password",
778
+ placeholder: t("neetoAccessControl.inputs.placeholders.enterPassword")
779
+ })
780
+ }), values.auth === AUTH.EMAIL && /*#__PURE__*/jsx(AllowedKeywords, {
781
+ label: t("neetoAccessControl.inputs.labels.keywords"),
782
+ name: "allowedKeywords"
783
+ })]
754
784
  }), /*#__PURE__*/jsx(ActionBlock, {
755
785
  cancelButtonProps: {
756
786
  onClick: handleCancel
@@ -762,15 +792,16 @@ var Configuration = function Configuration(_ref) {
762
792
  });
763
793
  }
764
794
  }), /*#__PURE__*/jsx(Invitations$1, {
795
+ inviteButtonProps: inviteButtonProps,
765
796
  onDestroyInvitationsSuccess: onDestroyInvitationsSuccess,
766
797
  ownerId: ownerId,
767
798
  ownerType: ownerType,
768
799
  configurationId: configuration.id,
769
800
  extraColumnsData: invitationsTableExtraColumnsData,
770
801
  hideAddEmailsForm: hideAddEmailsFromInvitationPane,
771
- isOpen: showInviationsPane && !isFetching,
802
+ isOpen: showInvitationsPane && !isFetching,
772
803
  onClose: function onClose() {
773
- return setShowInviationsPane(false);
804
+ return setShowInvitationsPane(false);
774
805
  }
775
806
  }), children]
776
807
  })]