@reltio/components 1.4.914 → 1.4.918

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 (39) hide show
  1. package/cjs/components/SideIconPanel/SideButtonsPanel.d.ts +3 -3
  2. package/cjs/components/SideIconPanel/SideButtonsPanel.js +3 -3
  3. package/cjs/components/SidePanel/SidePanelContentHeader/SidePanelContentHeader.d.ts +3 -2
  4. package/cjs/components/SidePanel/SidePanelContentHeader/SidePanelContentHeader.js +6 -5
  5. package/cjs/components/attributes/AttributesView/index.js +1 -1
  6. package/cjs/components/attributes/editMode/SimpleAttributeEditor/selectors/helpers/parents.js +3 -1
  7. package/cjs/components/history/HistoryFilterButton/HistoryFilterButton.js +7 -1
  8. package/cjs/components/history/HistoryTree/HistoryTree.js +11 -1
  9. package/cjs/components/history/hooks/useHistory.d.ts +2 -2
  10. package/cjs/components/history/hooks/useHistory.js +20 -6
  11. package/cjs/components/history/hooks/useHistoryDiff.d.ts +2 -0
  12. package/cjs/components/history/hooks/useHistoryDiff.js +62 -0
  13. package/cjs/components/history/hooks/useHistoryWithTotal.d.ts +3 -2
  14. package/cjs/components/history/hooks/useHistoryWithTotal.js +6 -6
  15. package/cjs/components/history/index.d.ts +1 -0
  16. package/cjs/components/history/index.js +3 -1
  17. package/cjs/components/history/utils/filters.d.ts +3 -0
  18. package/cjs/components/history/utils/filters.js +67 -0
  19. package/cjs/contexts/HistoryAppearanceContext/index.js +3 -1
  20. package/esm/components/SideIconPanel/SideButtonsPanel.d.ts +3 -3
  21. package/esm/components/SideIconPanel/SideButtonsPanel.js +3 -3
  22. package/esm/components/SidePanel/SidePanelContentHeader/SidePanelContentHeader.d.ts +3 -2
  23. package/esm/components/SidePanel/SidePanelContentHeader/SidePanelContentHeader.js +6 -5
  24. package/esm/components/attributes/AttributesView/index.js +1 -1
  25. package/esm/components/attributes/editMode/SimpleAttributeEditor/selectors/helpers/parents.js +3 -1
  26. package/esm/components/history/HistoryFilterButton/HistoryFilterButton.js +8 -2
  27. package/esm/components/history/HistoryTree/HistoryTree.js +12 -2
  28. package/esm/components/history/hooks/useHistory.d.ts +2 -2
  29. package/esm/components/history/hooks/useHistory.js +20 -6
  30. package/esm/components/history/hooks/useHistoryDiff.d.ts +2 -0
  31. package/esm/components/history/hooks/useHistoryDiff.js +39 -0
  32. package/esm/components/history/hooks/useHistoryWithTotal.d.ts +3 -2
  33. package/esm/components/history/hooks/useHistoryWithTotal.js +6 -6
  34. package/esm/components/history/index.d.ts +1 -0
  35. package/esm/components/history/index.js +1 -0
  36. package/esm/components/history/utils/filters.d.ts +3 -0
  37. package/esm/components/history/utils/filters.js +60 -0
  38. package/esm/contexts/HistoryAppearanceContext/index.js +3 -1
  39. package/package.json +3 -3
@@ -3,11 +3,11 @@ declare type Props = {
3
3
  buttonsProps: {
4
4
  icon: ElementType;
5
5
  tooltipTitle: string;
6
- id: string;
6
+ id: number;
7
7
  }[];
8
- activeIndex: number;
8
+ activeIndexId: number;
9
9
  className?: string;
10
- onButtonClick: (index: number) => void;
10
+ onButtonClick: (id: number) => void;
11
11
  };
12
12
  export declare const SideButtonsPanel: VFC<Props>;
13
13
  export {};
@@ -31,12 +31,12 @@ var classnames_1 = __importDefault(require("classnames"));
31
31
  var SmallIconButton_1 = require("../SmallIconButton");
32
32
  var styles_1 = require("./styles");
