@giteeteam/apps-team-components 1.2.1 → 1.2.2-alpha.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.
@@ -8,8 +8,8 @@ import TransitionButton from './TransitionButton';
8
8
  import View from './View';
9
9
  const SelectTransition = ({ fetching, flowing, tasks, itemId, itemData, currentUser, workspace, setPopoverVisible, name, objectId, workflowData, roleIds, groupIds, workspaceRoleIds, approval, checkIn, handleTransition, readonly, flowHandlerActive, }) => {
10
10
  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.map(task => {
11
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
12
- return (_jsx(TransitionButton, { itemId: itemId, loading: flowing, text: task.name, item: itemData, workspace: workspace, userId: currentUser.id, groupIds: groupIds, roleIds: roleIds, workspaceRoleIds: workspaceRoleIds, currentTaskId: task.id, authUsers: (_b = (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.permissionType) === null || _b === void 0 ? void 0 : _b.users, authRoles: (_d = (_c = task.parameters) === null || _c === void 0 ? void 0 : _c.permissionType) === null || _d === void 0 ? void 0 : _d.roles, authGroups: (_f = (_e = task.parameters) === null || _e === void 0 ? void 0 : _e.permissionType) === null || _f === void 0 ? void 0 : _f.groups, authUserFields: (_h = (_g = task.parameters) === null || _g === void 0 ? void 0 : _g.permissionType) === null || _h === void 0 ? void 0 : _h.customFields, authWorkSpaceRoles: (_k = (_j = task.parameters) === null || _j === void 0 ? void 0 : _j.permissionType) === null || _k === void 0 ? void 0 : _k.workspaceRoles, creatorAuth: (_m = (_l = task.parameters) === null || _l === void 0 ? void 0 : _l.permissionType) === null || _m === void 0 ? void 0 : _m.creatorAuth, scriptValidator: (_o = task.parameters) === null || _o === void 0 ? void 0 : _o.scriptValidator, conditions: (_p = task.parameters) === null || _p === void 0 ? void 0 : _p.fieldType, screenId: (_r = (_q = task.parameters) === null || _q === void 0 ? void 0 : _q.screen) === null || _r === void 0 ? void 0 : _r.key, target: task.target, approval: approval, checkIn: checkIn, handleTransition: handleTransition, hiddenPopover: () => setPopoverVisible(false), readonly: readonly, flowHandlerActive: flowHandlerActive }, task.id));
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
12
+ return (_jsx(TransitionButton, { itemId: itemId, loading: flowing, text: task.name, item: itemData, workspace: workspace, userId: currentUser.id, groupIds: groupIds, roleIds: roleIds, workspaceRoleIds: workspaceRoleIds, currentTaskId: task.id, authUsers: (_b = (_a = task.parameters) === null || _a === void 0 ? void 0 : _a.permissionType) === null || _b === void 0 ? void 0 : _b.users, authRoles: (_d = (_c = task.parameters) === null || _c === void 0 ? void 0 : _c.permissionType) === null || _d === void 0 ? void 0 : _d.roles, authGroups: (_f = (_e = task.parameters) === null || _e === void 0 ? void 0 : _e.permissionType) === null || _f === void 0 ? void 0 : _f.groups, authUserFields: (_h = (_g = task.parameters) === null || _g === void 0 ? void 0 : _g.permissionType) === null || _h === void 0 ? void 0 : _h.customFields, authWorkSpaceRoles: (_k = (_j = task.parameters) === null || _j === void 0 ? void 0 : _j.permissionType) === null || _k === void 0 ? void 0 : _k.workspaceRoles, creatorAuth: (_m = (_l = task.parameters) === null || _l === void 0 ? void 0 : _l.permissionType) === null || _m === void 0 ? void 0 : _m.creatorAuth, scriptValidator: (_o = task.parameters) === null || _o === void 0 ? void 0 : _o.scriptValidator, conditions: (_p = task.parameters) === null || _p === void 0 ? void 0 : _p.fieldType, screenId: (_r = (_q = task.parameters) === null || _q === void 0 ? void 0 : _q.screen) === null || _r === void 0 ? void 0 : _r.key, target: task.target, approval: approval, checkIn: checkIn, handleTransition: handleTransition, hiddenPopover: () => setPopoverVisible(false), readonly: readonly, flowHandlerActive: flowHandlerActive, conditionKey: (_s = task.parameters) === null || _s === void 0 ? void 0 : _s.conditionKey, fieldTypeConditionKey: (_t = task.parameters) === null || _t === void 0 ? void 0 : _t.fieldTypeConditionKey, userConditionKey: (_v = (_u = task.parameters) === null || _u === void 0 ? void 0 : _u.permissionType) === null || _v === void 0 ? void 0 : _v.conditionKey }, task.id));
13
13
  }) }) })) : (_jsx("span", { onClick: () => {
14
14
  setPopoverVisible(false);
15
15
  }, css: css(noPermissionStyle), children: i18n.t('pages.fields.view.noWorkflowOrAuth') })), _jsx(View, { workflowData: workflowData, hiddenPopover: () => setPopoverVisible(false), name: name, objectId: objectId })] })) }));
