@bigbinary/neeto-fields-frontend 1.1.9 → 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 +54 -51
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +56 -53
- 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
|
-
import { Checkbox as Checkbox$1, TimePicker, DatePicker, Select, Input, Textarea, Typography, Pane, Label, Button as Button$1, Dropdown, Alert, NoData, Table, Spinner } from '@bigbinary/neetoui';
|
|
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';
|
|
@@ -5324,6 +5324,7 @@ var validations = {
|
|
|
5324
5324
|
fieldOptionIsRequired: "Field option is required",
|
|
5325
5325
|
kindIsRequired: "Kind is required",
|
|
5326
5326
|
invalidRegexPattern: "Invalid regex pattern",
|
|
5327
|
+
advancedRegexAssertionsNotSupported: "Advanced regex assertions are not supported",
|
|
5327
5328
|
notAValidNumber: "Entered number is not valid",
|
|
5328
5329
|
notAValidInteger: "Entered number is not a valid integer",
|
|
5329
5330
|
notAValid: "Entered number is not valid",
|
|
@@ -5844,6 +5845,15 @@ var dayjs_minExports = dayjs_min.exports;
|
|
|
5844
5845
|
var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
|
|
5845
5846
|
|
|
5846
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
|
+
};
|
|
5847
5857
|
var buildSchemaAllowingEmptyValue = function buildSchemaAllowingEmptyValue(schema) {
|
|
5848
5858
|
return yup.mixed().test({
|
|
5849
5859
|
name: "validate-if-not-empty",
|
|
@@ -5855,11 +5865,11 @@ var buildSchemaAllowingEmptyValue = function buildSchemaAllowingEmptyValue(schem
|
|
|
5855
5865
|
}
|
|
5856
5866
|
});
|
|
5857
5867
|
};
|
|
5858
|
-
var buildSchemaForRequiredInputs = function buildSchemaForRequiredInputs(schema) {
|
|
5868
|
+
var buildSchemaForRequiredInputs = function buildSchemaForRequiredInputs(schema, kind) {
|
|
5859
5869
|
return yup.mixed().test({
|
|
5860
5870
|
name: "validate-required-inputs",
|
|
5861
5871
|
test: function test(value) {
|
|
5862
|
-
if (
|
|
5872
|
+
if (isNil(value) || isValueEmpty(value) || isArrayEmpty(kind, value) || isCheckboxUnchecked(kind, value)) {
|
|
5863
5873
|
throw new yup.ValidationError(t$1("validations.thisIsRequired"));
|
|
5864
5874
|
}
|
|
5865
5875
|
schema.validateSync(value);
|
|
@@ -5869,14 +5879,16 @@ var buildSchemaForRequiredInputs = function buildSchemaForRequiredInputs(schema)
|
|
|
5869
5879
|
};
|
|
5870
5880
|
var buildSchema = function buildSchema(_ref) {
|
|
5871
5881
|
var schema = _ref.schema,
|
|
5872
|
-
isRequired = _ref.isRequired
|
|
5873
|
-
|
|
5882
|
+
isRequired = _ref.isRequired,
|
|
5883
|
+
kind = _ref.kind;
|
|
5884
|
+
return isRequired ? buildSchemaForRequiredInputs(schema, kind) : buildSchemaAllowingEmptyValue(schema);
|
|
5874
5885
|
};
|
|
5875
5886
|
var getBasicValidationSchema = function getBasicValidationSchema(_ref2) {
|
|
5876
5887
|
var kind = _ref2.kind,
|
|
5877
5888
|
fieldData = _ref2.fieldData;
|
|
5878
5889
|
switch (kind) {
|
|
5879
5890
|
case KINDS.singleOption:
|
|
5891
|
+
case KINDS.textarea:
|
|
5880
5892
|
case KINDS.text:
|
|
5881
5893
|
{
|
|
5882
5894
|
return yup.string().trim().nullable();
|
|
@@ -5926,7 +5938,8 @@ var buildFieldValidationSchema = function buildFieldValidationSchema(_ref3) {
|
|
|
5926
5938
|
});
|
|
5927
5939
|
return buildSchema({
|
|
5928
5940
|
schema: schema,
|
|
5929
|
-
isRequired: isRequired
|
|
5941
|
+
isRequired: isRequired,
|
|
5942
|
+
kind: kind
|
|
5930
5943
|
});
|
|
5931
5944
|
};
|
|
5932
5945
|
var cleanedRegex = function cleanedRegex(regexCondition) {
|
|
@@ -6053,11 +6066,13 @@ var useFormikFields = function useFormikFields(_ref) {
|
|
|
6053
6066
|
dirty: dirty,
|
|
6054
6067
|
handleSubmit: handleSubmit,
|
|
6055
6068
|
fieldProps: _objectSpread$b(_objectSpread$b({}, formikFieldProps), {}, {
|
|
6056
|
-
required: props[isRequiredColumnName],
|
|
6057
6069
|
error: individualSubmit ? meta.error : meta.touched && meta.error,
|
|
6058
6070
|
options: isDropdown ? buildOptionsToLabelAndValue(fieldData) : undefined,
|
|
6059
6071
|
value: getValueForField(formikFieldProps.value),
|
|
6060
6072
|
label: capitalize$1(name),
|
|
6073
|
+
labelProps: {
|
|
6074
|
+
required: props[isRequiredColumnName]
|
|
6075
|
+
},
|
|
6061
6076
|
disabled: disabled
|
|
6062
6077
|
})
|
|
6063
6078
|
};
|
|
@@ -6111,7 +6126,8 @@ var MultiOption = function MultiOption(props) {
|
|
|
6111
6126
|
fieldProps = _useFormikFields.fieldProps;
|
|
6112
6127
|
return /*#__PURE__*/React.createElement(Select, _extends({
|
|
6113
6128
|
isMulti: true,
|
|
6114
|
-
isSearchable: true
|
|
6129
|
+
isSearchable: true,
|
|
6130
|
+
strategy: "fixed"
|
|
6115
6131
|
}, fieldProps, {
|
|
6116
6132
|
onChange: function onChange(selectedOptions) {
|
|
6117
6133
|
return handleSubmit(pluck("value", selectedOptions));
|
|
@@ -6173,7 +6189,8 @@ var SingleOption = function SingleOption(props) {
|
|
|
6173
6189
|
fieldProps = _useFormikFields.fieldProps;
|
|
6174
6190
|
return /*#__PURE__*/React.createElement(Select, _extends({
|
|
6175
6191
|
isClearable: true,
|
|
6176
|
-
isSearchable: true
|
|
6192
|
+
isSearchable: true,
|
|
6193
|
+
strategy: "fixed"
|
|
6177
6194
|
}, fieldProps, {
|
|
6178
6195
|
onChange: function onChange(option) {
|
|
6179
6196
|
return handleSubmit((option === null || option === void 0 ? void 0 : option.value) || "");
|
|
@@ -6633,9 +6650,17 @@ var renderFormFooter = function renderFormFooter(_ref3) {
|
|
|
6633
6650
|
}));
|
|
6634
6651
|
};
|
|
6635
6652
|
|
|
6653
|
+
var PERMITTED_REGEX_PATTERN = /^\/.*\/[igmsyu]*$/;
|
|
6654
|
+
var ADVANCED_REGEX_ASSERTION_PATTERN = /\(\?=[^)]*\)|\(\?![^)]*\)|\(\?<=[^)]*\)|\(\?<![^)]*\)/;
|
|
6636
6655
|
var regexValidationSchema = yup.object().shape({
|
|
6637
|
-
condition: yup.string().required(t$1("validations.regexConditionIsRequired")).matches(
|
|
6638
|
-
name: "regex",
|
|
6656
|
+
condition: yup.string().required(t$1("validations.regexConditionIsRequired")).matches(PERMITTED_REGEX_PATTERN, t$1("validations.invalidRegexPattern")).test({
|
|
6657
|
+
name: "test-regex-is-advanced",
|
|
6658
|
+
message: t$1("validations.advancedRegexAssertionsNotSupported") || "",
|
|
6659
|
+
test: function test(value) {
|
|
6660
|
+
return !ADVANCED_REGEX_ASSERTION_PATTERN.test(value);
|
|
6661
|
+
}
|
|
6662
|
+
}).test({
|
|
6663
|
+
name: "test-regex-condition-pattern",
|
|
6639
6664
|
message: t$1("validations.invalidRegexPattern") || "",
|
|
6640
6665
|
test: function test(value) {
|
|
6641
6666
|
try {
|
|
@@ -7657,34 +7682,27 @@ var renderMenuBarItems = function renderMenuBarItems(_ref2) {
|
|
|
7657
7682
|
});
|
|
7658
7683
|
});
|
|
7659
7684
|
};
|
|
7660
|
-
var
|
|
7685
|
+
var renderStateFilterTabs = function renderStateFilterTabs(_ref3) {
|
|
7661
7686
|
var selectedState = _ref3.selectedState,
|
|
7662
7687
|
fieldStatesTaxonomy = _ref3.fieldStatesTaxonomy,
|
|
7663
7688
|
activeFieldsCount = _ref3.activeFieldsCount,
|
|
7664
7689
|
inactiveFieldsCount = _ref3.inactiveFieldsCount,
|
|
7665
7690
|
handleBlockClick = _ref3.handleBlockClick;
|
|
7666
|
-
return /*#__PURE__*/React.createElement(
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
textTransform: "uppercase",
|
|
7670
|
-
weight: "bold"
|
|
7671
|
-
}, t$1("titles.filters"))), /*#__PURE__*/React.createElement(MenuBar.Block, {
|
|
7691
|
+
return /*#__PURE__*/React.createElement(Tab, {
|
|
7692
|
+
className: "mb-4"
|
|
7693
|
+
}, /*#__PURE__*/React.createElement(Tab.Item, {
|
|
7672
7694
|
active: selectedState === FIELD_STATES.active,
|
|
7673
|
-
count: activeFieldsCount,
|
|
7674
7695
|
"data-cy": "menubar-active-block",
|
|
7675
|
-
label: fieldStatesTaxonomy.active,
|
|
7676
7696
|
onClick: handleBlockClick({
|
|
7677
7697
|
state: FIELD_STATES.active
|
|
7678
7698
|
})
|
|
7679
|
-
}), /*#__PURE__*/React.createElement(
|
|
7699
|
+
}, fieldStatesTaxonomy.active, "(", activeFieldsCount, ")"), /*#__PURE__*/React.createElement(Tab.Item, {
|
|
7680
7700
|
active: selectedState === FIELD_STATES.inactive,
|
|
7681
|
-
count: inactiveFieldsCount,
|
|
7682
7701
|
"data-cy": "menubar-inactive-block",
|
|
7683
|
-
label: fieldStatesTaxonomy.inactive,
|
|
7684
7702
|
onClick: handleBlockClick({
|
|
7685
7703
|
state: FIELD_STATES.inactive
|
|
7686
7704
|
})
|
|
7687
|
-
}));
|
|
7705
|
+
}, fieldStatesTaxonomy.inactive, "(", inactiveFieldsCount, ")"));
|
|
7688
7706
|
};
|
|
7689
7707
|
var getResourceName = function getResourceName(_ref4) {
|
|
7690
7708
|
var isOwnerBased = _ref4.isOwnerBased,
|
|
@@ -7702,24 +7720,11 @@ var getResourceName = function getResourceName(_ref4) {
|
|
|
7702
7720
|
var getDashBoardTitle = function getDashBoardTitle(_ref5) {
|
|
7703
7721
|
var resourceName = _ref5.resourceName,
|
|
7704
7722
|
isSingleResource = _ref5.isSingleResource,
|
|
7705
|
-
showStateFilter = _ref5.showStateFilter,
|
|
7706
|
-
selectedState = _ref5.selectedState,
|
|
7707
7723
|
title = _ref5.title;
|
|
7708
|
-
var displayTitle = title
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
title: title,
|
|
7713
|
-
resource: resourceName
|
|
7714
|
-
});
|
|
7715
|
-
} else if (showStateFilter && isSingleResource) {
|
|
7716
|
-
displayTitle = "".concat(selectedState, " ").concat(title);
|
|
7717
|
-
} else if (!showStateFilter && !isSingleResource) {
|
|
7718
|
-
displayTitle = t$1("messages.titleForResource", {
|
|
7719
|
-
title: title,
|
|
7720
|
-
resource: resourceName
|
|
7721
|
-
});
|
|
7722
|
-
}
|
|
7724
|
+
var displayTitle = isSingleResource ? title : t$1("messages.titleForResource", {
|
|
7725
|
+
title: title,
|
|
7726
|
+
resource: resourceName
|
|
7727
|
+
});
|
|
7723
7728
|
return humanize(displayTitle);
|
|
7724
7729
|
};
|
|
7725
7730
|
var renderNoDataHelpText = function renderNoDataHelpText(title, url) {
|
|
@@ -7921,7 +7926,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
|
|
|
7921
7926
|
}
|
|
7922
7927
|
};
|
|
7923
7928
|
var isScreenLoading = isFieldsLoading || isConfigsLoading;
|
|
7924
|
-
var showCountSubheader = count > 0;
|
|
7929
|
+
var showCountSubheader = count > 0 && !showStateFilter;
|
|
7925
7930
|
var searchProps = {
|
|
7926
7931
|
onChange: function onChange(e) {
|
|
7927
7932
|
return setSearchTerm(e.target.value);
|
|
@@ -7931,7 +7936,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
|
|
|
7931
7936
|
className: "w-44"
|
|
7932
7937
|
};
|
|
7933
7938
|
var isSingleResource = menuItems.length === 1;
|
|
7934
|
-
var isMenuBarNeeded =
|
|
7939
|
+
var isMenuBarNeeded = !isSingleResource && !isConfigsLoading;
|
|
7935
7940
|
var resourceName = useMemo(function () {
|
|
7936
7941
|
return getResourceName({
|
|
7937
7942
|
isOwnerBased: isOwnerBased,
|
|
@@ -7943,14 +7948,12 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
|
|
|
7943
7948
|
var headerDisplayTitle = useMemo(function () {
|
|
7944
7949
|
return getDashBoardTitle({
|
|
7945
7950
|
resourceName: resourceName,
|
|
7946
|
-
showStateFilter: showStateFilter,
|
|
7947
|
-
selectedState: state,
|
|
7948
7951
|
isSingleResource: isSingleResource,
|
|
7949
7952
|
title: title
|
|
7950
7953
|
});
|
|
7951
7954
|
}, [state, isSingleResource, resourceName]);
|
|
7952
|
-
var
|
|
7953
|
-
return
|
|
7955
|
+
var stateFilterTabs = useMemo(function () {
|
|
7956
|
+
return renderStateFilterTabs({
|
|
7954
7957
|
selectedState: state,
|
|
7955
7958
|
fieldStatesTaxonomy: fieldStatesTaxonomy,
|
|
7956
7959
|
activeFieldsCount: activeFieldsCount,
|
|
@@ -7999,7 +8002,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
|
|
|
7999
8002
|
handleClosePane: handleClosePane,
|
|
8000
8003
|
handleReorderPaneClose: handleReorderPaneClose,
|
|
8001
8004
|
searchProps: searchProps,
|
|
8002
|
-
|
|
8005
|
+
stateFilterTabs: stateFilterTabs,
|
|
8003
8006
|
menuBarItems: menuBarItems,
|
|
8004
8007
|
allFields: allFields,
|
|
8005
8008
|
headerDisplayTitle: headerDisplayTitle
|
|
@@ -12503,7 +12506,7 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
12503
12506
|
handleClosePane = _useFieldsDashboard.handleClosePane,
|
|
12504
12507
|
handleReorderPaneClose = _useFieldsDashboard.handleReorderPaneClose,
|
|
12505
12508
|
searchProps = _useFieldsDashboard.searchProps,
|
|
12506
|
-
|
|
12509
|
+
stateFilterTabs = _useFieldsDashboard.stateFilterTabs,
|
|
12507
12510
|
menuBarItems = _useFieldsDashboard.menuBarItems,
|
|
12508
12511
|
allFields = _useFieldsDashboard.allFields,
|
|
12509
12512
|
headerDisplayTitle = _useFieldsDashboard.headerDisplayTitle;
|
|
@@ -12512,8 +12515,8 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
12512
12515
|
title: title
|
|
12513
12516
|
}, isConfigsLoading ? /*#__PURE__*/React.createElement("div", {
|
|
12514
12517
|
className: "flex items-center justify-center"
|
|
12515
|
-
}, /*#__PURE__*/React.createElement(Spinner, null)) : menuBarItems
|
|
12516
|
-
className: "flex w-full flex-grow items-center justify-center"
|
|
12518
|
+
}, /*#__PURE__*/React.createElement(Spinner, null)) : menuBarItems), isScreenLoading && isEmpty(fields) ? /*#__PURE__*/React.createElement("div", {
|
|
12519
|
+
className: "flex h-screen w-full flex-grow items-center justify-center"
|
|
12517
12520
|
}, /*#__PURE__*/React.createElement(PageLoader, null)) : /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Header, _extends({}, _objectSpread$2(_objectSpread$2({
|
|
12518
12521
|
breadcrumbs: breadcrumbs
|
|
12519
12522
|
}, isMenuBarNeeded && {
|
|
@@ -12551,7 +12554,7 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
|
|
|
12551
12554
|
"data-cy": "neeto-fields-subheader-text",
|
|
12552
12555
|
style: "h4"
|
|
12553
12556
|
}, "".concat(count, " "), t("titles.field", count > 1 ? PLURAL : SINGULAR).toLocaleLowerCase())
|
|
12554
|
-
}), /*#__PURE__*/React.createElement(FieldsTable, {
|
|
12557
|
+
}), showStateFilter && stateFilterTabs, /*#__PURE__*/React.createElement(FieldsTable, {
|
|
12555
12558
|
isLoading: isFieldsFetching || isFieldsLoading,
|
|
12556
12559
|
rowData: isEmpty(rowData) ? fields : rowData,
|
|
12557
12560
|
totalCount: count,
|