@bigbinary/neeto-molecules 1.1.11 → 1.1.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.
@@ -30,12 +30,15 @@ var AllowedIpRanges = function AllowedIpRanges() {
30
30
  }, /*#__PURE__*/React.createElement("div", {
31
31
  className: "grid grid-cols-12 gap-4 px-3"
32
32
  }, /*#__PURE__*/React.createElement(Typography, {
33
- className: "neeto-ui-text-gray-700 col-span-5 uppercase",
33
+ className: "neeto-ui-text-gray-700 col-span-4 uppercase",
34
34
  style: "h6"
35
35
  }, t("neetoMolecules.ipRestriction.ipStart")), /*#__PURE__*/React.createElement(Typography, {
36
- className: "neeto-ui-text-gray-700 col-span-5 uppercase",
36
+ className: "neeto-ui-text-gray-700 col-span-4 uppercase",
37
37
  style: "h6"
38
38
  }, t("neetoMolecules.ipRestriction.ipEnd")), /*#__PURE__*/React.createElement(Typography, {
39
+ className: "neeto-ui-text-gray-700 col-span-2 uppercase",
40
+ style: "h6"
41
+ }, t("neetoMolecules.ipRestriction.type")), /*#__PURE__*/React.createElement(Typography, {
39
42
  className: "neeto-ui-text-gray-700 col-span-2 text-center uppercase",
40
43
  style: "h6"
41
44
  }, t("neetoMolecules.ipRestriction.actions"))), /*#__PURE__*/React.createElement("div", {
@@ -1,10 +1,12 @@
1
1
  import React from "react";
2
2
  import { Check, Close } from "@bigbinary/neeto-icons";
3
3
  import { Button } from "@bigbinary/neetoui";
4
- import { Input, Form, Button as FormikButton } from "@bigbinary/neetoui/formik";
4
+ import { Input, Form, Button as FormikButton, Select } from "@bigbinary/neetoui/formik";
5
+ import { assoc } from "ramda";
5
6
  import { useTranslation } from "react-i18next";
7
+ import { ADDRESS_TYPE_SELECT_OPTIONS } from "./constants";
6
8
  import { useCreateAllowedIpRanges, useUpdateAllowedIpRanges } from "./hooks/reactQuery/useAllowedIpRanges";
7
- import { getIpRestrictionValidationSchema } from "./utils";
9
+ import { buildInitialValue, getIpRestrictionValidationSchema } from "./utils";
8
10
  var FormRow = function FormRow(_ref) {
9
11
  var data = _ref.data,
10
12
  isAddNew = _ref.isAddNew,
@@ -16,12 +18,13 @@ var FormRow = function FormRow(_ref) {
16
18
  var _useTranslation = useTranslation(),
17
19
  t = _useTranslation.t;
18
20
  var handleSubmit = function handleSubmit(values) {
21
+ var payload = assoc("addressType", values.addressType.value, values);
19
22
  if (isAddNew) {
20
- createAllowedIpRange(values);
23
+ createAllowedIpRange(payload);
21
24
  } else {
22
25
  updateAllowedIpRange({
23
26
  id: data.id,
24
- payload: values
27
+ payload: payload
25
28
  });
26
29
  }
27
30
  onCollapse();
@@ -29,7 +32,7 @@ var FormRow = function FormRow(_ref) {
29
32
  return /*#__PURE__*/React.createElement(Form, {
30
33
  "data-cy": "allowed-ip-range-form",
31
34
  formikProps: {
32
- initialValues: data,
35
+ initialValues: buildInitialValue(data),
33
36
  validationSchema: getIpRestrictionValidationSchema(),
34
37
  onSubmit: handleSubmit
35
38
  }
@@ -39,15 +42,19 @@ var FormRow = function FormRow(_ref) {
39
42
  className: "neeto-ui-bg-white neeto-ui-rounded-lg grid grid-cols-12 gap-4 p-3"
40
43
  }, /*#__PURE__*/React.createElement(Input, {
41
44
  autoFocus: true,
42
- className: "col-span-5 text-left",
45
+ className: "col-span-4 text-left",
43
46
  "data-cy": "ip-start-text-field",
44
47
  name: "ipStart",
45
48
  placeholder: t("neetoMolecules.ipRestriction.ipStart")
46
49
  }), /*#__PURE__*/React.createElement(Input, {
47
- className: "col-span-5 text-left",
50
+ className: "col-span-4 text-left",
48
51
  "data-cy": "ip-end-text-field",
49
52
  name: "ipEnd",
50
53
  placeholder: t("neetoMolecules.ipRestriction.ipEnd")
54
+ }), /*#__PURE__*/React.createElement(Select, {
55
+ className: "col-span-2 text-left",
56
+ name: "addressType",
57
+ options: ADDRESS_TYPE_SELECT_OPTIONS
51
58
  }), /*#__PURE__*/React.createElement("div", {
52
59
  className: "col-span-2 flex items-start justify-center gap-1"
53
60
  }, /*#__PURE__*/React.createElement(FormikButton, {
@@ -6,6 +6,7 @@ import { useTranslation, Trans } from "react-i18next";
6
6
  import MoreDropdown from "../MoreDropdown";
7
7
  import { TRUNCATE_LENGTH } from "./constants";
8
8
  import { useDestroyAllowedIpRanges } from "./hooks/reactQuery/useAllowedIpRanges";
9
+ import { humanizeIpAddressFormat } from "./utils";
9
10
  var Row = function Row(_ref) {
10
11
  var data = _ref.data,
11
12
  setEditingRow = _ref.setEditingRow;
@@ -29,7 +30,7 @@ var Row = function Row(_ref) {
29
30
  disabled: data.ipStart.length < TRUNCATE_LENGTH,
30
31
  position: "top"
31
32
  }, /*#__PURE__*/React.createElement(Typography, {
32
- className: "col-span-5",
33
+ className: "col-span-4",
33
34
  "data-cy": "ip-range-start-value",
34
35
  style: "body2"
35
36
  }, truncate(data.ipStart, TRUNCATE_LENGTH))), /*#__PURE__*/React.createElement(Tooltip, {
@@ -37,10 +38,14 @@ var Row = function Row(_ref) {
37
38
  disabled: data.ipEnd.length < TRUNCATE_LENGTH,
38
39
  position: "top"
39
40
  }, /*#__PURE__*/React.createElement(Typography, {
40
- className: "col-span-5",
41
+ className: "col-span-4",
41
42
  "data-cy": "ip-range-end-value",
42
43
  style: "body2"
43
- }, truncate(data.ipEnd, TRUNCATE_LENGTH))), /*#__PURE__*/React.createElement("div", {
44
+ }, truncate(data.ipEnd, TRUNCATE_LENGTH))), /*#__PURE__*/React.createElement(Typography, {
45
+ className: "col-span-2",
46
+ "data-cy": "ip-range-end-value",
47
+ style: "body2"
48
+ }, humanizeIpAddressFormat(data.addressType)), /*#__PURE__*/React.createElement("div", {
44
49
  className: "col-span-2 flex justify-center"
45
50
  }, /*#__PURE__*/React.createElement(MoreDropdown, {
46
51
  dropdownButtonProps: {
@@ -1,11 +1,20 @@
1
+ import { t } from "i18next";
1
2
  export var IP_RESTRICTIONS_ENGINE_BASE_URL = "ip_restrictions/api/v1";
2
- export var INITIAL_VALUES = {
3
- ipStart: "",
4
- ipEnd: ""
5
- };
6
3
  export var QUERY_KEYS = {
7
4
  IP_RESTRICTION: "IP_RESTRICTION",
8
5
  ALLOWED_IP_RANGES: "ALLOWED_IP_RANGES",
9
6
  CURRENT_IP: "CURRENT_IP"
10
7
  };
11
- export var TRUNCATE_LENGTH = 18;
8
+ export var TRUNCATE_LENGTH = 18;
9
+ export var ADDRESS_TYPE_SELECT_OPTIONS = [{
10
+ label: t("neetoMolecules.ipRestriction.ipv4"),
11
+ value: "ipv4"
12
+ }, {
13
+ label: t("neetoMolecules.ipRestriction.ipv6"),
14
+ value: "ipv6"
15
+ }];
16
+ export var INITIAL_VALUES = {
17
+ ipStart: "",
18
+ ipEnd: "",
19
+ addressType: ADDRESS_TYPE_SELECT_OPTIONS[0].value
20
+ };
@@ -1,6 +1,6 @@
1
1
  import { t } from "i18next";
2
2
  import { IPv4, IPv6, Validator } from "ip-num";
3
- import { isNil, isNotNil } from "ramda";
3
+ import { assoc, isNil, isNotNil } from "ramda";
4
4
  import * as yup from "yup";
5
5
  var isValidIPv4String = function isValidIPv4String(ip) {
6
6
  return isNotNil(ip) && Validator.isValidIPv4String(ip)[0];
@@ -62,6 +62,24 @@ export var getIpRestrictionValidationSchema = function getIpRestrictionValidatio
62
62
  },
63
63
  message: t("neetoMolecules.ipRestriction.validations.ipEndGreaterThanIpStart")
64
64
  });
65
- }).required(t("neetoMolecules.ipRestriction.validations.ipEndRequired"))
65
+ }).required(t("neetoMolecules.ipRestriction.validations.ipEndRequired")),
66
+ addressType: yup.object().shape({
67
+ value: yup.string().required(),
68
+ label: yup.string().required()
69
+ }).nullable().required(t("neetoMolecules.ipRestriction.validations.addressTypeRequired"))
66
70
  });
71
+ };
72
+ export var humanizeIpAddressFormat = function humanizeIpAddressFormat(addressFormat) {
73
+ var addressFormats = {
74
+ ipv4: "IPv4",
75
+ ipv6: "IPv6"
76
+ };
77
+ return addressFormats[addressFormat];
78
+ };
79
+ export var buildInitialValue = function buildInitialValue(values) {
80
+ var labelAndValue = {
81
+ label: humanizeIpAddressFormat(values.addressType),
82
+ value: values.addressType
83
+ };
84
+ return assoc("addressType", labelAndValue, values);
67
85
  };
@@ -75,7 +75,7 @@ var Rename = function Rename(_ref) {
75
75
  setEditMode(false);
76
76
  };
77
77
  var handleClose = function handleClose(event) {
78
- event.stopPropagation();
78
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
79
79
  setName(value);
80
80
  setEditMode(false);
81
81
  };
@@ -0,0 +1,52 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["value", "debounceTime", "onChange", "onSearch"];
5
+ import React, { useEffect, useState } from "react";
6
+ import { useDebounce } from "@bigbinary/neeto-commons-frontend/react-utils";
7
+ import { Search as NeetoUISearchIcon } from "@bigbinary/neeto-icons";
8
+ import { Input } from "@bigbinary/neetoui";
9
+ import { useTranslation } from "react-i18next";
10
+ var Search = function Search(_ref) {
11
+ var _ref$value = _ref.value,
12
+ value = _ref$value === void 0 ? "" : _ref$value,
13
+ _ref$debounceTime = _ref.debounceTime,
14
+ debounceTime = _ref$debounceTime === void 0 ? 300 : _ref$debounceTime,
15
+ onChange = _ref.onChange,
16
+ onSearch = _ref.onSearch,
17
+ inputProps = _objectWithoutProperties(_ref, _excluded);
18
+ var _useTranslation = useTranslation(),
19
+ t = _useTranslation.t;
20
+ var _useState = useState(value),
21
+ _useState2 = _slicedToArray(_useState, 2),
22
+ internalValue = _useState2[0],
23
+ setInternalValue = _useState2[1];
24
+ var _useState3 = useState(),
25
+ _useState4 = _slicedToArray(_useState3, 2),
26
+ untrimmedValue = _useState4[0],
27
+ setUntrimmedValue = _useState4[1];
28
+ useEffect(function () {
29
+ if (untrimmedValue && untrimmedValue.includes(value)) {
30
+ setInternalValue(untrimmedValue);
31
+ } else {
32
+ setInternalValue(value);
33
+ }
34
+ }, [value]);
35
+ var debouncedValue = useDebounce(internalValue, debounceTime);
36
+ useEffect(function () {
37
+ onSearch === null || onSearch === void 0 ? void 0 : onSearch(debouncedValue.trim());
38
+ }, [debouncedValue, onSearch]);
39
+ var handleOnChange = function handleOnChange(e) {
40
+ onChange === null || onChange === void 0 ? void 0 : onChange(e);
41
+ setInternalValue(e.target.value);
42
+ setUntrimmedValue(e.target.value);
43
+ };
44
+ return /*#__PURE__*/React.createElement(Input, _extends({
45
+ placeholder: t("neetoMolecules.common.actions.search"),
46
+ prefix: /*#__PURE__*/React.createElement(NeetoUISearchIcon, null),
47
+ type: "search",
48
+ value: internalValue,
49
+ onChange: handleOnChange
50
+ }, inputProps));
51
+ };
52
+ export default Search;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-molecules",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "A package of reusable molecular components for neeto products.",
5
5
  "repository": "git@github.com:bigbinary/neeto-molecules.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -66,6 +66,7 @@
66
66
  "@babel/runtime": "^7.19.0",
67
67
  "@bigbinary/babel-preset-neeto": "^1.0.3",
68
68
  "@bigbinary/eslint-plugin-neeto": "^1.1.14",
69
+ "@bigbinary/neeto-audit-frontend": "2.0.1",
69
70
  "@bigbinary/neeto-commons-frontend": "2.0.134",
70
71
  "@bigbinary/neeto-editor": "1.27.0-beta.1",
71
72
  "@bigbinary/neeto-filters-frontend": "^2.11.15",
@@ -279,6 +279,9 @@
279
279
  "allowedIpRangeTitle": "Allowed IP range",
280
280
  "ipStart": "IP start",
281
281
  "ipEnd": "IP end",
282
+ "type": "Type",
283
+ "ipv4": "IPv4",
284
+ "ipv6": "IPv6",
282
285
  "actions": "Actions",
283
286
  "addNew": "Add new IP range",
284
287
  "allowedIpRangeConfirmationTitle": "allowed IP range",
@@ -288,7 +291,8 @@
288
291
  "ipEndGreaterThanIpStart": "IP end should be greater than or equal to IP start",
289
292
  "eitherIpv4OrIpv6": "IPs should be in either IPv6 or IPv4",
290
293
  "ipStartRequired": "IP start is required",
291
- "ipEndRequired": "IP end is required"
294
+ "ipEndRequired": "IP end is required",
295
+ "addressTypeRequired": "Address type is required"
292
296
  },
293
297
  "currentIpTitle": "Your current IP is",
294
298
  "currentIpDescription": "and it will be added to the allowed IP range by default.",
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { InputProps } from "neetoui";
3
+ /**
4
+ *
5
+ * A common search component with search value debounced
6
+ *
7
+ * @example
8
+ *
9
+ * import React from "react";
10
+ * import Search from "@bigbinary/neeto-molecules/Search";
11
+ *
12
+ * const Page = () => <Search debounceTime={500} onChange={e => noop} />;
13
+ * @endexample
14
+ */
15
+ const Search: React.FC<{
16
+ debounceTime?: number;
17
+ onSearch?: (value: string) => void;
18
+ } & InputProps>;
19
+ export default Search;