@reltio/components 1.4.2120 → 1.4.2122

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.
@@ -1,15 +1,15 @@
1
- import { DataTypeDefinition } from '@reltio/mdm-sdk';
1
+ import { DataTypeDefinition, Lookups } from '@reltio/mdm-sdk';
2
2
  export declare const useEditorContext: (fieldName: string, dataTypeDefinition: DataTypeDefinition) => {
3
- lookups: import("@reltio/mdm-sdk").Lookups;
3
+ lookups: Lookups;
4
4
  lookupCode: string;
5
- getLookups: () => any;
5
+ getLookups: () => Promise<void>;
6
6
  resolveLookups?: undefined;
7
7
  getSuggestions?: undefined;
8
8
  format?: undefined;
9
9
  tenant?: undefined;
10
10
  entries?: undefined;
11
11
  } | {
12
- lookups: import("@reltio/mdm-sdk").Lookups;
12
+ lookups: Lookups;
13
13
  lookupCode: string;
14
14
  getLookups: ({ type, parents, displayNamePrefix, max, offset }: {
15
15
  type: any;
@@ -45,17 +45,26 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
48
57
  var _a;
49
58
  import React from 'react';
50
59
  import userEvent from '@testing-library/user-event';
51
60
  import { render, screen, act, within } from '@testing-library/react';
52
61
  import { assocPath } from 'ramda';
53
- import { ErrorType, Mode, uploadImage } from '@reltio/mdm-sdk';
62
+ import { ErrorType, Mode, uploadImage, getLookups } from '@reltio/mdm-sdk';
54
63
  import { MdmModuleProvider } from '../contexts/MdmModuleContext';
55
64
  import { ScrollToElementProvider } from '../contexts/ScrollToElementContext';
56
65
  import { HiddenAttributesContext } from '../contexts/HiddenAttributesContext';
57
66
  import { EditModeAttributesView } from './EditModeAttributesView';
58
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { uploadImage: jest.fn() })); });
67
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { uploadImage: jest.fn(), getLookups: jest.fn().mockResolvedValue({}) })); });
59
68
  var defaultEntity = {
60
69
  uri: 'entities/1E4APrQW',
61
70
  type: 'configuration/entityTypes/HCP'
@@ -121,7 +130,12 @@ var defaultMdmValues = {
121
130
  metadata: defaultMetadata,
122
131
  dependentLookups: { editors: {}, structure: {}, initedTypeUris: [] },
123
132
  profileErrors: [],
124
- user: { roles: [] }
133
+ lookups: {},
134
+ user: { roles: [] },
135
+ tenant: {
136
+ id: 'tenant',
137
+ name: 'tenant'
138
+ }
125
139
  };
126
140
  var mdmActions = {
127
141
  addAttributes: jest.fn(),
@@ -360,5 +374,49 @@ describe('Edit mode attributes view tests', function () {
360
374
  }
361
375
  });
362
376
  }); });
377
+ it('should request lookups if there are no dependent lookups and store already has some lookups', function () { return __awaiter(void 0, void 0, void 0, function () {
378
+ var modifiedEntities, metadata, lookups, mdmValues;
379
+ var _a;
380
+ return __generator(this, function (_b) {
381
+ modifiedEntities = __assign(__assign({}, defaultModifiedEntities), (_a = {}, _a[defaultEntity.uri] = __assign(__assign({}, defaultEntity), { attributes: {
382
+ CountryCode: [
383
+ {
384
+ uri: 'entities/1E4APrQW/attributes/CountryCode/uri1',
385
+ value: 'Portugal',
386
+ lookupCode: 'PT',
387
+ type: 'configuration/entityTypes/HCP/attributes/CountryCode'
388
+ }
389
+ ]
390
+ } }), _a));
391
+ metadata = {
392
+ uri: 'configuration',
393
+ entityTypes: [
394
+ {
395
+ uri: 'configuration/entityTypes/HCP',
396
+ attributes: __spreadArray(__spreadArray([], defaultMetadata.entityTypes[0].attributes, true), [
397
+ {
398
+ label: 'Country',
399
+ name: 'CountryCode',
400
+ type: 'String',
401
+ uri: 'configuration/entityTypes/HCP/attributes/CountryCode',
402
+ lookupCode: 'CountryCode'
403
+ }
404
+ ], false)
405
+ }
406
+ ]
407
+ };
408
+ lookups = {
409
+ CountryCode: {
410
+ PT: {
411
+ displayName: 'Portugal'
412
+ }
413
+ }
414
+ };
415
+ mdmValues = __assign(__assign({}, defaultMdmValues), { metadata: metadata, modifiedEntities: modifiedEntities, lookups: lookups });
416
+ setUp({ mdmValues: mdmValues });
417
+ expect(getLookups).toHaveBeenCalled();
418
+ return [2 /*return*/];
419
+ });
420
+ }); });
363
421
  });
