-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* style: add instances tree * refactor: add label to tree view and remove unnecessary map index * refactor: pass default tree node props instead of manually setting them * refactor: set default value to isRoot
- Loading branch information
Showing
8 changed files
with
804 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
263 changes: 263 additions & 0 deletions
263
client/src/App/Carbon/ProcessInstance/FlowNodeInstancesTree/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,263 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
|
||
import React, {useRef} from 'react'; | ||
import {observer} from 'mobx-react'; | ||
import {processInstanceDetailsDiagramStore} from 'modules/stores/processInstanceDetailsDiagram'; | ||
import {processInstanceDetailsStore} from 'modules/stores/processInstanceDetails'; | ||
import {flowNodeSelectionStore} from 'modules/stores/flowNodeSelection'; | ||
import { | ||
flowNodeInstanceStore, | ||
FlowNodeInstance, | ||
MAX_INSTANCES_STORED, | ||
} from 'modules/stores/flowNodeInstance'; | ||
import {InfiniteScroller} from 'modules/components/InfiniteScroller'; | ||
import {tracking} from 'modules/tracking'; | ||
import {modificationsStore} from 'modules/stores/modifications'; | ||
import {instanceHistoryModificationStore} from 'modules/stores/instanceHistoryModification'; | ||
import {TreeNode, NodeName} from './styled'; | ||
import {FlowNodeIcon} from 'modules/components/Carbon/FlowNodeIcon'; | ||
import {isSubProcess} from 'modules/bpmn-js/utils/isSubProcess'; | ||
|
||
type Props = { | ||
flowNodeInstance: FlowNodeInstance; | ||
isRoot?: boolean; | ||
rowRef?: React.Ref<HTMLDivElement>; | ||
scrollableContainerRef: React.RefObject<HTMLElement>; | ||
}; | ||
|
||
const getVisibleChildPlaceholders = ({ | ||
isModificationModeEnabled, | ||
flowNodeInstance, | ||
}: { | ||
isModificationModeEnabled: boolean; | ||
flowNodeInstance: FlowNodeInstance; | ||
}) => { | ||
const {state, isPlaceholder, flowNodeId, id} = flowNodeInstance; | ||
if ( | ||
!isModificationModeEnabled || | ||
(!isPlaceholder && | ||
(state === undefined || !['ACTIVE', 'INCIDENT'].includes(state))) | ||
) { | ||
return []; | ||
} | ||
|
||
return instanceHistoryModificationStore.getVisibleChildPlaceholders( | ||
id, | ||
flowNodeId, | ||
isPlaceholder | ||
); | ||
}; | ||
|
||
const ScrollableNodes: React.FC< | ||
Omit<React.ComponentProps<typeof InfiniteScroller>, 'children'> & { | ||
visibleChildren: FlowNodeInstance[]; | ||
} | ||
> = ({ | ||
onVerticalScrollEndReach, | ||
onVerticalScrollStartReach, | ||
visibleChildren, | ||
scrollableContainerRef, | ||
...carbonTreeNodeProps | ||
}) => { | ||
return ( | ||
<InfiniteScroller | ||
onVerticalScrollEndReach={onVerticalScrollEndReach} | ||
onVerticalScrollStartReach={onVerticalScrollStartReach} | ||
scrollableContainerRef={scrollableContainerRef} | ||
> | ||
<ul> | ||
{visibleChildren.map((childNode: FlowNodeInstance) => { | ||
return ( | ||
<FlowNodeInstancesTree | ||
flowNodeInstance={childNode} | ||
key={childNode.id} | ||
scrollableContainerRef={scrollableContainerRef} | ||
{...carbonTreeNodeProps} | ||
/> | ||
); | ||
})} | ||
</ul> | ||
</InfiniteScroller> | ||
); | ||
}; | ||
|
||
const FlowNodeInstancesTree: React.FC<Props> = observer( | ||
({flowNodeInstance, scrollableContainerRef, isRoot = false, ...rest}) => { | ||
const {fetchSubTree, removeSubTree, getVisibleChildNodes} = | ||
flowNodeInstanceStore; | ||
|
||
const isProcessInstance = | ||
flowNodeInstance.id === | ||
processInstanceDetailsStore.state.processInstance?.id; | ||
|
||
const visibleChildNodes = getVisibleChildNodes(flowNodeInstance); | ||
|
||
const visibleChildPlaceholders: FlowNodeInstance[] = | ||
getVisibleChildPlaceholders({ | ||
isModificationModeEnabled: modificationsStore.isModificationModeEnabled, | ||
flowNodeInstance, | ||
}); | ||
|
||
const visibleChildren = [...visibleChildNodes, ...visibleChildPlaceholders]; | ||
|
||
const hasVisibleChildPlaceholders = visibleChildPlaceholders.length > 0; | ||
const hasVisibleChildNodes = visibleChildNodes.length > 0; | ||
|
||
const businessObject = isProcessInstance | ||
? processInstanceDetailsDiagramStore.processBusinessObject | ||
: processInstanceDetailsDiagramStore.businessObjects[ | ||
flowNodeInstance.flowNodeId | ||
]; | ||
|
||
const isMultiInstanceBody = flowNodeInstance.type === 'MULTI_INSTANCE_BODY'; | ||
|
||
const isFoldable = | ||
isMultiInstanceBody || isSubProcess(businessObject) || isRoot; | ||
|
||
const hasChildren = flowNodeInstance.isPlaceholder | ||
? isFoldable && | ||
instanceHistoryModificationStore.hasChildPlaceholders( | ||
flowNodeInstance.id | ||
) | ||
: isFoldable; | ||
|
||
const isSelected = flowNodeSelectionStore.isSelected({ | ||
flowNodeInstanceId: flowNodeInstance.id, | ||
flowNodeId: flowNodeInstance.flowNodeId, | ||
isMultiInstance: isMultiInstanceBody, | ||
}); | ||
|
||
const rowRef = useRef<HTMLDivElement>(null); | ||
|
||
const expandSubtree = (flowNodeInstance: FlowNodeInstance) => { | ||
if (!flowNodeInstance.isPlaceholder) { | ||
fetchSubTree({treePath: flowNodeInstance.treePath}); | ||
} else { | ||
instanceHistoryModificationStore.appendExpandedFlowNodeInstanceIds( | ||
flowNodeInstance.id | ||
); | ||
} | ||
}; | ||
|
||
const collapseSubtree = (flowNodeInstance: FlowNodeInstance) => { | ||
if (!flowNodeInstance.isPlaceholder) { | ||
removeSubTree({ | ||
treePath: flowNodeInstance.treePath, | ||
}); | ||
} else { | ||
instanceHistoryModificationStore.removeFromExpandedFlowNodeInstanceIds( | ||
flowNodeInstance.id | ||
); | ||
} | ||
}; | ||
|
||
const handleEndReach = async (scrollUp: (distance: number) => void) => { | ||
if (flowNodeInstance?.treePath === undefined) { | ||
return; | ||
} | ||
if (flowNodeInstance.treePath !== null) { | ||
const fetchedInstancesCount = await flowNodeInstanceStore.fetchNext( | ||
flowNodeInstance.treePath | ||
); | ||
|
||
// This ensures that the container is scrolling up when MAX_INSTANCES_STORED is reached. | ||
if ( | ||
fetchedInstancesCount !== undefined && | ||
flowNodeInstanceStore.state.flowNodeInstances[ | ||
flowNodeInstance.treePath | ||
]?.children.length === MAX_INSTANCES_STORED | ||
) { | ||
scrollUp(fetchedInstancesCount * (rowRef.current?.offsetHeight ?? 0)); | ||
} | ||
} | ||
}; | ||
|
||
const nodeName = `${businessObject?.name || flowNodeInstance.flowNodeId}${ | ||
isMultiInstanceBody ? ` (Multi Instance)` : '' | ||
}`; | ||
|
||
let {rowRef: _, ...carbonTreeNodeProps} = rest; | ||
return ( | ||
<TreeNode | ||
{...carbonTreeNodeProps} | ||
selected={isSelected ? [flowNodeInstance.id] : []} | ||
active={isSelected ? flowNodeInstance.id : undefined} | ||
key={flowNodeInstance.id} | ||
id={flowNodeInstance.id} | ||
value={flowNodeInstance.id} | ||
renderIcon={() => ( | ||
<FlowNodeIcon | ||
flowNodeInstanceType={flowNodeInstance.type} | ||
diagramBusinessObject={businessObject!} | ||
/> | ||
)} | ||
onSelect={() => { | ||
if (modificationsStore.state.status === 'adding-token') { | ||
modificationsStore.finishAddingToken( | ||
flowNodeInstance.flowNodeId, | ||
flowNodeInstance.id | ||
); | ||
} else { | ||
tracking.track({eventName: 'instance-history-item-clicked'}); | ||
flowNodeSelectionStore.selectFlowNode({ | ||
flowNodeId: isProcessInstance | ||
? undefined | ||
: flowNodeInstance.flowNodeId, | ||
flowNodeInstanceId: flowNodeInstance.id, | ||
isMultiInstance: isMultiInstanceBody, | ||
isPlaceholder: flowNodeInstance.isPlaceholder, | ||
}); | ||
} | ||
}} | ||
onToggle={ | ||
isFoldable | ||
? (event) => { | ||
event.stopPropagation(); | ||
return (flowNodeInstance.isPlaceholder && | ||
hasVisibleChildPlaceholders) || | ||
(!flowNodeInstance.isPlaceholder && hasVisibleChildNodes) | ||
? collapseSubtree(flowNodeInstance) | ||
: expandSubtree(flowNodeInstance); | ||
} | ||
: undefined | ||
} | ||
isExpanded={ | ||
flowNodeInstance.isPlaceholder | ||
? hasVisibleChildPlaceholders | ||
: hasVisibleChildNodes | ||
} | ||
label={<NodeName>{nodeName}</NodeName>} | ||
> | ||
{hasChildren ? ( | ||
<ScrollableNodes | ||
onVerticalScrollEndReach={handleEndReach} | ||
onVerticalScrollStartReach={async (scrollDown) => { | ||
if (flowNodeInstance.treePath === null) { | ||
return; | ||
} | ||
const fetchedInstancesCount = | ||
await flowNodeInstanceStore.fetchPrevious( | ||
flowNodeInstance.treePath | ||
); | ||
|
||
if (fetchedInstancesCount !== undefined) { | ||
scrollDown( | ||
fetchedInstancesCount * (rowRef.current?.offsetHeight ?? 0) | ||
); | ||
} | ||
}} | ||
scrollableContainerRef={scrollableContainerRef} | ||
visibleChildren={visibleChildren} | ||
/> | ||
) : undefined} | ||
</TreeNode> | ||
); | ||
} | ||
); | ||
|
||
export {FlowNodeInstancesTree}; |
21 changes: 21 additions & 0 deletions
21
client/src/App/Carbon/ProcessInstance/FlowNodeInstancesTree/styled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
|
||
import styled from 'styled-components'; | ||
import {TreeNode as BaseTreeNode} from '@carbon/react'; | ||
|
||
const TreeNode = styled(BaseTreeNode)` | ||
.cds--tree-node__label { | ||
height: 2rem; | ||
} | ||
`; | ||
|
||
const NodeName = styled.span` | ||
margin-left: var(--cds-spacing-02); | ||
`; | ||
|
||
export {TreeNode, NodeName}; |
Oops, something went wrong.