@bigbinary/neeto-fields-frontend 1.1.14 → 1.3.0

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,11 @@
1
1
  import React, { useContext, useState, useRef, useEffect, useMemo, useLayoutEffect, useCallback, createContext, memo, useReducer } from 'react';
2
2
  import { Checkbox as Checkbox$1, TimePicker, DatePicker, Select, Input, Textarea, Typography, Pane, Label, Button as Button$1, Dropdown, Tab, Alert, NoData, Table, Spinner } from '@bigbinary/neetoui';
3
- import { toLabelAndValue, isNotEmpty, capitalize as capitalize$1, filterBy, findBy, slugify, humanize, truncate, countBy, noop as noop$2 } from '@bigbinary/neeto-commons-frontend/pure';
4
- import { values, map, isNotNil, isNil, isEmpty, prop, pluck, clone as clone$1, pipe, mergeAll, omit, pick, assoc, any, head } from 'ramda';
3
+ import { isNotEmpty, renameKeys, capitalize as capitalize$1, findBy, filterBy, toLabelAndValue, slugify, humanize, truncate, countBy, noop as noop$2 } from '@bigbinary/neeto-commons-frontend/pure';
4
+ import { values, isNotNil, isNil, isEmpty, prop, pluck, clone as clone$1, pipe, mergeAll, omit, map, pick, assoc, any, head } from 'ramda';
5
5
  import { useFormikContext, useField, FieldArray } from 'formik';
6
6
  import { useFuncDebounce, useDebounce, handleMetaClick } from '@bigbinary/neeto-commons-frontend/react-utils';
7
7
  import * as yup from 'yup';
8
+ import { joinHyphenCase, buildUrl, getQueryParams } from '@bigbinary/neeto-commons-frontend/utils';
8
9
  import { Check, Delete, MenuHorizontal, Info, Reorder } from '@bigbinary/neeto-icons';
9
10
  import { Button, ActionBlock as ActionBlock$1, Input as Input$1, Select as Select$1, Switch, Form } from '@bigbinary/neetoui/formik';
10
11
  import { DEFAULT_PAGE_INDEX, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
@@ -12,7 +13,7 @@ import Container from '@bigbinary/neeto-molecules/Container';
12
13
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
13
14
  import { useQuery, useQueryClient, useMutation } from 'react-query';
14
15
  import axios from 'axios';
15
- import { buildUrl, getQueryParams } from '@bigbinary/neeto-commons-frontend/utils';
16
+ import { v4 } from 'uuid';
16
17
  import { Link, useHistory } from 'react-router-dom';
17
18
  import MenuBar from '@bigbinary/neeto-molecules/MenuBar';
18
19
  import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
@@ -5969,27 +5970,13 @@ var cleanedRegex = function cleanedRegex(regexCondition) {
5969
5970
  }
5970
5971
  return RegExp(conditionWithoutFlags, sanitizedFlags);
5971
5972
  };
