@reltio/components 1.4.1481 → 1.4.1483

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.
Files changed (27) hide show
  1. package/cjs/components/attributes/editMode/SimpleAttributeEditor/SimpleAttributeEditor.js +8 -1
  2. package/cjs/components/attributes/editMode/SimpleAttributeEditor/selectors/getDependentLookupEditorContext.js +1 -5
  3. package/cjs/components/attributes/editMode/SimpleAttributeEditor/selectors/types.d.ts +0 -1
  4. package/cjs/components/attributes/editMode/SimpleAttributeEditor/useAutopopulationContextValue.d.ts +13 -0
  5. package/cjs/components/attributes/editMode/SimpleAttributeEditor/useAutopopulationContextValue.js +52 -0
  6. package/cjs/components/editors/DependentLookupEditor/DependentLookupEditor.d.ts +1 -3
  7. package/cjs/components/editors/DependentLookupEditor/DependentLookupEditor.js +1 -3
  8. package/cjs/components/editors/DependentLookupEditor/useAutopopulation.d.ts +1 -2
  9. package/cjs/components/editors/DependentLookupEditor/useAutopopulation.js +6 -9
  10. package/cjs/contexts/DependentLookupAutopopulationContext/index.d.ts +8 -0
  11. package/cjs/contexts/DependentLookupAutopopulationContext/index.js +9 -0
  12. package/cjs/contexts/index.d.ts +1 -0
  13. package/cjs/contexts/index.js +3 -1
  14. package/esm/components/attributes/editMode/SimpleAttributeEditor/SimpleAttributeEditor.js +9 -2
  15. package/esm/components/attributes/editMode/SimpleAttributeEditor/selectors/getDependentLookupEditorContext.js +1 -5
  16. package/esm/components/attributes/editMode/SimpleAttributeEditor/selectors/types.d.ts +0 -1
  17. package/esm/components/attributes/editMode/SimpleAttributeEditor/useAutopopulationContextValue.d.ts +13 -0
  18. package/esm/components/attributes/editMode/SimpleAttributeEditor/useAutopopulationContextValue.js +25 -0
  19. package/esm/components/editors/DependentLookupEditor/DependentLookupEditor.d.ts +1 -3
  20. package/esm/components/editors/DependentLookupEditor/DependentLookupEditor.js +1 -3
  21. package/esm/components/editors/DependentLookupEditor/useAutopopulation.d.ts +1 -2
  22. package/esm/components/editors/DependentLookupEditor/useAutopopulation.js +7 -10
  23. package/esm/contexts/DependentLookupAutopopulationContext/index.d.ts +8 -0
  24. package/esm/contexts/DependentLookupAutopopulationContext/index.js +3 -0
  25. package/esm/contexts/index.d.ts +1 -0
  26. package/esm/contexts/index.js +1 -0
  27. package/package.json +3 -3
