@giteeteam/apps-team-components 1.2.3-alpha.1 → 1.2.3-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.
@@ -4,14 +4,79 @@ import { ClassNames } from '@emotion/react';
4
4
  import { Spin } from 'antd';
5
5
  import useWorkflowConfig from '../../../lib/hooks/useWorkflowConfig';
6
6
  import { i18n } from '../../../lib/i18n';
7
+ import { checkFlowHandler } from '../../../lib/workflow';
7
8
  import { flowNextStyle, flowWrapperStyle, noPermissionStyle, spinStyle } from './style';
8
9
  import TransitionButton from './TransitionButton';
9
10
  import View from './View';
10
- const SelectTransition = ({ fetching, flowing, tasks, itemId, itemData, currentUser, workspace, setPopoverVisible, name, objectId, workflowData, roleIds, groupIds, workspaceRoleIds, approval, checkIn, handleTransition, readonly, flowHandlerActive, }) => {
11
+ const ApprovalStatus = {
12
+ approved: 'approved',
13
+ rejected: 'rejected',
14
+ };
15
+ const CheckInStatus = {
16
+ closed: 'closed',
17
+ pending: 'pending',
18
+ };
19
+ const SelectTransition = ({ fetching, flowing, tasks, itemId, itemData, currentUser, setPopoverVisible, name, objectId, workflowData, approval, checkIn, handleTransition, readonly, flowHandlerActive, }) => {
20
+ const [transitionList, setTransitionList] = useState([]);
21
+ const [checkResultList, setCheckResultList] = useState([]);
11
22
  const [init, setInit] = useState(false);
12
23
  const { postCheckTransitions, hideDisabledStatusTransition } = useWorkflowConfig();
13
- const [checkResultList, setCheckResultList] = useState([]);
14
- const [hideIds, setHideIds] = useState([]);
24
+ const checkApproval = useCallback(({ text }) => {
25
+ var _a;
26
+ if (!approval.requireApproval)
27
+ return [true];
28
+ const approvedTransitions = approval.transition.approved.map(approved => approved.label);
29
+ const rejectedTransitions = approval.transition.rejected.map(rejected => rejected.label);
30
+ const unrestrictedTransitions = ((_a = approval.transition.unrestricted) === null || _a === void 0 ? void 0 : _a.map(unrestricted => unrestricted.label)) || [];
31
+ if ((ApprovalStatus.approved === approval.approvalStatus && approvedTransitions.includes(text)) ||
32
+ (ApprovalStatus.rejected === approval.approvalStatus && rejectedTransitions.includes(text))) {
33
+ return [true];
34
+ }
35
+ if (![ApprovalStatus.approved, ApprovalStatus.rejected].includes(approval.approvalStatus) &&
36
+ (unrestrictedTransitions === null || unrestrictedTransitions === void 0 ? void 0 : unrestrictedTransitions.includes(text))) {
37
+ if (!approval.startApproval) {
38
+ return [true];
39
+ }
40
+ else {
41
+ return [false, i18n.t('pages.fields.view.unrestrictedStatus')];
42
+ }
43
+ }
44
+ return [false, i18n.t('pages.fields.view.approvalStatus')];
45
+ }, [approval]);
46
+ const validateCheckIn = useCallback(() => {
47
+ if (!checkIn.requireCheckIn)
48
+ return true;
49
+ if (checkIn.checkInStatus !== CheckInStatus.pending) {
50
+ return true;
51
+ }
52
+ return false;
53
+ }, [checkIn]);
54
+ const checkOneTransition = useCallback(({ text, conditionCheck }) => {
55
+ const [checkApprovalResult, checkApprovalMessage] = checkApproval({ text });
56
+ if (!checkApprovalResult) {
57
+ return {
58
+ result: false,
59
+ message: checkApprovalMessage,
60
+ };
61
+ }
62
+ if (!validateCheckIn()) {
63
+ return {
64
+ result: false,
65
+ message: i18n.t('pages.fields.view.checkInStatus'),
66
+ };
67
+ }
68
+ const checkResult = checkFlowHandler(itemData, { userId: currentUser.id }, flowHandlerActive);
69
+ if (checkResult && !checkResult.result) {
70
+ return checkResult;
71
+ }
72
+ if (!(conditionCheck === null || conditionCheck === void 0 ? void 0 : conditionCheck.result) && conditionCheck) {
73
+ if (hideDisabledStatusTransition === 'enabled') {
74
+ return { result: false, isHide: true };
75
+ }
76
+ return conditionCheck;
77
+ }
78
+ return { result: true };
79
+ }, [checkApproval, currentUser, flowHandlerActive, hideDisabledStatusTransition, validateCheckIn, itemData]);
15
80
  useEffect(() => {
16
81
  if (!init && workflowData.objectId && tasks.length && postCheckTransitions && itemId) {
17
82
  setInit(true);
@@ -19,23 +84,32 @@ const SelectTransition = ({ fetching, flowing, tasks, itemId, itemData, currentU
19
84
  transitionId: _transition.id,
20
85
  itemId,
21
86
  workflowId: workflowData.objectId,
22
- }))).then(checkResultList => {
23
- setCheckResultList(checkResultList);
87
+ }))).then(_checkResultList => {
88
+ setCheckResultList(_checkResultList);
24
89
  });
25
90
  }
