Skip to content

Commit 4052b54

Browse files
authored
ENH: Open new documents in a split pane with the parent (#908)
1 parent 93e3389 commit 4052b54

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

packages/frontend/src/page/document_menu.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import invariant from "tiny-invariant";
66

77
import { IconButton } from "catcolab-ui-components";
88
import { createAnalysis } from "../analysis";
9-
import { type DocRef, type LiveDoc, useApi } from "../api";
9+
import { type DocRef, DocumentType, type LiveDoc, useApi } from "../api";
1010
import { DocumentTypeIcon } from "../components/document_type_icon";
1111
import { createDiagram } from "../diagram";
1212
import {
@@ -24,14 +24,22 @@ import { TheoryLibraryContext } from "../theory";
2424
export function DocumentMenu(props: {
2525
liveDoc: LiveDoc;
2626
docRef: DocRef;
27-
onDocCreated?: () => void;
27+
onDocCreated?: (docType: DocumentType, refId: string) => void;
2828
onDocDeleted?: () => void;
2929
}) {
3030
const api = useApi();
3131

3232
const navigate = useNavigate();
3333
const docType = () => props.liveDoc.doc.type;
3434

35+
const handleDocCreated = (docType: DocumentType, refId: string) => {
36+
if (props.onDocCreated) {
37+
props.onDocCreated(docType, refId);
38+
} else {
39+
navigate(`/${docType}/${refId}`);
40+
}
41+
};
42+
3543
const onNewDiagram = async () => {
3644
let modelRefId: string | undefined;
3745
switch (props.liveDoc.doc.type) {
@@ -47,8 +55,7 @@ export function DocumentMenu(props: {
4755
}
4856

4957
const newRef = await createDiagram(api, api.makeUnversionedRef(modelRefId));
50-
props.onDocCreated?.();
51-
navigate(`/diagram/${newRef}`);
58+
handleDocCreated("diagram", newRef);
5259
};
5360

5461
const onNewAnalysis = async () => {
@@ -57,8 +64,7 @@ export function DocumentMenu(props: {
5764
invariant(docType !== "analysis", "Analysis cannot be created on other analysis");
5865

5966
const newRef = await createAnalysis(api, docType, api.makeUnversionedRef(docRefId));
60-
props.onDocCreated?.();
61-
navigate(`/analysis/${newRef}`);
67+
handleDocCreated("analysis", newRef);
6268
};
6369

6470
const theories = useContext(TheoryLibraryContext);

packages/frontend/src/page/document_page_sidebar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ function DocumentsTreeLeaf(props: {
206206
<DocumentMenu
207207
liveDoc={props.doc.liveDoc}
208208
docRef={props.doc.docRef}
209-
onDocCreated={props.refetchDoc}
209+
onDocCreated={(docType, refId) => {
210+
props.refetchDoc();
211+
navigate(`/${createLinkPart(props.doc)}/${docType}/${refId}`);
212+
}}
210213
onDocDeleted={async () => {
211214
const deletedRefId = props.doc.docRef.refId;
212215
const isPrimaryDeleted = deletedRefId === primaryRefId();

0 commit comments

Comments
 (0)