33
33
  var SideButtonsPanel = function (_a) {
34
- var buttonsProps = _a.buttonsProps, activeIndex = _a.activeIndex, className = _a.className, onButtonClick = _a.onButtonClick;
34
+ var buttonsProps = _a.buttonsProps, activeIndexId = _a.activeIndexId, className = _a.className, onButtonClick = _a.onButtonClick;
35
35
  var styles = styles_1.useStyles();
36
- return (react_1.default.createElement("div", { className: classnames_1.default(styles.container, className) }, buttonsProps.map(function (_a, index) {
36
+ return (react_1.default.createElement("div", { className: classnames_1.default(styles.container, className) }, buttonsProps.map(function (_a) {
37
37
  var _b;
38
38
  var id = _a.id, buttonProps = __rest(_a, ["id"]);
39
- return (react_1.default.createElement(SmallIconButton_1.SmallIconButtonWithTooltip, __assign({}, buttonProps, { size: "S", key: id, className: classnames_1.default((_b = {}, _b[styles.active] = activeIndex === index, _b), styles.buttonWrapper), onClick: function () { return onButtonClick(index); }, "data-reltio-id": "reltio-profile-right-side-button-" + id })));
39
+ return (react_1.default.createElement(SmallIconButton_1.SmallIconButtonWithTooltip, __assign({}, buttonProps, { size: "S", key: id, className: classnames_1.default((_b = {}, _b[styles.active] = activeIndexId === id, _b), styles.buttonWrapper), onClick: function () { return onButtonClick(id); }, "data-reltio-id": "reltio-profile-right-side-button-" + id })));
40
40
  })));
41
41
  };
42
42
  exports.SideButtonsPanel = SideButtonsPanel;
@@ -1,7 +1,8 @@
1
1
  import { ReactNode, VFC } from 'react';
2
2
  declare type HeaderProps = {
3
- mainTitle: string;
4
- secondTitle: string;
3
+ mainTitle?: string;
4
+ secondTitle?: string;
5
+ content?: ReactNode;
5
6
  rightContent?: ReactNode;
6
7
  };
7
8
  declare type Props = HeaderProps & {
@@ -12,13 +12,14 @@ var Divider_1 = __importDefault(require("@material-ui/core/Divider"));
12
12
  var ui_i18n_1 = __importDefault(require("ui-i18n"));
13
13
  var SmallIconButton_1 = require("../../SmallIconButton");
14
14
  var SidePanelContentHeader = function (_a) {
15
- var onClose = _a.onClose, mainTitle = _a.mainTitle, secondTitle = _a.secondTitle, rightContent = _a.rightContent;
15
+ var onClose = _a.onClose, mainTitle = _a.mainTitle, secondTitle = _a.secondTitle, content = _a.content, rightContent = _a.rightContent;
16
16
  var styles = styles_1.useStyles();
17
17
  return (react_1.default.createElement("div", { className: styles.container },
18
18
  react_1.default.createElement(SmallIconButton_1.SmallIconButtonWithTooltip, { size: "S", icon: Close_1.default, onClick: onClose, className: styles.icon, tooltipTitle: ui_i18n_1.default.text('Close') }),
19
- react_1.default.createElement(Typography_1.default, { variant: "h6" }, mainTitle),
20
- react_1.default.createElement(Divider_1.default, { orientation: "vertical", flexItem: true, className: styles.divider }),
21
- react_1.default.createElement(Typography_1.default, { variant: "body1", color: "textSecondary", className: styles.secondTitle }, secondTitle),
22
- rightContent));
19
+ content || (react_1.default.createElement(react_1.default.Fragment, null,
20
+ react_1.default.createElement(Typography_1.default, { variant: "h6" }, mainTitle),
21
+ react_1.default.createElement(Divider_1.default, { orientation: "vertical", flexItem: true, className: styles.divider }),
22
+ react_1.default.createElement(Typography_1.default, { variant: "body1", color: "textSecondary", className: styles.secondTitle }, secondTitle),
23
+ rightContent))));
23
24
  };
24
25
  exports.SidePanelContentHeader = SidePanelContentHeader;
@@ -9,7 +9,7 @@ var mdm_module_1 = __importDefault(require("@reltio/mdm-module"));
9
9
  var AttributesView_1 = __importDefault(require("./AttributesView"));
10
10
  exports.AttributesView = AttributesView_1.default;
11
11
  var mapStateToProps = function (state, ownProps) { return ({
12
- entity: ownProps.entity || mdm_module_1.default.selectors.getEntity(state),
12
+ entity: ownProps.entity || mdm_module_1.default.selectors.getEntityWithDiff(state),
13
13
  mode: ownProps.mode || mdm_module_1.default.selectors.getMode(state)
14
14
  }); };
15
15
  exports.default = react_redux_1.connect(mapStateToProps)(AttributesView_1.default);
@@ -30,11 +30,13 @@ var getParents = function (state, valueUri, node) {
30
30
  });
31
31
  var modifiedEntities = mdm_module_1.default.selectors.getModifiedEntities(state);
32
32
  var entityUri = mdm_module_1.default.selectors.getEntityUri(state);
33
+ var connections = mdm_module_1.default.selectors.getAllRelationsToAddAndEdit(state);
33
34
  var ownParentNodesValues = mdm_sdk_1.filterRelatedParentValuesForDependentLookupValueUri({
34
35
  parentValues: parentNodesValues,
35
36
  valueUri: valueUri,
36
37
  entityUri: entityUri,
37
- modifiedEntities: modifiedEntities
38
+ modifiedEntities: modifiedEntities,
39
+ connections: connections
38
40
  });
39
41
  var neededParentsAttributeTypes = node.parents.map(function (type) {
40
42
  var parentNode = mdm_module_1.default.selectors.getDependentLookupsStructureNode(state, type);
@@ -41,6 +41,7 @@ var Button_1 = __importDefault(require("@material-ui/core/Button"));
41
41
  var Popover_1 = __importDefault(require("@material-ui/core/Popover"));
42
42
  var Typography_1 = __importDefault(require("@material-ui/core/Typography"));
43
43
  var SmallIconButton_1 = require("../../SmallIconButton");
44
+ var filters_1 = require("../utils/filters");
44
45
  var UserSelector_1 = __importDefault(require("../../UserSelector/UserSelector"));
45
46
  var AttributeSelector_1 = __importDefault(require("../../AttributeSelector/AttributeSelector"));
46
47
  var DateRangeSelector_1 = __importDefault(require("../DateRangeSelector/DateRangeSelector"));
@@ -80,7 +81,12 @@ var HistoryFilterButton = function (_a) {
80
81
  react_1.default.createElement(Button_1.default, { onClick: clearCurrentValue, className: styles.clearButton }, ui_i18n_1.default.text('Clear all')),
81
82
  react_1.default.createElement(Button_1.default, { onClick: closePopup }, ui_i18n_1.default.text('Cancel')),
82
83
  react_1.default.createElement(Button_1.default, { color: "primary", onClick: function () {
83
- onApplyFilter(currentValue);
84
+ if (dateRange && filters_1.isDateRangeValid(dateRange)) {
85
+ onApplyFilter(currentValue);
86
+ }
87
+ else {
88
+ onApplyFilter(ramda_1.dissoc('dateRange', currentValue));
89
+ }
84
90
  closePopup();
85
91
  } }, ui_i18n_1.default.text('Apply'))))));
86
92
  };
@@ -39,7 +39,8 @@ var react_resize_detector_1 = __importDefault(require("react-resize-detector"));
39
39
  var ui_i18n_1 = __importDefault(require("ui-i18n"));
40
40
  var ramda_1 = require("ramda");
41
41
  var classnames_1 = __importDefault(require("classnames"));
42
- var mdm_module_1 = require("@reltio/mdm-module");
42
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
43
+ var mdm_module_1 = __importStar(require("@reltio/mdm-module"));
43
44
  var Button_1 = __importDefault(require("@material-ui/core/Button"));
44
45
  var HistoryRow_1 = __importDefault(require("../HistoryRow/HistoryRow"));
45
46
  var HistoryGraph_1 = __importDefault(require("../HistoryGraph/HistoryGraph"));