26
- }, [init, itemId, workflowData, postCheckTransitions, tasks]);
27
- const handleHide = useCallback(id => {
28
- setHideIds(c => {
29
- if (!c.includes(id)) {
30
- return c.concat(id);
31
- }
32
- return c;
91
+ }, [init, itemId, workflowData, postCheckTransitions, tasks, itemData]);
92
+ useEffect(() => {
93
+ const _transitionList = [];
94
+ if (checkResultList.length === 0)
95
+ return;
96
+ tasks.forEach(task => {
97
+ var _a;
98
+ const conditionCheck = (_a = checkResultList.find(checkResult => checkResult.transitionId === task.id)) === null || _a === void 0 ? void 0 : _a.result;
99
+ const allResult = checkOneTransition({ text: task.name, conditionCheck });
100
+ _transitionList.push({
101
+ data: task,
102
+ checkResult: allResult,
103
+ });
33
104
  });
34
- }, []);
35
- const isAllHide = tasks.every(task => hideIds.includes(task.id));
36
- return (_jsx(ClassNames, { children: ({ cx, css }) => (_jsxs(_Fragment, { children: [fetching ? (_jsx(Spin, { css: css(spinStyle) })) : tasks.length && !isAllHide ? (_jsx("div", { className: cx(css(flowNextStyle), `flow-next-global`), children: _jsx("div", { className: cx(css(flowWrapperStyle)), children: tasks.map(task => {
37
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
38
- 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, conditionCheck: (_w = checkResultList.find(checkResult => checkResult.transitionId === task.id)) === null || _w === void 0 ? void 0 : _w.result, hideDisabledStatusTransition: hideDisabledStatusTransition, onHide: handleHide }, task.id));
105
+ setTransitionList(_transitionList);
106
+ }, [checkResultList, checkOneTransition, itemData, tasks]);
107
+ 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
108
+ .filter(_task => { var _a; return !((_a = _task === null || _task === void 0 ? void 0 : _task.checkResult) === null || _a === void 0 ? void 0 : _a.isHide); })
109
+ .map(_task => {
110
+ var _a, _b, _c;
111
+ const { data: task, checkResult } = _task;
112
+ 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));
39
113
  }) }) })) : (_jsx("span", { onClick: () => {
40
114
  setPopoverVisible(false);
41
115
  }, css: css(noPermissionStyle), children: i18n.t('pages.fields.view.noWorkflowOrAuth') })), _jsx(View, { workflowData: workflowData, hiddenPopover: () => setPopoverVisible(false), name: name, objectId: objectId })] })) }));
@@ -1,44 +1,19 @@
1
1
  import React from 'react';
2
- import { ItemResultProps } from '../../../lib/types/item';
3
- import { ApprovalData, CheckInData, ConditionType, ListItemType, NodeItemProps } from '../../../lib/types/workflow';
2
+ import { NodeItemProps } from '../../../lib/types/workflow';
4
3
  interface FlowButtonProps {
5
- itemId: string;
6
4
  loading: boolean;
7
5
  text: string;
8
6
  screenId: string;
9
- item: ItemResultProps;
10
- workspace: string;
11
- authRoles: ListItemType[] | undefined;
12
- authUsers: ListItemType[] | undefined;
13
- authGroups: ListItemType[] | undefined;
14
- authUserFields: ListItemType[] | undefined;
15
- authWorkSpaceRoles: ListItemType[] | undefined;
16
- creatorAuth: boolean | undefined;
17
7
  scriptValidator: string;
18
- userId: string;
19
- roleIds: string[];
20
- groupIds: string[];
21
- workspaceRoleIds: string[];
22
- currentTaskId: string;
23
- conditions?: ConditionType[];
24
- approval: ApprovalData;
25
- checkIn: CheckInData;
26
8
  handleTransition: (updateTask: string, screenId: string, script: string) => void;
27
9
  target: NodeItemProps & {
28
10
  type?: string;
29
11
  };
30
- hiddenPopover?: () => void;
31
12
  readonly?: boolean;
32
- conditionKey: string;
33
- fieldTypeConditionKey: string;
34
- userConditionKey: string;
35
- flowHandlerActive?: boolean;
36
13
  conditionCheck?: {
37
14
  result: boolean;
38
15
  message: string;
39
16
  };
40
- hideDisabledStatusTransition?: string;
41
- onHide?: (id: string) => void;
42
17
  }
