Skip to content

Commit

Permalink
feat: add condition activity property defaultCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
fengxiaotx committed Dec 16, 2024
1 parent 5dbb39e commit 24d8510
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
4 changes: 1 addition & 3 deletions examples/approval-process-designer-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ function App() {
{
type: 'CONDITION',
componentName: 'ConditionActivity',
props: {
defaultCondition: true,
}
defaultCondition: true,
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/approval-process-designer-react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';

// https://vite.dev/config/
export default defineConfig({
base: '/triones-approval-process-designer/',
base: process.env.NODE_ENV === 'production' ?'/triones-approval-process-designer/': '/',
plugins: [react()],
resolve: {
alias: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const ConditionActivity: FC<ConditionActivityProps> = ({
const [editing, setEditing] = useState(false)

const handleOnClick = (e: any) => {
if (processNode.props?.defaultCondition) {
if (processNode?.defaultCondition) {
return
}
onClick?.(processNode)
Expand All @@ -171,7 +171,7 @@ export const ConditionActivity: FC<ConditionActivityProps> = ({
<div className={classNames('condition-activity-box')} onClick={handleOnClick}>
<div className={classNames(`header`)} >
{
processNode?.props?.defaultCondition ?
processNode?.defaultCondition ?
<>
<span className={classNames('default-title')}>默认条件
<Tooltip placement={`top`} showArrow={true} trigger={`hover`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const popoverCss = css({
minWidth: '250px',
color: 'rgba(255,255,255)',
transformOrigin: 'var(--arrow-x, 50%) var(--arrow-y, 50%)',
boxShadow:'0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05)',
[`&-hidden`]: {
display: 'none'
},
Expand Down
39 changes: 24 additions & 15 deletions packages/approval-process-designer-react/src/model/ProcessNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Chance from 'chance';
import _ from "lodash";
import {GlobalStore} from "../store";
import {ApprovalProcessEngine} from "./ApprovalProcessEngine";

const chance = new Chance();

export type ProcessNodeType = 'START' | 'ROUTE' | 'CONDITION' | 'APPROVAL' | 'CC' | 'END'
Expand All @@ -18,6 +19,7 @@ export interface IProcessNode {
title?: string
description?: string
props?: any
defaultCondition?: boolean
}

const ProcessNodes = new Map<string, ProcessNode>()
Expand All @@ -34,11 +36,12 @@ export class ProcessNode {
title: string
description: string
props: any
defaultCondition?: boolean

constructor(node: IProcessNode, parentNode?: ProcessNode) {
this.engine = node.engine
this.isSourceNode = node.isSourceNode
this.id = node.id || `Activity_${chance.string({ length: 10, alpha: true })}`
this.id = node.id || `Activity_${chance.string({length: 10, alpha: true})}`
this.type = node.type
this.componentName = node.componentName || node.type
this.prevNodeId = parentNode?.id
Expand All @@ -48,6 +51,7 @@ export class ProcessNode {
this.description = node.description
this.props = node.props
this.engine = parentNode?.engine
this.defaultCondition = node.defaultCondition

ProcessNodes.set(this.id, this)
if (node) {
Expand Down Expand Up @@ -141,10 +145,11 @@ export class ProcessNode {
}, parentNode)
if (this.type == 'ROUTE') {
const conditionResource = GlobalStore.getConditionActivityResource()
const condition1 = conditionResource.node.clone(node)
const firstCondition = conditionResource.node.clone(node)
const conditionDefault = conditionResource.node.clone(node)
conditionDefault.props = _.assign(conditionDefault.props, {defaultCondition: true})
node.setConditionNodes([condition1, conditionDefault])
// conditionDefault.props = _.assign(conditionDefault.props, {defaultCondition: true})
conditionDefault.defaultCondition = true
node.setConditionNodes([firstCondition, conditionDefault])
}
return node
}
Expand Down Expand Up @@ -178,12 +183,12 @@ export class ProcessNode {
const remainNode = _.find(parentNode.conditionNodes, (conditionNode: any) => {
return conditionNode.id !== this.id
})
const {deleteIds,startNode,endNode} = this.processRaminRouteBranch(remainNode)
const {deleteIds, startNode, endNode} = this.processRaminRouteBranch(remainNode)
linkedIds.push(...deleteIds)
if (startNode){
if (startNode) {
parentParentNode.setNextNode(startNode)
endNode.setNextNode(parentNodeNextNode)
}else {
} else {
parentParentNode?.setNextNode(parentNodeNextNode)
}
}
Expand Down Expand Up @@ -235,27 +240,31 @@ export class ProcessNode {
* 处理剩下的分支(default branch),删除条件节点,保留其他节点
* @param node
*/
processRaminRouteBranch=(node:ProcessNode):{deleteIds?:string[],startNode?:ProcessNode,endNode?:ProcessNode}=>{
processRaminRouteBranch = (node: ProcessNode): {
deleteIds?: string[],
startNode?: ProcessNode,
endNode?: ProcessNode
} => {
const ids = []
const getStartNode = (node:ProcessNode) => {
if (!node){
const getStartNode = (node: ProcessNode) => {
if (!node) {
return null;
}
let startNode = node
while (startNode?.type==='CONDITION'){
while (startNode?.type === 'CONDITION') {
ids.push(startNode.id)
startNode = startNode.nextNode
}
return startNode
}

const getEndNode = (node:ProcessNode) => {
if (!node){
const getEndNode = (node: ProcessNode) => {
if (!node) {
return null
}
let endNode = node
while (endNode?.nextNode){
endNode = endNode.nextNode
while (endNode?.nextNode) {
endNode = endNode.nextNode
}
return endNode
}
Expand Down

0 comments on commit 24d8510

Please sign in to comment.