@@ -50,6 +51,7 @@ var HistoryTree = function (_a) {
50
51
  var historyData = _a.historyData, isLoading = _a.isLoading, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore, entityUri = _a.entityUri, historyEvent = _a.historyEvent, findPreviousChange = _a.findPreviousChange;
51
52
  var styles = styles_1.useStyles();
52
53
  var dispatch = react_redux_1.useDispatch();
54
+ var isEditableMode = react_redux_1.useSelector(mdm_module_1.default.selectors.getIsEditableMode);
53
55
  var _c = react_1.useState({ historyLanes: {}, rows: [] }), graphData = _c[0], setGraphData = _c[1];
54
56
  var _d = react_1.useState(false), isScrollable = _d[0], setIsScrollable = _d[1];
55
57
  var _e = react_1.useState(-1), selectedIndex = _e[0], setSelectedIndex = _e[1];
@@ -78,6 +80,14 @@ var HistoryTree = function (_a) {
78
80
  setIsScrollable(scrollLeft < scrollWidth - clientWidth);
79
81
  };
80
82
  var handleHistoryRowClick = function (index, change, isSelected, isCurrent) {
83
+ if (isEditableMode) {
84
+ if (window.confirm(ui_i18n_1.default.text('Are you sure you want to go in history mode? All your changes will be lost.'))) {
85
+ dispatch(mdm_module_1.profile.mode.actions.modeUpdated(mdm_sdk_1.Mode.Viewing));
86
+ }
87
+ else {
88
+ return;
89
+ }
90
+ }
81
91
  if ((isCurrent && !isSelected) || (!isCurrent && isSelected)) {
82
92
  dispatch(mdm_module_1.profile.history.actions.clearHistoryEvent());
83
93
  setSelectedIndex(0);
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { HistoryFilter } from '../types';
3
2
  declare type Props = {
4
3
  entityUri: string;
@@ -8,9 +7,10 @@ export declare const useHistory: ({ entityUri, enabled }: Props) => {
8
7
  isLoading: boolean;
9
8
  canLoadMore: boolean;
10
9
  onLoadMore: () => void;
10
+ onApplyFilter: (filter: HistoryFilter) => void;
11
11
  historicUris: string[];
12
12
  historyWithTotal: import("@reltio/mdm-sdk").HistoryWithTotal;
13
13
  historyFilter: HistoryFilter;
14
- setHistoryFilter: import("react").Dispatch<import("react").SetStateAction<HistoryFilter>>;
14
+ reloadHistory: () => void;
15
15
  };
16
16
  export {};
@@ -4,11 +4,16 @@ exports.useHistory = void 0;
4
4
  var react_1 = require("react");
5
5
  var useHistoricUris_1 = require("./useHistoricUris");
6
6
  var useHistoryWithTotal_1 = require("./useHistoryWithTotal");
7
+ var types_1 = require("../types");
8
+ var filters_1 = require("../utils/filters");
7
9
  var MAX_HISTORY_ROWS = 32;
8
10
  var useHistory = function (_a) {
9
11
  var entityUri = _a.entityUri, enabled = _a.enabled;
10
- var _b = react_1.useState(null), historyFilter = _b[0], setHistoryFilter = _b[1];
12
+ var _b = react_1.useState({
13
+ activities: [types_1.HistoryActivityType.MERGE, types_1.HistoryActivityType.UNMERGE, types_1.HistoryActivityType.UPDATE]
14
+ }), historyFilter = _b[0], setHistoryFilter = _b[1];
11
15
  var _c = react_1.useState(0), historyPage = _c[0], setHistoryPage = _c[1];
16
+ var historyFilterString = react_1.useMemo(function () { return filters_1.buildHistoryFilterString(historyFilter); }, [historyFilter]);
12
17
  var _d = useHistoricUris_1.useHistoricUris({
13
18
  entityUri: entityUri,
14
19
  enabled: enabled
@@ -16,30 +21,39 @@ var useHistory = function (_a) {
16
21
  var _e = useHistoryWithTotal_1.useHistoryWithTotal({
17
22
  entityUri: entityUri,
18
23
  enabled: enabled && !!historicUris,
24
+ filter: historyFilterString,
19
25
  historicUris: historicUris,
20
26
  max: MAX_HISTORY_ROWS,
21
27
  offset: historyPage * MAX_HISTORY_ROWS,
22
- order: 'desc',
23
- showAll: true
24
- }), isHistoryLoading = _e.isLoading, historyWithTotal = _e.historyWithTotal, loadMore = _e.loadMore;
25
- var canLoadMore = react_1.useMemo(function () { return (historyPage + 1) * MAX_HISTORY_ROWS <= (historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.total); }, [
28
+ order: 'desc'
29
+ }), isHistoryLoading = _e.isLoading, historyWithTotal = _e.historyWithTotal, loadMore = _e.loadMore, loadData = _e.loadData;
30
+ var canLoadMore = react_1.useMemo(function () { return (historyPage + 1) * MAX_HISTORY_ROWS < (historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.total); }, [
26
31
  historyWithTotal,
27
32
  historyPage
28
33
  ]);
34
+ var onApplyFilter = react_1.useCallback(function (filter) {
35
+ setHistoryPage(0);
36
+ setHistoryFilter(filter);
37
+ }, []);
29
38
  var onLoadMore = react_1.useCallback(function () {
30
39
  if (!canLoadMore)
31
40
  return;
32
41
  loadMore((historyPage + 1) * MAX_HISTORY_ROWS);
33
42
  setHistoryPage(historyPage + 1);
34
43
  }, [loadMore, historyPage, canLoadMore]);
44
+ var reloadHistory = react_1.useCallback(function () {
45
+ loadData();
46
+ setHistoryPage(0);
47
+ }, [loadData]);
35
48
  return {
36
49
  isLoading: isHistoryLoading || isHistoricUrisLoading,
37
50
  canLoadMore: canLoadMore,
38
51
  onLoadMore: onLoadMore,
52
+ onApplyFilter: onApplyFilter,
39
53
  historicUris: historicUris,
40
54
  historyWithTotal: historyWithTotal,
41
55
  historyFilter: historyFilter,
42
- setHistoryFilter: setHistoryFilter
56
+ reloadHistory: reloadHistory
43
57
  };
44
58
  };
45
59
  exports.useHistory = useHistory;
@@ -0,0 +1,2 @@
1
+ import { HistoryDiff } from '@reltio/mdm-sdk';
2
+ export declare const useHistoryDiff: () => HistoryDiff;
@@ -0,0 +1,62 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.useHistoryDiff = void 0;
23
+ var react_1 = require("react");
24
+ var react_redux_1 = require("react-redux");
25
+ var ramda_1 = require("ramda");
26
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
27
+ var mdm_module_1 = __importStar(require("@reltio/mdm-module"));
28
+ var defaultHistoryDiff = {
29
+ appearance: {},
30
+ attributes: {},
31
+ roles: [],
32
+ tags: []
33
+ };
34
+ var fixRefEntity = ramda_1.evolve({
35
+ refEntity: mdm_sdk_1.wrapInArrayIfNeeded,
36
+ refRelation: mdm_sdk_1.wrapInArrayIfNeeded
37
+ });
38
+ var prepareHistorySlice = function (historySlice) {
39
+ if (historySlice) {
40
+ return ramda_1.evolve({
41
+ attributes: ramda_1.map(ramda_1.map(fixRefEntity))
42
+ })(historySlice);
43
+ }
44
+ return historySlice;
45
+ };
46
+ var useHistoryDiff = function () {
47
+ var dispatch = react_redux_1.useDispatch();
48
+ var historySlice = react_redux_1.useSelector(mdm_module_1.default.selectors.getHistorySlice);
49
+ var historyDiff = react_redux_1.useSelector(mdm_module_1.default.selectors.getHistoryDiff);
50
+ var historyMode = react_redux_1.useSelector(mdm_module_1.default.selectors.getHistoryMode);
51
+ var entity = react_redux_1.useSelector(mdm_module_1.default.selectors.getEntity);
52
+ react_1.useEffect(function () {
53
+ if (historySlice) {
54
+ var aEntity = historySlice.aEntity, bEntity = historySlice.bEntity;
55
+ var historyManager = mdm_sdk_1.entity.HistoryManager.createHistoryManager(mdm_sdk_1.entity.AttributesDiff);
56
+ var historyDiff_1 = historyManager.computeEntityHistoryDiff(prepareHistorySlice(historyMode === mdm_module_1.HistoryMode.Current ? entity : bEntity), prepareHistorySlice(aEntity));
57
+ dispatch(mdm_module_1.profile.history.actions.setHistoryDiff(historyDiff_1));
58
+ }
59
+ }, [historySlice, historyMode, dispatch, entity]);
60
+ return historyDiff || defaultHistoryDiff;
61
+ };
62
+ exports.useHistoryDiff = useHistoryDiff;
@@ -7,11 +7,12 @@ declare type Props = {
7
7
  max?: number;
8
8
  offset?: number;
9
9
  order?: string;
10
- filter?: any;
10
+ filter?: string;
11
11
  };
12
- export declare const useHistoryWithTotal: ({ entityUri, enabled, historicUris, ...options }: Props) => {
12
+ export declare const useHistoryWithTotal: ({ entityUri, enabled, historicUris, filter, ...options }: Props) => {
13
13
  isLoading: boolean;
14
14
  historyWithTotal: HistoryWithTotal;
15
15
  loadMore: (offset: number) => void;
16
+ loadData: () => void;
16
17
  };
17
18
  export {};
@@ -32,7 +32,7 @@ var react_1 = require("react");
32
32
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
33
33
  var hooks_1 = require("../../../hooks");
34
34
  var useHistoryWithTotal = function (_a) {
35
- var entityUri = _a.entityUri, _b = _a.enabled, enabled = _b === void 0 ? true : _b, historicUris = _a.historicUris, options = __rest(_a, ["entityUri", "enabled", "historicUris"]);
35
+ var entityUri = _a.entityUri, _b = _a.enabled, enabled = _b === void 0 ? true : _b, historicUris = _a.historicUris, filter = _a.filter, options = __rest(_a, ["entityUri", "enabled", "historicUris", "filter"]);
36
36
  var _c = react_1.useState(null), historyWithTotal = _c[0], setHistoryWithTotal = _c[1];
37
37
  var _d = react_1.useState(false), isLoading = _d[0], setIsLoading = _d[1];
38
38
  var safePromise = hooks_1.useSafePromise();
@@ -43,7 +43,7 @@ var useHistoryWithTotal = function (_a) {
43
43
  var loadData = react_1.useCallback(function () {
44
44
  if (entityUri && historicUris) {
45
45
  setIsLoading(true);
46
- safePromise(mdm_sdk_1.getHistoryWithTotal(__assign({ entityUri: entityUri, historicUris: historicUris }, options)))
46
+ safePromise(mdm_sdk_1.getHistoryWithTotal(__assign({ entityUri: entityUri, historicUris: historicUris, filter: filter }, options)))
47
47
  .then(function (results) {
48
48
  setHistoryWithTotal(results);
49
49
  })
@@ -55,11 +55,11 @@ var useHistoryWithTotal = function (_a) {
55
55
  else {
56
56
  setHistoryWithTotal(null);
57
57
  }
58
- }, [entityUri, historicUris]);
58
+ }, [entityUri, historicUris, filter]);
59
59
  var loadMore = react_1.useCallback(function (offset) {
60
60
  if (entityUri && historicUris) {
61
61
  setIsLoading(true);
62
- safePromise(mdm_sdk_1.getHistoryWithTotal(__assign(__assign({ entityUri: entityUri, historicUris: historicUris }, options), { offset: offset })))
62
+ safePromise(mdm_sdk_1.getHistoryWithTotal(__assign(__assign({ entityUri: entityUri, historicUris: historicUris, filter: filter }, options), { offset: offset })))
63
63
  .then(function (results) {
64
64
  setHistoryWithTotal(function (prev) { return (__assign(__assign({}, prev), { changes: __spreadArray(__spreadArray([], prev === null || prev === void 0 ? void 0 : prev.changes), results.changes) })); });
65
65
  })
@@ -68,12 +68,12 @@ var useHistoryWithTotal = function (_a) {
68
68
  setIsLoading(false);
69
69
  });
70
70
  }
71
- }, [entityUri, historicUris]);
71
+ }, [entityUri, historicUris, filter]);
72
72
  react_1.useEffect(function () {
73
73
  if (enabled) {
74
74
  loadData();
75
75
  }
76
76
  }, [loadData, enabled]);
77
- return { isLoading: isLoading, historyWithTotal: historyWithTotal, loadMore: loadMore };
77
+ return { isLoading: isLoading, historyWithTotal: historyWithTotal, loadMore: loadMore, loadData: loadData };
78
78
  };
79
79
  exports.useHistoryWithTotal = useHistoryWithTotal;
@@ -2,6 +2,7 @@ export { useHistoricUris } from './hooks/useHistoricUris';
2
2
  export { useHistoryWithTotal } from './hooks/useHistoryWithTotal';
3
3
  export { useHistorySlice } from './hooks/useHistorySlice';
4
4
  export { useHistory } from './hooks/useHistory';
5
+ export { useHistoryDiff } from './hooks/useHistoryDiff';
5
6
  export { default as HistoryView } from './HistoryView/HistoryView';
6
7
  export { default as HistoryHeader } from './HistoryHeader/HistoryHeader';
7
8
  export { default as ProfileBandHistory } from './ProfileBandHistory/ProfileBandHistory';
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ProfileBandHistory = exports.HistoryHeader = exports.HistoryView = exports.useHistory = exports.useHistorySlice = exports.useHistoryWithTotal = exports.useHistoricUris = void 0;
16
+ exports.ProfileBandHistory = exports.HistoryHeader = exports.HistoryView = exports.useHistoryDiff = exports.useHistory = exports.useHistorySlice = exports.useHistoryWithTotal = exports.useHistoricUris = void 0;
17
17
  var useHistoricUris_1 = require("./hooks/useHistoricUris");
18
18
  Object.defineProperty(exports, "useHistoricUris", { enumerable: true, get: function () { return useHistoricUris_1.useHistoricUris; } });
19
19
  var useHistoryWithTotal_1 = require("./hooks/useHistoryWithTotal");
@@ -22,6 +22,8 @@ var useHistorySlice_1 = require("./hooks/useHistorySlice");
22
22
  Object.defineProperty(exports, "useHistorySlice", { enumerable: true, get: function () { return useHistorySlice_1.useHistorySlice; } });
23
23
  var useHistory_1 = require("./hooks/useHistory");
24
24
  Object.defineProperty(exports, "useHistory", { enumerable: true, get: function () { return useHistory_1.useHistory; } });
25
+ var useHistoryDiff_1 = require("./hooks/useHistoryDiff");
26
+ Object.defineProperty(exports, "useHistoryDiff", { enumerable: true, get: function () { return useHistoryDiff_1.useHistoryDiff; } });
25
27
  var HistoryView_1 = require("./HistoryView/HistoryView");
26
28
  Object.defineProperty(exports, "HistoryView", { enumerable: true, get: function () { return __importDefault(HistoryView_1).default; } });
27
29
  var HistoryHeader_1 = require("./HistoryHeader/HistoryHeader");
@@ -0,0 +1,3 @@
1
+ import { DateRangeFilter } from '../../../types';
2
+ export declare const buildHistoryFilterString: any;
3
+ export declare const isDateRangeValid: (value: DateRangeFilter) => boolean;
@@ -0,0 +1,67 @@
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.isDateRangeValid = exports.buildHistoryFilterString = void 0;
7
+ var moment_1 = __importDefault(require("moment"));
8
+ var ramda_1 = require("ramda");
9
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
10
+ var HistoryFilter_1 = require("../types/HistoryFilter");
11
+ var ActivityTypes_1 = require("../../activityLog/types/ActivityTypes");
12
+ var types_1 = require("../../../types");
13
+ var wrapInBrackets = function (str) { return "(" + str + ")"; };
14
+ var multiValueFilter = function (filterClauseFn) { return ramda_1.pipe(ramda_1.map(filterClauseFn), ramda_1.join(' or ')); };
15
+ var durationToTimestamp = function (period) {
16
+ var amount = period[0], unit = period[1];
17
+ return moment_1.default().subtract(amount, unit).valueOf();
18
+ };
19
+ var convertHistoryTypes = ramda_1.chain(ramda_1.cond([
20
+ [
21
+ ramda_1.equals(HistoryFilter_1.HistoryActivityType.MERGE),
22
+ function () { return [
23
+ ActivityTypes_1.ActivityTypes.ENTITIES_MERGED,
24
+ ActivityTypes_1.ActivityTypes.ENTITIES_MERGED_MANUALLY,
25
+ ActivityTypes_1.ActivityTypes.ENTITIES_MERGED_ON_THE_FLY
26
+ ]; }
27
+ ],
28
+ [ramda_1.equals(HistoryFilter_1.HistoryActivityType.UNMERGE), function () { return [ActivityTypes_1.ActivityTypes.ENTITIES_SPLITTED]; }],
29
+ [ramda_1.equals(HistoryFilter_1.HistoryActivityType.UPDATE), function () { return [ActivityTypes_1.ActivityTypes.ENTITY_CHANGED]; }]
30
+ ]));
31
+ var buildActivityFilterClause = ramda_1.pipe(ramda_1.defaultTo([]), convertHistoryTypes, ramda_1.concat([ActivityTypes_1.ActivityTypes.ENTITY_CREATED, ActivityTypes_1.ActivityTypes.ENTITY_REMOVED, ActivityTypes_1.ActivityTypes.ENTITY_LOST_MERGE]), multiValueFilter(function (value) { return "equals(type, '" + value + "')"; }));
32
+ var buildUserFilterClause = function (user) { return "equals(user, '" + mdm_sdk_1.escapeQueryValue(user) + "')"; };
33
+ var buildAttributeFilterClause = function (attribute) { return "changes(" + mdm_sdk_1.escapeQueryValue(attribute.value) + ")"; };
34
+ var buildDateRangeFilterClause = function (_a) {
35
+ var type = _a.type, period = _a.period;
36
+ switch (type) {
37
+ case types_1.DateRangeTypes.WITHIN: {
38
+ return "gte(timestamp, " + durationToTimestamp(period) + ")";
39
+ }
40
+ case types_1.DateRangeTypes.AGO: {
41
+ return "lte(timestamp, " + durationToTimestamp(period) + ")";
42
+ }
43
+ case types_1.DateRangeTypes.BETWEEN: {
44
+ var start = period[0], end = period[1];
45
+ return "gte(timestamp, " + start.valueOf() + ") and lte(timestamp, " + moment_1.default(end).endOf('date').valueOf() + ")";
46
+ }
47
+ default: {
48
+ return '';
49
+ }
50
+ }
51
+ };
52
+ exports.buildHistoryFilterString = ramda_1.pipe(ramda_1.defaultTo({}), ramda_1.reject(mdm_sdk_1.isEmptyValue), ramda_1.evolve({
53
+ users: multiValueFilter(buildUserFilterClause),
54
+ attributes: multiValueFilter(buildAttributeFilterClause),
55
+ dateRange: buildDateRangeFilterClause
56
+ }), ramda_1.over(ramda_1.lensProp('activities'), buildActivityFilterClause), ramda_1.values, ramda_1.reject(mdm_sdk_1.isEmptyValue), ramda_1.append("not equals(user, 'collaboration-service')"), ramda_1.map(wrapInBrackets), ramda_1.join(' and '));
57
+ var isDateRangeValid = function (value) {
58
+ if (value.type === types_1.DateRangeTypes.AGO || value.type === types_1.DateRangeTypes.WITHIN) {
59
+ var _a = value.period, amount = _a[0], unit = _a[1];
60
+ return ramda_1.type(amount) === 'Number' && ramda_1.type(unit) === 'String' && amount > 0;
61
+ }
62
+ else if (value.type === types_1.DateRangeTypes.BETWEEN) {
63
+ var _b = value.period, startDate = _b[0], endDate = _b[1];
64
+ return startDate instanceof Date && endDate instanceof Date;
65
+ }
66
+ };
67
+ exports.isDateRangeValid = isDateRangeValid;
@@ -7,6 +7,8 @@ exports.HistoryDiffContext = void 0;
7
7
  var react_1 = __importDefault(require("react"));
8
8
  exports.HistoryDiffContext = react_1.default.createContext({
9
9
  appearance: undefined,
10
- attributes: undefined
10
+ attributes: undefined,
11
+ roles: undefined,
12
+ tags: undefined
11
13
  });
12
14
  exports.HistoryDiffContext.displayName = 'HistoryDiffContext';
@@ -3,11 +3,11 @@ declare type Props = {
3
3
  buttonsProps: {
4
4
  icon: ElementType;
5
5
  tooltipTitle: string;
6
- id: string;
6
+ id: number;
7
7
  }[];
8
- activeIndex: number;
8
+ activeIndexId: number;
9
9
  className?: string;
10
- onButtonClick: (index: number) => void;
10
+ onButtonClick: (id: number) => void;
11
11
  };
12
12
  export declare const SideButtonsPanel: VFC<Props>;
13
13
  export {};
@@ -25,11 +25,11 @@ import classnames from 'classnames';
25
25
  import { SmallIconButtonWithTooltip } from '../SmallIconButton';
26
26
  import { useStyles } from './styles';
27
27
  export var SideButtonsPanel = function (_a) {
28
- var buttonsProps = _a.buttonsProps, activeIndex = _a.activeIndex, className = _a.className, onButtonClick = _a.onButtonClick;
28
+ var buttonsProps = _a.buttonsProps, activeIndexId = _a.activeIndexId, className = _a.className, onButtonClick = _a.onButtonClick;
29
29
  var styles = useStyles();
30
- return (React.createElement("div", { className: classnames(styles.container, className) }, buttonsProps.map(function (_a, index) {
30
+ return (React.createElement("div", { className: classnames(styles.container, className) }, buttonsProps.map(function (_a) {
31
31
  var _b;
32
32
  var id = _a.id, buttonProps = __rest(_a, ["id"]);
33
- return (React.createElement(SmallIconButtonWithTooltip, __assign({}, buttonProps, { size: "S", key: id, className: classnames((_b = {}, _b[styles.active] = activeIndex === index, _b), styles.buttonWrapper), onClick: function () { return onButtonClick(index); }, "data-reltio-id": "reltio-profile-right-side-button-" + id })));
33
+ return (React.createElement(SmallIconButtonWithTooltip, __assign({}, buttonProps, { size: "S", key: id, className: classnames((_b = {}, _b[styles.active] = activeIndexId === id, _b), styles.buttonWrapper), onClick: function () { return onButtonClick(id); }, "data-reltio-id": "reltio-profile-right-side-button-" + id })));
34
34
  })));
35
35
  };
@@ -1,7 +1,8 @@
1
1
  import { ReactNode, VFC } from 'react';
2
2
  declare type HeaderProps = {
3
- mainTitle: string;
4
- secondTitle: string;
3
+ mainTitle?: string;
4
+ secondTitle?: string;
5
+ content?: ReactNode;
5
6
  rightContent?: ReactNode;
6
7
  };
7
8
  declare type Props = HeaderProps & {
@@ -6,12 +6,13 @@ import Divider from '@material-ui/core/Divider';
6
6
  import i18n from 'ui-i18n';
7
7
  import { SmallIconButtonWithTooltip } from '../../SmallIconButton';
8
8
  export var SidePanelContentHeader = function (_a) {
9
- var onClose = _a.onClose, mainTitle = _a.mainTitle, secondTitle = _a.secondTitle, rightContent = _a.rightContent;
9
+ var onClose = _a.onClose, mainTitle = _a.mainTitle, secondTitle = _a.secondTitle, content = _a.content, rightContent = _a.rightContent;
10
10
  var styles = useStyles();
11
11
  return (React.createElement("div", { className: styles.container },
12
12
  React.createElement(SmallIconButtonWithTooltip, { size: "S", icon: CloseIcon, onClick: onClose, className: styles.icon, tooltipTitle: i18n.text('Close') }),
13
- React.createElement(Typography, { variant: "h6" }, mainTitle),
14
- React.createElement(Divider, { orientation: "vertical", flexItem: true, className: styles.divider }),
15
- React.createElement(Typography, { variant: "body1", color: "textSecondary", className: styles.secondTitle }, secondTitle),
16
- rightContent));
13
+ content || (React.createElement(React.Fragment, null,
14
+ React.createElement(Typography, { variant: "h6" }, mainTitle),
15
+ React.createElement(Divider, { orientation: "vertical", flexItem: true, className: styles.divider }),
16
+ React.createElement(Typography, { variant: "body1", color: "textSecondary", className: styles.secondTitle }, secondTitle),
17
+ rightContent))));
17
18
  };
@@ -2,7 +2,7 @@ import { connect } from 'react-redux';
2
2
  import mdm from '@reltio/mdm-module';
3
3
  import AttributesView from './AttributesView';
4
4
  var mapStateToProps = function (state, ownProps) { return ({
5
- entity: ownProps.entity || mdm.selectors.getEntity(state),
5
+ entity: ownProps.entity || mdm.selectors.getEntityWithDiff(state),
6
6
  mode: ownProps.mode || mdm.selectors.getMode(state)
7
7
  }); };
8
8
  export { AttributesView };
@@ -24,11 +24,13 @@ export var getParents = function (state, valueUri, node) {
24
24
  });
25
25
  var modifiedEntities = mdmModule.selectors.getModifiedEntities(state);
26
26
  var entityUri = mdmModule.selectors.getEntityUri(state);
27
+ var connections = mdmModule.selectors.getAllRelationsToAddAndEdit(state);
27
28
  var ownParentNodesValues = filterRelatedParentValuesForDependentLookupValueUri({
28
29
  parentValues: parentNodesValues,
29
30
  valueUri: valueUri,
30
31
  entityUri: entityUri,
31
- modifiedEntities: modifiedEntities
32
+ modifiedEntities: modifiedEntities,
33
+ connections: connections
32
34
  });
33
35
  var neededParentsAttributeTypes = node.parents.map(function (type) {
34
36
  var parentNode = mdmModule.selectors.getDependentLookupsStructureNode(state, type);
@@ -11,12 +11,13 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import React, { useState } from 'react';
13
13
  import i18n from 'ui-i18n';
14
- import { curry } from 'ramda';
14
+ import { curry, dissoc } from 'ramda';
15
15
  import FilterListIcon from '@material-ui/icons/FilterList';
16
16
  import Button from '@material-ui/core/Button';
17
17
  import Popover from '@material-ui/core/Popover';
18
18
  import Typography from '@material-ui/core/Typography';
19
19
  import { SmallIconButton } from '../../SmallIconButton';
20
+ import { isDateRangeValid } from '../utils/filters';
20
21
  import UserSelector from '../../UserSelector/UserSelector';
21
22
  import AttributeSelector from '../../AttributeSelector/AttributeSelector';
22
23
  import DateRangeSelector from '../DateRangeSelector/DateRangeSelector';
@@ -56,7 +57,12 @@ var HistoryFilterButton = function (_a) {
56
57
  React.createElement(Button, { onClick: clearCurrentValue, className: styles.clearButton }, i18n.text('Clear all')),
57
58
  React.createElement(Button, { onClick: closePopup }, i18n.text('Cancel')),
58
59
  React.createElement(Button, { color: "primary", onClick: function () {
59
- onApplyFilter(currentValue);
60
+ if (dateRange && isDateRangeValid(dateRange)) {
61
+ onApplyFilter(currentValue);
62
+ }
63
+ else {
64
+ onApplyFilter(dissoc('dateRange', currentValue));
65
+ }
60
66
  closePopup();
61
67
  } }, i18n.text('Apply'))))));
62
68
  };
@@ -10,12 +10,13 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import React, { useCallback, useEffect, useRef, useState } from 'react';
13
- import { useDispatch } from 'react-redux';
13
+ import { useDispatch, useSelector } from 'react-redux';
14
14
  import ReactResizeDetector from 'react-resize-detector';
15
15
  import i18n from 'ui-i18n';
16
16
  import { isNil } from 'ramda';
17
17
  import classnames from 'classnames';
18
- import { profile } from '@reltio/mdm-module';
18
+ import { Mode } from '@reltio/mdm-sdk';
19
+ import mdm, { profile } from '@reltio/mdm-module';
19
20
  import Button from '@material-ui/core/Button';
20
21
  import HistoryRow from '../HistoryRow/HistoryRow';
21
22
  import HistoryGraph from '../HistoryGraph/HistoryGraph';
@@ -26,6 +27,7 @@ var HistoryTree = function (_a) {
26
27
  var historyData = _a.historyData, isLoading = _a.isLoading, canLoadMore = _a.canLoadMore, onLoadMore = _a.onLoadMore, entityUri = _a.entityUri, historyEvent = _a.historyEvent, findPreviousChange = _a.findPreviousChange;
27
28
  var styles = useStyles();
28
29
  var dispatch = useDispatch();
30
+ var isEditableMode = useSelector(mdm.selectors.getIsEditableMode);
29
31
  var _c = useState({ historyLanes: {}, rows: [] }), graphData = _c[0], setGraphData = _c[1];
30
32
  var _d = useState(false), isScrollable = _d[0], setIsScrollable = _d[1];
31
33
  var _e = useState(-1), selectedIndex = _e[0], setSelectedIndex = _e[1];
@@ -54,6 +56,14 @@ var HistoryTree = function (_a) {
54
56
  setIsScrollable(scrollLeft < scrollWidth - clientWidth);
55
57
  };
56
58
  var handleHistoryRowClick = function (index, change, isSelected, isCurrent) {
59
+ if (isEditableMode) {
60
+ if (window.confirm(i18n.text('Are you sure you want to go in history mode? All your changes will be lost.'))) {
61
+ dispatch(profile.mode.actions.modeUpdated(Mode.Viewing));
62
+ }
63
+ else {
64
+ return;
65
+ }
66
+ }
57
67
  if ((isCurrent && !isSelected) || (!isCurrent && isSelected)) {
58
68
  dispatch(profile.history.actions.clearHistoryEvent());
59
69
  setSelectedIndex(0);
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { HistoryFilter } from '../types';
3
2
  declare type Props = {
4
3
  entityUri: string;
@@ -8,9 +7,10 @@ export declare const useHistory: ({ entityUri, enabled }: Props) => {
8
7
  isLoading: boolean;
9
8
  canLoadMore: boolean;
10
9
  onLoadMore: () => void;
10
+ onApplyFilter: (filter: HistoryFilter) => void;
11
11
  historicUris: string[];
12
12
  historyWithTotal: import("@reltio/mdm-sdk").HistoryWithTotal;
13
13
  historyFilter: HistoryFilter;
14
- setHistoryFilter: import("react").Dispatch<import("react").SetStateAction<HistoryFilter>>;
14
+ reloadHistory: () => void;
15
15
  };
16
16
  export {};
@@ -1,11 +1,16 @@
1
1
  import { useState, useMemo, useCallback } from 'react';
2
2
  import { useHistoricUris } from './useHistoricUris';
3
3
  import { useHistoryWithTotal } from './useHistoryWithTotal';
4
+ import { HistoryActivityType } from '../types';
5
+ import { buildHistoryFilterString } from '../utils/filters';
4
6
  var MAX_HISTORY_ROWS = 32;
5
7
  export var useHistory = function (_a) {
6
8
  var entityUri = _a.entityUri, enabled = _a.enabled;
7
- var _b = useState(null), historyFilter = _b[0], setHistoryFilter = _b[1];
9
+ var _b = useState({
10
+ activities: [HistoryActivityType.MERGE, HistoryActivityType.UNMERGE, HistoryActivityType.UPDATE]
11
+ }), historyFilter = _b[0], setHistoryFilter = _b[1];
8
12
  var _c = useState(0), historyPage = _c[0], setHistoryPage = _c[1];
13
+ var historyFilterString = useMemo(function () { return buildHistoryFilterString(historyFilter); }, [historyFilter]);
9
14
  var _d = useHistoricUris({
10
15
  entityUri: entityUri,
11
16
  enabled: enabled
@@ -13,29 +18,38 @@ export var useHistory = function (_a) {
13
18
  var _e = useHistoryWithTotal({
14
19
  entityUri: entityUri,
15
20
  enabled: enabled && !!historicUris,
21
+ filter: historyFilterString,
16
22
  historicUris: historicUris,
17
23
  max: MAX_HISTORY_ROWS,
18
24
  offset: historyPage * MAX_HISTORY_ROWS,
19
- order: 'desc',
20
- showAll: true
21
- }), isHistoryLoading = _e.isLoading, historyWithTotal = _e.historyWithTotal, loadMore = _e.loadMore;
22
- var canLoadMore = useMemo(function () { return (historyPage + 1) * MAX_HISTORY_ROWS <= (historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.total); }, [
25
+ order: 'desc'
26
+ }), isHistoryLoading = _e.isLoading, historyWithTotal = _e.historyWithTotal, loadMore = _e.loadMore, loadData = _e.loadData;
27
+ var canLoadMore = useMemo(function () { return (historyPage + 1) * MAX_HISTORY_ROWS < (historyWithTotal === null || historyWithTotal === void 0 ? void 0 : historyWithTotal.total); }, [
23
28
  historyWithTotal,
24
29
  historyPage
25
30
  ]);
31
+ var onApplyFilter = useCallback(function (filter) {
32
+ setHistoryPage(0);
33
+ setHistoryFilter(filter);
34
+ }, []);
26
35
  var onLoadMore = useCallback(function () {
27
36
  if (!canLoadMore)
28
37
  return;
29
38
  loadMore((historyPage + 1) * MAX_HISTORY_ROWS);
30
39
  setHistoryPage(historyPage + 1);
31
40
  }, [loadMore, historyPage, canLoadMore]);
41
+ var reloadHistory = useCallback(function () {
42
+ loadData();
43
+ setHistoryPage(0);
44
+ }, [loadData]);
32
45
  return {
33
46
  isLoading: isHistoryLoading || isHistoricUrisLoading,
34
47
  canLoadMore: canLoadMore,
35
48
  onLoadMore: onLoadMore,
49
+ onApplyFilter: onApplyFilter,
36
50
  historicUris: historicUris,
37
51
  historyWithTotal: historyWithTotal,
38
52
  historyFilter: historyFilter,
39
- setHistoryFilter: setHistoryFilter
53
+ reloadHistory: reloadHistory
40
54
  };
41
55
  };
@@ -0,0 +1,2 @@
1
+ import { HistoryDiff } from '@reltio/mdm-sdk';
2
+ export declare const useHistoryDiff: () => HistoryDiff;
@@ -0,0 +1,39 @@
1
+ import { useEffect } from 'react';
2
+ import { useDispatch, useSelector } from 'react-redux';
3
+ import { evolve, map } from 'ramda';
4
+ import { entity as History, wrapInArrayIfNeeded } from '@reltio/mdm-sdk';
5
+ import mdmModule, { HistoryMode, profile } from '@reltio/mdm-module';
6
+ var defaultHistoryDiff = {
7
+ appearance: {},
8
+ attributes: {},
9
+ roles: [],
10
+ tags: []
11
+ };
12
+ var fixRefEntity = evolve({
13
+ refEntity: wrapInArrayIfNeeded,
14
+ refRelation: wrapInArrayIfNeeded
15
+ });
16
+ var prepareHistorySlice = function (historySlice) {
17
+ if (historySlice) {
18
+ return evolve({
19
+ attributes: map(map(fixRefEntity))
20
+ })(historySlice);
21
+ }
22
+ return historySlice;
23
+ };
24
+ export var useHistoryDiff = function () {
25
+ var dispatch = useDispatch();
26
+ var historySlice = useSelector(mdmModule.selectors.getHistorySlice);
27
+ var historyDiff = useSelector(mdmModule.selectors.getHistoryDiff);
28
+ var historyMode = useSelector(mdmModule.selectors.getHistoryMode);
29
+ var entity = useSelector(mdmModule.selectors.getEntity);
30
+ useEffect(function () {
31
+ if (historySlice) {
32
+ var aEntity = historySlice.aEntity, bEntity = historySlice.bEntity;
33
+ var historyManager = History.HistoryManager.createHistoryManager(History.AttributesDiff);
34
+ var historyDiff_1 = historyManager.computeEntityHistoryDiff(prepareHistorySlice(historyMode === HistoryMode.Current ? entity : bEntity), prepareHistorySlice(aEntity));
35
+ dispatch(profile.history.actions.setHistoryDiff(historyDiff_1));
36
+ }
37
+ }, [historySlice, historyMode, dispatch, entity]);
38
+ return historyDiff || defaultHistoryDiff;
39
+ };
@@ -7,11 +7,12 @@ declare type Props = {
7
7
  max?: number;
8
8
  offset?: number;
9
9
  order?: string;
10
- filter?: any;
10
+ filter?: string;
11
11
  };
12
- export declare const useHistoryWithTotal: ({ entityUri, enabled, historicUris, ...options }: Props) => {
12
+ export declare const useHistoryWithTotal: ({ entityUri, enabled, historicUris, filter, ...options }: Props) => {
13
13
  isLoading: boolean;
14
14
  historyWithTotal: HistoryWithTotal;
15
15
  loadMore: (offset: number) => void;
16
+ loadData: () => void;
16
17
  };
17
18
  export {};
@@ -29,7 +29,7 @@ import { useCallback, useEffect, useState } from 'react';
29
29
  import { getHistoryWithTotal } from '@reltio/mdm-sdk';
30
30
  import { useSafePromise } from '../../../hooks';
31
31
  export var useHistoryWithTotal = function (_a) {
32
- var entityUri = _a.entityUri, _b = _a.enabled, enabled = _b === void 0 ? true : _b, historicUris = _a.historicUris, options = __rest(_a, ["entityUri", "enabled", "historicUris"]);
32
+ var entityUri = _a.entityUri, _b = _a.enabled, enabled = _b === void 0 ? true : _b, historicUris = _a.historicUris, filter = _a.filter, options = __rest(_a, ["entityUri", "enabled", "historicUris", "filter"]);
33
33
  var _c = useState(null), historyWithTotal = _c[0], setHistoryWithTotal = _c[1];
34
34
  var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
35
35
  var safePromise = useSafePromise();
@@ -40,7 +40,7 @@ export var useHistoryWithTotal = function (_a) {
40
40
  var loadData = useCallback(function () {
41
41
  if (entityUri && historicUris) {
42
42
  setIsLoading(true);
43
- safePromise(getHistoryWithTotal(__assign({ entityUri: entityUri, historicUris: historicUris }, options)))
43
+ safePromise(getHistoryWithTotal(__assign({ entityUri: entityUri, historicUris: historicUris, filter: filter }, options)))
44
44
  .then(function (results) {
45
45
  setHistoryWithTotal(results);
46
46
  })
@@ -52,11 +52,11 @@ export var useHistoryWithTotal = function (_a) {
52
52
  else {
53
53
  setHistoryWithTotal(null);
54
54
  }
55
- }, [entityUri, historicUris]);
55
+ }, [entityUri, historicUris, filter]);
56
56
  var loadMore = useCallback(function (offset) {
57
57
  if (entityUri && historicUris) {
58
58
  setIsLoading(true);
59
- safePromise(getHistoryWithTotal(__assign(__assign({ entityUri: entityUri, historicUris: historicUris }, options), { offset: offset })))
59
+ safePromise(getHistoryWithTotal(__assign(__assign({ entityUri: entityUri, historicUris: historicUris, filter: filter }, options), { offset: offset })))
60
60
  .then(function (results) {
61
61
  setHistoryWithTotal(function (prev) { return (__assign(__assign({}, prev), { changes: __spreadArray(__spreadArray([], prev === null || prev === void 0 ? void 0 : prev.changes), results.changes) })); });
62
62
  })
@@ -65,11 +65,11 @@ export var useHistoryWithTotal = function (_a) {
65
65
  setIsLoading(false);
66
66
  });
67
67
  }
68
- }, [entityUri, historicUris]);
68
+ }, [entityUri, historicUris, filter]);
69
69
  useEffect(function () {
70
70
  if (enabled) {
71
71
  loadData();
72
72
  }
73
73
  }, [loadData, enabled]);
74
- return { isLoading: isLoading, historyWithTotal: historyWithTotal, loadMore: loadMore };
74
+ return { isLoading: isLoading, historyWithTotal: historyWithTotal, loadMore: loadMore, loadData: loadData };
75
75
  };
@@ -2,6 +2,7 @@ export { useHistoricUris } from './hooks/useHistoricUris';
2
2
  export { useHistoryWithTotal } from './hooks/useHistoryWithTotal';
3
3
  export { useHistorySlice } from './hooks/useHistorySlice';
4
4
  export { useHistory } from './hooks/useHistory';
5
+ export { useHistoryDiff } from './hooks/useHistoryDiff';
5
6
  export { default as HistoryView } from './HistoryView/HistoryView';
6
7
  export { default as HistoryHeader } from './HistoryHeader/HistoryHeader';
7
8
  export { default as ProfileBandHistory } from './ProfileBandHistory/ProfileBandHistory';
@@ -2,6 +2,7 @@ export { useHistoricUris } from './hooks/useHistoricUris';
2
2
  export { useHistoryWithTotal } from './hooks/useHistoryWithTotal';
3
3
  export { useHistorySlice } from './hooks/useHistorySlice';
4
4
  export { useHistory } from './hooks/useHistory';
5
+ export { useHistoryDiff } from './hooks/useHistoryDiff';
5
6
  export { default as HistoryView } from './HistoryView/HistoryView';
6
7
  export { default as HistoryHeader } from './HistoryHeader/HistoryHeader';
7
8
  export { default as ProfileBandHistory } from './ProfileBandHistory/ProfileBandHistory';
@@ -0,0 +1,3 @@
1
+ import { DateRangeFilter } from '../../../types';
2
+ export declare const buildHistoryFilterString: any;
3
+ export declare const isDateRangeValid: (value: DateRangeFilter) => boolean;
@@ -0,0 +1,60 @@
1
+ import moment from 'moment';
2
+ import { type, pipe, defaultTo, reject, map, join, cond, equals, append, concat, chain, evolve, values, over, lensProp } from 'ramda';
3
+ import { isEmptyValue, escapeQueryValue } from '@reltio/mdm-sdk';
4
+ import { HistoryActivityType } from '../types/HistoryFilter';
5
+ import { ActivityTypes } from '../../activityLog/types/ActivityTypes';
6
+ import { DateRangeTypes } from '../../../types';
7
+ var wrapInBrackets = function (str) { return "(" + str + ")"; };
8
+ var multiValueFilter = function (filterClauseFn) { return pipe(map(filterClauseFn), join(' or ')); };
9
+ var durationToTimestamp = function (period) {
10
+ var amount = period[0], unit = period[1];
11
+ return moment().subtract(amount, unit).valueOf();
12
+ };
13
+ var convertHistoryTypes = chain(cond([
14
+ [
15
+ equals(HistoryActivityType.MERGE),
16
+ function () { return [
17
+ ActivityTypes.ENTITIES_MERGED,
18
+ ActivityTypes.ENTITIES_MERGED_MANUALLY,
19
+ ActivityTypes.ENTITIES_MERGED_ON_THE_FLY
20
+ ]; }
21
+ ],
22
+ [equals(HistoryActivityType.UNMERGE), function () { return [ActivityTypes.ENTITIES_SPLITTED]; }],
23
+ [equals(HistoryActivityType.UPDATE), function () { return [ActivityTypes.ENTITY_CHANGED]; }]
24
+ ]));
25
+ var buildActivityFilterClause = pipe(defaultTo([]), convertHistoryTypes, concat([ActivityTypes.ENTITY_CREATED, ActivityTypes.ENTITY_REMOVED, ActivityTypes.ENTITY_LOST_MERGE]), multiValueFilter(function (value) { return "equals(type, '" + value + "')"; }));
26
+ var buildUserFilterClause = function (user) { return "equals(user, '" + escapeQueryValue(user) + "')"; };
27
+ var buildAttributeFilterClause = function (attribute) { return "changes(" + escapeQueryValue(attribute.value) + ")"; };
28
+ var buildDateRangeFilterClause = function (_a) {
29
+ var type = _a.type, period = _a.period;
30
+ switch (type) {
31
+ case DateRangeTypes.WITHIN: {
32
+ return "gte(timestamp, " + durationToTimestamp(period) + ")";
33
+ }
34
+ case DateRangeTypes.AGO: {
35
+ return "lte(timestamp, " + durationToTimestamp(period) + ")";
36
+ }
37
+ case DateRangeTypes.BETWEEN: {
38
+ var start = period[0], end = period[1];
39
+ return "gte(timestamp, " + start.valueOf() + ") and lte(timestamp, " + moment(end).endOf('date').valueOf() + ")";
40
+ }
41
+ default: {
42
+ return '';
43
+ }
44
+ }
45
+ };
46
+ export var buildHistoryFilterString = pipe(defaultTo({}), reject(isEmptyValue), evolve({
47
+ users: multiValueFilter(buildUserFilterClause),
48
+ attributes: multiValueFilter(buildAttributeFilterClause),
49
+ dateRange: buildDateRangeFilterClause
50
+ }), over(lensProp('activities'), buildActivityFilterClause), values, reject(isEmptyValue), append("not equals(user, 'collaboration-service')"), map(wrapInBrackets), join(' and '));
51
+ export var isDateRangeValid = function (value) {
52
+ if (value.type === DateRangeTypes.AGO || value.type === DateRangeTypes.WITHIN) {
53
+ var _a = value.period, amount = _a[0], unit = _a[1];
54
+ return type(amount) === 'Number' && type(unit) === 'String' && amount > 0;
55
+ }
56
+ else if (value.type === DateRangeTypes.BETWEEN) {
57
+ var _b = value.period, startDate = _b[0], endDate = _b[1];
58
+ return startDate instanceof Date && endDate instanceof Date;
59
+ }
60
+ };
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  export var HistoryDiffContext = React.createContext({
3
3
  appearance: undefined,
4
- attributes: undefined
4
+ attributes: undefined,
5
+ roles: undefined,
6
+ tags: undefined
5
7
  });
6
8
  HistoryDiffContext.displayName = 'HistoryDiffContext';
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.914",
3
+ "version": "1.4.918",
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.914",
11
- "@reltio/mdm-sdk": "^1.4.914",
10
+ "@reltio/mdm-module": "^1.4.918",
11
+ "@reltio/mdm-sdk": "^1.4.918",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",