Skip to content

Commit

Permalink
Fix subprocess back button
Browse files Browse the repository at this point in the history
  • Loading branch information
OhKai committed Jan 10, 2024
1 parent 5618805 commit 43fe65c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
'use client';

import React, { useCallback, useEffect, useMemo, useRef, useState, useTransition } from 'react';
import React, {
use,
useCallback,
useEffect,
useMemo,
useRef,
useState,
useTransition,
} from 'react';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import ModelerToolbar from './modeler-toolbar';
import XmlEditor from './xml-editor';
Expand All @@ -9,8 +17,8 @@ import { debounce } from '@/lib/utils';
import VersionToolbar from './version-toolbar';
import useMobileModeler from '@/lib/useMobileModeler';
import { updateProcess } from '@/lib/data/processes';
import { is as bpmnIs } from 'bpmn-js/lib/util/ModelUtil';
import { App } from 'antd';
import { is as bpmnIs, isAny as bpmnIsAny } from 'bpmn-js/lib/util/ModelUtil';
import BPMNCanvas, { BPMNCanvasProps, BPMNCanvasRef } from '@/components/bpmn-canvas';

type ModelerProps = React.HTMLAttributes<HTMLDivElement> & {
Expand Down Expand Up @@ -151,6 +159,26 @@ const Modeler = ({ versionName, process, versions, ...divProps }: ModelerProps)
}
}, [messageApi, subprocessId]);

useEffect(() => {
if (modeler.current) {
const canvas = modeler.current.getCanvas();
const subprocessPlane = canvas
.getRootElements()
.find((el: any) => el.businessObject.id === subprocessId);
if (subprocessPlane) {
canvas.setRootElement(subprocessPlane);
} else {
const processPlane = canvas
.getRootElements()
.find((el) => bpmnIsAny(el, ['bpmn:Process', 'bpmn:Collaboration']));
if (!processPlane) {
return;
}
canvas.setRootElement(processPlane);
}
}
}, [subprocessId]);

const handleOpenXmlEditor = async () => {
// Undefined can maybe happen when click happens during router transition?
if (modeler.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import EllipsisBreadcrumb from '@/components/ellipsis-breadcrumb';
import { is as bpmnIs, isAny as bpmnIsAny } from 'bpmn-js/lib/util/ModelUtil';
import { isExpanded } from 'bpmn-js/lib/util/DiUtil';
import { isPlane } from 'bpmn-js/lib/util/DrilldownUtil';
import type ElementRegistry from 'diagram-js/lib/core/ElementRegistry';
import type Canvas from 'diagram-js/lib/core/Canvas';
import { Root } from 'bpmn-js/lib/model/Types';

type SubprocessInfo = {
Expand Down

0 comments on commit 43fe65c

Please sign in to comment.