@reltio/interactions 1.4.1584 → 1.4.1586-mui5

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 (51) hide show
  1. package/index.ts +1 -0
  2. package/package.json +38 -21
  3. package/public/bundle.js +205 -0
  4. package/public/bundle.js.LICENSE.txt +79 -0
  5. package/public/package.json +22 -0
  6. package/scripts/build/index.js +20 -0
  7. package/src/InteractionsTableView/InteractionsTable/InteractionsTable.tsx +87 -0
  8. package/src/InteractionsTableView/InteractionsTable/__tests__/InteractionsTable.test.js +146 -0
  9. package/src/InteractionsTableView/InteractionsTable/cell-renderers/ActorsRenderer.js +57 -0
  10. package/src/InteractionsTableView/InteractionsTable/cell-renderers/AttributesRenderer.js +50 -0
  11. package/src/InteractionsTableView/InteractionsTable/cell-renderers/BlobRenderer.js +14 -0
  12. package/src/InteractionsTableView/InteractionsTable/cell-renderers/DefaultCellValueRenderer.js +22 -0
  13. package/src/InteractionsTableView/InteractionsTable/cell-renderers/HeadCellRenderer.js +16 -0
  14. package/src/InteractionsTableView/InteractionsTable/cell-renderers/LinkRenderer.js +22 -0
  15. package/src/InteractionsTableView/InteractionsTable/cell-renderers/RowCellRenderer.js +31 -0
  16. package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/ActorsRenderer.test.js +87 -0
  17. package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/AttributesRenderer.test.js +118 -0
  18. package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/DefaultCellValueRenderer.test.js +23 -0
  19. package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/LinkRenderer.test.js +20 -0
  20. package/src/InteractionsTableView/InteractionsTable/cell-renderers/__tests__/RowCellRenderer.test.js +53 -0
  21. package/src/InteractionsTableView/InteractionsTable/cell-renderers/styles.js +67 -0
  22. package/src/InteractionsTableView/InteractionsTable/helpers/__tests__/dataHelpers.spec.js +286 -0
  23. package/src/InteractionsTableView/InteractionsTable/helpers/dataHelpers.ts +120 -0
  24. package/src/InteractionsTableView/InteractionsTable/styles.ts +29 -0
  25. package/src/InteractionsTableView/InteractionsTableHeader/InteractionTypeSelector/InteractionTypeSelector.tsx +26 -0
  26. package/src/InteractionsTableView/InteractionsTableHeader/InteractionTypeSelector/__tests__/InteractionTypeSelector.test.js +34 -0
  27. package/src/InteractionsTableView/InteractionsTableHeader/InteractionsTableHeader.js +76 -0
  28. package/src/InteractionsTableView/InteractionsTableHeader/__tests__/InteractionsTableHeader.test.js +106 -0
  29. package/src/InteractionsTableView/InteractionsTableHeader/styles.js +21 -0
  30. package/src/InteractionsTableView/__tests__/InteractionsTableView.test.js +570 -0
  31. package/src/InteractionsTableView/__tests__/stateReducer.test.js +260 -0
  32. package/src/InteractionsTableView/helpers/__tests__/filtersHelper.test.js +221 -0
  33. package/src/InteractionsTableView/helpers/__tests__/tableHelper.test.js +300 -0
  34. package/src/InteractionsTableView/helpers/filtersHelpers.ts +18 -0
  35. package/src/InteractionsTableView/helpers/tableHelpers.ts +157 -0
  36. package/src/InteractionsTableView/hooks/useInteractions.ts +45 -0
  37. package/src/InteractionsTableView/index.tsx +200 -0
  38. package/src/InteractionsTableView/stateReducer.ts +132 -0
  39. package/src/InteractionsTableView/styles.ts +18 -0
  40. package/src/InteractionsTableView/types/index.ts +8 -0
  41. package/src/index.tsx +59 -0
  42. package/stories/Interactions.stories.js +31 -0
  43. package/stories/utils/entity.js +11 -0
  44. package/stories/utils/interactions.js +837 -0
  45. package/stories/utils/interactionsViewConfig.js +6 -0
  46. package/stories/utils/mdmStore.js +28 -0
  47. package/stories/utils/metadata.js +7221 -0
  48. package/tsconfig.json +4 -0
  49. package/webpack.config.js +10 -0
  50. package/bundle.js +0 -2
  51. package/bundle.js.LICENSE.txt +0 -36
