@bigbinary/neeto-fields-frontend 1.1.10 → 1.1.11
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/README.md +11 -7
- package/dist/index.cjs.js +24 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +25 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
3
|
import { toLabelAndValue, isNotEmpty, capitalize as capitalize$1, filterBy, findBy, slugify, humanize, countBy, existsBy, noop as noop$2 } from '@bigbinary/neeto-commons-frontend/pure';
|
|
4
|
-
import { values, map, isNotNil,
|
|
4
|
+
import { values, map, isNotNil, isNil, isEmpty, pluck, clone as clone$1, pipe, mergeAll, omit, prop, pick, assoc, any, not, 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';
|
|
@@ -5845,6 +5845,15 @@ var dayjs_minExports = dayjs_min.exports;
|
|
|
5845
5845
|
var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
|
|
5846
5846
|
|
|
5847
5847
|
var dateSchema = yup.date().nullable();
|
|
5848
|
+
var isValueEmpty = function isValueEmpty(value) {
|
|
5849
|
+
return typeof value === "string" && isEmpty(value.trim());
|
|
5850
|
+
};
|
|
5851
|
+
var isCheckboxUnchecked = function isCheckboxUnchecked(kind, value) {
|
|
5852
|
+
return kind === KINDS.checkbox && !value;
|
|
5853
|
+
};
|
|
5854
|
+
var isArrayEmpty = function isArrayEmpty(kind, value) {
|
|
5855
|
+
return [KINDS.multiOption, KINDS.singleOption, KINDS.dateRange, KINDS.timeRange].includes(kind) && isEmpty(value);
|
|
5856
|
+
};
|
|
5848
5857
|
var buildSchemaAllowingEmptyValue = function buildSchemaAllowingEmptyValue(schema) {
|
|
5849
5858
|
return yup.mixed().test({
|
|
5850
5859
|
name: "validate-if-not-empty",
|
|
@@ -5856,11 +5865,11 @@ var buildSchemaAllowingEmptyValue = function buildSchemaAllowingEmptyValue(schem
|
|
|
5856
5865
|
}
|
|
5857
5866
|
});
|
|
5858
5867
|
};
|
|
5859
|
-
var buildSchemaForRequiredInputs = function buildSchemaForRequiredInputs(schema) {
|
|
5868
|
+
var buildSchemaForRequiredInputs = function buildSchemaForRequiredInputs(schema, kind) {
|
|
5860
5869
|
return yup.mixed().test({
|
|
5861
5870
|
name: "validate-required-inputs",
|
|
5862
5871
|
test: function test(value) {
|
|
5863
|
-
if (
|
|
5872
|
+
if (isNil(value) || isValueEmpty(value) || isArrayEmpty(kind, value) || isCheckboxUnchecked(kind, value)) {
|
|
5864
5873
|
throw new yup.ValidationError(t$1("validations.thisIsRequired"));
|
|
5865
5874
|
}
|
|
5866
5875
|
schema.validateSync(value);
|
|
@@ -5870,14 +5879,16 @@ var buildSchemaForRequiredInputs = function buildSchemaForRequiredInputs(schema)
|
|
|
5870
5879
|
};
|
|
5871
5880
|
var buildSchema = function buildSchema(_ref) {
|
|
5872
5881
|
var schema = _ref.schema,
|
|
5873
|
-
isRequired = _ref.isRequired
|
|
5874
|
-
|
|
5882
|
+
isRequired = _ref.isRequired,
|
|
5883
|
+
kind = _ref.kind;
|
|
5884
|
+
return isRequired ? buildSchemaForRequiredInputs(schema, kind) : buildSchemaAllowingEmptyValue(schema);
|
|
5875
5885
|
};
|
|
5876
5886
|
var getBasicValidationSchema = function getBasicValidationSchema(_ref2) {
|
|
5877
5887
|
var kind = _ref2.kind,
|
|
5878
5888
|
fieldData = _ref2.fieldData;
|
|
5879
5889
|
switch (kind) {
|
|
5880
5890
|
case KINDS.singleOption:
|
|
5891
|
+
case KINDS.textarea:
|
|
5881
5892
|
case KINDS.text:
|
|
5882
5893
|
{
|
|
5883
5894
|
return yup.string().trim().nullable();
|
|
@@ -5927,7 +5938,8 @@ var buildFieldValidationSchema = function buildFieldValidationSchema(_ref3) {
|
|
|
5927
5938
|
});
|
|
5928
5939
|
return buildSchema({
|
|
5929
5940
|
schema: schema,
|
|
5930
|
-
isRequired: isRequired
|
|
5941
|
+
isRequired: isRequired,
|
|
5942
|
+
kind: kind
|
|
5931
5943
|
});
|
|
5932
5944
|
};
|
|
5933
5945
|
var cleanedRegex = function cleanedRegex(regexCondition) {
|
|
@@ -6054,11 +6066,13 @@ var useFormikFields = function useFormikFields(_ref) {
|
|
|
6054
6066
|
dirty: dirty,
|
|
6055
6067
|
handleSubmit: handleSubmit,
|
|
6056
6068
|
fieldProps: _objectSpread$b(_objectSpread$b({}, formikFieldProps), {}, {
|
|
6057
|
-
required: props[isRequiredColumnName],
|
|
6058
6069
|
error: individualSubmit ? meta.error : meta.touched && meta.error,
|
|
6059
6070
|
options: isDropdown ? buildOptionsToLabelAndValue(fieldData) : undefined,
|
|
6060
6071
|
value: getValueForField(formikFieldProps.value),
|
|
6061
6072
|
label: capitalize$1(name),
|
|
6073
|
+
labelProps: {
|
|
6074
|
+
required: props[isRequiredColumnName]
|
|
6075
|
+
},
|
|
6062
6076
|
disabled: disabled
|
|
6063
6077
|
})
|
|
6064
6078
|
};
|
|
@@ -6112,7 +6126,8 @@ var MultiOption = function MultiOption(props) {
|
|
|
6112
6126
|
fieldProps = _useFormikFields.fieldProps;
|
|
6113
6127
|
return /*#__PURE__*/React.createElement(Select, _extends({
|
|
6114
6128
|
isMulti: true,
|
|
6115
|
-
isSearchable: true
|
|
6129
|
+
isSearchable: true,
|
|
6130
|
+
strategy: "fixed"
|
|
6116
6131
|
}, fieldProps, {
|
|
6117
6132
|
onChange: function onChange(selectedOptions) {
|
|
6118
6133
|
return handleSubmit(pluck("value", selectedOptions));
|
|
@@ -6174,7 +6189,8 @@ var SingleOption = function SingleOption(props) {
|
|
|
6174
6189
|
fieldProps = _useFormikFields.fieldProps;
|
|
6175
6190
|
return /*#__PURE__*/React.createElement(Select, _extends({
|
|
6176
6191
|
isClearable: true,
|
|
6177
|
-
isSearchable: true
|
|
6192
|
+
isSearchable: true,
|
|
6193
|
+
strategy: "fixed"
|
|
6178
6194
|
}, fieldProps, {
|
|
6179
6195
|
onChange: function onChange(option) {
|
|
6180
6196
|
return handleSubmit((option === null || option === void 0 ? void 0 : option.value) || "");
|