@reltio/components 1.4.902 → 1.4.906

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 (25) hide show
  1. package/cjs/components/history/HistoryRow/HistoryRow.d.ts +5 -3
  2. package/cjs/components/history/HistoryRow/HistoryRow.js +5 -23
  3. package/cjs/components/history/HistoryRow/styles.d.ts +1 -1
  4. package/cjs/components/history/HistoryRow/styles.js +15 -1
  5. package/cjs/components/history/HistoryTree/HistoryTree.d.ts +6 -2
  6. package/cjs/components/history/HistoryTree/HistoryTree.js +39 -5
  7. package/cjs/components/history/HistoryView/HistoryView.d.ts +3 -1
  8. package/cjs/components/history/HistoryView/HistoryView.js +7 -3
  9. package/cjs/components/history/hooks/useHistorySlice.d.ts +8 -1
  10. package/cjs/components/history/hooks/useHistorySlice.js +5 -6
  11. package/cjs/components/history/hooks/useHistoryTree.d.ts +13 -2
  12. package/cjs/components/history/hooks/useHistoryTree.js +10 -4
  13. package/esm/components/history/HistoryRow/HistoryRow.d.ts +5 -3
  14. package/esm/components/history/HistoryRow/HistoryRow.js +5 -4
  15. package/esm/components/history/HistoryRow/styles.d.ts +1 -1
  16. package/esm/components/history/HistoryRow/styles.js +15 -1
  17. package/esm/components/history/HistoryTree/HistoryTree.d.ts +6 -2
  18. package/esm/components/history/HistoryTree/HistoryTree.js +40 -6
  19. package/esm/components/history/HistoryView/HistoryView.d.ts +3 -1
  20. package/esm/components/history/HistoryView/HistoryView.js +7 -3
  21. package/esm/components/history/hooks/useHistorySlice.d.ts +8 -1
  22. package/esm/components/history/hooks/useHistorySlice.js +5 -6
  23. package/esm/components/history/hooks/useHistoryTree.d.ts +13 -2
  24. package/esm/components/history/hooks/useHistoryTree.js +10 -4
  25. package/package.json +3 -3
@@ -1,8 +1,10 @@
1
- import React from 'react';
1
+ /// <reference types="react" />
2
2
  import { HistoryChange } from '@reltio/mdm-sdk';
3
3
  declare type Props = {
4
4
  change: HistoryChange;
5
5
  isCurrent?: boolean;
6
+ isSelected: boolean;
7
+ onClick: () => void;
6
8
  };
7
- declare const _default: React.MemoExoticComponent<({ change, isCurrent }: Props) => JSX.Element>;
8
- export default _default;
9
+ declare const HistoryRow: ({ change, isCurrent, isSelected, onClick }: Props) => JSX.Element;
10
+ export default HistoryRow;
@@ -1,28 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
22
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
4
  };
24
5
  Object.defineProperty(exports, "__esModule", { value: true });
25
- var react_1 = __importStar(require("react"));
6
+ var react_1 = __importDefault(require("react"));
26
7
  var classnames_1 = __importDefault(require("classnames"));
27
8
  var ui_i18n_1 = __importDefault(require("ui-i18n"));
28
9
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
@@ -30,11 +11,12 @@ var Typography_1 = __importDefault(require("@material-ui/core/Typography"));
30
11
  var activities_1 = require("../../activityLog/utils/activities");
31
12
  var styles_1 = require("./styles");
