@reltio/dashboard 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.
- package/.DS_Store +0 -0
- package/index.ts +12 -0
- package/package.json +42 -25
- package/public/bundle.js +205 -0
- package/public/bundle.js.LICENSE.txt +59 -0
- package/public/package.json +26 -0
- package/public/types/components/DashboardConfigItem/styles.d.ts +1 -0
- package/{types → public/types}/components/DashboardError/styles.d.ts +1 -1
- package/public/types/components/DashboardLayout/styles.d.ts +1 -0
- package/public/types/components/DashboardLayoutItem/styles.d.ts +1 -0
- package/public/types/components/DashboardLayoutPanel/styles.d.ts +1 -0
- package/public/types/components/DashboardLinearLoader/styles.d.ts +1 -0
- package/{types → public/types}/components/DashboardNoData/styles.d.ts +1 -1
- package/public/types/components/DashboardPerspectiveHeader/styles.d.ts +2 -0
- package/{types → public/types}/components/DashboardPopupMenu/DashboardPopupMenu.d.ts +1 -1
- package/public/types/components/DashboardPopupMenu/styles.d.ts +1 -0
- package/public/types/components/EntityTable/cell-renderers/styles.d.ts +1 -0
- package/{types → public/types}/components/EntityTable/styles.d.ts +1 -1
- package/public/types/components/LayoutItemContent/styles.d.ts +1 -0
- package/public/types/components/LayoutItemHeader/styles.d.ts +1 -0
- package/public/types/components/LayoutItemView/styles.d.ts +1 -0
- package/public/types/components/StatsChart/customized/styles.d.ts +1 -0
- package/public/types/components/WorkflowTaskItem/styles.d.ts +1 -0
- package/public/types/perspective/styles.d.ts +1 -0
- package/public/types/views/chartBased/styles.d.ts +1 -0
- package/public/types/views/custom/styles.d.ts +1 -0
- package/public/types/views/tableBased/styles.d.ts +1 -0
- package/scripts/build/index.js +21 -0
- package/src/HOCs/withPagination.tsx +39 -0
- package/src/components/DashboardConfigItem/DashboardConfigItem.tsx +101 -0
- package/src/components/DashboardConfigItem/__tests__/DashboardConfigItem.specs.tsx +81 -0
- package/src/components/DashboardConfigItem/icons/barChart.svg +12 -0
- package/src/components/DashboardConfigItem/icons/bubbleChart.svg +18 -0
- package/src/components/DashboardConfigItem/icons/customChart.svg +66 -0
- package/src/components/DashboardConfigItem/icons/donutChart.svg +33 -0
- package/src/components/DashboardConfigItem/icons/geomap.svg +23 -0
- package/src/components/DashboardConfigItem/icons/lineChart.svg +16 -0
- package/src/components/DashboardConfigItem/icons/pieChart.svg +27 -0
- package/src/components/DashboardConfigItem/icons/tableWithBars.svg +27 -0
- package/src/components/DashboardConfigItem/icons/treemap.svg +15 -0
- package/src/components/DashboardConfigItem/icons/wordCloud.svg +27 -0
- package/src/components/DashboardConfigItem/styles.ts +56 -0
- package/src/components/DashboardError/DashboardError.tsx +34 -0
- package/src/components/DashboardError/__tests__/DashboardError.test.js +34 -0
- package/src/components/DashboardError/icons/error.svg +113 -0
- package/src/components/DashboardError/styles.ts +30 -0
- package/src/components/DashboardLayout/DashboardLayout.tsx +59 -0
- package/src/components/DashboardLayout/__tests__/DashboardLayout.specs.tsx +56 -0
- package/src/components/DashboardLayout/styles.ts +30 -0
- package/src/components/DashboardLayoutItem/DashboardLayoutItem.tsx +59 -0
- package/src/components/DashboardLayoutItem/__tests__/DashboardLayoutItem.specs.tsx +145 -0
- package/src/components/DashboardLayoutItem/styles.ts +10 -0
- package/src/components/DashboardLayoutPanel/DashboardLayoutPanel.tsx +59 -0
- package/src/components/DashboardLayoutPanel/__tests__/DashboardLayoutPanel.specs.tsx +58 -0
- package/src/components/DashboardLayoutPanel/styles.ts +43 -0
- package/src/components/DashboardLinearLoader/DashboardLinearLoader.tsx +10 -0
- package/src/components/DashboardLinearLoader/__tests__/DashboardLinearLoader.test.js +12 -0
- package/src/components/DashboardLinearLoader/styles.ts +11 -0
- package/src/components/DashboardNoData/.DS_Store +0 -0
- package/src/components/DashboardNoData/DashboardNoData.tsx +21 -0
- package/src/components/DashboardNoData/__tests__/DashboardNoData.test.js +15 -0
- package/src/components/DashboardNoData/icons/noData.svg +68 -0
- package/src/components/DashboardNoData/styles.ts +21 -0
- package/src/components/DashboardPerspectiveHeader/DashboardPerspectiveHeader.tsx +43 -0
- package/src/components/DashboardPerspectiveHeader/__tests__/DashboardPerspectiveHeader.specs.tsx +41 -0
- package/src/components/DashboardPerspectiveHeader/styles.ts +24 -0
- package/src/components/DashboardPopupMenu/DashboardPopupMenu.tsx +75 -0
- package/src/components/DashboardPopupMenu/__tests__/DashboardPopupMenu.test.tsx +51 -0
- package/src/components/DashboardPopupMenu/styles.ts +20 -0
- package/src/components/EntityTable/EntityTable.tsx +49 -0
- package/src/components/EntityTable/__tests__/EntityTable.test.tsx +33 -0
- package/src/components/EntityTable/cell-renderers/EntityLabelRenderer.tsx +24 -0
- package/src/components/EntityTable/cell-renderers/HeadCellRenderer.tsx +34 -0
- package/src/components/EntityTable/cell-renderers/__tests__/EntityLabelRenderer.test.tsx +25 -0
- package/src/components/EntityTable/cell-renderers/styles.ts +46 -0
- package/src/components/EntityTable/styles.ts +19 -0
- package/src/components/LayoutItemContent/LayoutItemContent.tsx +63 -0
- package/src/components/LayoutItemContent/__tests__/LayoutItemContent.test.tsx +71 -0
- package/src/components/LayoutItemContent/styles.ts +36 -0
- package/src/components/LayoutItemHeader/LayoutItemHeader.tsx +86 -0
- package/src/components/LayoutItemHeader/__tests__/LayoutItemHeader.specs.tsx +48 -0
- package/src/components/LayoutItemHeader/styles.ts +44 -0
- package/src/components/LayoutItemView/LayoutItemView.tsx +24 -0
- package/src/components/LayoutItemView/styles.ts +11 -0
- package/src/components/StatsChart/StatsChart.tsx +77 -0
- package/src/components/StatsChart/__tests__/StatsChart.test.tsx +106 -0
- package/src/components/StatsChart/customized/CustomAxisTick.tsx +28 -0
- package/src/components/StatsChart/customized/CustomLegend.tsx +37 -0
- package/src/components/StatsChart/customized/CustomTooltip.tsx +41 -0
- package/src/components/StatsChart/customized/styles.ts +53 -0
- package/src/components/StatsChart/getStatsChartSettings.ts +65 -0
- package/src/components/WorkflowTaskItem/WorkflowTaskItem.tsx +67 -0
- package/src/components/WorkflowTaskItem/WorkflowTaskObject.tsx +54 -0
- package/src/components/WorkflowTaskItem/__tests__/WorkflowTaskItem.test.tsx +73 -0
- package/src/components/WorkflowTaskItem/__tests__/WorkflowTaskObject.test.tsx +95 -0
- package/src/components/WorkflowTaskItem/styles.ts +74 -0
- package/src/components/WorkflowTasksList/WorkflowTasksList.tsx +34 -0
- package/src/components/WorkflowTasksList/__tests__/WorkflowTasksList.test.tsx +98 -0
- package/src/components/index.ts +8 -0
- package/src/contexts/DashboardViewIdContext/index.ts +5 -0
- package/src/hooks/__tests__/useActivititesRequest.specs.tsx +106 -0
- package/src/hooks/__tests__/useEntityByTypeRequest.specs.tsx +280 -0
- package/src/hooks/__tests__/useFacetRequest.specs.tsx +437 -0
- package/src/hooks/__tests__/useFilteredEntitiesRequest.specs.tsx +103 -0
- package/src/hooks/__tests__/useSavedSearchesRequest.specs.tsx +201 -0
- package/src/hooks/__tests__/useStatsRequest.specs.tsx +212 -0
- package/src/hooks/__tests__/useWorkflowTasksRequest.specs.tsx +388 -0
- package/src/hooks/useActivitiesRequest.ts +50 -0
- package/src/hooks/useEntityByTypeRequest.ts +67 -0
- package/src/hooks/useFacetRequest.ts +117 -0
- package/src/hooks/useFilteredEntitiesRequest.ts +57 -0
- package/src/hooks/useSavedSearchesRequest.ts +82 -0
- package/src/hooks/useStatsRequest.ts +47 -0
- package/src/hooks/useWorkflowTasksRequest.ts +66 -0
- package/src/index.ts +25 -0
- package/src/perspective/DashboardPerspectiveView.tsx +132 -0
- package/src/perspective/__tests__/DashboardPerspectiveView.specs.tsx +276 -0
- package/src/perspective/__tests__/data/metadata.data.ts +33 -0
- package/src/perspective/__tests__/data/store.data.ts +15 -0
- package/src/perspective/__tests__/helpers.specs.ts +33 -0
- package/src/perspective/helpers.ts +19 -0
- package/src/perspective/index.tsx +65 -0
- package/src/perspective/styles.ts +16 -0
- package/src/services/__tests__/facets.specs.ts +42 -0
- package/src/services/__tests__/filters.specs.ts +60 -0
- package/src/services/__tests__/period.test.ts +33 -0
- package/src/services/__tests__/stats.test.ts +319 -0
- package/src/services/entityTypes.ts +66 -0
- package/src/services/facets.ts +178 -0
- package/src/services/filters.ts +87 -0
- package/src/services/period.ts +33 -0
- package/src/services/savedSearches.ts +20 -0
- package/src/services/stats.ts +191 -0
- package/src/services/workflowTasks.ts +116 -0
- package/src/types/ActivitiesViewFacetConfig.ts +5 -0
- package/src/types/CustomActionViewFacetConfig.ts +5 -0
- package/src/types/DashboardPerspectiveConfig.ts +18 -0
- package/src/types/DashboardSavedState.ts +7 -0
- package/src/types/EntityByTypeViewFacetConfig.ts +7 -0
- package/src/types/EntityData.ts +4 -0
- package/src/types/FilteredEntitiesFacetConfig.ts +6 -0
- package/src/types/FilteredSavedSearchesFacetConfig.ts +6 -0
- package/src/types/PeriodStep.ts +4 -0
- package/src/types/SavedSearchData.ts +6 -0
- package/src/types/SearchOptions.ts +10 -0
- package/src/types/StatsData.ts +14 -0
- package/src/types/WorkflowTasks.ts +26 -0
- package/src/types/index.ts +14 -0
- package/src/views/ViewsFactory.tsx +79 -0
- package/src/views/__tests__/ViewsFactory.specs.tsx +70 -0
- package/src/views/chartBased/DashboardFacet.tsx +71 -0
- package/src/views/chartBased/EntitiesByTypeViewFacet.tsx +60 -0
- package/src/views/chartBased/ProfileStatsFacet.tsx +54 -0
- package/src/views/chartBased/__tests__/DashboardFacet.specs.tsx +358 -0
- package/src/views/chartBased/__tests__/EntitiesByTypeViewFacet.specs.tsx +101 -0
- package/src/views/chartBased/__tests__/ProfileStatsFacet.specs.tsx +106 -0
- package/src/views/chartBased/styles.ts +13 -0
- package/src/views/custom/CustomActionViewFacet.tsx +36 -0
- package/src/views/custom/NotificationInboxFacet.tsx +86 -0
- package/src/views/custom/__tests__/CustomActionViewFacet.specs.tsx +35 -0
- package/src/views/custom/__tests__/NotificationInboxFacet.specs.tsx +144 -0
- package/src/views/custom/styles.ts +31 -0
- package/src/views/tableBased/ActivitiesViewFacet.tsx +79 -0
- package/src/views/tableBased/FilteredEntitiesViewFacet.tsx +67 -0
- package/src/views/tableBased/FilteredSavedSearchesFacet.tsx +85 -0
- package/src/views/tableBased/__tests__/ActivitiesViewFacet.specs.tsx +113 -0
- package/src/views/tableBased/__tests__/FIlteredEntitiesViewFacet.specs.tsx +90 -0
- package/src/views/tableBased/__tests__/FilteredSavedSearchesFacet.specs.tsx +133 -0
- package/src/views/tableBased/helpers.ts +8 -0
- package/src/views/tableBased/styles.ts +7 -0
- package/stories/Dashboards.stories.js +118 -0
- package/stories/utils/dashboardPerspectiveConfig.js +78 -0
- package/stories/utils/dashboardsViewConfig.js +17 -0
- package/stories/utils/mdmStore.js +73 -0
- package/stories/utils/responses.js +10 -0
- package/tsconfig.json +14 -0
- package/webpack.config.js +10 -0
- package/bundle.js +0 -2
- package/bundle.js.LICENSE.txt +0 -22
- package/types/components/DashboardConfigItem/styles.d.ts +0 -1
- package/types/components/DashboardLayout/styles.d.ts +0 -1
- package/types/components/DashboardLayoutItem/styles.d.ts +0 -1
- package/types/components/DashboardLayoutPanel/styles.d.ts +0 -1
- package/types/components/DashboardLinearLoader/styles.d.ts +0 -1
- package/types/components/DashboardPerspectiveHeader/styles.d.ts +0 -2
- package/types/components/DashboardPopupMenu/styles.d.ts +0 -1
- package/types/components/EntityTable/cell-renderers/styles.d.ts +0 -1
- package/types/components/LayoutItemContent/styles.d.ts +0 -1
- package/types/components/LayoutItemHeader/styles.d.ts +0 -1
- package/types/components/LayoutItemView/styles.d.ts +0 -1
- package/types/components/StatsChart/customized/styles.d.ts +0 -1
- package/types/components/WorkflowTaskItem/styles.d.ts +0 -1
- package/types/perspective/styles.d.ts +0 -1
- package/types/views/chartBased/styles.d.ts +0 -1
- package/types/views/custom/styles.d.ts +0 -1
- package/types/views/tableBased/styles.d.ts +0 -1
- /package/{types → public/types}/HOCs/withPagination.d.ts +0 -0
- /package/{types → public/types}/components/DashboardConfigItem/DashboardConfigItem.d.ts +0 -0
- /package/{types → public/types}/components/DashboardError/DashboardError.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLayout/DashboardLayout.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLayoutItem/DashboardLayoutItem.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLayoutPanel/DashboardLayoutPanel.d.ts +0 -0
- /package/{types → public/types}/components/DashboardLinearLoader/DashboardLinearLoader.d.ts +0 -0
- /package/{types → public/types}/components/DashboardNoData/DashboardNoData.d.ts +0 -0
- /package/{types → public/types}/components/DashboardPerspectiveHeader/DashboardPerspectiveHeader.d.ts +0 -0
- /package/{types → public/types}/components/EntityTable/EntityTable.d.ts +0 -0
- /package/{types → public/types}/components/EntityTable/cell-renderers/EntityLabelRenderer.d.ts +0 -0
- /package/{types → public/types}/components/EntityTable/cell-renderers/HeadCellRenderer.d.ts +0 -0
- /package/{types → public/types}/components/LayoutItemContent/LayoutItemContent.d.ts +0 -0
- /package/{types → public/types}/components/LayoutItemHeader/LayoutItemHeader.d.ts +0 -0
- /package/{types → public/types}/components/LayoutItemView/LayoutItemView.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/StatsChart.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/customized/CustomAxisTick.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/customized/CustomLegend.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/customized/CustomTooltip.d.ts +0 -0
- /package/{types → public/types}/components/StatsChart/getStatsChartSettings.d.ts +0 -0
- /package/{types → public/types}/components/WorkflowTaskItem/WorkflowTaskItem.d.ts +0 -0
- /package/{types → public/types}/components/WorkflowTaskItem/WorkflowTaskObject.d.ts +0 -0
- /package/{types → public/types}/components/WorkflowTasksList/WorkflowTasksList.d.ts +0 -0
- /package/{types → public/types}/components/index.d.ts +0 -0
- /package/{types → public/types}/contexts/DashboardViewIdContext/index.d.ts +0 -0
- /package/{types → public/types}/hooks/useActivitiesRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useEntityByTypeRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useFacetRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useFilteredEntitiesRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useSavedSearchesRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useStatsRequest.d.ts +0 -0
- /package/{types → public/types}/hooks/useWorkflowTasksRequest.d.ts +0 -0
- /package/{types → public/types}/index.d.ts +0 -0
- /package/{types → public/types}/perspective/DashboardPerspectiveView.d.ts +0 -0
- /package/{types → public/types}/perspective/helpers.d.ts +0 -0
- /package/{types → public/types}/perspective/index.d.ts +0 -0
- /package/{types → public/types}/services/entityTypes.d.ts +0 -0
- /package/{types → public/types}/services/facets.d.ts +0 -0
- /package/{types → public/types}/services/filters.d.ts +0 -0
- /package/{types → public/types}/services/period.d.ts +0 -0
- /package/{types → public/types}/services/savedSearches.d.ts +0 -0
- /package/{types → public/types}/services/stats.d.ts +0 -0
- /package/{types → public/types}/services/workflowTasks.d.ts +0 -0
- /package/{types → public/types}/types/ActivitiesViewFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/CustomActionViewFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/DashboardPerspectiveConfig.d.ts +0 -0
- /package/{types → public/types}/types/DashboardSavedState.d.ts +0 -0
- /package/{types → public/types}/types/EntityByTypeViewFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/EntityData.d.ts +0 -0
- /package/{types → public/types}/types/FilteredEntitiesFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/FilteredSavedSearchesFacetConfig.d.ts +0 -0
- /package/{types → public/types}/types/PeriodStep.d.ts +0 -0
- /package/{types → public/types}/types/SavedSearchData.d.ts +0 -0
- /package/{types → public/types}/types/SearchOptions.d.ts +0 -0
- /package/{types → public/types}/types/StatsData.d.ts +0 -0
- /package/{types → public/types}/types/WorkflowTasks.d.ts +0 -0
- /package/{types → public/types}/types/index.d.ts +0 -0
- /package/{types → public/types}/views/ViewsFactory.d.ts +0 -0
- /package/{types → public/types}/views/chartBased/DashboardFacet.d.ts +0 -0
- /package/{types → public/types}/views/chartBased/EntitiesByTypeViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/chartBased/ProfileStatsFacet.d.ts +0 -0
- /package/{types → public/types}/views/custom/CustomActionViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/custom/NotificationInboxFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/ActivitiesViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/FilteredEntitiesViewFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/FilteredSavedSearchesFacet.d.ts +0 -0
- /package/{types → public/types}/views/tableBased/helpers.d.ts +0 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {act} from 'react-dom/test-utils';
|
|
3
|
+
import {mount} from 'enzyme';
|
|
4
|
+
import * as mdmSdkModule from '@reltio/mdm-sdk';
|
|
5
|
+
import {useWorkflowTasksRequest} from '../useWorkflowTasksRequest';
|
|
6
|
+
import {WorkflowTasksCategories} from '../../types/WorkflowTasks';
|
|
7
|
+
import {createStore} from 'redux';
|
|
8
|
+
import {Provider} from 'react-redux';
|
|
9
|
+
|
|
10
|
+
jest.mock('@reltio/mdm-sdk', () => ({
|
|
11
|
+
...jest.requireActual<Record<string, unknown>>('@reltio/mdm-sdk'),
|
|
12
|
+
getTasksForTenant: jest.fn(),
|
|
13
|
+
getGroupTasksForTenant: jest.fn(),
|
|
14
|
+
getDataChangeRequest: jest.fn(),
|
|
15
|
+
getEntitiesByUris: jest.fn()
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
options: {
|
|
20
|
+
max?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
tasksCategory: WorkflowTasksCategories;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('useWorkflowTasksRequest behavior', () => {
|
|
27
|
+
const TestComponent = ({options}: Props) => {
|
|
28
|
+
const {state, data, reload} = useWorkflowTasksRequest(options);
|
|
29
|
+
return state ? <div data-test={{state, data, reload}} /> : null;
|
|
30
|
+
};
|
|
31
|
+
const getHooksValues = (component) => component.find('TestComponent').childAt(0).prop('data-test');
|
|
32
|
+
|
|
33
|
+
let initialStore;
|
|
34
|
+
|
|
35
|
+
const createTestStore = () => {
|
|
36
|
+
const reducer = (state = initialStore) => {
|
|
37
|
+
return state;
|
|
38
|
+
};
|
|
39
|
+
return createStore(reducer);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
initialStore = {
|
|
44
|
+
ui: {
|
|
45
|
+
paths: {
|
|
46
|
+
workflowPath: 'workflowPath',
|
|
47
|
+
workflowEnvironmentURL: 'workflowEnvironmentURL'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
tenant: {
|
|
51
|
+
id: 'tenant'
|
|
52
|
+
},
|
|
53
|
+
user: {
|
|
54
|
+
username: 'polina.arsenteva'
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
let resolveTasks;
|
|
60
|
+
|
|
61
|
+
const getTasksForTenantSpy = jest.spyOn(mdmSdkModule, 'getTasksForTenant');
|
|
62
|
+
const getEntitiesByUrisSpy = jest.spyOn(mdmSdkModule, 'getEntitiesByUris');
|
|
63
|
+
const getGroupTasksForTenantSpy = jest.spyOn(mdmSdkModule, 'getGroupTasksForTenant');
|
|
64
|
+
const getDataChangeRequestSpy = jest.spyOn(mdmSdkModule, 'getDataChangeRequest');
|
|
65
|
+
|
|
66
|
+
beforeAll(() => {
|
|
67
|
+
getTasksForTenantSpy.mockImplementation(() => {
|
|
68
|
+
return new Promise((_resolve) => {
|
|
69
|
+
resolveTasks = () =>
|
|
70
|
+
_resolve({
|
|
71
|
+
status: 'ok',
|
|
72
|
+
data: [
|
|
73
|
+
{
|
|
74
|
+
assignee: 'polina.arsenteva',
|
|
75
|
+
objectURIs: ['entities/1fIVXrYH'],
|
|
76
|
+
taskType: 'review',
|
|
77
|
+
taskId: '123',
|
|
78
|
+
createdBy: 'sairam.singireesu@reltio.com',
|
|
79
|
+
priorityClass: 'Medium',
|
|
80
|
+
createTime: 1621534310502,
|
|
81
|
+
dueDate: 1621707110507,
|
|
82
|
+
displayName: 'Delete Review',
|
|
83
|
+
processDefinitionDisplayName: 'Recommend for Delete'
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
total: 1
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
getEntitiesByUrisSpy.mockResolvedValue([
|
|
91
|
+
{
|
|
92
|
+
uri: 'entities/1fIVXrYH',
|
|
93
|
+
type: 'configuration/entityTypes/HCO',
|
|
94
|
+
label: 'Belize',
|
|
95
|
+
secondaryLabel: ''
|
|
96
|
+
}
|
|
97
|
+
]);
|
|
98
|
+
getGroupTasksForTenantSpy.mockImplementation(() => {
|
|
99
|
+
return new Promise((_resolve) => {
|
|
100
|
+
resolveTasks = () =>
|
|
101
|
+
_resolve({
|
|
102
|
+
status: 'ok',
|
|
103
|
+
data: [
|
|
104
|
+
{
|
|
105
|
+
assignee: 'johnconnor1131',
|
|
106
|
+
taskType: 'review',
|
|
107
|
+
taskId: '123',
|
|
108
|
+
objectURIs: ['changeRequests/7ZotlRoP', 'entities/1aAyKH7k'],
|
|
109
|
+
createdBy: 'sairam.singireesu@reltio.com',
|
|
110
|
+
priorityClass: 'Medium',
|
|
111
|
+
createTime: 1620897479535,
|
|
112
|
+
dueDate: 1621070279536,
|
|
113
|
+
displayName: 'DCR Review',
|
|
114
|
+
processDefinitionDisplayName: 'Data Change Request Review'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
assignee: 'marat.ahmetzyanov',
|
|
118
|
+
objectURIs: ['changeRequests/3BlTJj8z', 'entities/1RVnhXSL'],
|
|
119
|
+
createdBy: 'marat.ahmetzyanov',
|
|
120
|
+
priorityClass: 'Medium',
|
|
121
|
+
taskType: 'dcrReview',
|
|
122
|
+
createTime: 1644499067234,
|
|
123
|
+
dueDate: 1644671867234,
|
|
124
|
+
taskId: '30746510',
|
|
125
|
+
displayName: 'DCR Review',
|
|
126
|
+
processDefinitionDisplayName: 'Data Change Request Review'
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
total: 2
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
getDataChangeRequestSpy
|
|
134
|
+
.mockResolvedValueOnce({
|
|
135
|
+
uri: 'changeRequests/7ZotlRoP',
|
|
136
|
+
createdBy: 'sairam.singireesu@reltio.com',
|
|
137
|
+
createdTime: 1620897478450,
|
|
138
|
+
updatedBy: 'sairam.singireesu@reltio.com',
|
|
139
|
+
updatedTime: 1620897478450,
|
|
140
|
+
changes: {
|
|
141
|
+
'entities/1aAyKH7k': [
|
|
142
|
+
{
|
|
143
|
+
id: '7ZotlNY9',
|
|
144
|
+
type: 'UPDATE_TAGS',
|
|
145
|
+
createdTime: 1620897478450,
|
|
146
|
+
createdBy: 'sairam.singireesu@reltio.com',
|
|
147
|
+
newValue: ['lkl']
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
objectsInfo: {
|
|
152
|
+
'entities/1aAyKH7k': {
|
|
153
|
+
type: 'configuration/entityTypes/HCO',
|
|
154
|
+
label: 'Bahrain',
|
|
155
|
+
secondaryLabel: '',
|
|
156
|
+
isExist: true
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
type: 'configuration/changeRequestTypes/default',
|
|
160
|
+
state: 'AWAITING_REVIEW'
|
|
161
|
+
})
|
|
162
|
+
.mockResolvedValueOnce({
|
|
163
|
+
uri: 'changeRequests/3BlTJj8z',
|
|
164
|
+
createdBy: 'marat.ahmetzyanov',
|
|
165
|
+
createdTime: 1644499065831,
|
|
166
|
+
updatedBy: 'marat.ahmetzyanov',
|
|
167
|
+
updatedTime: 1644499065831,
|
|
168
|
+
changes: {
|
|
169
|
+
'entities/1RVnhXSL': [
|
|
170
|
+
{
|
|
171
|
+
id: '3BlTJnPF',
|
|
172
|
+
type: 'CREATE_ENTITY',
|
|
173
|
+
createdTime: 1644499065831,
|
|
174
|
+
createdBy: 'marat.ahmetzyanov',
|
|
175
|
+
newValue: {
|
|
176
|
+
uri: 'entities/1RVnhXSL',
|
|
177
|
+
type: 'configuration/entityTypes/HCPLongName',
|
|
178
|
+
attributes: {
|
|
179
|
+
CountryCode: [
|
|
180
|
+
{
|
|
181
|
+
value: 'Italy',
|
|
182
|
+
lookupCode: 'IT',
|
|
183
|
+
lookupRawValue: 'IT'
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
objectsInfo: {
|
|
192
|
+
'entities/1RVnhXSL': {
|
|
193
|
+
type: 'configuration/entityTypes/HCPLongName',
|
|
194
|
+
label: 'last name',
|
|
195
|
+
secondaryLabel: '',
|
|
196
|
+
isExist: false
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
type: 'configuration/changeRequestTypes/default',
|
|
200
|
+
state: 'AWAITING_REVIEW'
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
afterEach(() => {
|
|
205
|
+
jest.clearAllMocks();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should send request for MY tasks and be in the loading state, and be in loaded state once data is loaded', async () => {
|
|
209
|
+
const store = createTestStore();
|
|
210
|
+
const options = {
|
|
211
|
+
tasksCategory: WorkflowTasksCategories.MY
|
|
212
|
+
};
|
|
213
|
+
const component = mount(
|
|
214
|
+
<Provider store={store}>
|
|
215
|
+
<TestComponent options={options} />
|
|
216
|
+
</Provider>
|
|
217
|
+
);
|
|
218
|
+
expect(getHooksValues(component).state).toBe('loading');
|
|
219
|
+
expect(getHooksValues(component).data).toEqual([]);
|
|
220
|
+
|
|
221
|
+
await act(async () => {
|
|
222
|
+
resolveTasks();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
component.update();
|
|
226
|
+
expect(getHooksValues(component).state).toBe('loaded');
|
|
227
|
+
expect(getHooksValues(component).data).toEqual([
|
|
228
|
+
{
|
|
229
|
+
assignee: 'polina.arsenteva',
|
|
230
|
+
objectURIs: ['entities/1fIVXrYH'],
|
|
231
|
+
createdBy: 'sairam.singireesu@reltio.com',
|
|
232
|
+
priorityClass: 'Medium',
|
|
233
|
+
createTime: 1621534310502,
|
|
234
|
+
dueDate: 1621707110507,
|
|
235
|
+
displayName: 'Delete Review',
|
|
236
|
+
processDefinitionDisplayName: 'Recommend for Delete',
|
|
237
|
+
taskId: '123',
|
|
238
|
+
taskType: 'review',
|
|
239
|
+
objects: [
|
|
240
|
+
{
|
|
241
|
+
uri: 'entities/1fIVXrYH',
|
|
242
|
+
type: 'configuration/entityTypes/HCO',
|
|
243
|
+
label: 'Belize',
|
|
244
|
+
secondaryLabel: ''
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
|
|
250
|
+
expect(getTasksForTenantSpy).toBeCalledWith({
|
|
251
|
+
workflowPath: 'workflowPath',
|
|
252
|
+
environment: 'workflowEnvironmentURL',
|
|
253
|
+
tenant: 'tenant',
|
|
254
|
+
assignee: 'polina.arsenteva'
|
|
255
|
+
});
|
|
256
|
+
expect(getEntitiesByUrisSpy).toBeCalledWith(['entities/1fIVXrYH']);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should send request for TEAM tasks and be in the loading state, and be in loaded state once data is loaded', async () => {
|
|
260
|
+
const store = createTestStore();
|
|
261
|
+
const options = {
|
|
262
|
+
tasksCategory: WorkflowTasksCategories.TEAM
|
|
263
|
+
};
|
|
264
|
+
const component = mount(
|
|
265
|
+
<Provider store={store}>
|
|
266
|
+
<TestComponent options={options} />
|
|
267
|
+
</Provider>
|
|
268
|
+
);
|
|
269
|
+
expect(getHooksValues(component).state).toBe('loading');
|
|
270
|
+
expect(getHooksValues(component).data).toEqual([]);
|
|
271
|
+
|
|
272
|
+
await act(async () => {
|
|
273
|
+
resolveTasks();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
component.update();
|
|
277
|
+
expect(getHooksValues(component).state).toBe('loaded');
|
|
278
|
+
expect(getHooksValues(component).data).toEqual([
|
|
279
|
+
{
|
|
280
|
+
assignee: 'johnconnor1131',
|
|
281
|
+
objectURIs: ['changeRequests/7ZotlRoP', 'entities/1aAyKH7k'],
|
|
282
|
+
createdBy: 'sairam.singireesu@reltio.com',
|
|
283
|
+
priorityClass: 'Medium',
|
|
284
|
+
createTime: 1620897479535,
|
|
285
|
+
dueDate: 1621070279536,
|
|
286
|
+
displayName: 'DCR Review',
|
|
287
|
+
processDefinitionDisplayName: 'Data Change Request Review',
|
|
288
|
+
taskId: '123',
|
|
289
|
+
taskType: 'review',
|
|
290
|
+
objects: [
|
|
291
|
+
{
|
|
292
|
+
uri: 'entities/1aAyKH7k',
|
|
293
|
+
type: 'configuration/entityTypes/HCO',
|
|
294
|
+
label: 'Bahrain',
|
|
295
|
+
secondaryLabel: '',
|
|
296
|
+
isExist: true
|
|
297
|
+
}
|
|
298
|
+
]
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
assignee: 'marat.ahmetzyanov',
|
|
302
|
+
objectURIs: ['changeRequests/3BlTJj8z', 'entities/1RVnhXSL'],
|
|
303
|
+
createdBy: 'marat.ahmetzyanov',
|
|
304
|
+
priorityClass: 'Medium',
|
|
305
|
+
taskType: 'dcrReview',
|
|
306
|
+
createTime: 1644499067234,
|
|
307
|
+
dueDate: 1644671867234,
|
|
308
|
+
taskId: '30746510',
|
|
309
|
+
displayName: 'DCR Review',
|
|
310
|
+
processDefinitionDisplayName: 'Data Change Request Review',
|
|
311
|
+
objects: [
|
|
312
|
+
{
|
|
313
|
+
uri: 'changeRequests/3BlTJj8z/changes/entities/1RVnhXSL',
|
|
314
|
+
type: 'configuration/entityTypes/HCPLongName',
|
|
315
|
+
label: 'last name',
|
|
316
|
+
secondaryLabel: '',
|
|
317
|
+
isExist: false
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
]);
|
|
322
|
+
|
|
323
|
+
expect(getGroupTasksForTenantSpy).toBeCalledWith({
|
|
324
|
+
workflowPath: 'workflowPath',
|
|
325
|
+
environment: 'workflowEnvironmentURL',
|
|
326
|
+
tenant: 'tenant'
|
|
327
|
+
});
|
|
328
|
+
expect(getDataChangeRequestSpy).toBeCalledWith('changeRequests/7ZotlRoP');
|
|
329
|
+
expect(getEntitiesByUrisSpy).not.toHaveBeenCalled();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('should send request with max, offset params for TEAM tasks and be in the loading state, and be in loaded state once data is loaded', async () => {
|
|
333
|
+
const store = createTestStore();
|
|
334
|
+
const options = {
|
|
335
|
+
tasksCategory: WorkflowTasksCategories.TEAM,
|
|
336
|
+
max: 10,
|
|
337
|
+
offset: 10
|
|
338
|
+
};
|
|
339
|
+
const component = mount(
|
|
340
|
+
<Provider store={store}>
|
|
341
|
+
<TestComponent options={options} />
|
|
342
|
+
</Provider>
|
|
343
|
+
);
|
|
344
|
+
expect(getHooksValues(component).state).toBe('loading');
|
|
345
|
+
expect(getHooksValues(component).data).toEqual([]);
|
|
346
|
+
|
|
347
|
+
await act(async () => {
|
|
348
|
+
resolveTasks();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
expect(getGroupTasksForTenantSpy).toBeCalledWith({
|
|
352
|
+
workflowPath: 'workflowPath',
|
|
353
|
+
environment: 'workflowEnvironmentURL',
|
|
354
|
+
tenant: 'tenant',
|
|
355
|
+
max: 10,
|
|
356
|
+
offset: 10
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('should send request with max, offset params for MY tasks and be in the loading state, and be in loaded state once data is loaded', async () => {
|
|
361
|
+
const store = createTestStore();
|
|
362
|
+
const options = {
|
|
363
|
+
tasksCategory: WorkflowTasksCategories.MY,
|
|
364
|
+
max: 10,
|
|
365
|
+
offset: 10
|
|
366
|
+
};
|
|
367
|
+
const component = mount(
|
|
368
|
+
<Provider store={store}>
|
|
369
|
+
<TestComponent options={options} />
|
|
370
|
+
</Provider>
|
|
371
|
+
);
|
|
372
|
+
expect(getHooksValues(component).state).toBe('loading');
|
|
373
|
+
expect(getHooksValues(component).data).toEqual([]);
|
|
374
|
+
|
|
375
|
+
await act(async () => {
|
|
376
|
+
resolveTasks();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
expect(getTasksForTenantSpy).toBeCalledWith({
|
|
380
|
+
workflowPath: 'workflowPath',
|
|
381
|
+
environment: 'workflowEnvironmentURL',
|
|
382
|
+
tenant: 'tenant',
|
|
383
|
+
assignee: 'polina.arsenteva',
|
|
384
|
+
max: 10,
|
|
385
|
+
offset: 10
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {useCallback, useEffect, useState} from 'react';
|
|
2
|
+
import {andThen, otherwise, pipe} from 'ramda';
|
|
3
|
+
import {ActivitiesFilter, ActivityData, useActivitiesLoader, useSafePromise, RequestStates} from '@reltio/components';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
filter: ActivitiesFilter;
|
|
7
|
+
max: number;
|
|
8
|
+
offset: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const useActivitiesRequest = ({filter, max, offset}: Props) => {
|
|
12
|
+
const [data, setData] = useState<ActivityData[]>([]);
|
|
13
|
+
const [total, setTotal] = useState(0);
|
|
14
|
+
const [requestState, setRequestState] = useState<RequestStates>(RequestStates.INIT);
|
|
15
|
+
const safePromise = useSafePromise();
|
|
16
|
+
|
|
17
|
+
const onError = (error) => {
|
|
18
|
+
console.error(error); // eslint-disable-line
|
|
19
|
+
setRequestState(RequestStates.ERROR);
|
|
20
|
+
setData([]);
|
|
21
|
+
setTotal(0);
|
|
22
|
+
};
|
|
23
|
+
const getActivities = useActivitiesLoader({filter, max, offset});
|
|
24
|
+
|
|
25
|
+
const loadData = useCallback(() => {
|
|
26
|
+
setRequestState(RequestStates.LOADING);
|
|
27
|
+
const onRequestFinished = ({data, total}: {data: ActivityData[]; total: number}) => {
|
|
28
|
+
setData(data);
|
|
29
|
+
setTotal(total);
|
|
30
|
+
setRequestState(RequestStates.LOADED);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const getData = pipe(getActivities, safePromise, andThen(onRequestFinished), otherwise(onError));
|
|
34
|
+
getData();
|
|
35
|
+
}, [getActivities]); // eslint-disable-line
|
|
36
|
+
|
|
37
|
+
const refreshAction = () => {
|
|
38
|
+
try {
|
|
39
|
+
loadData();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
onError(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
refreshAction();
|
|
47
|
+
}, [loadData]);
|
|
48
|
+
|
|
49
|
+
return {state: requestState, data, total, reload: refreshAction};
|
|
50
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {useEffect, useState, useCallback} from 'react';
|
|
2
|
+
import {useSelector} from 'react-redux';
|
|
3
|
+
import mdmModule from '@reltio/mdm-module';
|
|
4
|
+
import {pipe, andThen, otherwise, when, always, unless} from 'ramda';
|
|
5
|
+
import {requestFacets, localizeFacetValues} from '../services/facets';
|
|
6
|
+
import {ChartData, RequestStates} from '@reltio/components';
|
|
7
|
+
import {GlobalSearchRequestOptions} from '../types/SearchOptions';
|
|
8
|
+
import {addEmptyEntityTypesFacets, getParentEntityTypeFacets, resolveTypeFacetsLabels} from '../services/entityTypes';
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
hideEmpty?: boolean;
|
|
12
|
+
orderType?: string;
|
|
13
|
+
inheritChildren?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const filters = [];
|
|
17
|
+
|
|
18
|
+
export const useEntityByTypeRequest = ({orderType, inheritChildren, hideEmpty}: Props) => {
|
|
19
|
+
const [data, setData] = useState<ChartData[]>([]);
|
|
20
|
+
const [requestState, setRequestState] = useState<RequestStates>(RequestStates.INIT);
|
|
21
|
+
const metadata: Record<string, any> = useSelector(mdmModule.selectors.getMetadata);
|
|
22
|
+
const pageSize = metadata.entityTypes.length;
|
|
23
|
+
const {globalFilter, activityFilter}: GlobalSearchRequestOptions = useSelector(
|
|
24
|
+
mdmModule.selectors.getGlobalSearchRequestOptions
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const searchByOv: boolean = useSelector(mdmModule.selectors.getShowSearchByOv);
|
|
28
|
+
const onError = (error) => {
|
|
29
|
+
console.error(error); // eslint-disable-line
|
|
30
|
+
setRequestState(RequestStates.ERROR);
|
|
31
|
+
setData([]);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const loadData = useCallback(() => {
|
|
35
|
+
setRequestState(RequestStates.LOADING);
|
|
36
|
+
const onRequestFinished = (data: ChartData[]) => {
|
|
37
|
+
setRequestState(RequestStates.LOADED);
|
|
38
|
+
setData(data);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getData = pipe(
|
|
42
|
+
requestFacets,
|
|
43
|
+
andThen(unless(always(hideEmpty), addEmptyEntityTypesFacets(metadata))),
|
|
44
|
+
andThen(when(always(inheritChildren), getParentEntityTypeFacets(metadata))),
|
|
45
|
+
andThen(resolveTypeFacetsLabels(metadata)),
|
|
46
|
+
andThen(localizeFacetValues),
|
|
47
|
+
andThen(onRequestFinished),
|
|
48
|
+
otherwise(onError)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
getData({attribute: 'type', pageSize, filters, globalFilter, searchByOv, activityFilter, orderType});
|
|
52
|
+
}, [hideEmpty, metadata, inheritChildren, pageSize, globalFilter, searchByOv, activityFilter, orderType]);
|
|
53
|
+
|
|
54
|
+
const refreshAction = () => {
|
|
55
|
+
try {
|
|
56
|
+
loadData();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
onError(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
refreshAction();
|
|
64
|
+
}, [loadData]);
|
|
65
|
+
|
|
66
|
+
return {state: requestState, data, reload: refreshAction};
|
|
67
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {useCallback, useEffect, useState, useContext, useMemo} from 'react';
|
|
2
|
+
import {useSelector} from 'react-redux';
|
|
3
|
+
import mdmModule from '@reltio/mdm-module';
|
|
4
|
+
import {
|
|
5
|
+
DashboardConfigFilter,
|
|
6
|
+
findAttributeTypeByUri,
|
|
7
|
+
getSpecialAttrTypeByFieldName,
|
|
8
|
+
SearchFilter
|
|
9
|
+
} from '@reltio/mdm-sdk';
|
|
10
|
+
import {always, andThen, otherwise, pipe, when, unless} from 'ramda';
|
|
11
|
+
import {
|
|
12
|
+
getFacetFieldName,
|
|
13
|
+
getFiltersForFacet,
|
|
14
|
+
requestFacets,
|
|
15
|
+
requestOtherValues,
|
|
16
|
+
resolveFacetLabels,
|
|
17
|
+
localizeFacetValues
|
|
18
|
+
} from '../services/facets';
|
|
19
|
+
import {ChartData, RequestStates, SearchFiltersContext} from '@reltio/components';
|
|
20
|
+
import {GlobalSearchRequestOptions} from '../types/SearchOptions';
|
|
21
|
+
import {convertSearchFilterToDashboardConfigFilter} from '../services/filters';
|
|
22
|
+
|
|
23
|
+
type Props = {
|
|
24
|
+
filters: DashboardConfigFilter[];
|
|
25
|
+
attributeUri: string;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
orderType?: string;
|
|
28
|
+
options?: {
|
|
29
|
+
showOthers: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const useFacetRequest = ({
|
|
34
|
+
filters: facetFilters,
|
|
35
|
+
attributeUri,
|
|
36
|
+
pageSize,
|
|
37
|
+
orderType = 'reversedCount',
|
|
38
|
+
options
|
|
39
|
+
}: Props) => {
|
|
40
|
+
const [data, setData] = useState<ChartData[]>([]);
|
|
41
|
+
const [requestState, setRequestState] = useState<RequestStates>(RequestStates.INIT);
|
|
42
|
+
const searchFilters = useContext<SearchFilter[]>(SearchFiltersContext);
|
|
43
|
+
const facetAndSpecialFilters = useMemo(
|
|
44
|
+
() => searchFilters.map(convertSearchFilterToDashboardConfigFilter).concat(facetFilters || []),
|
|
45
|
+
[searchFilters, facetFilters]
|
|
46
|
+
);
|
|
47
|
+
const metadata = useSelector(mdmModule.selectors.getMetadata);
|
|
48
|
+
const {globalFilter, activityFilter}: GlobalSearchRequestOptions = useSelector(
|
|
49
|
+
mdmModule.selectors.getGlobalSearchRequestOptions
|
|
50
|
+
);
|
|
51
|
+
const attributePresentations = useSelector(mdmModule.selectors.getAttributePresentations);
|
|
52
|
+
const hasAttrPresentation = !!attributePresentations?.[attributeUri];
|
|
53
|
+
const searchByOv: boolean = useSelector(mdmModule.selectors.getShowSearchByOv);
|
|
54
|
+
const showOthers: boolean = options?.showOthers;
|
|
55
|
+
const onError = (error) => {
|
|
56
|
+
console.error(error); // eslint-disable-line
|
|
57
|
+
setRequestState(RequestStates.ERROR);
|
|
58
|
+
setData([]);
|
|
59
|
+
};
|
|
60
|
+
const loadData = useCallback(() => {
|
|
61
|
+
setRequestState(RequestStates.LOADING);
|
|
62
|
+
const filters = getFiltersForFacet(attributeUri, facetAndSpecialFilters);
|
|
63
|
+
const fieldName = getFacetFieldName(attributeUri);
|
|
64
|
+
const attrType = getSpecialAttrTypeByFieldName(fieldName) || findAttributeTypeByUri(metadata, attributeUri);
|
|
65
|
+
const onRequestFinished = (data: ChartData[]) => {
|
|
66
|
+
setRequestState(RequestStates.LOADED);
|
|
67
|
+
setData(data);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (!attrType) {
|
|
71
|
+
onError('Configuration is incorrect');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const getData = pipe(
|
|
76
|
+
requestFacets,
|
|
77
|
+
andThen(resolveFacetLabels(metadata, attrType)),
|
|
78
|
+
andThen(unless(always(hasAttrPresentation), localizeFacetValues)),
|
|
79
|
+
andThen(
|
|
80
|
+
when(
|
|
81
|
+
always(showOthers),
|
|
82
|
+
requestOtherValues({attribute: fieldName, filters, globalFilter, searchByOv, activityFilter})
|
|
83
|
+
)
|
|
84
|
+
),
|
|
85
|
+
andThen(onRequestFinished),
|
|
86
|
+
otherwise(onError)
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
getData({attribute: fieldName, filters, globalFilter, searchByOv, activityFilter, pageSize, orderType});
|
|
90
|
+
}, [
|
|
91
|
+
setRequestState,
|
|
92
|
+
attributeUri,
|
|
93
|
+
metadata,
|
|
94
|
+
showOthers,
|
|
95
|
+
facetAndSpecialFilters,
|
|
96
|
+
globalFilter,
|
|
97
|
+
searchByOv,
|
|
98
|
+
activityFilter,
|
|
99
|
+
pageSize,
|
|
100
|
+
orderType,
|
|
101
|
+
hasAttrPresentation
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
const refreshAction = () => {
|
|
105
|
+
try {
|
|
106
|
+
loadData();
|
|
107
|
+
} catch (e) {
|
|
108
|
+
onError(e);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
refreshAction();
|
|
114
|
+
}, [loadData]);
|
|
115
|
+
|
|
116
|
+
return {state: requestState, data, reload: refreshAction};
|
|
117
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {useCallback, useContext, useEffect, useMemo, useState} from 'react';
|
|
2
|
+
import {RequestStates, SearchFiltersContext} from '@reltio/components';
|
|
3
|
+
import {DashboardConfigFilter, getFilteredEntities, getTotals, SearchFilter} from '@reltio/mdm-sdk';
|
|
4
|
+
import {EntityData} from '../types/EntityData';
|
|
5
|
+
import {convertSearchFilterToDashboardConfigFilter} from '../services/filters';
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
filters: DashboardConfigFilter[];
|
|
9
|
+
offset: number;
|
|
10
|
+
max: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const useFilteredEntitiesRequest = ({filters, max, offset}: Props) => {
|
|
14
|
+
const [data, setData] = useState<EntityData[]>([]);
|
|
15
|
+
const [total, setTotal] = useState<number>(0);
|
|
16
|
+
const [requestState, setRequestState] = useState<RequestStates>(RequestStates.INIT);
|
|
17
|
+
|
|
18
|
+
const searchFilters = useContext<SearchFilter[]>(SearchFiltersContext);
|
|
19
|
+
const allFilters = useMemo(
|
|
20
|
+
() => searchFilters.map(convertSearchFilterToDashboardConfigFilter).concat(filters || []),
|
|
21
|
+
[searchFilters, filters]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const onError = (error) => {
|
|
25
|
+
console.error(error); // eslint-disable-line
|
|
26
|
+
setRequestState(RequestStates.ERROR);
|
|
27
|
+
setData([]);
|
|
28
|
+
setTotal(0);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const loadData = useCallback(() => {
|
|
32
|
+
setRequestState(RequestStates.LOADING);
|
|
33
|
+
|
|
34
|
+
Promise.all([getFilteredEntities(allFilters, {max, offset}), getTotals(allFilters, {max, offset})])
|
|
35
|
+
.then((results) => {
|
|
36
|
+
const [entities, {total}] = results;
|
|
37
|
+
setData(entities || []);
|
|
38
|
+
setTotal(total);
|
|
39
|
+
setRequestState(RequestStates.LOADED);
|
|
40
|
+
})
|
|
41
|
+
.catch(onError);
|
|
42
|
+
}, [allFilters, max, offset]);
|
|
43
|
+
|
|
44
|
+
const refreshAction = () => {
|
|
45
|
+
try {
|
|
46
|
+
loadData();
|
|
47
|
+
} catch (e) {
|
|
48
|
+
onError(e);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
refreshAction();
|
|
54
|
+
}, [loadData]);
|
|
55
|
+
|
|
56
|
+
return {state: requestState, data, reload: refreshAction, total};
|
|
57
|
+
};
|