@@ -29,6 +29,9 @@ interface FlowButtonProps {
29
29
  };
30
30
  hiddenPopover?: () => void;
31
31
  readonly?: boolean;
32
+ conditionKey: string;
33
+ fieldTypeConditionKey: string;
34
+ userConditionKey: string;
32
35
  flowHandlerActive?: boolean;
33
36
  }
34
37
  declare const _default: React.NamedExoticComponent<FlowButtonProps>;
@@ -15,7 +15,7 @@ const CheckInStatus = {
15
15
  closed: 'closed',
16
16
  pending: 'pending',
17
17
  };
18
- const FlowButton = ({ loading, screenId, text, item, userId, roleIds, groupIds, workspaceRoleIds, authRoles, authUsers, authGroups, creatorAuth, authUserFields, authWorkSpaceRoles, scriptValidator, approval, checkIn, conditions = [], handleTransition, target, readonly, flowHandlerActive, }) => {
18
+ const FlowButton = ({ loading, screenId, text, item, userId, roleIds, groupIds, workspaceRoleIds, authRoles, authUsers, authGroups, creatorAuth, authUserFields, authWorkSpaceRoles, scriptValidator, approval, checkIn, conditions = [], handleTransition, target, readonly, conditionKey, fieldTypeConditionKey, userConditionKey, flowHandlerActive, }) => {
19
19
  const [isCheck, setIsCheck] = useState(true);
20
20
  const [tip, setTip] = useState('');
21
21
  const checkApproval = useCallback(() => {
@@ -62,6 +62,7 @@ const FlowButton = ({ loading, screenId, text, item, userId, roleIds, groupIds,
62
62
  return;
63
63
  }
64
64
  const transition = {
65
+ conditionKey,
65
66
  parameters: {
66
67
  fieldType: conditions,
67
68
  permissionType: {
@@ -71,7 +72,9 @@ const FlowButton = ({ loading, screenId, text, item, userId, roleIds, groupIds,
71
72
  workspaceRoles: authWorkSpaceRoles,
72
73
  customFields: authUserFields,
73
74
  creatorAuth,
75
+ conditionKey: userConditionKey,
74
76
  },
77
+ fieldTypeConditionKey,
75
78
  },
76
79
  };
77
80
  const checkResult = checkTransition(item, transition, { userId, roleIds, groupIds, workspaceRoleIds }, flowHandlerActive);
@@ -94,6 +97,9 @@ const FlowButton = ({ loading, screenId, text, item, userId, roleIds, groupIds,
94
97
  roleIds,
95
98
  groupIds,
96
99
  workspaceRoleIds,
100
+ conditionKey,
101
+ fieldTypeConditionKey,
102
+ userConditionKey,
97
103
  flowHandlerActive,
98
104
  ]);
99
105
  useEffect(() => {
@@ -118,7 +118,7 @@ function listToCompare(list1, list2, compareString) {
118
118
  export function checkUserPermission({ transition, userId, roleIds, groupIds, item, workspaceRoleIds, }) {
119
119
  var _a, _b, _c;
120
120
  const values = (item === null || item === void 0 ? void 0 : item.values) || {};
121
- const { users: authUsers, roles: authRoles, groups: authGroups, customFields: authUserFields, workspaceRoles: authWorkspaceRoles, creatorAuth, } = ((_a = transition.parameters) === null || _a === void 0 ? void 0 : _a.permissionType) || {};
121
+ const { users: authUsers, roles: authRoles, groups: authGroups, customFields: authUserFields, workspaceRoles: authWorkspaceRoles, creatorAuth, conditionKey, } = ((_a = transition.parameters) === null || _a === void 0 ? void 0 : _a.permissionType) || {};
122
122
  const hasUsers = (authUsers === null || authUsers === void 0 ? void 0 : authUsers.length) > 0;
123
123
  const hasRoles = (authRoles === null || authRoles === void 0 ? void 0 : authRoles.length) > 0;
124
124
  const hasGroups = (authGroups === null || authGroups === void 0 ? void 0 : authGroups.length) > 0;
@@ -126,14 +126,18 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
126
126
  const hasWorkspaceRoles = (authWorkspaceRoles === null || authWorkspaceRoles === void 0 ? void 0 : authWorkspaceRoles.length) > 0;
127
127
  const tipText = [];
128
128
  if (!hasUsers && !hasRoles && !hasGroups && !hasUserFields && !hasWorkspaceRoles && !creatorAuth) {
129
- return { result: true };
129
+ return { result: true, isEmpty: true };
130
130
  }
131
+ const defaultConditionKey = conditionKey || 'any';
132
+ const isAny = defaultConditionKey === 'any';
131
133
  if (creatorAuth) {
132
134
  if (![(_b = item.createdBy) === null || _b === void 0 ? void 0 : _b.objectId, (_c = item.createdBy) === null || _c === void 0 ? void 0 : _c.id].includes(userId)) {
133
135
  tipText.push(i18n.t('pages.workflow.default.userType.creatorAuth'));
134
136
  }
135
137
  else {
136
- return { result: true };
138
+ if (isAny) {
139
+ return { result: true };
140
+ }
137
141
  }
138
142
  }
139
143
  if (hasUsers) {
@@ -143,7 +147,9 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
143
147
  tipText.push(`${i18n.t('libs.workflow.user')}:${tipUsers}`);
144
148
  }
145
149
  else {
146
- return { result: true };
150
+ if (isAny) {
151
+ return { result: true };
152
+ }
147
153
  }
148
154
  }
149
155
  if (hasRoles) {
@@ -153,7 +159,9 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
153
159
  tipText.push(`${i18n.t('libs.workflow.role')}:${tipRoles}`);
154
160
  }
155
161
  else {
156
- return { result: true };
162
+ if (isAny) {
163
+ return { result: true };
164
+ }
157
165
  }
158
166
  }
159
167
  if (hasGroups) {
@@ -163,7 +171,9 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
163
171
  tipText.push(`${i18n.t('libs.workflow.group')}:${tipGroup}`);
164
172
  }
165
173
  else {
166
- return { result: true };
174
+ if (isAny) {
175
+ return { result: true };
176
+ }
167
177
  }
168
178
  }
169
179
  if (hasUserFields) {
@@ -194,7 +204,9 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
194
204
  tipText.push(`${i18n.t('libs.workflow.userFields')}:${tipRoles}`);
195
205
  }
196
206
  else {
197
- return { result: true };
207
+ if (isAny) {
208
+ return { result: true };
209
+ }
198
210
  }
199
211
  }
200
212
  if (hasWorkspaceRoles) {
@@ -206,7 +218,9 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
206
218
  tipText.push(`${i18n.t('libs.workflow.workspaceRoles')}:${tipWorkspaceRoles}`);
207
219
  }
208
220
  else {
209
- return { result: true };
221
+ if (isAny) {
222
+ return { result: true };
223
+ }
210
224
  }
211
225
  }
212
226
  if (tipText.length) {
@@ -215,8 +229,13 @@ export function checkUserPermission({ transition, userId, roleIds, groupIds, ite
215
229
  return { result: true };
216
230
  }
217
231
  export function checkItemCondition(transition, item) {
218
- var _a, _b;
219
- const conditions = ((_a = transition.parameters) === null || _a === void 0 ? void 0 : _a.fieldType) || [];
232
+ var _a, _b, _c;
233
+ const defaultConditionKey = ((_a = transition === null || transition === void 0 ? void 0 : transition.parameters) === null || _a === void 0 ? void 0 : _a.fieldTypeConditionKey) || 'all';
234
+ const conditions = ((_b = transition.parameters) === null || _b === void 0 ? void 0 : _b.fieldType) || [];
235
+ const isAny = defaultConditionKey === 'any';
236
+ if (!conditions.length) {
237
+ return { result: true, isEmpty: true };
238
+ }
220
239
  for (const i in conditions) {
221
240
  const { comparedValue, numberCompare, stringCompare, dropDownCompare, field, pickerType } = conditions[i];
222
241
  let fieldValue;
@@ -231,12 +250,12 @@ export function checkItemCondition(transition, item) {
231
250
  fieldValue = item[field.key].objectId;
232
251
  }
233
252
  else {
234
- fieldValue = (_b = item.values) === null || _b === void 0 ? void 0 : _b[field.key];
253
+ fieldValue = (_c = item.values) === null || _c === void 0 ? void 0 : _c[field.key];
235
254
  }
236
255
  let sourceValue = null, targetValue = null;
237
256
  switch (field.componentType) {
238
257
  case CustomFieldComponentTypes.Number:
239
- case CustomFieldComponentTypes.Date:
258
+ case CustomFieldComponentTypes.Date: {
240
259
  targetValue = comparedValue;
241
260
  if (field.componentType === CustomFieldComponentTypes.Date && NumberConditions.equalTo.key === numberCompare) {
242
261
  targetValue = getFormat(targetValue || null, getDateType(pickerType));
@@ -251,6 +270,13 @@ export function checkItemCondition(transition, item) {
251
270
  }),
252
271
  };
253
272
  }
273
+ else {
274
+ if (isAny) {
275
+ return {
276
+ result: true,
277
+ };
278
+ }
279
+ }
254
280
  }
255
281
  else if (!numberToCompare(fieldValue, Number(targetValue), numberCompare)) {
256
282
  if (isEmptyCondition(numberCompare)) {
@@ -275,7 +301,14 @@ export function checkItemCondition(transition, item) {
275
301
  }),
276
302
  };
277
303
  }
278
- break;
304
+ else {
305
+ if (isAny) {
306
+ return {
307
+ result: true,
308
+ };
309
+ }
310
+ }
311
+ }
279
312
  case CustomFieldComponentTypes.Text:
280
313
  case CustomFieldComponentTypes.LongText:
281
314
  targetValue = comparedValue;
@@ -299,6 +332,13 @@ export function checkItemCondition(transition, item) {
299
332
  message,
300
333
  };
301
334
  }
335
+ else {
336
+ if (isAny) {
337
+ return {
338
+ result: true,
339
+ };
340
+ }
341
+ }
302
342
  break;
303
343
  case CustomFieldComponentTypes.User:
304
344
  case CustomFieldComponentTypes.Dropdown:
@@ -337,8 +377,13 @@ export function checkItemCondition(transition, item) {
337
377
  }),
338
378
  };
339
379
  }
340
- break;
341
- default:
380
+ else {
381
+ if (isAny) {
382
+ return {
383
+ result: true,
384
+ };
385
+ }
386
+ }
342
387
  break;
343
388
  }
344
389
  }
@@ -348,6 +393,8 @@ export function checkTransition(item, transition, permissions, flowHandlerActive
348
393
  var _a, _b;
349
394
  if (!item || !transition)
350
395
  return { result: false };
396
+ const defaultConditionKey = (transition === null || transition === void 0 ? void 0 : transition.conditionKey) || 'all';
397
+ const isAll = defaultConditionKey === 'all';
351
398
  if (flowHandlerActive && ((_b = (_a = item === null || item === void 0 ? void 0 : item.values) === null || _a === void 0 ? void 0 : _a.flowHandler) === null || _b === void 0 ? void 0 : _b.length)) {
352
399
  const flowHandler = item.values.flowHandler;
353
400
  const flowUser = flowHandler.find(user => user.value === permissions.userId);
@@ -367,12 +414,27 @@ export function checkTransition(item, transition, permissions, flowHandlerActive
367
414
  item,
368
415
  ...permissions,
369
416
  });
370
- if (!roleCheck.result)
371
- return roleCheck;
372
417
  const conditionCheck = checkItemCondition(transition, item);
373
- if (!conditionCheck.result)
374
- return conditionCheck;
375
- return { result: true };
418
+ if (isAll) {
419
+ if (!roleCheck.result)
420
+ return roleCheck;
421
+ if (!conditionCheck.result)
422
+ return conditionCheck;
423
+ return { result: true };
424
+ }
425
+ else {
426
+ const conditionList = [roleCheck, conditionCheck];
427
+ const notEmpty = conditionList.filter(item => !item.isEmpty);
428
+ if ((notEmpty === null || notEmpty === void 0 ? void 0 : notEmpty.length) > 0) {
429
+ const [notEmptyCondition] = notEmpty;
430
+ if (!notEmptyCondition.result) {
431
+ return notEmptyCondition;
432
+ }
433
+ }
434
+ else {
435
+ return { result: true };
436
+ }
437
+ }
376
438
  }
377
439
  export const useWorkflowPermission = (workspaceId) => {
378
440
  const [roles, setRoles] = useState([]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-team-components",
3
- "version": "1.2.1",
3
+ "version": "1.2.2-alpha.2",
4
4
  "description": "Gitee team components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -64,6 +64,7 @@
64
64
  "@emotion/cache": "^11.11.0",
65
65
  "@emotion/react": "^11.11.1",
66
66
  "debug": "^4.3.4",
67
+ "fs-extra": "^11.2.0",
67
68
  "lodash-es": "^4.17.21"
68
69
  }
69
70
  }