@giteeteam/apps-team-components 1.4.0 → 1.4.2

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
@@ -22,6 +22,6 @@ pnpm storybook
22
22
 
23
23
  # 1.3.x版本
24
24
  - team最低版本为4.23.0
25
-
25
+
26
26
  # 1.4.x版本
27
27
  - team最低版本为4.24.0
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { NodeItemProps } from '../../../lib/types/workflow';
2
3
  interface SelectFlowHandlerProps {
3
4
  itemId: string;
4
5
  onBack: () => void;
@@ -7,7 +8,7 @@ interface SelectFlowHandlerProps {
7
8
  loading: boolean;
8
9
  loadingUser: boolean;
9
10
  fetchUsers: (itemId: string, status: string, keyword?: string) => Promise<void>;
10
- handleTransition: (updateTask: string, screenId: string, script: string, flowHandler?: Array<{
11
+ handleTransition: (updateTask: string, screenId: string, script: string, target: NodeItemProps, flowHandler?: Array<{
11
12
  label: string;
12
13
  value: string;
13
14
  }>) => void;
@@ -55,7 +55,7 @@ const SelectFlowHandler = ({ itemId, task, onBack, users, loading, loadingUser,
55
55
  label: user.nickname ? `${user.nickname}(${user.username})` : user.username,
56
56
  value: user.objectId,
57
57
  }));
58
- handleTransition(task.name, (_b = (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.screen) === null || _b === void 0 ? void 0 : _b.key, (_c = task.parameters) === null || _c === void 0 ? void 0 : _c.scriptValidator, submitUsers);
58
+ handleTransition(task.name, (_b = (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.screen) === null || _b === void 0 ? void 0 : _b.key, (_c = task.parameters) === null || _c === void 0 ? void 0 : _c.scriptValidator, task.target, submitUsers);
59
59
  }, [
60
60
  handleTransition,
61
61
  selectedUserIds.length,
@@ -63,6 +63,7 @@ const SelectFlowHandler = ({ itemId, task, onBack, users, loading, loadingUser,
63
63
  task.name,
64
64
  (_b = (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.screen) === null || _b === void 0 ? void 0 : _b.key,
65
65
  (_c = task.parameters) === null || _c === void 0 ? void 0 : _c.scriptValidator,
66
+ task.target,
66
67
  ]);
67
68
  const OverflowText = () => {
68
69
  var _a, _b;
@@ -14,7 +14,7 @@ interface SelectTransitionProps {
14
14
  workflowData: WorkflowDataProps;
15
15
  approval: ApprovalData;
16
16
  checkIn: CheckInData;
17
- handleTransition: (updateTask: string, screenId: string, script: string) => void;
17
+ handleTransition: (updateTask: string, screenId: string, script: string, target?: any) => void;
18
18
  readonly: boolean;
19
19
  flowHandlerActive?: boolean;
20
20
  }
@@ -1,116 +1,18 @@
1
1
  import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
2
- import { useState, useCallback, useEffect, memo } from 'react';
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 ApprovalStatus = {
13
- approved: 'approved',
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(_task => {
13
+ .map(task => {
111
14
  var _a, _b, _c;
112
- const { data: task, checkResult } = _task;
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 })] })) }));
@@ -5,7 +5,7 @@ interface TransitionButtonProps {
5
5
  text: string;
6
6
  screenId: string;
7
7
  scriptValidator: string;
8
- handleTransition: (updateTask: string, screenId: string, script: string) => void;
8
+ handleTransition: (updateTask: string, screenId: string, script: string, target: NodeItemProps) => void;
9
9
  target: NodeItemProps & {
10
10
  type?: string;
11
11
  };
@@ -27,7 +27,7 @@ const TransitionButton = ({ loading, screenId, text, scriptValidator, handleTran
27
27
  return (jsx(ClassNames, { children: ({ cx, css }) => {
28
28
  return conditionCheck ? ((conditionCheck === null || conditionCheck === void 0 ? void 0 : conditionCheck.result) && !readonly ? (jsx("div", { className: cx(css(flowBtnStyle), loading ? css(notAllowedStyle) : css(pointerStyle)), onClick: () => {
29
29
  if (!loading) {
30
- handleTransition(text, screenId, scriptValidator);
30
+ handleTransition(text, screenId, scriptValidator, target);
31
31
  }
32
32
  }, children: jsx(OverflowText, { text: text, target: target }) })) : (jsx(Tooltip, { title: tipContent, placement: "right", children: jsx("div", { className: cx(css(flowBtnStyle), css(notAllowedStyle)), children: jsx(OverflowText, { text: text, target: target }) }) }))) : null;
33
33
  } }));
@@ -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 updateWorkflowMessage = useCallback((workflowData, statusId) => {
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
- setTasks(sortList);
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
- updateWorkflowMessage(workflowData, statusId);
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
- }, [itemId, statusId, updateWorkflowMessage, getWorkflowData]);
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;
@@ -172,13 +269,16 @@ const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSu
172
269
  const submitTransition = useCallback(async (itemDetail) => {
173
270
  await submitHandle(updateTransitionText, itemDetail);
174
271
  }, [submitHandle, updateTransitionText]);
175
- const handleTransition = useCallback(async (transitionText, screenId, scriptValidator, flowHandler) => {
272
+ const handleTransition = useCallback(async (transitionText, screenId, scriptValidator, target, flowHandler) => {
176
273
  if (flowHandlerActive) {
177
274
  if (transitionStep === TransitionStepType.SelectTransition) {
178
- setCurrentFlowHandler(undefined);
179
- setFlowTask(tasks.find(task => task.name === transitionText));
180
- setTransitionStep(TransitionStepType.SelectFlowHandler);
181
- return;
275
+ const nextStateTransition = workflowData.transitions.find(t => t.source.id === target.key);
276
+ if (nextStateTransition) {
277
+ setCurrentFlowHandler(undefined);
278
+ setFlowTask(tasks.find(task => task.name === transitionText));
279
+ setTransitionStep(TransitionStepType.SelectFlowHandler);
280
+ return;
281
+ }
182
282
  }
183
283
  else {
184
284
  console.info('flowHandler', flowHandler);
@@ -221,8 +321,9 @@ const TransitionPanel = ({ itemId, itemType, workspace, objectId, onTransitionSu
221
321
  }
222
322
  }, [
223
323
  flowHandlerActive,
224
- transitionStep,
225
324
  setFlowing,
325
+ transitionStep,
326
+ workflowData.transitions,
226
327
  tasks,
227
328
  itemId,
228
329
  itemType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-team-components",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Gitee team components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",