@@ -68,6 +68,7 @@ var getDependentLookupEditorContext_1 = require("./selectors/getDependentLookupE
68
68
  var HOCs_1 = require("../../../../HOCs");
69
69
  var contexts_1 = require("../../../../contexts");
70
70
  var hooks_1 = require("../../../../hooks");
71
+ var useAutopopulationContextValue_1 = require("./useAutopopulationContextValue");
71
72
  var styles_1 = require("./styles");
72
73
  var AsyncMountPlaceholder = function () {
73
74
  var styles = (0, styles_1.useStyles)();
@@ -109,9 +110,15 @@ var SimpleAttributeEditor = function (_a) {
109
110
  var showDeleteButton = !deleted && !!onDeleteAttribute && canDelete;
110
111
  var hasError = !!errorMessage;
111
112
  var deletedProps = deleted ? { disabled: true } : {};
113
+ var autopopulationContextValue = (0, useAutopopulationContextValue_1.useAutopopulationContextValue)({
114
+ enabled: Boolean(dependentLookupEditorContext),
115
+ attributeTypeUri: attributeType === null || attributeType === void 0 ? void 0 : attributeType.uri,
116
+ valueUri: attributeValue.uri
117
+ }).autopopulationContextValue;
112
118
  return (react_1.default.createElement("div", { ref: ref, className: (0, classnames_1.default)(styles.editor, className, errorClassName) },
113
119
  react_1.default.createElement(ErrorWrapper_1.default, { errorMessage: errorMessage, className: styles.errorWrapper },
114
- react_1.default.createElement("div", { className: (0, classnames_1.default)(styles['editor-value'], (_b = {}, _b[styles.deleted] = deleted, _b), (_c = {}, _c[styles['editor-read-only-value']] = !showToEdit, _c)), "data-reltio-id": "reltio-attribute-value" }, showToEdit ? (react_1.default.createElement(DataTypeValueEditor_1.default, __assign({ fieldName: (0, mdm_sdk_1.attributeUriToSearchUri)(attributeType.uri), value: value, dataTypeDefinition: dataTypeDefinition, error: hasError, onChange: onValueEditorChange, fullWidth: true }, dependentLookupEditorContext, otherProps, deletedProps))) : (react_1.default.createElement(DataTypeValue_1.default, { value: (0, mdm_sdk_1.getAttributeValue)(attributeValue), dataTypeDefinition: dataTypeDefinition })))),
120
+ react_1.default.createElement("div", { className: (0, classnames_1.default)(styles['editor-value'], (_b = {}, _b[styles.deleted] = deleted, _b), (_c = {}, _c[styles['editor-read-only-value']] = !showToEdit, _c)), "data-reltio-id": "reltio-attribute-value" }, showToEdit ? (react_1.default.createElement(contexts_1.DependentLookupAutopopulationContext.Provider, { value: autopopulationContextValue },
121
+ react_1.default.createElement(DataTypeValueEditor_1.default, __assign({ fieldName: (0, mdm_sdk_1.attributeUriToSearchUri)(attributeType.uri), value: value, dataTypeDefinition: dataTypeDefinition, error: hasError, onChange: onValueEditorChange, fullWidth: true }, dependentLookupEditorContext, otherProps, deletedProps)))) : (react_1.default.createElement(DataTypeValue_1.default, { value: (0, mdm_sdk_1.getAttributeValue)(attributeValue), dataTypeDefinition: dataTypeDefinition })))),
115
122
  react_1.default.createElement("div", { className: styles['editor-actions'] },
116
123
  edited && (react_1.default.createElement(Typography_1.default, { variant: "caption", className: styles.editedLabel },
117
124
  "(",
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getDependentLookupEditorContext = void 0;
7
- var mdm_sdk_1 = require("@reltio/mdm-sdk");
8
7
  var mdm_module_1 = __importDefault(require("@reltio/mdm-module"));
9
8
  var ui_i18n_1 = __importDefault(require("ui-i18n"));
10
9
  var parents_1 = require("./helpers/parents");
@@ -17,8 +16,6 @@ var getDependentLookupEditorContext = function (state, attributeValue, attribute
17
16
  var _a = (0, parents_1.getParents)(state, valueUri, node), parents = _a.parents, missedParentsAttributeTypes = _a.missedParentsAttributeTypes;
18
17
  var _b = (mdm_module_1.default.selectors.getDependentLookupEditorState(state, valueUri) || {}).isBlocked, isBlocked = _b === void 0 ? false : _b;
19
18
  var missedParentsMessage = (0, missedParentsMessage_1.buildMissedParentsMessage)(missedParentsAttributeTypes);
20
- var autocompleteConfig = mdm_module_1.default.selectors.getLookupAutocomplete(state);
21
- var autopopulationEnabled = (0, mdm_sdk_1.isAutopopulationEnabled)(autocompleteConfig, attributeTypeUri);
22
19
  var isEmptyValue = !(attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.lookupCode) && !(attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.value);
23
20
  var placeholder = (isEmptyValue && isBlocked && ui_i18n_1.default.text('Populating values...')) ||
24
21
  (isEmptyValue && missedParentsMessage) ||
@@ -26,8 +23,7 @@ var getDependentLookupEditorContext = function (state, attributeValue, attribute
26
23
  var context = {
27
24
  parents: missedParentsMessage ? null : parents,
28
25
  disabled: (!!missedParentsMessage && isEmptyValue) || isBlocked,
29
- placeholder: placeholder,
30
- autopopulationId: autopopulationEnabled ? valueUri : null
26
+ placeholder: placeholder
31
27
  };
32
28
  if (placeholder) {
33
29
  context.value = null;
@@ -7,6 +7,5 @@ export declare type DependentLookupEditorContext = {
7
7
  parents: DependentLookupsParentForApi[];
8
8
  disabled: boolean;
9
9
  placeholder: string;
10
- autopopulationId: string;
11
10
  value?: null;
12
11
  };
@@ -0,0 +1,13 @@
1
+ declare type Props = {
2
+ enabled: boolean;
3
+ attributeTypeUri: string;
4
+ valueUri: string;
5
+ };
6
+ export declare const useAutopopulationContextValue: ({ enabled, attributeTypeUri, valueUri }: Props) => {
7
+ autopopulationContextValue: {
8
+ id: string;
9
+ isTouched: boolean;
10
+ onTouch: (id: string) => void;
11
+ };
12
+ };
13
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useAutopopulationContextValue = void 0;
27
+ var react_1 = require("react");
28
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
29
+ var react_redux_1 = require("react-redux");
30
+ var mdm_module_1 = __importStar(require("@reltio/mdm-module"));
31
+ var useAutopopulationContextValue = function (_a) {
32
+ var enabled = _a.enabled, attributeTypeUri = _a.attributeTypeUri, valueUri = _a.valueUri;
33
+ var dispatch = (0, react_redux_1.useDispatch)();
34
+ var autocompleteConfig = (0, react_redux_1.useSelector)(mdm_module_1.default.selectors.getLookupAutocomplete);
35
+ var autopopulationEnabled = enabled && (0, mdm_sdk_1.isAutopopulationEnabled)(autocompleteConfig, attributeTypeUri);
36
+ var autopopulationId = autopopulationEnabled ? valueUri : null;
37
+ var _b = ((0, react_redux_1.useSelector)(function (state) { return mdm_module_1.default.selectors.getDependentLookupEditorState(state, valueUri); }) || {}).isTouched, isTouched = _b === void 0 ? false : _b;
38
+ var onTouch = (0, react_1.useCallback)(function (valueUri) {
39
+ dispatch(mdm_module_1.profile.dependentLookups.actions.dependentLookupsEditorTouched({ uri: valueUri, isTouched: true }));
40
+ }, [dispatch]);
41
+ var autopopulationContextValue = (0, react_1.useMemo)(function () {
42
+ return autopopulationId
43
+ ? {
44
+ id: autopopulationId,
45
+ isTouched: isTouched,
46
+ onTouch: onTouch
47
+ }
48
+ : null;
49
+ }, [autopopulationId, isTouched, onTouch]);
50
+ return { autopopulationContextValue: autopopulationContextValue };
51
+ };
52
+ exports.useAutopopulationContextValue = useAutopopulationContextValue;
@@ -1,6 +1,6 @@
1
1
  export const DEBOUNCE_INTERVAL: 400;
2
2
  export default DependentLookupEditor;
3
- declare function DependentLookupEditor({ multiple, value, lookupCode: lookupTypeCode, TextFieldProps, parents, onChange, getLookups, lookups, resolveLookups, fullWidth, disabled, placeholder, autopopulationId, max, ...otherProps }: {
3
+ declare function DependentLookupEditor({ multiple, value, lookupCode: lookupTypeCode, TextFieldProps, parents, onChange, getLookups, lookups, resolveLookups, fullWidth, disabled, placeholder, max, ...otherProps }: {
4
4
  [x: string]: any;
5
5
  multiple: any;
6
6
  value: any;
@@ -14,7 +14,6 @@ declare function DependentLookupEditor({ multiple, value, lookupCode: lookupType
14
14
  fullWidth: any;
15
15
  disabled: any;
16
16
  placeholder: any;
17
- autopopulationId: any;
18
17
  max?: number;
19
18
  }): JSX.Element;
20
19
  declare namespace DependentLookupEditor {
@@ -41,7 +40,6 @@ declare namespace DependentLookupEditor {
41
40
  const fullWidth: PropTypes.Requireable<boolean>;
42
41
  const placeholder: PropTypes.Requireable<string>;
43
42
  const disabled: PropTypes.Requireable<boolean>;
44
- const autopopulationId: PropTypes.Requireable<string>;
45
43
  const max: PropTypes.Requireable<number>;
46
44
  }
47
45
  }
@@ -84,7 +84,7 @@ var SelectComponents = {
84
84
  exports.DEBOUNCE_INTERVAL = 400;
85
85
  var MAX_DEPENDENT_LOOKUP_VALUES = 50;
86
86
  var DependentLookupEditor = function (_a) {
87
- var multiple = _a.multiple, value = _a.value, lookupTypeCode = _a.lookupCode, TextFieldProps = _a.TextFieldProps, parents = _a.parents, onChange = _a.onChange, getLookups = _a.getLookups, _b = _a.lookups, lookups = _b === void 0 ? {} : _b, resolveLookups = _a.resolveLookups, fullWidth = _a.fullWidth, disabled = _a.disabled, placeholder = _a.placeholder, autopopulationId = _a.autopopulationId, _c = _a.max, max = _c === void 0 ? MAX_DEPENDENT_LOOKUP_VALUES : _c, otherProps = __rest(_a, ["multiple", "value", "lookupCode", "TextFieldProps", "parents", "onChange", "getLookups", "lookups", "resolveLookups", "fullWidth", "disabled", "placeholder", "autopopulationId", "max"]);
87
+ var multiple = _a.multiple, value = _a.value, lookupTypeCode = _a.lookupCode, TextFieldProps = _a.TextFieldProps, parents = _a.parents, onChange = _a.onChange, getLookups = _a.getLookups, _b = _a.lookups, lookups = _b === void 0 ? {} : _b, resolveLookups = _a.resolveLookups, fullWidth = _a.fullWidth, disabled = _a.disabled, placeholder = _a.placeholder, _c = _a.max, max = _c === void 0 ? MAX_DEPENDENT_LOOKUP_VALUES : _c, otherProps = __rest(_a, ["multiple", "value", "lookupCode", "TextFieldProps", "parents", "onChange", "getLookups", "lookups", "resolveLookups", "fullWidth", "disabled", "placeholder", "max"]);
88
88
  var inputRef = (0, react_1.useRef)(null);
89
89
  var selectRef = (0, react_1.useRef)(null);
90
90
  var styles = (0, styles_1.useStyles)();
@@ -188,7 +188,6 @@ var DependentLookupEditor = function (_a) {
188
188
  var showMoreButton = options.length > displayedOptions.length;
189
189
  var isEmptyValue = multiple ? (0, ramda_1.isEmpty)(value) : !(value === null || value === void 0 ? void 0 : value.lookupCode) && !(value === null || value === void 0 ? void 0 : value.value);
190
190
  var markAsTouched = (0, useAutopopulation_1.default)({
191
- id: autopopulationId,
192
191
  initialDefaultOptions: initialDefaultOptions,
193
192
  isEmptyValue: isEmptyValue,
194
193
  multiple: multiple,
@@ -218,7 +217,6 @@ DependentLookupEditor.propTypes = {
218
217
  fullWidth: prop_types_1.default.bool,
219
218
  placeholder: prop_types_1.default.string,
220
219
  disabled: prop_types_1.default.bool,
221
- autopopulationId: prop_types_1.default.string,
222
220
  max: prop_types_1.default.number
223
221
  };
224
222
  exports.default = DependentLookupEditor;
@@ -3,13 +3,12 @@ declare type Option = {
3
3
  value: string;
4
4
  };
5
5
  declare type Props = {
6
- id: string;
7
6
  initialDefaultOptions: Option[];
8
7
  isEmptyValue: boolean;
9
8
  multiple: boolean;
10
9
  onChange: (value: Option | Option[]) => void;
11
10
  };
12
- declare const useAutopopulation: ({ id, initialDefaultOptions, isEmptyValue, multiple, onChange }: Props) => {
11
+ declare const useAutopopulation: ({ initialDefaultOptions, isEmptyValue, multiple, onChange }: Props) => {
13
12
  markAsTouched: () => void;
14
13
  };
15
14
  export default useAutopopulation;
@@ -1,25 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var react_1 = require("react");
4
- var touchedEditorsMap = {};
5
- var addTouchedEditor = function (id) {
6
- touchedEditorsMap[id] = true;
7
- };
8
- var isTouchedEditor = function (id) { return touchedEditorsMap[id]; };
4
+ var contexts_1 = require("../../../contexts");
9
5
  // Autopopulation for just added editor. Other autopopulation cases should be covered by cascadeUpdate flow.
10
6
  var useAutopopulation = function (_a) {
11
- var id = _a.id, initialDefaultOptions = _a.initialDefaultOptions, isEmptyValue = _a.isEmptyValue, multiple = _a.multiple, onChange = _a.onChange;
7
+ var initialDefaultOptions = _a.initialDefaultOptions, isEmptyValue = _a.isEmptyValue, multiple = _a.multiple, onChange = _a.onChange;
8
+ var _b = (0, react_1.useContext)(contexts_1.DependentLookupAutopopulationContext) || {}, id = _b.id, isTouched = _b.isTouched, onTouch = _b.onTouch;
12
9
  (0, react_1.useEffect)(function () {
13
- if (id && initialDefaultOptions && initialDefaultOptions.length === 1 && isEmptyValue && !isTouchedEditor(id)) {
10
+ if (id && initialDefaultOptions && initialDefaultOptions.length === 1 && isEmptyValue && !isTouched) {
14
11
  onChange(multiple ? initialDefaultOptions : initialDefaultOptions[0]);
15
12
  }
16
13
  //eslint-disable-next-line react-hooks/exhaustive-deps
17
14
  }, [initialDefaultOptions]);
18
15
  var markAsTouched = (0, react_1.useCallback)(function () {
19
16
  if (id) {
20
- addTouchedEditor(id);
17
+ onTouch === null || onTouch === void 0 ? void 0 : onTouch(id);
21
18
  }
22
- }, [id]);
19
+ }, [onTouch, id]);
23
20
  return { markAsTouched: markAsTouched };
24
21
  };
25
22
  exports.default = useAutopopulation;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ declare type DependentLookupAutopopulationContextValue = {
3
+ id: string;
4
+ isTouched: boolean;
5
+ onTouch: (id: string) => void;
6
+ };
7
+ export declare const DependentLookupAutopopulationContext: React.Context<DependentLookupAutopopulationContextValue>;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DependentLookupAutopopulationContext = void 0;
7
+ var react_1 = __importDefault(require("react"));
8
+ exports.DependentLookupAutopopulationContext = react_1.default.createContext(null);
9
+ exports.DependentLookupAutopopulationContext.displayName = 'DependentLookupAutopopulationContext';
@@ -26,4 +26,5 @@ export { ScrollToErrorContext, ScrollToErrorProvider } from './ScrollToErrorCont
26
26
  export { UrlGeneratorsContext } from './UrlGeneratorsContext';
27
27
  export { LabelsContext } from './LabelsContext';
28
28
  export { FeaturesContext } from './FeaturesContext';
29
+ export { DependentLookupAutopopulationContext } from './DependentLookupAutopopulationContext';
29
30
  export { PageRequestsAbortingContext } from './PageRequestsAbortingContext';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageRequestsAbortingContext = exports.FeaturesContext = exports.LabelsContext = exports.UrlGeneratorsContext = exports.ScrollToErrorProvider = exports.ScrollToErrorContext = exports.SearchValueContext = exports.InterceptHandlersContext = exports.HighlightedValuesContext = exports.SnackbarContext = exports.SearchFiltersContext = exports.useReloadFacet = exports.ReloadFacetProvider = exports.useReloadAllFacets = exports.SandboxAPIContext = exports.EntityContext = exports.RelatedObjectUrisContext = exports.WorkflowTasksContext = exports.EntityMarkerContext = exports.useAttributeExpanded = exports.ExpandedAttributesProvider = exports.useHighlightedCrosswalks = exports.useCrosswalkHighlight = exports.useCrosswalkFocus = exports.useCrosswalkColor = exports.CrosswalksDisplayProvider = exports.EntitiesMapContext = exports.IdContext = exports.ProfilePerspectiveViewContext = exports.PivotingAttributeContext = exports.UsersContext = exports.CollaborationContextProvider = exports.CollaborationContext = exports.BlockImageGalleryDialogContext = exports.ViewIdContext = exports.PopupBoundariesContext = exports.HistoryDiffContext = exports.AsyncMountContext = void 0;
3
+ exports.PageRequestsAbortingContext = exports.DependentLookupAutopopulationContext = exports.FeaturesContext = exports.LabelsContext = exports.UrlGeneratorsContext = exports.ScrollToErrorProvider = exports.ScrollToErrorContext = exports.SearchValueContext = exports.InterceptHandlersContext = exports.HighlightedValuesContext = exports.SnackbarContext = exports.SearchFiltersContext = exports.useReloadFacet = exports.ReloadFacetProvider = exports.useReloadAllFacets = exports.SandboxAPIContext = exports.EntityContext = exports.RelatedObjectUrisContext = exports.WorkflowTasksContext = exports.EntityMarkerContext = exports.useAttributeExpanded = exports.ExpandedAttributesProvider = exports.useHighlightedCrosswalks = exports.useCrosswalkHighlight = exports.useCrosswalkFocus = exports.useCrosswalkColor = exports.CrosswalksDisplayProvider = exports.EntitiesMapContext = exports.IdContext = exports.ProfilePerspectiveViewContext = exports.PivotingAttributeContext = exports.UsersContext = exports.CollaborationContextProvider = exports.CollaborationContext = exports.BlockImageGalleryDialogContext = exports.ViewIdContext = exports.PopupBoundariesContext = exports.HistoryDiffContext = exports.AsyncMountContext = void 0;
4
4
  var AsyncMountContext_1 = require("./AsyncMountContext");
5
5
  Object.defineProperty(exports, "AsyncMountContext", { enumerable: true, get: function () { return AsyncMountContext_1.AsyncMountContext; } });
6
6
  var HistoryAppearanceContext_1 = require("./HistoryAppearanceContext");
@@ -66,5 +66,7 @@ var LabelsContext_1 = require("./LabelsContext");
66
66
  Object.defineProperty(exports, "LabelsContext", { enumerable: true, get: function () { return LabelsContext_1.LabelsContext; } });
67
67
  var FeaturesContext_1 = require("./FeaturesContext");
68
68
  Object.defineProperty(exports, "FeaturesContext", { enumerable: true, get: function () { return FeaturesContext_1.FeaturesContext; } });
69
+ var DependentLookupAutopopulationContext_1 = require("./DependentLookupAutopopulationContext");
70
+ Object.defineProperty(exports, "DependentLookupAutopopulationContext", { enumerable: true, get: function () { return DependentLookupAutopopulationContext_1.DependentLookupAutopopulationContext; } });
69
71
  var PageRequestsAbortingContext_1 = require("./PageRequestsAbortingContext");
70
72
  Object.defineProperty(exports, "PageRequestsAbortingContext", { enumerable: true, get: function () { return PageRequestsAbortingContext_1.PageRequestsAbortingContext; } });
@@ -38,8 +38,9 @@ import { attributeValueToEditorValue, prepareChangeData } from './utils';
38
38
  import withAsyncMount from '../../../../HOCs/withAsyncMount/withAsyncMount';
39
39
  import { getDependentLookupEditorContext } from './selectors/getDependentLookupEditorContext';
40
40
  import { withContext } from '../../../../HOCs';
41
- import { ScrollToErrorContext } from '../../../../contexts';
41
+ import { ScrollToErrorContext, DependentLookupAutopopulationContext } from '../../../../contexts';
42
42
  import { useScrollToAttributeError } from '../../../../hooks';
43
+ import { useAutopopulationContextValue } from './useAutopopulationContextValue';
43
44
  import { useStyles } from './styles';
44
45
  var AsyncMountPlaceholder = function () {
45
46
  var styles = useStyles();
@@ -81,9 +82,15 @@ var SimpleAttributeEditor = function (_a) {
81
82
  var showDeleteButton = !deleted && !!onDeleteAttribute && canDelete;
82
83
  var hasError = !!errorMessage;
83
84
  var deletedProps = deleted ? { disabled: true } : {};
85
+ var autopopulationContextValue = useAutopopulationContextValue({
86
+ enabled: Boolean(dependentLookupEditorContext),
87
+ attributeTypeUri: attributeType === null || attributeType === void 0 ? void 0 : attributeType.uri,
88
+ valueUri: attributeValue.uri
89
+ }).autopopulationContextValue;
84
90
  return (React.createElement("div", { ref: ref, className: classnames(styles.editor, className, errorClassName) },
85
91
  React.createElement(ErrorWrapper, { errorMessage: errorMessage, className: styles.errorWrapper },
86
- React.createElement("div", { className: classnames(styles['editor-value'], (_b = {}, _b[styles.deleted] = deleted, _b), (_c = {}, _c[styles['editor-read-only-value']] = !showToEdit, _c)), "data-reltio-id": "reltio-attribute-value" }, showToEdit ? (React.createElement(DataTypeValueEditor, __assign({ fieldName: attributeUriToSearchUri(attributeType.uri), value: value, dataTypeDefinition: dataTypeDefinition, error: hasError, onChange: onValueEditorChange, fullWidth: true }, dependentLookupEditorContext, otherProps, deletedProps))) : (React.createElement(DataTypeValue, { value: getAttributeValue(attributeValue), dataTypeDefinition: dataTypeDefinition })))),
92
+ React.createElement("div", { className: classnames(styles['editor-value'], (_b = {}, _b[styles.deleted] = deleted, _b), (_c = {}, _c[styles['editor-read-only-value']] = !showToEdit, _c)), "data-reltio-id": "reltio-attribute-value" }, showToEdit ? (React.createElement(DependentLookupAutopopulationContext.Provider, { value: autopopulationContextValue },
93
+ React.createElement(DataTypeValueEditor, __assign({ fieldName: attributeUriToSearchUri(attributeType.uri), value: value, dataTypeDefinition: dataTypeDefinition, error: hasError, onChange: onValueEditorChange, fullWidth: true }, dependentLookupEditorContext, otherProps, deletedProps)))) : (React.createElement(DataTypeValue, { value: getAttributeValue(attributeValue), dataTypeDefinition: dataTypeDefinition })))),
87
94
  React.createElement("div", { className: styles['editor-actions'] },
88
95
  edited && (React.createElement(Typography, { variant: "caption", className: styles.editedLabel },
89
96
  "(",
@@ -1,4 +1,3 @@
1
- import { isAutopopulationEnabled } from '@reltio/mdm-sdk';
2
1
  import mdmModule from '@reltio/mdm-module';
3
2
  import i18n from 'ui-i18n';
4
3
  import { getParents } from './helpers/parents';
@@ -11,8 +10,6 @@ export var getDependentLookupEditorContext = function (state, attributeValue, at
11
10
  var _a = getParents(state, valueUri, node), parents = _a.parents, missedParentsAttributeTypes = _a.missedParentsAttributeTypes;
12
11
  var _b = (mdmModule.selectors.getDependentLookupEditorState(state, valueUri) || {}).isBlocked, isBlocked = _b === void 0 ? false : _b;
13
12
  var missedParentsMessage = buildMissedParentsMessage(missedParentsAttributeTypes);
14
- var autocompleteConfig = mdmModule.selectors.getLookupAutocomplete(state);
15
- var autopopulationEnabled = isAutopopulationEnabled(autocompleteConfig, attributeTypeUri);
16
13
  var isEmptyValue = !(attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.lookupCode) && !(attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.value);
17
14
  var placeholder = (isEmptyValue && isBlocked && i18n.text('Populating values...')) ||
18
15
  (isEmptyValue && missedParentsMessage) ||
@@ -20,8 +17,7 @@ export var getDependentLookupEditorContext = function (state, attributeValue, at
20
17
  var context = {
21
18
  parents: missedParentsMessage ? null : parents,
22
19
  disabled: (!!missedParentsMessage && isEmptyValue) || isBlocked,
23
- placeholder: placeholder,
24
- autopopulationId: autopopulationEnabled ? valueUri : null
20
+ placeholder: placeholder
25
21
  };
26
22
  if (placeholder) {
27
23
  context.value = null;
@@ -7,6 +7,5 @@ export declare type DependentLookupEditorContext = {
7
7
  parents: DependentLookupsParentForApi[];
8
8
  disabled: boolean;
9
9
  placeholder: string;
10
- autopopulationId: string;
11
10
  value?: null;
12
11
  };
@@ -0,0 +1,13 @@
1
+ declare type Props = {
2
+ enabled: boolean;
3
+ attributeTypeUri: string;
4
+ valueUri: string;
5
+ };
6
+ export declare const useAutopopulationContextValue: ({ enabled, attributeTypeUri, valueUri }: Props) => {
7
+ autopopulationContextValue: {
8
+ id: string;
9
+ isTouched: boolean;
10
+ onTouch: (id: string) => void;
11
+ };
12
+ };
13
+ export {};
@@ -0,0 +1,25 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { isAutopopulationEnabled } from '@reltio/mdm-sdk';
3
+ import { useDispatch, useSelector } from 'react-redux';
4
+ import mdmModule, { profile } from '@reltio/mdm-module';
5
+ export var useAutopopulationContextValue = function (_a) {
6
+ var enabled = _a.enabled, attributeTypeUri = _a.attributeTypeUri, valueUri = _a.valueUri;
7
+ var dispatch = useDispatch();
8
+ var autocompleteConfig = useSelector(mdmModule.selectors.getLookupAutocomplete);
9
+ var autopopulationEnabled = enabled && isAutopopulationEnabled(autocompleteConfig, attributeTypeUri);
10
+ var autopopulationId = autopopulationEnabled ? valueUri : null;
11
+ var _b = (useSelector(function (state) { return mdmModule.selectors.getDependentLookupEditorState(state, valueUri); }) || {}).isTouched, isTouched = _b === void 0 ? false : _b;
12
+ var onTouch = useCallback(function (valueUri) {
13
+ dispatch(profile.dependentLookups.actions.dependentLookupsEditorTouched({ uri: valueUri, isTouched: true }));
14
+ }, [dispatch]);
15
+ var autopopulationContextValue = useMemo(function () {
16
+ return autopopulationId
17
+ ? {
18
+ id: autopopulationId,
19
+ isTouched: isTouched,
20
+ onTouch: onTouch
21
+ }
22
+ : null;
23
+ }, [autopopulationId, isTouched, onTouch]);
24
+ return { autopopulationContextValue: autopopulationContextValue };
25
+ };
@@ -1,6 +1,6 @@
1
1
  export const DEBOUNCE_INTERVAL: 400;
2
2
  export default DependentLookupEditor;
3
- declare function DependentLookupEditor({ multiple, value, lookupCode: lookupTypeCode, TextFieldProps, parents, onChange, getLookups, lookups, resolveLookups, fullWidth, disabled, placeholder, autopopulationId, max, ...otherProps }: {
3
+ declare function DependentLookupEditor({ multiple, value, lookupCode: lookupTypeCode, TextFieldProps, parents, onChange, getLookups, lookups, resolveLookups, fullWidth, disabled, placeholder, max, ...otherProps }: {
4
4
  [x: string]: any;
5
5
  multiple: any;
6
6
  value: any;
@@ -14,7 +14,6 @@ declare function DependentLookupEditor({ multiple, value, lookupCode: lookupType
14
14
  fullWidth: any;
15
15
  disabled: any;
16
16
  placeholder: any;
17
- autopopulationId: any;
18
17
  max?: number;
19
18
  }): JSX.Element;
20
19
  declare namespace DependentLookupEditor {
@@ -41,7 +40,6 @@ declare namespace DependentLookupEditor {
41
40
  const fullWidth: PropTypes.Requireable<boolean>;
42
41
  const placeholder: PropTypes.Requireable<string>;
43
42
  const disabled: PropTypes.Requireable<boolean>;
44
- const autopopulationId: PropTypes.Requireable<string>;
45
43
  const max: PropTypes.Requireable<number>;
46
44
  }
47
45
  }
@@ -55,7 +55,7 @@ var SelectComponents = {
55
55
  export var DEBOUNCE_INTERVAL = 400;
56
56
  var MAX_DEPENDENT_LOOKUP_VALUES = 50;
57
57
  var DependentLookupEditor = function (_a) {
58
- var multiple = _a.multiple, value = _a.value, lookupTypeCode = _a.lookupCode, TextFieldProps = _a.TextFieldProps, parents = _a.parents, onChange = _a.onChange, getLookups = _a.getLookups, _b = _a.lookups, lookups = _b === void 0 ? {} : _b, resolveLookups = _a.resolveLookups, fullWidth = _a.fullWidth, disabled = _a.disabled, placeholder = _a.placeholder, autopopulationId = _a.autopopulationId, _c = _a.max, max = _c === void 0 ? MAX_DEPENDENT_LOOKUP_VALUES : _c, otherProps = __rest(_a, ["multiple", "value", "lookupCode", "TextFieldProps", "parents", "onChange", "getLookups", "lookups", "resolveLookups", "fullWidth", "disabled", "placeholder", "autopopulationId", "max"]);
58
+ var multiple = _a.multiple, value = _a.value, lookupTypeCode = _a.lookupCode, TextFieldProps = _a.TextFieldProps, parents = _a.parents, onChange = _a.onChange, getLookups = _a.getLookups, _b = _a.lookups, lookups = _b === void 0 ? {} : _b, resolveLookups = _a.resolveLookups, fullWidth = _a.fullWidth, disabled = _a.disabled, placeholder = _a.placeholder, _c = _a.max, max = _c === void 0 ? MAX_DEPENDENT_LOOKUP_VALUES : _c, otherProps = __rest(_a, ["multiple", "value", "lookupCode", "TextFieldProps", "parents", "onChange", "getLookups", "lookups", "resolveLookups", "fullWidth", "disabled", "placeholder", "max"]);
59
59
  var inputRef = useRef(null);
60
60
  var selectRef = useRef(null);
61
61
  var styles = useStyles();
@@ -159,7 +159,6 @@ var DependentLookupEditor = function (_a) {
159
159
  var showMoreButton = options.length > displayedOptions.length;
160
160
  var isEmptyValue = multiple ? isEmpty(value) : !(value === null || value === void 0 ? void 0 : value.lookupCode) && !(value === null || value === void 0 ? void 0 : value.value);
161
161
  var markAsTouched = useAutopopulation({
162
- id: autopopulationId,
163
162
  initialDefaultOptions: initialDefaultOptions,
164
163
  isEmptyValue: isEmptyValue,
165
164
  multiple: multiple,
@@ -189,7 +188,6 @@ DependentLookupEditor.propTypes = {
189
188
  fullWidth: PropTypes.bool,
190
189
  placeholder: PropTypes.string,
191
190
  disabled: PropTypes.bool,
192
- autopopulationId: PropTypes.string,
193
191
  max: PropTypes.number
194
192
  };
195
193
  export default DependentLookupEditor;
@@ -3,13 +3,12 @@ declare type Option = {
3
3
  value: string;
4
4
  };
5
5
  declare type Props = {
6
- id: string;
7
6
  initialDefaultOptions: Option[];
8
7
  isEmptyValue: boolean;
9
8
  multiple: boolean;
10
9
  onChange: (value: Option | Option[]) => void;
11
10
  };
12
- declare const useAutopopulation: ({ id, initialDefaultOptions, isEmptyValue, multiple, onChange }: Props) => {
11
+ declare const useAutopopulation: ({ initialDefaultOptions, isEmptyValue, multiple, onChange }: Props) => {
13
12
  markAsTouched: () => void;
14
13
  };
15
14
  export default useAutopopulation;
@@ -1,23 +1,20 @@
1
- import { useCallback, useEffect } from 'react';
2
- var touchedEditorsMap = {};
3
- var addTouchedEditor = function (id) {
4
- touchedEditorsMap[id] = true;
5
- };
6
- var isTouchedEditor = function (id) { return touchedEditorsMap[id]; };
1
+ import { useCallback, useContext, useEffect } from 'react';
2
+ import { DependentLookupAutopopulationContext } from '../../../contexts';
7
3
  // Autopopulation for just added editor. Other autopopulation cases should be covered by cascadeUpdate flow.
8
4
  var useAutopopulation = function (_a) {
9
- var id = _a.id, initialDefaultOptions = _a.initialDefaultOptions, isEmptyValue = _a.isEmptyValue, multiple = _a.multiple, onChange = _a.onChange;
5
+ var initialDefaultOptions = _a.initialDefaultOptions, isEmptyValue = _a.isEmptyValue, multiple = _a.multiple, onChange = _a.onChange;
6
+ var _b = useContext(DependentLookupAutopopulationContext) || {}, id = _b.id, isTouched = _b.isTouched, onTouch = _b.onTouch;
10
7
  useEffect(function () {
11
- if (id && initialDefaultOptions && initialDefaultOptions.length === 1 && isEmptyValue && !isTouchedEditor(id)) {
8
+ if (id && initialDefaultOptions && initialDefaultOptions.length === 1 && isEmptyValue && !isTouched) {
12
9
  onChange(multiple ? initialDefaultOptions : initialDefaultOptions[0]);
13
10
  }
14
11
  //eslint-disable-next-line react-hooks/exhaustive-deps
15
12
  }, [initialDefaultOptions]);
16
13
  var markAsTouched = useCallback(function () {
17
14
  if (id) {
18
- addTouchedEditor(id);
15
+ onTouch === null || onTouch === void 0 ? void 0 : onTouch(id);
19
16
  }
20
- }, [id]);
17
+ }, [onTouch, id]);
21
18
  return { markAsTouched: markAsTouched };
22
19
  };
23
20
  export default useAutopopulation;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ declare type DependentLookupAutopopulationContextValue = {
3
+ id: string;
4
+ isTouched: boolean;
5
+ onTouch: (id: string) => void;
6
+ };
7
+ export declare const DependentLookupAutopopulationContext: React.Context<DependentLookupAutopopulationContextValue>;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export var DependentLookupAutopopulationContext = React.createContext(null);
3
+ DependentLookupAutopopulationContext.displayName = 'DependentLookupAutopopulationContext';
@@ -26,4 +26,5 @@ export { ScrollToErrorContext, ScrollToErrorProvider } from './ScrollToErrorCont
26
26
  export { UrlGeneratorsContext } from './UrlGeneratorsContext';
27
27
  export { LabelsContext } from './LabelsContext';
28
28
  export { FeaturesContext } from './FeaturesContext';
29
+ export { DependentLookupAutopopulationContext } from './DependentLookupAutopopulationContext';
29
30
  export { PageRequestsAbortingContext } from './PageRequestsAbortingContext';
@@ -26,4 +26,5 @@ export { ScrollToErrorContext, ScrollToErrorProvider } from './ScrollToErrorCont
26
26
  export { UrlGeneratorsContext } from './UrlGeneratorsContext';
27
27
  export { LabelsContext } from './LabelsContext';
28
28
  export { FeaturesContext } from './FeaturesContext';
29
+ export { DependentLookupAutopopulationContext } from './DependentLookupAutopopulationContext';
29
30
  export { PageRequestsAbortingContext } from './PageRequestsAbortingContext';
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1481",
3
+ "version": "1.4.1483",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
7
7
  "dependencies": {
8
8
  "@date-io/moment": "^1.3.5",
9
9
  "@react-google-maps/api": "2.7.0",
10
- "@reltio/mdm-module": "^1.4.1481",
11
- "@reltio/mdm-sdk": "^1.4.1481",
10
+ "@reltio/mdm-module": "^1.4.1483",
11
+ "@reltio/mdm-sdk": "^1.4.1483",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",