32
13
  var HistoryRow = function (_a) {
33
- var change = _a.change, isCurrent = _a.isCurrent;
14
+ var _b;
15
+ var change = _a.change, isCurrent = _a.isCurrent, isSelected = _a.isSelected, onClick = _a.onClick;
34
16
  var uri = change.uri, type = change.type, matchGroups = change.matchGroups, user = change.user, timestamp = change.timestamp;
35
17
  var color = mdm_sdk_1.getContributorColor(uri);
36
18
  var styles = styles_1.useStyles({ color: color });
37
- return (react_1.default.createElement("div", { className: styles.historyRow },
19
+ return (react_1.default.createElement("div", { className: classnames_1.default(styles.historyRow, (_b = {}, _b[styles.selected] = isSelected, _b)), onClick: onClick },
38
20
  react_1.default.createElement("div", { className: styles.rowHeader },
39
21
  react_1.default.createElement("div", { className: styles.badge }),
40
22
  react_1.default.createElement(Typography_1.default, { className: classnames_1.default(styles.title, { bold: isCurrent }) }, isCurrent ? ui_i18n_1.default.text('Current view') : activities_1.getActivityLabel(type)),
@@ -45,4 +27,4 @@ var HistoryRow = function (_a) {
45
27
  matchGroups.join(', '))),
46
28
  react_1.default.createElement(Typography_1.default, { className: styles.user }, user)));
47
29
  };
48
- exports.default = react_1.memo(HistoryRow);
30
+ exports.default = HistoryRow;
@@ -1,5 +1,5 @@
1
1
  declare type Type = {
2
2
  color?: string;
3
3
  };
4
- export declare const useStyles: (props: Type) => import("@material-ui/core/styles/withStyles").ClassNameMap<"title" | "date" | "user" | "badge" | "historyRow" | "rowHeader">;
4
+ export declare const useStyles: (props: Type) => import("@material-ui/core/styles/withStyles").ClassNameMap<"title" | "date" | "selected" | "user" | "badge" | "historyRow" | "rowHeader">;
5
5
  export {};
@@ -4,7 +4,21 @@ exports.useStyles = void 0;
4
4
  var styles_1 = require("@material-ui/core/styles");
5
5
  exports.useStyles = styles_1.makeStyles(function () { return ({
6
6
  historyRow: {
7
- padding: '8px 12px 16px'
7
+ position: 'relative',
8
+ padding: '8px 12px 16px',
9
+ cursor: 'pointer'
10
+ },
11
+ selected: {
12
+ background: 'rgba(0,0,0,0.05)',
13
+ '&:before': {
14
+ content: '""',
15
+ background: 'rgba(0,0,0,0.05)',
16
+ width: '100%',
17
+ height: '100%',
18
+ position: 'absolute',
19
+ left: '-100%',
20
+ top: 0
21
+ }
8
22
  },
9
23
  rowHeader: {
10
24
  display: 'flex',
@@ -1,10 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { HistoryData } from '../types';
2
+ import { HistoryEvent } from '@reltio/mdm-module';
3
+ import { HistoryData, HistoryRowData } from '../types';
3
4
  declare type Props = {
4
5
  historyData: HistoryData;
5
6
  canLoadMore: boolean;
6
7
  onLoadMore: () => void;
7
8
  isLoading: boolean;
9
+ entityUri: string;
10
+ historyEvent: HistoryEvent;
11
+ findPreviousChange: (index: number, uri: string) => HistoryRowData;
8
12
  };
9
- declare const HistoryTree: ({ historyData, isLoading, canLoadMore, onLoadMore }: Props) => JSX.Element;
13
+ declare const HistoryTree: ({ historyData, isLoading, canLoadMore, onLoadMore, entityUri, historyEvent, findPreviousChange }: Props) => JSX.Element;
10
14
  export default HistoryTree;
@@ -34,10 +34,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
34
  };
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  var react_1 = __importStar(require("react"));
37
+ var react_redux_1 = require("react-redux");
37
38
  var react_resize_detector_1 = __importDefault(require("react-resize-detector"));
38
39
  var ui_i18n_1 = __importDefault(require("ui-i18n"));
39
40
  var ramda_1 = require("ramda");
40
41
  var classnames_1 = __importDefault(require("classnames"));
42
+ var mdm_module_1 = require("@reltio/mdm-module");
41
43
  var Button_1 = __importDefault(require("@material-ui/core/Button"));
42
44
  var HistoryRow_1 = __importDefault(require("../HistoryRow/HistoryRow"));
43
45
  var HistoryGraph_1 = __importDefault(require("../HistoryGraph/HistoryGraph"));
@@ -45,11 +47,24 @@ var LinearLoadIndicator_1 = __importDefault(require("../../LinearLoadIndicator/L
45
47
  var styles_1 = require("./styles");
46
48
  var HistoryTree = function (_a) {
47
49
  var _b;
48
- var _c;
49
- var historyData = _a.historyData, isLoading = _a.isLoading, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore;
50
+ var historyData = _a.historyData, isLoading = _a.isLoading, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore, entityUri = _a.entityUri, historyEvent = _a.historyEvent, findPreviousChange = _a.findPreviousChange;
50
51
  var styles = styles_1.useStyles();
51
- var _d = react_1.useState({ historyLanes: {}, rows: [] }), graphData = _d[0], setGraphData = _d[1];
52
- var _e = react_1.useState(false), isScrollable = _e[0], setIsScrollable = _e[1];
52
+ var dispatch = react_redux_1.useDispatch();
53
+ var _c = react_1.useState({ historyLanes: {}, rows: [] }), graphData = _c[0], setGraphData = _c[1];
54
+ var _d = react_1.useState(false), isScrollable = _d[0], setIsScrollable = _d[1];
55
+ var _e = react_1.useState(-1), selectedIndex = _e[0], setSelectedIndex = _e[1];
56
+ react_1.useEffect(function () {
57
+ if (ramda_1.isNil(historyEvent)) {
58
+ setSelectedIndex(0);
59
+ return;
60
+ }
61
+ var isCurrentEventChange = function (change) {
62
+ return (change === null || change === void 0 ? void 0 : change.uri) === ((historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.overrideUri) || entityUri) && (change === null || change === void 0 ? void 0 : change.timestamp) === (historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.aStamp);
63
+ };
64
+ var selectedChangeByIndex = selectedIndex !== -1 ? historyData.rows[selectedIndex] : null;
65
+ var currentEventChangeIndex = historyData.rows.findIndex(function (change) { return isCurrentEventChange(change); });
66
+ setSelectedIndex(isCurrentEventChange(selectedChangeByIndex) ? selectedIndex : currentEventChangeIndex);
67
+ }, [historyData.rows, historyEvent]);
53
68
  var graphRef = react_1.useRef(null);
54
69
  var rowsRef = react_1.useCallback(function (node) {
55
70
  var _a;
@@ -62,12 +77,31 @@ var HistoryTree = function (_a) {
62
77
  var _a = (graphRef === null || graphRef === void 0 ? void 0 : graphRef.current) || {}, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth, scrollLeft = _a.scrollLeft;
63
78
  setIsScrollable(scrollLeft < scrollWidth - clientWidth);
64
79
  };
80
+ var handleHistoryRowClick = function (index, change, isSelected, isCurrent) {
81
+ if ((isCurrent && !isSelected) || (!isCurrent && isSelected)) {
82
+ dispatch(mdm_module_1.profile.history.actions.clearHistoryEvent());
83
+ setSelectedIndex(0);
84
+ }
85
+ else if (!isCurrent && !isSelected) {
86
+ var aChange = findPreviousChange(index - 1, change.uri || entityUri);
87
+ var bChange = findPreviousChange(index, change.uri || entityUri);
88
+ var aStamp = aChange === null || aChange === void 0 ? void 0 : aChange.timestamp;
89
+ var bStamp = bChange === null || bChange === void 0 ? void 0 : bChange.timestamp;
90
+ var overrideUri = (change === null || change === void 0 ? void 0 : change.uri) === entityUri ? null : change === null || change === void 0 ? void 0 : change.uri;
91
+ dispatch(mdm_module_1.profile.history.actions.setHistoryEvent({ aStamp: aStamp, bStamp: bStamp, overrideUri: overrideUri }));
92
+ setSelectedIndex(index);
93
+ }
94
+ };
65
95
  return (react_1.default.createElement("div", { className: styles.historyTree },
66
96
  isLoading && react_1.default.createElement(LinearLoadIndicator_1.default, null),
67
97
  react_1.default.createElement("div", { className: classnames_1.default(styles.graph, (_b = {}, _b[styles.shadow] = isScrollable, _b)), onScroll: handleGraphScroll, ref: graphRef },
68
98
  react_1.default.createElement(HistoryGraph_1.default, { graphData: graphData }),
69
99
  react_1.default.createElement(react_resize_detector_1.default, { handleWidth: true, onResize: handleGraphScroll })),
70
- react_1.default.createElement("div", { ref: rowsRef, className: styles.history }, (_c = historyData.rows) === null || _c === void 0 ? void 0 : _c.map(function (change, i) { return (react_1.default.createElement(HistoryRow_1.default, { key: "row-" + i, change: change, isCurrent: i === 0 })); })),
100
+ react_1.default.createElement("div", { ref: rowsRef, className: styles.history }, historyData.rows.map(function (change, i) {
101
+ var isSelected = i === selectedIndex;
102
+ var isCurrent = i === 0;
103
+ return (react_1.default.createElement(HistoryRow_1.default, { key: "row-" + i, change: change, isCurrent: isCurrent, isSelected: isSelected, onClick: function () { return handleHistoryRowClick(i, change, isSelected, isCurrent); } }));
104
+ })),
71
105
  canLoadMore && (react_1.default.createElement("div", { className: styles.buttonContainer },
72
106
  react_1.default.createElement(Button_1.default, { color: "primary", onClick: function () { return onLoadMore(); } }, ui_i18n_1.default.text('Show more'))))));
73
107
  };
@@ -1,12 +1,14 @@
1
1
  import React from 'react';
2
2
  import { HistoryWithTotal } from '@reltio/mdm-sdk';
3
+ import { HistoryEvent } from '@reltio/mdm-module';
3
4
  declare type Props = {
4
5
  isLoading: boolean;
5
6
  historyWithTotal: HistoryWithTotal;
6
7
  contributorsUris: string[];
7
8
  entityUri: string;
9
+ historyEvent: HistoryEvent;
8
10
  canLoadMore: boolean;
9
11
  onLoadMore: () => void;
10
12
  };
11
- declare const _default: React.MemoExoticComponent<({ isLoading, historyWithTotal, contributorsUris, entityUri, canLoadMore, onLoadMore }: Props) => JSX.Element>;
13
+ declare const _default: React.MemoExoticComponent<({ isLoading, historyWithTotal, contributorsUris, entityUri, canLoadMore, onLoadMore, historyEvent }: Props) => JSX.Element>;
12
14
  export default _default;
@@ -28,15 +28,19 @@ var ContributorsPanel_1 = __importDefault(require("../ContributorsPanel/Contribu
28
28
  var useHistoryTree_1 = require("../hooks/useHistoryTree");
29
29
  var styles_1 = require("./styles");
30
30
  var HistoryView = function (_a) {
31
- var isLoading = _a.isLoading, historyWithTotal = _a.historyWithTotal, contributorsUris = _a.contributorsUris, entityUri = _a.entityUri, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore;
31
+ var isLoading = _a.isLoading, historyWithTotal = _a.historyWithTotal, contributorsUris = _a.contributorsUris, entityUri = _a.entityUri, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore, historyEvent = _a.historyEvent;
32
32
  var styles = styles_1.useStyles();
33
33
  var _b = react_1.useState(null), selectedUris = _b[0], setSelectedUris = _b[1];
34
34
  react_1.useEffect(function () {
35
35
  setSelectedUris(contributorsUris);
36
36
  }, [contributorsUris]);
37
- var historyData = useHistoryTree_1.useHistoryTree({ entityUri: entityUri, historyChanges: historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.changes, selectedUris: selectedUris });
37
+ var _c = useHistoryTree_1.useHistoryTree({
38
+ entityUri: entityUri,
39
+ historyChanges: historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.changes,
40
+ selectedUris: selectedUris
41
+ }), historyData = _c.historyData, findPreviousChange = _c.findPreviousChange;
38
42
  return (react_1.default.createElement("div", { className: styles.root },
39
43
  react_1.default.createElement(ContributorsPanel_1.default, { values: contributorsUris, selectedValues: selectedUris, onSelectValues: setSelectedUris, entityUri: entityUri, className: styles.borderBottom }),
40
- react_1.default.createElement(HistoryTree_1.default, { historyData: historyData, isLoading: isLoading, onLoadMore: onLoadMore, canLoadMore: canLoadMore })));
44
+ react_1.default.createElement(HistoryTree_1.default, { historyData: historyData, isLoading: isLoading, onLoadMore: onLoadMore, canLoadMore: canLoadMore, entityUri: entityUri, historyEvent: historyEvent, findPreviousChange: findPreviousChange })));
41
45
  };
42
46
  exports.default = react_1.memo(HistoryView);
@@ -1,4 +1,11 @@
1
- export declare const useHistorySlice: () => {
1
+ import { HistoryEvent } from '@reltio/mdm-module';
2
+ import { Entity } from '@reltio/mdm-sdk';
3
+ declare type Props = {
4
+ entity: Entity;
5
+ historyEvent: HistoryEvent;
6
+ };
7
+ export declare const useHistorySlice: ({ entity, historyEvent }: Props) => {
2
8
  isLoading: boolean;
3
9
  historySlice: import("@reltio/mdm-module").HistorySlice;
4
10
  };
11
+ export {};
@@ -25,17 +25,16 @@ var react_redux_1 = require("react-redux");
25
25
  var mdm_module_1 = __importStar(require("@reltio/mdm-module"));
26
26
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
27
27
  var hooks_1 = require("../../../hooks");
28
- var useHistorySlice = function () {
29
- var _a = react_1.useState(false), isLoading = _a[0], setIsLoading = _a[1];
30
- var historyEvent = react_redux_1.useSelector(mdm_module_1.default.selectors.getHistoryEvent);
28
+ var useHistorySlice = function (_a) {
29
+ var entity = _a.entity, historyEvent = _a.historyEvent;
30
+ var _b = react_1.useState(false), isLoading = _b[0], setIsLoading = _b[1];
31
31
  var historySlice = react_redux_1.useSelector(mdm_module_1.default.selectors.getHistorySlice);
32
- var entity = react_redux_1.useSelector(mdm_module_1.default.selectors.getEntity);
33
32
  var dispatch = react_redux_1.useDispatch();
34
33
  var safePromise = hooks_1.useSafePromise();
35
- var _b = historyEvent || {}, aStamp = _b.aStamp, bStamp = _b.bStamp, overrideUri = _b.overrideUri;
34
+ var _c = historyEvent || {}, aStamp = _c.aStamp, bStamp = _c.bStamp, overrideUri = _c.overrideUri;
36
35
  var entityUri = overrideUri || (entity === null || entity === void 0 ? void 0 : entity.uri);
37
36
  react_1.useEffect(function () {
38
- if (!historySlice && historyEvent && entityUri) {
37
+ if (historyEvent && entityUri) {
39
38
  setIsLoading(true);
40
39
  safePromise(Promise.all([
41
40
  mdm_sdk_1.getEntityTimeSlice(entityUri, aStamp),
@@ -1,9 +1,20 @@
1
1
  import { HistoryChange } from '@reltio/mdm-sdk';
2
- import { HistoryData } from './../types';
2
+ import { HistoryRowData } from './../types';
3
3
  declare type Props = {
4
4
  entityUri: string;
5
5
  historyChanges: HistoryChange[];
6
6
  selectedUris: string[];
7
7
  };
8
- export declare const useHistoryTree: ({ entityUri, historyChanges, selectedUris }: Props) => HistoryData;
8
+ export declare const useHistoryTree: ({ entityUri, historyChanges, selectedUris }: Props) => {
9
+ historyData: {
10
+ historyLanes: {
11
+ [x: string]: {
12
+ index: number;
13
+ lifeTime: any[];
14
+ };
15
+ };
16
+ rows: HistoryRowData[];
17
+ };
18
+ findPreviousChange: (index: number, uri: string) => any;
19
+ };
9
20
  export {};
@@ -42,9 +42,12 @@ var useHistoryTree = function (_a) {
42
42
  }
43
43
  return null;
44
44
  });
45
- var findPreviousChange = function (index, involvedUris) {
45
+ var findNextChange = function (index, involvedUris) {
46
46
  return ramda_1.pipe(ramda_1.slice(0, index - 1), ramda_1.reverse, ramda_1.find(checkChange(involvedUris)))(historyChanges);
47
47
  };
48
+ var findPreviousChange = function (index, uri) {
49
+ return ramda_1.pipe(ramda_1.slice(index + 1, Infinity), ramda_1.find(checkChange(uri)))(rows);
50
+ };
48
51
  var checkLaneUri = function (uri) {
49
52
  var contributorLane = historyLanes[uri];
50
53
  if (!contributorLane && (!selectedUris || selectedUris.includes(uri))) {
@@ -135,13 +138,13 @@ var useHistoryTree = function (_a) {
135
138
  var _a;
136
139
  switch (change.type) {
137
140
  case types_1.HistoryChangeTypes.ENTITIES_SPLITTED:
138
- if (!findPreviousChange(index, change.uri || entityUri)) {
141
+ if (!findNextChange(index, change.uri || entityUri)) {
139
142
  return;
140
143
  }
141
144
  else {
142
145
  var uri = change.uri;
143
146
  var involvedUris = change.uris ? [change.uris, uri] : [uri];
144
- var lostMergeChange = findPreviousChange(index, involvedUris);
147
+ var lostMergeChange = findNextChange(index, involvedUris);
145
148
  if (lostMergeChange && (!uri || uri === lostMergeChange.uri))
146
149
  return;
147
150
  }
@@ -217,7 +220,10 @@ var useHistoryTree = function (_a) {
217
220
  row.index = i;
218
221
  row.uri = row.uri || entityUri;
219
222
  });
220
- return { historyLanes: historyLanes, rows: rows };
223
+ return {
224
+ historyData: { historyLanes: historyLanes, rows: rows },
225
+ findPreviousChange: findPreviousChange
226
+ };
221
227
  }, [entityUri, historyChanges, selectedUris]);
222
228
  };
223
229
  exports.useHistoryTree = useHistoryTree;
@@ -1,8 +1,10 @@
1
- import React from 'react';
1
+ /// <reference types="react" />
2
2
  import { HistoryChange } from '@reltio/mdm-sdk';
3
3
  declare type Props = {
4
4
  change: HistoryChange;
5
5
  isCurrent?: boolean;
6
+ isSelected: boolean;
7
+ onClick: () => void;
6
8
  };
7
- declare const _default: React.MemoExoticComponent<({ change, isCurrent }: Props) => JSX.Element>;
8
- export default _default;
9
+ declare const HistoryRow: ({ change, isCurrent, isSelected, onClick }: Props) => JSX.Element;
10
+ export default HistoryRow;
@@ -1,4 +1,4 @@
1
- import React, { memo } from 'react';
1
+ import React from 'react';
2
2
  import classnames from 'classnames';
3
3
  import i18n from 'ui-i18n';
4
4
  import { getContributorColor } from '@reltio/mdm-sdk';
@@ -6,11 +6,12 @@ import Typography from '@material-ui/core/Typography';
6
6
  import { getActivityLabel } from '../../activityLog/utils/activities';
7
7
  import { useStyles } from './styles';
8
8
  var HistoryRow = function (_a) {
9
- var change = _a.change, isCurrent = _a.isCurrent;
9
+ var _b;
10
+ var change = _a.change, isCurrent = _a.isCurrent, isSelected = _a.isSelected, onClick = _a.onClick;
10
11
  var uri = change.uri, type = change.type, matchGroups = change.matchGroups, user = change.user, timestamp = change.timestamp;
11
12
  var color = getContributorColor(uri);
12
13
  var styles = useStyles({ color: color });
13
- return (React.createElement("div", { className: styles.historyRow },
14
+ return (React.createElement("div", { className: classnames(styles.historyRow, (_b = {}, _b[styles.selected] = isSelected, _b)), onClick: onClick },
14
15
  React.createElement("div", { className: styles.rowHeader },
15
16
  React.createElement("div", { className: styles.badge }),
16
17
  React.createElement(Typography, { className: classnames(styles.title, { bold: isCurrent }) }, isCurrent ? i18n.text('Current view') : getActivityLabel(type)),
@@ -21,4 +22,4 @@ var HistoryRow = function (_a) {
21
22
  matchGroups.join(', '))),
22
23
  React.createElement(Typography, { className: styles.user }, user)));
23
24
  };
24
- export default memo(HistoryRow);
25
+ export default HistoryRow;
@@ -1,5 +1,5 @@
1
1
  declare type Type = {
2
2
  color?: string;
3
3
  };
4
- export declare const useStyles: (props: Type) => import("@material-ui/core/styles/withStyles").ClassNameMap<"title" | "date" | "user" | "badge" | "historyRow" | "rowHeader">;
4
+ export declare const useStyles: (props: Type) => import("@material-ui/core/styles/withStyles").ClassNameMap<"title" | "date" | "selected" | "user" | "badge" | "historyRow" | "rowHeader">;
5
5
  export {};
@@ -1,7 +1,21 @@
1
1
  import { makeStyles } from '@material-ui/core/styles';
2
2
  export var useStyles = makeStyles(function () { return ({
3
3
  historyRow: {
4
- padding: '8px 12px 16px'
4
+ position: 'relative',
5
+ padding: '8px 12px 16px',
6
+ cursor: 'pointer'
7
+ },
8
+ selected: {
9
+ background: 'rgba(0,0,0,0.05)',
10
+ '&:before': {
11
+ content: '""',
12
+ background: 'rgba(0,0,0,0.05)',
13
+ width: '100%',
14
+ height: '100%',
15
+ position: 'absolute',
16
+ left: '-100%',
17
+ top: 0
18
+ }
5
19
  },
6
20
  rowHeader: {
7
21
  display: 'flex',
@@ -1,10 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { HistoryData } from '../types';
2
+ import { HistoryEvent } from '@reltio/mdm-module';
3
+ import { HistoryData, HistoryRowData } from '../types';
3
4
  declare type Props = {
4
5
  historyData: HistoryData;
5
6
  canLoadMore: boolean;
6
7
  onLoadMore: () => void;
7
8
  isLoading: boolean;
9
+ entityUri: string;
10
+ historyEvent: HistoryEvent;
11
+ findPreviousChange: (index: number, uri: string) => HistoryRowData;
8
12
  };
9
- declare const HistoryTree: ({ historyData, isLoading, canLoadMore, onLoadMore }: Props) => JSX.Element;
13
+ declare const HistoryTree: ({ historyData, isLoading, canLoadMore, onLoadMore, entityUri, historyEvent, findPreviousChange }: Props) => JSX.Element;
10
14
  export default HistoryTree;
@@ -9,11 +9,13 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import React, { useCallback, useRef, useState } from 'react';
12
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
13
+ import { useDispatch } from 'react-redux';
13
14
  import ReactResizeDetector from 'react-resize-detector';
14
15
  import i18n from 'ui-i18n';
15
16
  import { isNil } from 'ramda';
16
17
  import classnames from 'classnames';
18
+ import { profile } from '@reltio/mdm-module';
17
19
  import Button from '@material-ui/core/Button';
18
20
  import HistoryRow from '../HistoryRow/HistoryRow';
19
21
  import HistoryGraph from '../HistoryGraph/HistoryGraph';
@@ -21,11 +23,24 @@ import LinearLoadIndicator from '../../LinearLoadIndicator/LinearLoadIndicator';
21
23
  import { useStyles } from './styles';
22
24
  var HistoryTree = function (_a) {
23
25
  var _b;
24
- var _c;
25
- var historyData = _a.historyData, isLoading = _a.isLoading, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore;
26
+ var historyData = _a.historyData, isLoading = _a.isLoading, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore, entityUri = _a.entityUri, historyEvent = _a.historyEvent, findPreviousChange = _a.findPreviousChange;
26
27
  var styles = useStyles();
27
- var _d = useState({ historyLanes: {}, rows: [] }), graphData = _d[0], setGraphData = _d[1];
28
- var _e = useState(false), isScrollable = _e[0], setIsScrollable = _e[1];
28
+ var dispatch = useDispatch();
29
+ var _c = useState({ historyLanes: {}, rows: [] }), graphData = _c[0], setGraphData = _c[1];
30
+ var _d = useState(false), isScrollable = _d[0], setIsScrollable = _d[1];
31
+ var _e = useState(-1), selectedIndex = _e[0], setSelectedIndex = _e[1];
32
+ useEffect(function () {
33
+ if (isNil(historyEvent)) {
34
+ setSelectedIndex(0);
35
+ return;
36
+ }
37
+ var isCurrentEventChange = function (change) {
38
+ return (change === null || change === void 0 ? void 0 : change.uri) === ((historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.overrideUri) || entityUri) && (change === null || change === void 0 ? void 0 : change.timestamp) === (historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.aStamp);
39
+ };
40
+ var selectedChangeByIndex = selectedIndex !== -1 ? historyData.rows[selectedIndex] : null;
41
+ var currentEventChangeIndex = historyData.rows.findIndex(function (change) { return isCurrentEventChange(change); });
42
+ setSelectedIndex(isCurrentEventChange(selectedChangeByIndex) ? selectedIndex : currentEventChangeIndex);
43
+ }, [historyData.rows, historyEvent]);
29
44
  var graphRef = useRef(null);
30
45
  var rowsRef = useCallback(function (node) {
31
46
  var _a;
@@ -38,12 +53,31 @@ var HistoryTree = function (_a) {
38
53
  var _a = (graphRef === null || graphRef === void 0 ? void 0 : graphRef.current) || {}, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth, scrollLeft = _a.scrollLeft;
39
54
  setIsScrollable(scrollLeft < scrollWidth - clientWidth);
40
55
  };
56
+ var handleHistoryRowClick = function (index, change, isSelected, isCurrent) {
57
+ if ((isCurrent && !isSelected) || (!isCurrent && isSelected)) {
58
+ dispatch(profile.history.actions.clearHistoryEvent());
59
+ setSelectedIndex(0);
60
+ }
61
+ else if (!isCurrent && !isSelected) {
62
+ var aChange = findPreviousChange(index - 1, change.uri || entityUri);
63
+ var bChange = findPreviousChange(index, change.uri || entityUri);
64
+ var aStamp = aChange === null || aChange === void 0 ? void 0 : aChange.timestamp;
65
+ var bStamp = bChange === null || bChange === void 0 ? void 0 : bChange.timestamp;
66
+ var overrideUri = (change === null || change === void 0 ? void 0 : change.uri) === entityUri ? null : change === null || change === void 0 ? void 0 : change.uri;
67
+ dispatch(profile.history.actions.setHistoryEvent({ aStamp: aStamp, bStamp: bStamp, overrideUri: overrideUri }));
68
+ setSelectedIndex(index);
69
+ }
70
+ };
41
71
  return (React.createElement("div", { className: styles.historyTree },
42
72
  isLoading && React.createElement(LinearLoadIndicator, null),
43
73
  React.createElement("div", { className: classnames(styles.graph, (_b = {}, _b[styles.shadow] = isScrollable, _b)), onScroll: handleGraphScroll, ref: graphRef },
44
74
  React.createElement(HistoryGraph, { graphData: graphData }),
45
75
  React.createElement(ReactResizeDetector, { handleWidth: true, onResize: handleGraphScroll })),
46
- React.createElement("div", { ref: rowsRef, className: styles.history }, (_c = historyData.rows) === null || _c === void 0 ? void 0 : _c.map(function (change, i) { return (React.createElement(HistoryRow, { key: "row-" + i, change: change, isCurrent: i === 0 })); })),
76
+ React.createElement("div", { ref: rowsRef, className: styles.history }, historyData.rows.map(function (change, i) {
77
+ var isSelected = i === selectedIndex;
78
+ var isCurrent = i === 0;
79
+ return (React.createElement(HistoryRow, { key: "row-" + i, change: change, isCurrent: isCurrent, isSelected: isSelected, onClick: function () { return handleHistoryRowClick(i, change, isSelected, isCurrent); } }));
80
+ })),
47
81
  canLoadMore && (React.createElement("div", { className: styles.buttonContainer },
48
82
  React.createElement(Button, { color: "primary", onClick: function () { return onLoadMore(); } }, i18n.text('Show more'))))));
49
83
  };
@@ -1,12 +1,14 @@
1
1
  import React from 'react';
2
2
  import { HistoryWithTotal } from '@reltio/mdm-sdk';
3
+ import { HistoryEvent } from '@reltio/mdm-module';
3
4
  declare type Props = {
4
5
  isLoading: boolean;
5
6
  historyWithTotal: HistoryWithTotal;
6
7
  contributorsUris: string[];
7
8
  entityUri: string;
9
+ historyEvent: HistoryEvent;
8
10
  canLoadMore: boolean;
9
11
  onLoadMore: () => void;
10
12
  };
11
- declare const _default: React.MemoExoticComponent<({ isLoading, historyWithTotal, contributorsUris, entityUri, canLoadMore, onLoadMore }: Props) => JSX.Element>;
13
+ declare const _default: React.MemoExoticComponent<({ isLoading, historyWithTotal, contributorsUris, entityUri, canLoadMore, onLoadMore, historyEvent }: Props) => JSX.Element>;
12
14
  export default _default;
@@ -4,15 +4,19 @@ import ContributorsPanel from '../ContributorsPanel/ContributorsPanel';
4
4
  import { useHistoryTree } from '../hooks/useHistoryTree';
5
5
  import { useStyles } from './styles';
6
6
  var HistoryView = function (_a) {
7
- var isLoading = _a.isLoading, historyWithTotal = _a.historyWithTotal, contributorsUris = _a.contributorsUris, entityUri = _a.entityUri, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore;
7
+ var isLoading = _a.isLoading, historyWithTotal = _a.historyWithTotal, contributorsUris = _a.contributorsUris, entityUri = _a.entityUri, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore, historyEvent = _a.historyEvent;
8
8
  var styles = useStyles();
9
9
  var _b = useState(null), selectedUris = _b[0], setSelectedUris = _b[1];
10
10
  useEffect(function () {
11
11
  setSelectedUris(contributorsUris);
12
12
  }, [contributorsUris]);
13
- var historyData = useHistoryTree({ entityUri: entityUri, historyChanges: historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.changes, selectedUris: selectedUris });
13
+ var _c = useHistoryTree({
14
+ entityUri: entityUri,
15
+ historyChanges: historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.changes,
16
+ selectedUris: selectedUris
17
+ }), historyData = _c.historyData, findPreviousChange = _c.findPreviousChange;
14
18
  return (React.createElement("div", { className: styles.root },
15
19
  React.createElement(ContributorsPanel, { values: contributorsUris, selectedValues: selectedUris, onSelectValues: setSelectedUris, entityUri: entityUri, className: styles.borderBottom }),
16
- React.createElement(HistoryTree, { historyData: historyData, isLoading: isLoading, onLoadMore: onLoadMore, canLoadMore: canLoadMore })));
20
+ React.createElement(HistoryTree, { historyData: historyData, isLoading: isLoading, onLoadMore: onLoadMore, canLoadMore: canLoadMore, entityUri: entityUri, historyEvent: historyEvent, findPreviousChange: findPreviousChange })));
17
21
  };
18
22
  export default memo(HistoryView);
@@ -1,4 +1,11 @@
1
- export declare const useHistorySlice: () => {
1
+ import { HistoryEvent } from '@reltio/mdm-module';
2
+ import { Entity } from '@reltio/mdm-sdk';
3
+ declare type Props = {
4
+ entity: Entity;
5
+ historyEvent: HistoryEvent;
6
+ };
7
+ export declare const useHistorySlice: ({ entity, historyEvent }: Props) => {
2
8
  isLoading: boolean;
3
9
  historySlice: import("@reltio/mdm-module").HistorySlice;
4
10
  };
11
+ export {};
@@ -3,17 +3,16 @@ import { useSelector, useDispatch } from 'react-redux';
3
3
  import mdmModule, { profile } from '@reltio/mdm-module';
4
4
  import { getEntityTimeSlice } from '@reltio/mdm-sdk';
5
5
  import { useSafePromise } from '../../../hooks';
6
- export var useHistorySlice = function () {
7
- var _a = useState(false), isLoading = _a[0], setIsLoading = _a[1];
8
- var historyEvent = useSelector(mdmModule.selectors.getHistoryEvent);
6
+ export var useHistorySlice = function (_a) {
7
+ var entity = _a.entity, historyEvent = _a.historyEvent;
8
+ var _b = useState(false), isLoading = _b[0], setIsLoading = _b[1];
9
9
  var historySlice = useSelector(mdmModule.selectors.getHistorySlice);
10
- var entity = useSelector(mdmModule.selectors.getEntity);
11
10
  var dispatch = useDispatch();
12
11
  var safePromise = useSafePromise();
13
- var _b = historyEvent || {}, aStamp = _b.aStamp, bStamp = _b.bStamp, overrideUri = _b.overrideUri;
12
+ var _c = historyEvent || {}, aStamp = _c.aStamp, bStamp = _c.bStamp, overrideUri = _c.overrideUri;
14
13
  var entityUri = overrideUri || (entity === null || entity === void 0 ? void 0 : entity.uri);
15
14
  useEffect(function () {
16
- if (!historySlice && historyEvent && entityUri) {
15
+ if (historyEvent && entityUri) {
17
16
  setIsLoading(true);
18
17
  safePromise(Promise.all([
19
18
  getEntityTimeSlice(entityUri, aStamp),
@@ -1,9 +1,20 @@
1
1
  import { HistoryChange } from '@reltio/mdm-sdk';
2
- import { HistoryData } from './../types';
2
+ import { HistoryRowData } from './../types';
3
3
  declare type Props = {
4
4
  entityUri: string;
5
5
  historyChanges: HistoryChange[];
6
6
  selectedUris: string[];
7
7
  };
8
- export declare const useHistoryTree: ({ entityUri, historyChanges, selectedUris }: Props) => HistoryData;
8
+ export declare const useHistoryTree: ({ entityUri, historyChanges, selectedUris }: Props) => {
9
+ historyData: {
10
+ historyLanes: {
11
+ [x: string]: {
12
+ index: number;
13
+ lifeTime: any[];
14
+ };
15
+ };
16
+ rows: HistoryRowData[];
17
+ };
18
+ findPreviousChange: (index: number, uri: string) => any;
19
+ };
9
20
  export {};
@@ -39,9 +39,12 @@ export var useHistoryTree = function (_a) {
39
39
  }
40
40
  return null;
41
41
  });
42
- var findPreviousChange = function (index, involvedUris) {
42
+ var findNextChange = function (index, involvedUris) {
43
43
  return pipe(slice(0, index - 1), reverse, find(checkChange(involvedUris)))(historyChanges);
44
44
  };
45
+ var findPreviousChange = function (index, uri) {
46
+ return pipe(slice(index + 1, Infinity), find(checkChange(uri)))(rows);
47
+ };
45
48
  var checkLaneUri = function (uri) {
46
49
  var contributorLane = historyLanes[uri];
47
50
  if (!contributorLane && (!selectedUris || selectedUris.includes(uri))) {
@@ -132,13 +135,13 @@ export var useHistoryTree = function (_a) {
132
135
  var _a;
133
136
  switch (change.type) {
134
137
  case HistoryChangeTypes.ENTITIES_SPLITTED:
135
- if (!findPreviousChange(index, change.uri || entityUri)) {
138
+ if (!findNextChange(index, change.uri || entityUri)) {
136
139
  return;
137
140
  }
138
141
  else {
139
142
  var uri = change.uri;
140
143
  var involvedUris = change.uris ? [change.uris, uri] : [uri];
141
- var lostMergeChange = findPreviousChange(index, involvedUris);
144
+ var lostMergeChange = findNextChange(index, involvedUris);
142
145
  if (lostMergeChange && (!uri || uri === lostMergeChange.uri))
143
146
  return;
144
147
  }
@@ -214,7 +217,10 @@ export var useHistoryTree = function (_a) {
214
217
  row.index = i;
215
218
  row.uri = row.uri || entityUri;
216
219
  });
217
- return { historyLanes: historyLanes, rows: rows };
220
+ return {
221
+ historyData: { historyLanes: historyLanes, rows: rows },
222
+ findPreviousChange: findPreviousChange
223
+ };
218
224
  }, [entityUri, historyChanges, selectedUris]);
219
225
  };
220
226
  var findClosestLife = function (lifeTime, timestamp) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.902",
3
+ "version": "1.4.906",
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.902",
11
- "@reltio/mdm-sdk": "^1.4.902",
10
+ "@reltio/mdm-module": "^1.4.906",
11
+ "@reltio/mdm-sdk": "^1.4.906",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",