364
422
  });
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import React, { useEffect } from 'react';
24
- import { always, defaultTo, isEmpty, map, path, pipe, pluck, prop, propEq } from 'ramda';
24
+ import { always, defaultTo, map, path, pipe, pluck, prop, propEq } from 'ramda';
25
25
  import { GroupedDropDownEditor } from './components/GroupedDropDownEditor';
26
26
  import { buildLookupEntries } from './helpers';
27
27
  export var LookupEditor = function (_a) {
@@ -32,10 +32,10 @@ export var LookupEditor = function (_a) {
32
32
  }); };
33
33
  useEffect(function () {
34
34
  var _a;
35
- if (isEmpty(lookups) && getLookups) {
35
+ if (getLookups) {
36
36
  (_a = getLookups()) === null || _a === void 0 ? void 0 : _a.catch(function () { });
37
37
  }
38
- }, [lookups, getLookups]);
38
+ }, [getLookups]);
39
39
  var entries = buildLookupEntries(lookupTypeCode, lookups); // TODO: this code could be not valid if lookups are not loaded
40
40
  var commonProps = __assign(__assign({}, otherProps), { multiple: multiple, entries: entries });
41
41
  value = defaultTo(multiple ? [] : {}, value);
@@ -94,11 +94,6 @@ describe('LookupEditor', function () {
94
94
  setUp({ getLookups: getLookups, lookups: {} });
95
95
  expect(getLookups).toHaveBeenCalled();
96
96
  });
97
- it('should not load lookups if lookups are available', function () {
98
- var getLookups = jest.fn();
99
- setUp({ getLookups: getLookups });
100
- expect(getLookups).not.toHaveBeenCalled();
101
- });
102
97
  describe('single mode', function () {
103
98
  it('should show lookup value as label if lookups do not contain specified lookupCode', function () {
104
99
  var value = { value: 'L3value', lookupCode: 'L3' };
@@ -1,15 +1,15 @@
1
- import { DataTypeDefinition } from '@reltio/mdm-sdk';
1
+ import { DataTypeDefinition, Lookups } from '@reltio/mdm-sdk';
2
2
  export declare const useEditorContext: (fieldName: string, dataTypeDefinition: DataTypeDefinition) => {
3
- lookups: import("@reltio/mdm-sdk").Lookups;
3
+ lookups: Lookups;
4
4
  lookupCode: string;
5
- getLookups: () => any;
5
+ getLookups: () => Promise<void>;
6
6
  resolveLookups?: undefined;
7
7
  getSuggestions?: undefined;
8
8
  format?: undefined;
9
9
  tenant?: undefined;
10
10
  entries?: undefined;
11
11
  } | {
12
- lookups: import("@reltio/mdm-sdk").Lookups;
12
+ lookups: Lookups;
13
13
  lookupCode: string;
14
14
  getLookups: ({ type, parents, displayNamePrefix, max, offset }: {
15
15
  type: any;
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
60
  };
@@ -60,7 +69,7 @@ var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
60
69
  var ScrollToElementContext_1 = require("../contexts/ScrollToElementContext");
61
70
  var HiddenAttributesContext_1 = require("../contexts/HiddenAttributesContext");
62
71
  var EditModeAttributesView_1 = require("./EditModeAttributesView");
63
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { uploadImage: jest.fn() })); });
72
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { uploadImage: jest.fn(), getLookups: jest.fn().mockResolvedValue({}) })); });
64
73
  var defaultEntity = {
65
74
  uri: 'entities/1E4APrQW',
66
75
  type: 'configuration/entityTypes/HCP'
@@ -126,7 +135,12 @@ var defaultMdmValues = {
126
135
  metadata: defaultMetadata,
127
136
  dependentLookups: { editors: {}, structure: {}, initedTypeUris: [] },
128
137
  profileErrors: [],
129
- user: { roles: [] }
138
+ lookups: {},
139
+ user: { roles: [] },
140
+ tenant: {
141
+ id: 'tenant',
142
+ name: 'tenant'
143
+ }
130
144
  };
131
145
  var mdmActions = {
132
146
  addAttributes: jest.fn(),
@@ -365,5 +379,49 @@ describe('Edit mode attributes view tests', function () {
365
379
  }
366
380
  });
367
381
  }); });