5972
- var buildOptionsToLabelAndValue = function buildOptionsToLabelAndValue() {
5973
- var optionObjects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
5974
- return optionObjects.map(function (_ref4) {
5975
- var label = _ref4.label,
5976
- value = _ref4.value;
5977
- return {
5978
- label: label,
5979
- value: value || label
5980
- };
5981
- });
5982
- };
5983
- var buildArrayToLabelAndValues = function buildArrayToLabelAndValues(value) {
5984
- return map(toLabelAndValue, value || []);
5985
- };
5986
5973
  var validateField = /*#__PURE__*/function () {
5987
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref5) {
5974
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref4) {
5988
5975
  var fieldValue, fieldName, isRequired, kind, fieldData;
5989
5976
  return _regeneratorRuntime.wrap(function _callee$(_context) {
5990
5977
  while (1) switch (_context.prev = _context.next) {
5991
5978
  case 0:
5992
- fieldValue = _ref5.fieldValue, fieldName = _ref5.fieldName, isRequired = _ref5.isRequired, kind = _ref5.kind, fieldData = _ref5.fieldData;
5979
+ fieldValue = _ref4.fieldValue, fieldName = _ref4.fieldName, isRequired = _ref4.isRequired, kind = _ref4.kind, fieldData = _ref4.fieldData;
5993
5980
  _context.prev = 1;
5994
5981
  _context.next = 4;
5995
5982
  return yup.object().shape(_defineProperty({}, fieldName, buildFieldValidationSchema({
@@ -6010,7 +5997,7 @@ var validateField = /*#__PURE__*/function () {
6010
5997
  }, _callee, null, [[1, 7]]);
6011
5998
  }));
6012
5999
  return function validateField(_x) {
6013
- return _ref6.apply(this, arguments);
6000
+ return _ref5.apply(this, arguments);
6014
6001
  };
6015
6002
  }();
6016
6003
  var dateTimeToString = function dateTimeToString(dateTime) {
@@ -6039,6 +6026,9 @@ var useFormikFields = function useFormikFields(_ref) {
6039
6026
  var fieldPath = escapeString("".concat(name, "-").concat(fieldId));
6040
6027
  var fieldName = kind === KINDS.multiOption ? "values" : "value";
6041
6028
  var fieldValuePath = "".concat(fieldPath, ".data.").concat(fieldName);
6029
+ isDropdown$1(kind) && (fieldData = renameKeys({
6030
+ id: "value"
6031
+ }, fieldData));
6042
6032
  if (isNil(formRef) && isNotNil(formRefs)) {
6043
6033
  formRefs.current[fieldValuePath] = formikContext;
6044
6034
  } else if (isNil(formRefs) && isNotNil(formRef)) {
@@ -6067,9 +6057,15 @@ var useFormikFields = function useFormikFields(_ref) {
6067
6057
  };
6068
6058
  var getValueForField = function getValueForField(value) {
6069
6059
  if (kind === KINDS.singleOption) {
6070
- value = toLabelAndValue(value);
6060
+ value = findBy({
6061
+ value: value
6062
+ }, fieldData);
6071
6063
  } else if (kind === KINDS.multiOption) {
6072
- value = buildArrayToLabelAndValues(value);
6064
+ value = value.map(function (optionId) {
6065
+ return findBy({
6066
+ value: optionId
6067
+ }, fieldData);
6068
+ });
6073
6069
  }
6074
6070
  return value || "";
6075
6071
  };
@@ -6090,7 +6086,7 @@ var useFormikFields = function useFormikFields(_ref) {
6090
6086
  },
6091
6087
  disabled: disabled,
6092
6088
  //conditional props
6093
- options: isDropdown$1(kind) ? buildOptionsToLabelAndValue(fieldData) : undefined,
6089
+ options: isDropdown$1(kind) ? fieldData : undefined,
6094
6090
  getPopupContainer: isDateTime(kind) ? prop("parentElement") : undefined
6095
6091
  })
6096
6092
  };
@@ -6159,6 +6155,7 @@ var Number$1 = function Number(props) {
6159
6155
  return /*#__PURE__*/React.createElement(Input, _extends({}, fieldProps, {
6160
6156
  type: "number",
6161
6157
  suffix: showSubmitButton && /*#__PURE__*/React.createElement(Button, {
6158
+ "data-cy": joinHyphenCase(fieldProps.label, "check-button"),
6162
6159
  icon: Check,
6163
6160
  style: "text",
6164
6161
  onClick: function onClick() {
@@ -6221,6 +6218,7 @@ var Text = function Text(props) {
6221
6218
  var showSubmitButton = props.individualSubmit && dirty;
6222
6219
  return /*#__PURE__*/React.createElement(Input, _extends({}, fieldProps, {
6223
6220
  suffix: showSubmitButton && /*#__PURE__*/React.createElement(Button, {
6221
+ "data-cy": joinHyphenCase(fieldProps.label, "check-button"),
6224
6222
  icon: Check,
6225
6223
  style: "text",
6226
6224
  onClick: function onClick() {
@@ -6644,6 +6642,13 @@ var renderFormFooter = function renderFormFooter(_ref3) {
6644
6642
  }
6645
6643
  }));
6646
6644
  };
6645
+ var getDefaultOption = function getDefaultOption() {
6646
+ return {
6647
+ id: v4(),
6648
+ label: "",
6649
+ displayOrder: 0
6650
+ };
6651
+ };
6647
6652
 
6648
6653
  var PERMITTED_REGEX_PATTERN = /^\/.*\/[igmsyu]*$/;
6649
6654
  var ADVANCED_REGEX_ASSERTION_PATTERN = /\(\?=[^)]*\)|\(\?![^)]*\)|\(\?<=[^)]*\)|\(\?<![^)]*\)/;
@@ -6769,11 +6774,6 @@ var INITIAL_FIELDS = {
6769
6774
  kind: toLabelAndValue("text"),
6770
6775
  isRequired: false
6771
6776
  };
6772
- var DEFAULT_OPTION = {
6773
- label: "",
6774
- displayOrder: 0
6775
- };
6776
- var DEFAULT_OPTIONS_DATA = [DEFAULT_OPTION];
6777
6777
  var DEFAULT_REGEX_DATA = {
6778
6778
  condition: "",
6779
6779
  helpMessage: ""
@@ -6809,7 +6809,7 @@ var AdditionalInputs = function AdditionalInputs() {
6809
6809
  return arrayHelpers.remove(index);
6810
6810
  };
6811
6811
  var addOption = function addOption(arrayHelpers) {
6812
- return arrayHelpers.push(DEFAULT_OPTION);
6812
+ return arrayHelpers.push(getDefaultOption());
6813
6813
  };
6814
6814
  if (isDropdown(kind.value)) {
6815
6815
  return /*#__PURE__*/React.createElement(FieldArray, {
@@ -6886,7 +6886,7 @@ var FieldForm = function FieldForm(_ref) {
6886
6886
  var handleKindChange = function handleKindChange(kind) {
6887
6887
  setFieldValue("kind", kind);
6888
6888
  if (isDropdown(kind.value)) {
6889
- setFieldValue("data", options !== null && options !== void 0 ? options : DEFAULT_OPTIONS_DATA);
6889
+ setFieldValue("data", options !== null && options !== void 0 ? options : [getDefaultOption()]);
6890
6890
  } else if (isRegex(kind.value)) {
6891
6891
  setFieldValue("data", options !== null && options !== void 0 ? options : DEFAULT_REGEX_DATA);
6892
6892
  }