@giteeteam/apps-team-components 1.4.0 → 1.4.1
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/README.md
CHANGED
|
@@ -1,116 +1,18 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { memo } from 'react';
|
|
3
3
|
import { ClassNames } from '@emotion/react';
|
|
4
4
|
import { Spin } from 'antd';
|
|
5
|
-
import useWorkflowConfig from '../../../lib/hooks/useWorkflowConfig.js';
|
|
6
5
|
import { i18n } from '../../../lib/i18n.js';
|
|
7
|
-
import { checkFlowHandler } from '../../../lib/workflow.js';
|
|
8
6
|
import { spinStyle, flowNextStyle, flowWrapperStyle, noPermissionStyle } from './style/index.js';
|
|
9
7
|
import TransitionButton from './TransitionButton.js';
|
|
10
8
|
import View from './View.js';
|
|
11
9
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
rejected: 'rejected',
|
|
15
|
-
};
|
|
16
|
-
const CheckInStatus = {
|
|
17
|
-
closed: 'closed',
|
|
18
|
-
pending: 'pending',
|
|
19
|
-
};
|
|
20
|
-
const SelectTransition = ({ fetching, flowing, tasks, itemId, itemData, currentUser, setPopoverVisible, name, objectId, workflowData, approval, checkIn, handleTransition, readonly, flowHandlerActive, }) => {
|
|
21
|
-
const [transitionList, setTransitionList] = useState([]);
|
|
22
|
-
const [checkResultList, setCheckResultList] = useState([]);
|
|
23
|
-
const [init, setInit] = useState(false);
|
|
24
|
-
const { postCheckTransitions, hideDisabledStatusTransition } = useWorkflowConfig();
|
|
25
|
-
const checkApproval = useCallback(({ text }) => {
|
|
26
|
-
var _a;
|
|
27
|
-
if (!approval.requireApproval)
|
|
28
|
-
return [true];
|
|
29
|
-
const approvedTransitions = approval.transition.approved.map(approved => approved.label);
|
|
30
|
-
const rejectedTransitions = approval.transition.rejected.map(rejected => rejected.label);
|
|
31
|
-
const unrestrictedTransitions = ((_a = approval.transition.unrestricted) === null || _a === void 0 ? void 0 : _a.map(unrestricted => unrestricted.label)) || [];
|
|
32
|
-
if ((ApprovalStatus.approved === approval.approvalStatus && approvedTransitions.includes(text)) ||
|
|
33
|
-
(ApprovalStatus.rejected === approval.approvalStatus && rejectedTransitions.includes(text))) {
|
|
34
|
-
return [true];
|
|
35
|
-
}
|
|
36
|
-
if (![ApprovalStatus.approved, ApprovalStatus.rejected].includes(approval.approvalStatus) &&
|
|
37
|
-
(unrestrictedTransitions === null || unrestrictedTransitions === void 0 ? void 0 : unrestrictedTransitions.includes(text))) {
|
|
38
|
-
if (!approval.startApproval) {
|
|
39
|
-
return [true];
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return [false, i18n.t('pages.fields.view.unrestrictedStatus')];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return [false, i18n.t('pages.fields.view.approvalStatus')];
|
|
46
|
-
}, [approval]);
|
|
47
|
-
const validateCheckIn = useCallback(() => {
|
|
48
|
-
if (!checkIn.requireCheckIn)
|
|
49
|
-
return true;
|
|
50
|
-
if (checkIn.checkInStatus !== CheckInStatus.pending) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}, [checkIn]);
|
|
55
|
-
const checkOneTransition = useCallback(({ text, conditionCheck }) => {
|
|
56
|
-
const [checkApprovalResult, checkApprovalMessage] = checkApproval({ text });
|
|
57
|
-
if (!checkApprovalResult) {
|
|
58
|
-
return {
|
|
59
|
-
result: false,
|
|
60
|
-
message: checkApprovalMessage,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (!validateCheckIn()) {
|
|
64
|
-
return {
|
|
65
|
-
result: false,
|
|
66
|
-
message: i18n.t('pages.fields.view.checkInStatus'),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const checkResult = checkFlowHandler(itemData, { userId: currentUser.id }, flowHandlerActive);
|
|
70
|
-
if (checkResult && !checkResult.result) {
|
|
71
|
-
return checkResult;
|
|
72
|
-
}
|
|
73
|
-
if (!(conditionCheck === null || conditionCheck === void 0 ? void 0 : conditionCheck.result) && conditionCheck) {
|
|
74
|
-
if (hideDisabledStatusTransition === 'enabled') {
|
|
75
|
-
return { result: false, isHide: true };
|
|
76
|
-
}
|
|
77
|
-
return conditionCheck;
|
|
78
|
-
}
|
|
79
|
-
return { result: true };
|
|
80
|
-
}, [checkApproval, currentUser, flowHandlerActive, hideDisabledStatusTransition, validateCheckIn, itemData]);
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (!init && workflowData.objectId && tasks.length && postCheckTransitions && itemId) {
|
|
83
|
-
setInit(true);
|
|
84
|
-
postCheckTransitions(tasks.map(_transition => ({
|
|
85
|
-
transitionId: _transition.id,
|
|
86
|
-
itemId,
|
|
87
|
-
workflowId: workflowData.objectId,
|
|
88
|
-
}))).then(_checkResultList => {
|
|
89
|
-
setCheckResultList(_checkResultList);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}, [init, itemId, workflowData, postCheckTransitions, tasks, itemData]);
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
const _transitionList = [];
|
|
95
|
-
if (checkResultList.length === 0)
|
|
96
|
-
return;
|
|
97
|
-
tasks.forEach(task => {
|
|
98
|
-
var _a;
|
|
99
|
-
const conditionCheck = (_a = checkResultList.find(checkResult => checkResult.transitionId === task.id)) === null || _a === void 0 ? void 0 : _a.result;
|
|
100
|
-
const allResult = checkOneTransition({ text: task.name, conditionCheck });
|
|
101
|
-
_transitionList.push({
|
|
102
|
-
data: task,
|
|
103
|
-
checkResult: allResult,
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
setTransitionList(_transitionList);
|
|
107
|
-
}, [checkResultList, checkOneTransition, itemData, tasks]);
|
|
108
|
-
return (jsx(ClassNames, { children: ({ cx, css }) => (jsxs(Fragment, { children: [fetching ? (jsx(Spin, { css: css(spinStyle) })) : transitionList.length ? (jsx("div", { className: cx(css(flowNextStyle), `flow-next-global`), children: jsx("div", { className: cx(css(flowWrapperStyle)), children: transitionList
|
|
10
|
+
const SelectTransition = ({ fetching, flowing, tasks, setPopoverVisible, name, objectId, workflowData, handleTransition, readonly, }) => {
|
|
11
|
+
return (jsx(ClassNames, { children: ({ cx, css }) => (jsxs(Fragment, { children: [fetching ? (jsx(Spin, { css: css(spinStyle) })) : tasks.length ? (jsx("div", { className: cx(css(flowNextStyle), `flow-next-global`), children: jsx("div", { className: cx(css(flowWrapperStyle)), children: tasks
|
|
109
12
|
.filter(_task => { var _a; return !((_a = _task === null || _task === void 0 ? void 0 : _task.checkResult) === null || _a === void 0 ? void 0 : _a.isHide); })
|
|
110
|
-
.map(
|
|
13
|
+
.map(task => {
|
|
111
14
|
var _a, _b, _c;
|
|
112
|
-
|
|
113
|
-
return (jsx(TransitionButton, { loading: flowing, text: task.name, scriptValidator: (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.scriptValidator, screenId: (_c = (_b = task.parameters) === null || _b === void 0 ? void 0 : _b.screen) === null || _c === void 0 ? void 0 : _c.key, target: task.target, handleTransition: handleTransition, readonly: readonly, conditionCheck: checkResult }, task.id));
|
|
15
|
+
return (jsx(TransitionButton, { loading: flowing, text: task.name, scriptValidator: (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.scriptValidator, screenId: (_c = (_b = task.parameters) === null || _b === void 0 ? void 0 : _b.screen) === null || _c === void 0 ? void 0 : _c.key, target: task.target, handleTransition: handleTransition, readonly: readonly, conditionCheck: task === null || task === void 0 ? void 0 : task.checkResult }, task.id));
|
|
114
16
|
}) }) })) : (jsx("span", { onClick: () => {
|
|
115
17
|
setPopoverVisible(false);
|
|
116
18
|
}, css: css(noPermissionStyle), children: i18n.t('pages.fields.view.noWorkflowOrAuth') })), jsx(View, { workflowData: workflowData, hiddenPopover: () => setPopoverVisible(false), name: name, objectId: objectId })] })) }));
|
|
@@ -8,7 +8,7 @@ import { cloneDeep } from 'lodash-es';
|
|
|
8
8
|
import useCurrentUser from '../../../lib/hooks/useCurrentUser.js';
|
|
9
9
|
import useWorkflowConfig from '../../../lib/hooks/useWorkflowConfig.js';
|
|
10
10
|
import { i18n } from '../../../lib/i18n.js';
|
|
11
|
-
import { useWorkflowPermission, getScriptUser } from '../../../lib/workflow.js';
|
|
11
|
+
import { useWorkflowPermission, checkFlowHandler, getScriptUser } from '../../../lib/workflow.js';
|
|
12
12
|
import { useItem } from '../../item/hooks.js';
|
|
13
13
|
import SelectFlowHandler from './SelectFlowHandler.js';
|
|
14
14
|
import SelectTransition from './SelectTransition.js';
|
|
@@ -27,6 +27,14 @@ const DEFAULT_APPROVAL_DATA = {
|
|
|
27
27
|
startApproval: false,
|
|
28
28
|
};
|
|
29
29
|
const DEFAULT_CHECK_IN_DATA = { requireCheckIn: false, checkInStatus: '', transition: null };
|
|
30
|
+
const ApprovalStatus = {
|
|
31
|
+
approved: 'approved',
|
|
32
|
+
rejected: 'rejected',
|
|
33
|
+
};
|
|
34
|
+
const CheckInStatus = {
|
|
35
|
+
closed: 'closed',
|
|
36
|
+
pending: 'pending',
|
|
37
|
+
};
|
|
30
38
|
const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSuccess, name, readonly, setPopoverVisible, isProcessing, flowing, setFlowing, flowHandlerActive, flowUsers, loadingFlowUsers, fetchFlowUsers, }) => {
|
|
31
39
|
var _a;
|
|
32
40
|
const [updateTransitionText, setUpdateTransitionText] = useState('');
|
|
@@ -46,12 +54,69 @@ const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSu
|
|
|
46
54
|
newItem.current = itemId;
|
|
47
55
|
};
|
|
48
56
|
}, [itemId, objectId]);
|
|
49
|
-
const { checkTransitionScript, getWorkflowData, getItemStatus, runTransition } = useWorkflowConfig();
|
|
57
|
+
const { checkTransitionScript, getWorkflowData, getItemStatus, runTransition, postCheckTransitions, hideDisabledStatusTransition, } = useWorkflowConfig();
|
|
50
58
|
const { currentUser } = useCurrentUser();
|
|
51
59
|
const [groupIds, , workspaceRoleIds] = useWorkflowPermission((_a = itemData === null || itemData === void 0 ? void 0 : itemData.workspace) === null || _a === void 0 ? void 0 : _a.objectId);
|
|
52
60
|
const [tasks, setTasks] = useState([]);
|
|
53
61
|
const [workflowData, setWorkflowData] = useState({ nodes: [], transitions: [] });
|
|
54
|
-
const
|
|
62
|
+
const [checkResultList, setCheckResultList] = useState([]);
|
|
63
|
+
const checkApproval = useCallback(({ text }) => {
|
|
64
|
+
var _a;
|
|
65
|
+
if (!approval.requireApproval)
|
|
66
|
+
return [true];
|
|
67
|
+
const approvedTransitions = approval.transition.approved.map(approved => approved.label);
|
|
68
|
+
const rejectedTransitions = approval.transition.rejected.map(rejected => rejected.label);
|
|
69
|
+
const unrestrictedTransitions = ((_a = approval.transition.unrestricted) === null || _a === void 0 ? void 0 : _a.map(unrestricted => unrestricted.label)) || [];
|
|
70
|
+
if ((ApprovalStatus.approved === approval.approvalStatus && approvedTransitions.includes(text)) ||
|
|
71
|
+
(ApprovalStatus.rejected === approval.approvalStatus && rejectedTransitions.includes(text))) {
|
|
72
|
+
return [true];
|
|
73
|
+
}
|
|
74
|
+
if (![ApprovalStatus.approved, ApprovalStatus.rejected].includes(approval.approvalStatus) &&
|
|
75
|
+
(unrestrictedTransitions === null || unrestrictedTransitions === void 0 ? void 0 : unrestrictedTransitions.includes(text))) {
|
|
76
|
+
if (!approval.startApproval) {
|
|
77
|
+
return [true];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return [false, i18n.t('pages.fields.view.unrestrictedStatus')];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [false, i18n.t('pages.fields.view.approvalStatus')];
|
|
84
|
+
}, [approval]);
|
|
85
|
+
const validateCheckIn = useCallback(() => {
|
|
86
|
+
if (!checkIn.requireCheckIn)
|
|
87
|
+
return true;
|
|
88
|
+
if (checkIn.checkInStatus !== CheckInStatus.pending) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}, [checkIn]);
|
|
93
|
+
const checkOneTransition = useCallback(({ text, conditionCheck }) => {
|
|
94
|
+
const [checkApprovalResult, checkApprovalMessage] = checkApproval({ text });
|
|
95
|
+
if (!checkApprovalResult) {
|
|
96
|
+
return {
|
|
97
|
+
result: false,
|
|
98
|
+
message: checkApprovalMessage,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (!validateCheckIn()) {
|
|
102
|
+
return {
|
|
103
|
+
result: false,
|
|
104
|
+
message: i18n.t('pages.fields.view.checkInStatus'),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const checkResult = checkFlowHandler(itemData, { userId: currentUser.id }, flowHandlerActive);
|
|
108
|
+
if (checkResult && !checkResult.result) {
|
|
109
|
+
return checkResult;
|
|
110
|
+
}
|
|
111
|
+
if (!(conditionCheck === null || conditionCheck === void 0 ? void 0 : conditionCheck.result) && conditionCheck) {
|
|
112
|
+
if (hideDisabledStatusTransition === 'enabled') {
|
|
113
|
+
return { result: false, isHide: true };
|
|
114
|
+
}
|
|
115
|
+
return conditionCheck;
|
|
116
|
+
}
|
|
117
|
+
return { result: true };
|
|
118
|
+
}, [checkApproval, currentUser, flowHandlerActive, hideDisabledStatusTransition, validateCheckIn, itemData]);
|
|
119
|
+
const getTheTargetTransitions = useCallback(({ workflowData, statusId }) => {
|
|
55
120
|
var _a;
|
|
56
121
|
if (workflowData && statusId) {
|
|
57
122
|
const transitions = workflowData.transitions || [];
|
|
@@ -65,6 +130,12 @@ const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSu
|
|
|
65
130
|
arr[i].target.type = nodes[index].key || nodes[index].statusType;
|
|
66
131
|
}
|
|
67
132
|
const list = ((_a = workflowData.transitions) === null || _a === void 0 ? void 0 : _a.filter(transition => transition.source.key === statusId)) || [];
|
|
133
|
+
return list;
|
|
134
|
+
}
|
|
135
|
+
}, []);
|
|
136
|
+
const updateWorkflowMessage = useCallback((workflowData, statusId, checkResultList) => {
|
|
137
|
+
const list = getTheTargetTransitions({ workflowData, statusId });
|
|
138
|
+
if (list.length > 0) {
|
|
68
139
|
const sortList = list.map(item => {
|
|
69
140
|
var _a;
|
|
70
141
|
const propertiesListItem = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.find(v => v.key === PROPERTY_ACTION_SORT_KEY);
|
|
@@ -77,12 +148,21 @@ const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSu
|
|
|
77
148
|
return item;
|
|
78
149
|
});
|
|
79
150
|
sortList.sort((item1, item2) => item1.orderNumber - item2.orderNumber);
|
|
80
|
-
|
|
151
|
+
const _sortList = sortList.map(_task => {
|
|
152
|
+
var _a;
|
|
153
|
+
const conditionCheck = (_a = checkResultList.find(_checkResult => _checkResult.transitionId === _task.id)) === null || _a === void 0 ? void 0 : _a.result;
|
|
154
|
+
const allResult = checkOneTransition({ text: _task.name, conditionCheck });
|
|
155
|
+
return {
|
|
156
|
+
..._task,
|
|
157
|
+
checkResult: allResult,
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
setTasks(_sortList);
|
|
81
161
|
const { approval, checkIn } = getWorkflowConfig(workflowData, statusId);
|
|
82
162
|
setApproval(approval);
|
|
83
163
|
setCheckIn(checkIn);
|
|
84
164
|
}
|
|
85
|
-
}, []);
|
|
165
|
+
}, [checkOneTransition, getTheTargetTransitions]);
|
|
86
166
|
const refresh = useCallback(async () => {
|
|
87
167
|
try {
|
|
88
168
|
if (!itemId) {
|
|
@@ -92,21 +172,38 @@ const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSu
|
|
|
92
172
|
const workflowData = await (getWorkflowData === null || getWorkflowData === void 0 ? void 0 : getWorkflowData(itemId));
|
|
93
173
|
if (workflowData) {
|
|
94
174
|
setWorkflowData(workflowData);
|
|
95
|
-
|
|
175
|
+
const targetList = getTheTargetTransitions({ workflowData, statusId });
|
|
176
|
+
if (targetList.length > 0) {
|
|
177
|
+
const checkResultList = await postCheckTransitions(targetList.map(_transition => ({
|
|
178
|
+
transitionId: _transition.id,
|
|
179
|
+
itemId,
|
|
180
|
+
workflowId: workflowData.objectId,
|
|
181
|
+
})));
|
|
182
|
+
setCheckResultList(checkResultList);
|
|
183
|
+
updateWorkflowMessage(workflowData, statusId, checkResultList);
|
|
184
|
+
}
|
|
96
185
|
}
|
|
97
186
|
}
|
|
98
187
|
finally {
|
|
99
188
|
setFetching(false);
|
|
100
189
|
}
|
|
101
|
-
}, [
|
|
190
|
+
}, [
|
|
191
|
+
itemId,
|
|
192
|
+
itemData,
|
|
193
|
+
statusId,
|
|
194
|
+
updateWorkflowMessage,
|
|
195
|
+
getWorkflowData,
|
|
196
|
+
postCheckTransitions,
|
|
197
|
+
getTheTargetTransitions,
|
|
198
|
+
]);
|
|
102
199
|
useEffect(() => {
|
|
103
200
|
logger('refresh workflow');
|
|
104
201
|
refresh();
|
|
105
202
|
}, []);
|
|
106
203
|
useEffect(() => {
|
|
107
204
|
logger('updateWorkflowMessage', statusId);
|
|
108
|
-
updateWorkflowMessage(workflowData, statusId);
|
|
109
|
-
}, [statusId]);
|
|
205
|
+
updateWorkflowMessage(workflowData, statusId, checkResultList);
|
|
206
|
+
}, [statusId, workflowData, checkResultList, itemData]);
|
|
110
207
|
const refreshItem = useCallback((status) => {
|
|
111
208
|
if (newItem.current !== itemId) {
|
|
112
209
|
return;
|