382
+ it('should request lookups if there are no dependent lookups and store already has some lookups', function () { return __awaiter(void 0, void 0, void 0, function () {
383
+ var modifiedEntities, metadata, lookups, mdmValues;
384
+ var _a;
385
+ return __generator(this, function (_b) {
386
+ modifiedEntities = __assign(__assign({}, defaultModifiedEntities), (_a = {}, _a[defaultEntity.uri] = __assign(__assign({}, defaultEntity), { attributes: {
387
+ CountryCode: [
388
+ {
389
+ uri: 'entities/1E4APrQW/attributes/CountryCode/uri1',
390
+ value: 'Portugal',
391
+ lookupCode: 'PT',
392
+ type: 'configuration/entityTypes/HCP/attributes/CountryCode'
393
+ }
394
+ ]
395
+ } }), _a));
396
+ metadata = {
397
+ uri: 'configuration',
398
+ entityTypes: [
399
+ {
400
+ uri: 'configuration/entityTypes/HCP',
401
+ attributes: __spreadArray(__spreadArray([], defaultMetadata.entityTypes[0].attributes, true), [
402
+ {
403
+ label: 'Country',
404
+ name: 'CountryCode',
405
+ type: 'String',
406
+ uri: 'configuration/entityTypes/HCP/attributes/CountryCode',
407
+ lookupCode: 'CountryCode'
408
+ }
409
+ ], false)
410
+ }
411
+ ]
412
+ };
413
+ lookups = {
414
+ CountryCode: {
415
+ PT: {
416
+ displayName: 'Portugal'
417
+ }
418
+ }
419
+ };
420
+ mdmValues = __assign(__assign({}, defaultMdmValues), { metadata: metadata, modifiedEntities: modifiedEntities, lookups: lookups });
421
+ setUp({ mdmValues: mdmValues });
422
+ expect(mdm_sdk_1.getLookups).toHaveBeenCalled();
423
+ return [2 /*return*/];
424
+ });
425
+ }); });
368
426
  });
369
427
  });
@@ -58,10 +58,10 @@ var LookupEditor = function (_a) {
58
58
  }); };
59
59
  (0, react_1.useEffect)(function () {
60
60
  var _a;
61
- if ((0, ramda_1.isEmpty)(lookups) && getLookups) {
61
+ if (getLookups) {
62
62
  (_a = getLookups()) === null || _a === void 0 ? void 0 : _a.catch(function () { });
63
63
  }
64
- }, [lookups, getLookups]);
64
+ }, [getLookups]);
65
65
  var entries = (0, helpers_1.buildLookupEntries)(lookupTypeCode, lookups); // TODO: this code could be not valid if lookups are not loaded
66
66
  var commonProps = __assign(__assign({}, otherProps), { multiple: multiple, entries: entries });
67
67
  value = (0, ramda_1.defaultTo)(multiple ? [] : {}, value);
@@ -99,11 +99,6 @@ describe('LookupEditor', function () {
99
99
  setUp({ getLookups: getLookups, lookups: {} });
100
100
  expect(getLookups).toHaveBeenCalled();
101
101
  });
102
- it('should not load lookups if lookups are available', function () {
103
- var getLookups = jest.fn();
104
- setUp({ getLookups: getLookups });
105
- expect(getLookups).not.toHaveBeenCalled();
106
- });
107
102
  describe('single mode', function () {
108
103
  it('should show lookup value as label if lookups do not contain specified lookupCode', function () {
109
104
  var value = { value: 'L3value', lookupCode: 'L3' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.2120",
3
+ "version": "1.4.2122",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -11,7 +11,7 @@
11
11
  "@fluentui/react-context-selector": "^9.1.26",
12
12
  "@googlemaps/markerclusterer": "^2.5.3",
13
13
  "@react-sigma/core": "3.4.0",
14
- "@reltio/mdm-sdk": "^1.4.1951",
14
+ "@reltio/mdm-sdk": "^1.4.1953",
15
15
  "@vis.gl/react-google-maps": "^1.3.0",
16
16
  "d3-cloud": "^1.2.5",
17
17
  "d3-geo": "^2.0.1",