43
18
  declare const _default: React.NamedExoticComponent<FlowButtonProps>;
44
19
  export default _default;
@@ -1,127 +1,21 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
- import { memo, useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { memo, useMemo } from 'react';
3
3
  import { ClassNames, css } from '@emotion/react';
4
4
  import { Tooltip } from 'antd';
5
5
  import { WorkFlowStatusColor } from '../../../lib/global';
6
6
  import { i18n } from '../../../lib/i18n';
7
- import { checkFlowHandler } from '../../../lib/workflow';
8
7
  import BaseOverflowTooltip from '../../common/overflow-tooltip/BaseOverflowTooltip';
9
8
  import { flowBtnStyle, flowStateStyle, iconStyle, notAllowedStyle, pointerStyle, stateBoxStyle, tipLineStyle, tooltipStyle, } from './style';
10
- const ApprovalStatus = {
11
- approved: 'approved',
12
- rejected: 'rejected',
13
- };
14
- const CheckInStatus = {
15
- closed: 'closed',
16
- pending: 'pending',
17
- };
18
- const FlowButton = ({ loading, screenId, text, item, userId, authRoles, authUsers, authGroups, creatorAuth, authUserFields, authWorkSpaceRoles, scriptValidator, approval, checkIn, conditions = [], handleTransition, target, readonly, conditionKey, fieldTypeConditionKey, userConditionKey, flowHandlerActive, conditionCheck, hideDisabledStatusTransition, onHide, currentTaskId, }) => {
19
- const [isCheck, setIsCheck] = useState(true);
20
- const [tip, setTip] = useState('');
21
- const [hide, setHide] = useState(false);
22
- const checkApproval = useCallback(() => {
23
- var _a;
24
- if (!approval.requireApproval)
25
- return true;
26
- const approvedTransitions = approval.transition.approved.map(approved => approved.label);
27
- const rejectedTransitions = approval.transition.rejected.map(rejected => rejected.label);
28
- const unrestrictedTransitions = ((_a = approval.transition.unrestricted) === null || _a === void 0 ? void 0 : _a.map(unrestricted => unrestricted.label)) || [];
29
- if ((ApprovalStatus.approved === approval.approvalStatus && approvedTransitions.includes(text)) ||
30
- (ApprovalStatus.rejected === approval.approvalStatus && rejectedTransitions.includes(text))) {
31
- return true;
32
- }
33
- if (![ApprovalStatus.approved, ApprovalStatus.rejected].includes(approval.approvalStatus) &&
34
- (unrestrictedTransitions === null || unrestrictedTransitions === void 0 ? void 0 : unrestrictedTransitions.includes(text))) {
35
- if (!approval.startApproval) {
36
- return true;
37
- }
38
- else {
39
- setTip(i18n.t('pages.fields.view.unrestrictedStatus'));
40
- return false;
41
- }
42
- }
43
- setTip(i18n.t('pages.fields.view.approvalStatus'));
44
- return false;
45
- }, [approval, text]);
46
- const validateCheckIn = useCallback(() => {
47
- if (!checkIn.requireCheckIn)
48
- return true;
49
- if (checkIn.checkInStatus !== CheckInStatus.pending) {
50
- return true;
51
- }
52
- return false;
53
- }, [checkIn]);
54
- const checkAuth = useCallback(async () => {
55
- setIsCheck(true);
56
- if (!checkApproval()) {
57
- setIsCheck(false);
58
- return;
59
- }
60
- if (!validateCheckIn()) {
61
- setTip(i18n.t('pages.fields.view.checkInStatus'));
62
- setIsCheck(false);
63
- return;
64
- }
65
- const transition = {
66
- conditionKey,
67
- parameters: {
68
- fieldType: conditions,
69
- permissionType: {
70
- users: authUsers,
71
- roles: authRoles,
72
- groups: authGroups,
73
- workspaceRoles: authWorkSpaceRoles,
74
- customFields: authUserFields,
75
- creatorAuth,
76
- conditionKey: userConditionKey,
77
- },
78
- fieldTypeConditionKey,
79
- },
80
- };
81
- let checkResult = checkFlowHandler(item, transition, { userId }, flowHandlerActive);
82
- if (!checkResult) {
83
- checkResult = conditionCheck;
84
- }
85
- if (!(checkResult === null || checkResult === void 0 ? void 0 : checkResult.result)) {
86
- setTip(checkResult === null || checkResult === void 0 ? void 0 : checkResult.message);
87
- setIsCheck(false);
88
- if (hideDisabledStatusTransition === 'enabled') {
89
- setHide(true);
90
- onHide(currentTaskId);
91
- }
92
- }
93
- }, [
94
- hideDisabledStatusTransition,
95
- checkApproval,
96
- validateCheckIn,
97
- conditions,
98
- authUsers,
99
- authRoles,
100
- authGroups,
101
- authWorkSpaceRoles,
102
- authUserFields,
103
- creatorAuth,
104
- item,
105
- userId,
106
- conditionKey,
107
- fieldTypeConditionKey,
108
- userConditionKey,
109
- flowHandlerActive,
110
- conditionCheck,
111
- onHide,
112
- currentTaskId,
113
- ]);
114
- useEffect(() => {
115
- checkAuth();
116
- }, [checkAuth]);
9
+ const FlowButton = ({ loading, screenId, text, scriptValidator, handleTransition, target, readonly, conditionCheck, }) => {
117
10
  const tipContent = useMemo(() => {
11
+ const _tip = conditionCheck.message;
118
12
  if (readonly)
119
13
  return i18n.t('pages.fields.view.readonlyStatus');
120
- if (!tip)
14
+ if (!_tip)
121
15
  return '';
122
- const contents = tip.split('--');
16
+ const contents = _tip.split('--');
123
17
  return (_jsx("div", { children: contents.map((text, index) => (_jsx("p", { css: css(tipLineStyle), children: text }, String(index)))) }));
124
- }, [tip, readonly]);
18
+ }, [readonly, conditionCheck]);
125
19
  const OverflowText = ({ text, target }) => {
126
20
  var _a, _b;
127
21
  return (_jsxs(_Fragment, { children: [_jsx(BaseOverflowTooltip, { css: css(tooltipStyle), title: text, children: text }), _jsx("span", { css: css(iconStyle), children: " \u2192 " }), _jsx("div", { css: css(stateBoxStyle), children: _jsx(BaseOverflowTooltip, { css: css(flowStateStyle), style: {
@@ -130,11 +24,11 @@ const FlowButton = ({ loading, screenId, text, item, userId, authRoles, authUser
130
24
  }, title: target.name, children: target.name }) })] }));
131
25
  };
132
26
  return (_jsx(ClassNames, { children: ({ cx, css }) => {
133
- return isCheck && !readonly ? (_jsx("div", { className: cx(css(flowBtnStyle), loading ? css(notAllowedStyle) : css(pointerStyle)), onClick: () => {
27
+ return conditionCheck ? ((conditionCheck === null || conditionCheck === void 0 ? void 0 : conditionCheck.result) && !readonly ? (_jsx("div", { className: cx(css(flowBtnStyle), loading ? css(notAllowedStyle) : css(pointerStyle)), onClick: () => {
134
28
  if (!loading) {
135
29
  handleTransition(text, screenId, scriptValidator);
136
30
  }
137
- }, children: _jsx(OverflowText, { text: text, target: target }) })) : hide ? null : (_jsx(Tooltip, { title: tipContent, placement: "right", children: _jsx("div", { className: cx(css(flowBtnStyle), css(notAllowedStyle)), children: _jsx(OverflowText, { text: text, target: target }) }) }));
31
+ }, 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;
138
32
  } }));
139
33
  };
140
34
  export default memo(FlowButton);
@@ -107,6 +107,6 @@ interface CheckUserPermissionParams {
107
107
  export declare function checkUserPermission({ transition, userId, roleIds, groupIds, item, workspaceRoleIds, }: CheckUserPermissionParams): ResultType;
108
108
  export declare function checkItemCondition(transition: TransitionProps, item: ItemResultProps): ResultType;
109
109
  export declare function checkTransition(item: ItemResultProps, transition: TransitionProps, permissions: WorkflowPermissionType, flowHandlerActive?: boolean): ResultType;
110
- export declare function checkFlowHandler(item: ItemResultProps, transition: TransitionProps, permissions: WorkflowPermissionType, flowHandlerActive?: boolean): ResultType;
110
+ export declare function checkFlowHandler(item: ItemResultProps, permissions: WorkflowPermissionType, flowHandlerActive?: boolean): ResultType;
111
111
  export declare const useWorkflowPermission: (workspaceId: ObjectId) => [ObjectId[], ObjectId[], ObjectId[]];
112
112
  export {};
@@ -440,9 +440,9 @@ export function checkTransition(item, transition, permissions, flowHandlerActive
440
440
  }
441
441
  }
442
442
  }
443
- export function checkFlowHandler(item, transition, permissions, flowHandlerActive) {
443
+ export function checkFlowHandler(item, permissions, flowHandlerActive) {
444
444
  var _a, _b;
445
- if (!item || !transition)
445
+ if (!item)
446
446
  return { result: false };
447
447
  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)) {
448
448
  const flowHandler = item.values.flowHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-team-components",
3
- "version": "1.2.3-alpha.1",
3
+ "version": "1.2.3-alpha.2",
4
4
  "description": "Gitee team components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",