@reltio/components 1.4.1966 → 1.4.1968

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.
@@ -28,7 +28,7 @@ var useHiddenAttributes = function () {
28
28
  var updateHiddenAttributes = (0, MdmModuleContext_1.useMdmAction)('updateHiddenAttributes');
29
29
  var resetHiddenAttributes = (0, MdmModuleContext_1.useMdmAction)('resetHiddenAttributes');
30
30
  var hiddenAttributes = (0, MdmModuleContext_1.useMdmHiddenAttributes)();
31
- var currentEntityHiddenAttributes = (0, react_1.useMemo)(function () { return hiddenAttributes[entityUri] || []; }, [hiddenAttributes, entityUri]);
31
+ var currentEntityHiddenAttributes = (0, react_1.useMemo)(function () { return hiddenAttributes[entityUri] || null; }, [hiddenAttributes, entityUri]);
32
32
  var updateControlAttributes = (0, MdmModuleContext_1.useMdmAction)('updateControlAttributes');
33
33
  var ruleBasedAttributes = (0, react_1.useMemo)(function () { return (0, mdm_sdk_1.getRuleBasedAttributes)(metadata, entity === null || entity === void 0 ? void 0 : entity.type); }, [metadata, entity === null || entity === void 0 ? void 0 : entity.type]);
34
34
  var parsedRuleBasedAttributes = (0, react_1.useMemo)(function () {
@@ -55,7 +55,10 @@ var useHiddenAttributes = function () {
55
55
  }, [rulesToCheck, entity, showAttributeURIs]);
56
56
  (0, react_1.useEffect)(function () {
57
57
  if (entityUri && (addedHiddenAttributes.length || showAttributeURIs.length)) {
58
- updateHiddenAttributes(entityUri, (0, ramda_1.without)(showAttributeURIs, currentEntityHiddenAttributes).concat(addedHiddenAttributes));
58
+ var updatedHiddenAttributes = (0, ramda_1.without)(showAttributeURIs, currentEntityHiddenAttributes || []).concat(addedHiddenAttributes);
59
+ if (!(0, ramda_1.equals)(currentEntityHiddenAttributes, updatedHiddenAttributes)) {
60
+ updateHiddenAttributes(entityUri, updatedHiddenAttributes);
61
+ }
59
62
  }
60
63
  }, [addedHiddenAttributes, showAttributeURIs, entityUri]);
61
64
  (0, react_1.useEffect)(function () {
@@ -463,4 +463,38 @@ describe('useHiddenAttributes', function () {
463
463
  expect(resetHiddenAttributes).toHaveBeenCalled();
464
464
  expect(updateHiddenAttributes).toHaveBeenCalledWith('entities/uri_e_permanent', []);
465
465
  });
466
+ it('should not dispatch action if value is unchanged', function () {
467
+ var entity = {
468
+ type: 'configuration/entityTypes/HCP',
469
+ uri: 'entities/uri_e',
470
+ attributes: {
471
+ Category1: [
472
+ {
473
+ uri: 'entities/uri_e/attributes/uri1',
474
+ value: 'category1_value1'
475
+ }
476
+ ],
477
+ Category2: [
478
+ {
479
+ uri: 'entities/uri_e/attributes/uri2',
480
+ value: 'category2_value1'
481
+ }
482
+ ]
483
+ }
484
+ };
485
+ MdmModuleContext_1.useMdmEntity.mockReturnValue(entity);
486
+ MdmModuleContext_1.useMdmMode.mockReturnValue(mdm_sdk_1.Mode.Editing);
487
+ var rerender = setUp().rerender;
488
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, []);
489
+ updateHiddenAttributes.mockClear();
490
+ var newEntity = (0, ramda_1.assocPath)(['attributes', 'Category3'], [
491
+ {
492
+ uri: 'entities/uri_e/attributes/uri3',
493
+ value: 'category3_value1'
494
+ }
495
+ ], entity);
496
+ MdmModuleContext_1.useMdmEntity.mockReturnValue(newEntity);
497
+ rerender();
498
+ expect(updateHiddenAttributes).not.toHaveBeenCalled();
499
+ });
466
500
  });
@@ -10,7 +10,7 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { useEffect, useMemo } from 'react';
13
- import { flatten, pipe, pluck, uniq, without } from 'ramda';
13
+ import { flatten, pipe, pluck, uniq, without, equals } from 'ramda';
14
14
  import { getRuleBasedAttributes, isEditableMode, parseRuleBasedAttribute } from '@reltio/mdm-sdk';
15
15
  import { useChangedAttributes } from '../useChangedAttributes';
16
16
  import { findRulesToCheck, findShowAttributeURIs } from './helpers';
@@ -25,7 +25,7 @@ export var useHiddenAttributes = function () {
25
25
  var updateHiddenAttributes = useMdmAction('updateHiddenAttributes');
26
26
  var resetHiddenAttributes = useMdmAction('resetHiddenAttributes');
27
27
  var hiddenAttributes = useMdmHiddenAttributes();
28
- var currentEntityHiddenAttributes = useMemo(function () { return hiddenAttributes[entityUri] || []; }, [hiddenAttributes, entityUri]);
28
+ var currentEntityHiddenAttributes = useMemo(function () { return hiddenAttributes[entityUri] || null; }, [hiddenAttributes, entityUri]);
29
29
  var updateControlAttributes = useMdmAction('updateControlAttributes');
30
30
  var ruleBasedAttributes = useMemo(function () { return getRuleBasedAttributes(metadata, entity === null || entity === void 0 ? void 0 : entity.type); }, [metadata, entity === null || entity === void 0 ? void 0 : entity.type]);
31
31
  var parsedRuleBasedAttributes = useMemo(function () {
@@ -52,7 +52,10 @@ export var useHiddenAttributes = function () {
52
52
  }, [rulesToCheck, entity, showAttributeURIs]);
53
53
  useEffect(function () {
54
54
  if (entityUri && (addedHiddenAttributes.length || showAttributeURIs.length)) {
55
- updateHiddenAttributes(entityUri, without(showAttributeURIs, currentEntityHiddenAttributes).concat(addedHiddenAttributes));
55
+ var updatedHiddenAttributes = without(showAttributeURIs, currentEntityHiddenAttributes || []).concat(addedHiddenAttributes);
56
+ if (!equals(currentEntityHiddenAttributes, updatedHiddenAttributes)) {
57
+ updateHiddenAttributes(entityUri, updatedHiddenAttributes);
58
+ }
56
59
  }
57
60
  }, [addedHiddenAttributes, showAttributeURIs, entityUri]);
58
61
  useEffect(function () {
@@ -461,4 +461,38 @@ describe('useHiddenAttributes', function () {
461
461
  expect(resetHiddenAttributes).toHaveBeenCalled();
462
462
  expect(updateHiddenAttributes).toHaveBeenCalledWith('entities/uri_e_permanent', []);
463
463
  });
464
+ it('should not dispatch action if value is unchanged', function () {
465
+ var entity = {
466
+ type: 'configuration/entityTypes/HCP',
467
+ uri: 'entities/uri_e',
468
+ attributes: {
469
+ Category1: [
470
+ {
471
+ uri: 'entities/uri_e/attributes/uri1',
472
+ value: 'category1_value1'
473
+ }
474
+ ],
475
+ Category2: [
476
+ {
477
+ uri: 'entities/uri_e/attributes/uri2',
478
+ value: 'category2_value1'
479
+ }
480
+ ]
481
+ }
482
+ };
483
+ useMdmEntity.mockReturnValue(entity);
484
+ useMdmMode.mockReturnValue(Mode.Editing);
485
+ var rerender = setUp().rerender;
486
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, []);
487
+ updateHiddenAttributes.mockClear();
488
+ var newEntity = assocPath(['attributes', 'Category3'], [
489
+ {
490
+ uri: 'entities/uri_e/attributes/uri3',
491
+ value: 'category3_value1'
492
+ }
493
+ ], entity);
494
+ useMdmEntity.mockReturnValue(newEntity);
495
+ rerender();
496
+ expect(updateHiddenAttributes).not.toHaveBeenCalled();
497
+ });
464
498
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1966",
3
+ "version": "1.4.1968",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -8,7 +8,7 @@
8
8
  "@fluentui/react-context-selector": "^9.1.26",
9
9
  "@react-google-maps/api": "2.7.0",
10
10
  "@react-sigma/core": "3.4.0",
11
- "@reltio/mdm-sdk": "^1.4.1870",
11
+ "@reltio/mdm-sdk": "^1.4.1871",
12
12
  "d3-cloud": "^1.2.5",
13
13
  "d3-geo": "^2.0.1",
14
14
  "d3-hierarchy": "^2.0.0",