@@ -0,0 +1,200 @@
1
+ import React, {useCallback, useEffect, useMemo, useReducer, useRef} from 'react';
2
+ import {useSelector} from 'react-redux';
3
+
4
+ import {
5
+ BasicTablePagination,
6
+ BasicView,
7
+ LinearLoadIndicator,
8
+ useActions,
9
+ useDidUpdateEffect,
10
+ useSavedStateForEntityType
11
+ } from '@reltio/components';
12
+ import mdmModule from '@reltio/mdm-module';
13
+ import {
14
+ Entity,
15
+ getInteractionType,
16
+ getInteractionTypesForEntityType,
17
+ InteractionsPerspectiveConfig,
18
+ Metadata
19
+ } from '@reltio/mdm-sdk';
20
+ import {pipe, propEq} from 'ramda';
21
+ import {buildInteractionsFilter} from './helpers/filtersHelpers';
22
+ import {DEFAULT_COLUMNS, getColumnsData, getRowsPerPageOptions} from './helpers/tableHelpers';
23
+ import useInteractions from './hooks/useInteractions';
24
+ import InteractionsTable from './InteractionsTable/InteractionsTable';
25
+ import InteractionsTableHeader from './InteractionsTableHeader/InteractionsTableHeader';
26
+ import reducer, {actions} from './stateReducer';
27
+ import {InteractionsSavedState} from './types';
28
+
29
+ import {useStyles} from './styles';
30
+
31
+ const DEFAULT_ROWS_PER_PAGE = 15;
32
+ const DEFAULT_SORT_ORDER = 'desc';
33
+ const [DEFAULT_SORT_FIELD] = DEFAULT_COLUMNS;
34
+
35
+ type Props = {
36
+ config: InteractionsPerspectiveConfig;
37
+ saveState: (state: Record<string, InteractionsSavedState>) => void;
38
+ getSavedState: () => Promise<Record<string, InteractionsSavedState>>;
39
+ };
40
+ const InteractionsTableView = ({config, getSavedState, saveState}: Props) => {
41
+ const entity: Entity = useSelector(mdmModule.selectors.getEntity);
42
+ const metadata: Metadata = useSelector(mdmModule.selectors.getMetadata);
43
+ const styles = useStyles();
44
+
45
+ const initialState = {
46
+ currentInteractionType: null,
47
+ filters: null,
48
+ visibleColumns: DEFAULT_COLUMNS,
49
+ sorting: {
50
+ order: config.sortOrder || DEFAULT_SORT_ORDER,
51
+ field: config.sortColumn || DEFAULT_SORT_FIELD
52
+ },
53
+ page: 0,
54
+ rowsPerPage: config.max || DEFAULT_ROWS_PER_PAGE,
55
+ stateToSave: null,
56
+ entityTypeOfAppliedSavedState: null,
57
+ visibleColumnsForInteractionTypes: {}
58
+ };
59
+
60
+ const [state, dispatch] = useReducer(reducer, initialState);
61
+ const {
62
+ visibleColumns,
63
+ filters,
64
+ sorting,
65
+ page,
66
+ rowsPerPage,
67
+ currentInteractionType,
68
+ stateToSave,
69
+ entityTypeOfAppliedSavedState
70
+ } = state;
71
+ const {
72
+ applySavedState,
73
+ saveCurrentState,
74
+ toggleFilters,
75
+ toggleSort,
76
+ changeFilter,
77
+ changeColumns,
78
+ changeInteractionType,
79
+ changePage,
80
+ changeRowsPerPage
81
+ } = useActions({actions, dispatch});
82
+
83
+ const {uri: entityUri, type: entityType} = entity || {};
84
+
85
+ const isSavedStateApplied = entityTypeOfAppliedSavedState === entityType;
86
+
87
+ const {
88
+ isLoaded: isSavedStateLoaded,
89
+ savedState,
90
+ updateSavedState
91
+ } = useSavedStateForEntityType<InteractionsSavedState>({
92
+ entityTypeUri: entityType,
93
+ getSavedState,
94
+ saveState
95
+ });
96
+
97
+ useEffect(() => {
98
+ if (isSavedStateLoaded) {
99
+ const interactionTypes = getInteractionTypesForEntityType(metadata, entityType);
100
+ const currentInteractionType = savedState?.currentInteractionType;
101
+ const isInteractionTypeExist =
102
+ !currentInteractionType || getInteractionType({interactionTypes}, currentInteractionType);
103
+ const savedStateToApply = isInteractionTypeExist ? savedState : null;
104
+ applySavedState({savedState: savedStateToApply, entityType});
105
+ }
106
+ }, [isSavedStateLoaded, entityType, metadata]); // eslint-disable-line
107
+
108
+ useDidUpdateEffect(() => {
109
+ if (isSavedStateApplied) {
110
+ updateSavedState(stateToSave);
111
+ }
112
+ }, [stateToSave]); // eslint-disable-line
113
+
114
+ const resetPage = () => {
115
+ changePage(0);
116
+ };
117
+ useDidUpdateEffect(resetPage, [entityUri]);
118
+
119
+ const interactionTypes = useMemo(
120
+ () => getInteractionTypesForEntityType(metadata, entityType),
121
+ [entityType, metadata]
122
+ );
123
+
124
+ const allColumnsData = useMemo(
125
+ () => getColumnsData(metadata, config, interactionTypes, currentInteractionType),
126
+ [metadata, config, interactionTypes, currentInteractionType]
127
+ );
128
+
129
+ const visibleColumnsData = useMemo(
130
+ () => visibleColumns.map((id) => allColumnsData.find(propEq('id', id))),
131
+ [visibleColumns, allColumnsData]
132
+ );
133
+
134
+ const filter = useMemo(
135
+ () => buildInteractionsFilter(currentInteractionType, filters, visibleColumnsData),
136
+ [currentInteractionType, filters] //eslint-disable-line
137
+ );
138
+
139
+ const {
140
+ isLoading: isInteractionsLoading,
141
+ interactions,
142
+ total
143
+ } = useInteractions({
144
+ enabled: !!entityUri && isSavedStateApplied,
145
+ entityUri,
146
+ filter,
147
+ sorting,
148
+ rowsPerPage,
149
+ page
150
+ });
151
+
152
+ const rowsPerPageOptions = useMemo(() => getRowsPerPageOptions(initialState.rowsPerPage), []); // eslint-disable-line
153
+
154
+ const isLoading = !isSavedStateApplied || isInteractionsLoading;
155
+
156
+ const handleFilterChange = useCallback(pipe(changeFilter, saveCurrentState), [changeFilter, saveCurrentState]);
157
+
158
+ const basicTableRef = useRef(null);
159
+
160
+ return (
161
+ <BasicView className={styles.basicView}>
162
+ <InteractionsTableHeader
163
+ title={config.caption}
164
+ total={total}
165
+ columnsData={allColumnsData}
166
+ selectedColumns={visibleColumns}
167
+ onChangeColumns={pipe(changeColumns, saveCurrentState)}
168
+ filtersEnabled={!!filters}
169
+ onToggleFilters={pipe(toggleFilters, saveCurrentState)}
170
+ interactionTypes={interactionTypes}
171
+ currentInteractionType={currentInteractionType}
172
+ onInteractionTypeChange={pipe(changeInteractionType, saveCurrentState)}
173
+ />
174
+ <div className={styles.tableView}>
175
+ <InteractionsTable
176
+ columnsData={visibleColumnsData}
177
+ interactions={interactions}
178
+ metadata={metadata}
179
+ filters={filters}
180
+ onFilter={handleFilterChange}
181
+ sorting={sorting}
182
+ onSort={pipe(toggleSort, saveCurrentState)}
183
+ basicTableRef={basicTableRef}
184
+ />
185
+ <BasicTablePagination
186
+ count={total}
187
+ rowsPerPageOptions={rowsPerPageOptions}
188
+ rowsPerPage={rowsPerPage}
189
+ onChangeRowsPerPage={changeRowsPerPage}
190
+ page={page}
191
+ onChangePage={changePage}
192
+ basicTableRef={basicTableRef}
193
+ />
194
+ {isLoading && <LinearLoadIndicator />}
195
+ </div>
196
+ </BasicView>
197
+ );
198
+ };
199
+
200
+ export default InteractionsTableView;
@@ -0,0 +1,132 @@
1
+ import {
2
+ always,
3
+ assoc,
4
+ concat,
5
+ dissoc,
6
+ either,
7
+ evolve,
8
+ ifElse,
9
+ intersection,
10
+ path,
11
+ pick,
12
+ pipe,
13
+ prop,
14
+ propOr,
15
+ when,
16
+ without,
17
+ unless,
18
+ isNil,
19
+ filter
20
+ } from 'ramda';
21
+ import {ACTORS_COLUMN_ID, ALL_TYPES_COLUMNS, DEFAULT_COLUMNS} from './helpers/tableHelpers';
22
+ import {basicTableViewState, createStandardAction, Sorting} from '@reltio/components';
23
+ import {SearchFilter, validateFilterValue} from '@reltio/mdm-sdk';
24
+ import {InteractionsSavedState} from './types';
25
+
26
+ const CHANGE_INTERACTION_TYPE = 'CHANGE_INTERACTION_TYPE';
27
+ const APPLY_SAVED_STATE = 'APPLY_SAVED_STATE';
28
+ const SAVE_CURRENT_STATE = 'SAVE_CURRENT_STATE';
29
+
30
+ const actions = {
31
+ ...basicTableViewState.actions,
32
+ changeInteractionType: createStandardAction(CHANGE_INTERACTION_TYPE),
33
+ applySavedState: createStandardAction(APPLY_SAVED_STATE),
34
+ saveCurrentState: createStandardAction(SAVE_CURRENT_STATE)
35
+ };
36
+
37
+ const resetActorsColumnFilters = evolve({
38
+ filters: when(prop(ACTORS_COLUMN_ID), dissoc(ACTORS_COLUMN_ID))
39
+ });
40
+
41
+ const resetPageNumber = assoc('page', 0);
42
+
43
+ const getDefaultVisibleColumnsForCurrentInteractionType = (state) =>
44
+ pipe(
45
+ prop('visibleColumns'),
46
+ ifElse(always(state.currentInteractionType), without(ALL_TYPES_COLUMNS), concat(ALL_TYPES_COLUMNS)),
47
+ intersection(DEFAULT_COLUMNS)
48
+ )(state);
49
+
50
+ const getSavedVisibleColumnsForCurrentInteractionType = (state) =>
51
+ path(['visibleColumnsForInteractionTypes', `${state.currentInteractionType}`], state);
52
+
53
+ const changeVisibleColumnsForCurrentInteractionType = (state) => {
54
+ const nextVisibleColumns = either(
55
+ getSavedVisibleColumnsForCurrentInteractionType,
56
+ getDefaultVisibleColumnsForCurrentInteractionType
57
+ )(state);
58
+ return basicTableViewState.changeVisibleColumns(state, nextVisibleColumns);
59
+ };
60
+
61
+ const getVisibleColumnsFromSavedState = either(getSavedVisibleColumnsForCurrentInteractionType, prop('visibleColumns'));
62
+ const getFiltersFromSavedState = pipe(
63
+ propOr(null, 'filters'),
64
+ unless(
65
+ isNil,
66
+ filter(({filter, value}) => validateFilterValue(filter, value))
67
+ )
68
+ );
69
+
70
+ const saveVisibleColumnsForCurrentInteractionType = (state) => {
71
+ const {currentInteractionType, visibleColumns} = state;
72
+ return evolve(
73
+ {
74
+ visibleColumnsForInteractionTypes: assoc(`${currentInteractionType}`, visibleColumns)
75
+ },
76
+ state
77
+ );
78
+ };
79
+
80
+ const getStateToSave = pipe(
81
+ saveVisibleColumnsForCurrentInteractionType,
82
+ pick(['currentInteractionType', 'visibleColumnsForInteractionTypes', 'filters', 'sorting'])
83
+ );
84
+
85
+ type InitialState = {
86
+ currentInteractionType?: string;
87
+ filters: SearchFilter[];
88
+ visibleColumns: string[];
89
+ sorting: Sorting;
90
+ page: number;
91
+ rowsPerPage: number;
92
+ saveToState?: InteractionsSavedState;
93
+ entityTypeOfAppliedSavedState?: string;
94
+ visibleColumnsForInteractionTypes: Record<string, string[]>;
95
+ };
96
+
97
+ const reducer = (state: InitialState, action) => {
98
+ switch (action.type) {
99
+ case CHANGE_INTERACTION_TYPE: {
100
+ const nextInteractionType = action.payload;
101
+ return pipe(
102
+ saveVisibleColumnsForCurrentInteractionType,
103
+ assoc('currentInteractionType', nextInteractionType),
104
+ changeVisibleColumnsForCurrentInteractionType,
105
+ resetActorsColumnFilters,
106
+ resetPageNumber
107
+ )(state);
108
+ }
109
+ case APPLY_SAVED_STATE: {
110
+ const {savedState, entityType} = action.payload;
111
+ const visibleColumns = savedState ? getVisibleColumnsFromSavedState(savedState) : state.visibleColumns;
112
+ const filters = savedState ? getFiltersFromSavedState(savedState) : state.filters;
113
+ return {
114
+ ...state,
115
+ ...savedState,
116
+ filters,
117
+ visibleColumns,
118
+ entityTypeOfAppliedSavedState: entityType
119
+ };
120
+ }
121
+ case SAVE_CURRENT_STATE: {
122
+ return {
123
+ ...state,
124
+ stateToSave: getStateToSave(state)
125
+ };
126
+ }
127
+ default:
128
+ return basicTableViewState.reducer(state, action);
129
+ }
130
+ };
131
+
132
+ export {reducer as default, actions};
@@ -0,0 +1,18 @@
1
+ import {makeStyles} from '@mui/styles';
2
+
3
+ export const useStyles = makeStyles((_) => ({
4
+ basicView: {
5
+ position: 'absolute',
6
+ top: 0,
7
+ bottom: 0,
8
+ left: 0,
9
+ right: 0,
10
+ boxShadow: 'none'
11
+ },
12
+ tableView: {
13
+ position: 'relative',
14
+ flex: 1,
15
+ display: 'flex',
16
+ flexDirection: 'column'
17
+ }
18
+ }));
@@ -0,0 +1,8 @@
1
+ import {ColumnFilter, Sorting} from '@reltio/components';
2
+
3
+ export type InteractionsSavedState = {
4
+ currentInteractionType: string;
5
+ visibleColumnsForInteractionTypes: Record<string, string[]>;
6
+ filters: ColumnFilter[];
7
+ sorting: Sorting;
8
+ };
package/src/index.tsx ADDED
@@ -0,0 +1,59 @@
1
+ import React, {useCallback} from 'react';
2
+ import {AdapterMoment} from '@mui/x-date-pickers/AdapterMoment';
3
+ import createGenerateClassName from '@mui/styles/createGenerateClassName';
4
+ import StylesProvider from '@mui/styles/StylesProvider';
5
+ import ReactResizeDetector from 'react-resize-detector';
6
+ import {Store} from 'redux';
7
+ import {LocalizationProvider} from '@mui/x-date-pickers/LocalizationProvider';
8
+ import {ErrorPopup, ViewIdContext} from '@reltio/components';
9
+ import {InteractionsPerspectiveConfig, promisifyCallback} from '@reltio/mdm-sdk';
10
+ import {identity} from 'ramda';
11
+ import {Provider} from 'react-redux';
12
+ import InteractionsTableView from './InteractionsTableView';
13
+ import {InteractionsSavedState} from './InteractionsTableView/types';
14
+
15
+ const generateClassName = createGenerateClassName({
16
+ productionPrefix: 'interactionTable',
17
+ disableGlobal: true,
18
+ seed: 'intr'
19
+ });
20
+
21
+ type Props = {
22
+ config: InteractionsPerspectiveConfig;
23
+ store: Store<unknown>;
24
+ onResize?: (width: number, height: number) => void;
25
+ saveState: (state: Record<string, InteractionsSavedState>) => void;
26
+ getSavedState: () => Record<string, InteractionsSavedState>;
27
+ };
28
+
29
+ const InteractionsView = ({config, store, onResize = identity, saveState, getSavedState}: Props) => {
30
+ const getSavedStatePromisified: () => Promise<Record<string, InteractionsSavedState>> = useCallback(
31
+ promisifyCallback(getSavedState),
32
+ [getSavedState]
33
+ );
34
+
35
+ return (
36
+ <Provider store={store}>
37
+ <ViewIdContext.Provider value={config.id}>
38
+ <StylesProvider generateClassName={generateClassName}>
39
+ <LocalizationProvider dateAdapter={AdapterMoment}>
40
+ <ReactResizeDetector
41
+ handleHeight
42
+ onResize={(width, height) => onResize(Math.floor(width), Math.floor(height))}
43
+ />
44
+ {config && (
45
+ <InteractionsTableView
46
+ config={config}
47
+ saveState={saveState}
48
+ getSavedState={getSavedStatePromisified}
49
+ />
50
+ )}
51
+ <ErrorPopup />
52
+ </LocalizationProvider>
53
+ </StylesProvider>
54
+ </ViewIdContext.Provider>
55
+ </Provider>
56
+ );
57
+ };
58
+
59
+ export default InteractionsView;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import InteractionsView from '../src/';
3
+ import mdmStore from './utils/mdmStore';
4
+ import interactionsViewConfig from './utils/interactionsViewConfig';
5
+ import interactionResponse from './utils/interactions';
6
+ import {createTheme, ThemeProvider, StyledEngineProvider} from '@mui/material/styles';
7
+ import {storiesOf} from '@storybook/react';
8
+ import {setRequestProvider, theme} from '@reltio/mdm-sdk';
9
+
10
+ const muiTheme = createTheme(theme);
11
+
12
+ const request = () => Promise.resolve({});
13
+
14
+ setRequestProvider(request);
15
+
16
+ storiesOf('InteractionsView', module).add('test', () => {
17
+ const request = () => Promise.resolve(interactionResponse);
18
+ setRequestProvider(request);
19
+ return (
20
+ <StyledEngineProvider injectFirst>
21
+ <ThemeProvider theme={muiTheme}>
22
+ <InteractionsView
23
+ config={interactionsViewConfig}
24
+ store={mdmStore}
25
+ saveState={() => {}}
26
+ getSavedState={(resolve) => resolve()}
27
+ />
28
+ </ThemeProvider>
29
+ </StyledEngineProvider>
30
+ );
31
+ });
@@ -0,0 +1,11 @@
1
+ export default {
2
+ uri: 'entities/369r06C',
3
+ type: 'configuration/entityTypes/Tenant',
4
+ createdBy: 'test',
5
+ createdTime: 1486575286175,
6
+ updatedBy: 'sfdc.connector.reltio360',
7
+ updatedTime: 1543530347506,
8
+ attributes: {},
9
+ label: 'Test',
10
+ secondaryLabel: ''
11
+ };