Skip to content

Commit

Permalink
feat: improve repo view layout when backups from multiple-instances a…
Browse files Browse the repository at this point in the history
…re found
  • Loading branch information
garethgeorge committed Jan 8, 2025
1 parent 407652c commit ad5d396
Showing 1 changed file with 57 additions and 11 deletions.
68 changes: 57 additions & 11 deletions webui/src/components/OperationTreeView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import React, { useEffect, useRef, useState } from "react";
import { Col, Empty, Flex, Modal, Row, Splitter, Tooltip, Tree } from "antd";
import {
Col,
Empty,
Flex,
Modal,
Row,
Splitter,
Tooltip,
Tree,
Typography,
} from "antd";
import _, { flow } from "lodash";
import { DataNode } from "antd/es/tree";
import { formatDate, formatTime, localISOTime } from "../lib/formatting";
Expand Down Expand Up @@ -29,6 +39,7 @@ import {
import { OperationIcon } from "./OperationIcon";
import { shouldHideOperation } from "../state/oplog";
import { create, toJsonString } from "@bufbuild/protobuf";
import { useConfig } from "./ConfigProvider";

type OpTreeNode = DataNode & {
backup?: FlowDisplayInfo;
Expand All @@ -41,6 +52,7 @@ export const OperationTreeView = ({
req: GetOperationsRequest;
isPlanView?: boolean;
}>) => {
const config = useConfig()[0];
const alertApi = useAlertApi();
const setScreenWidth = useState(window.innerWidth)[1];
const [backups, setBackups] = useState<FlowDisplayInfo[]>([]);
Expand Down Expand Up @@ -106,15 +118,49 @@ export const OperationTreeView = ({

const useMobileLayout = isMobile();

const displayTree = (
<DisplayOperationTree
operations={backups}
isPlanView={isPlanView}
onSelect={(flow) => {
setSelectedBackupId(flow ? flow.flowID : null);
}}
/>
);
const backupsByInstance = _.groupBy(backups, (b) => {
return b.instanceID;
});

let primaryTree: React.ReactNode | null = null;
const otherTrees: React.ReactNode[] = [];

for (const instance of Object.keys(backupsByInstance)) {
const instanceOps = backupsByInstance[instance];
const instTree = (
<DisplayOperationTree
operations={backups}
isPlanView={isPlanView}
onSelect={(flow) => {
setSelectedBackupId(flow ? flow.flowID : null);
}}
/>
);

if (instance === config!.instance) {
primaryTree = instTree;
} else {
otherTrees.push(
<>
<Typography.Title level={4}>{instance}</Typography.Title>
{instTree}
</>
);
}
}

let displayTree: React.ReactNode;
if (otherTrees.length > 0) {
displayTree = (
<>
<Typography.Title level={4}>{config!.instance}</Typography.Title>
{primaryTree}
{otherTrees}
</>
);
} else {
displayTree = primaryTree;
}

if (useMobileLayout) {
const backup = backups.find((b) => b.flowID === selectedBackupId);
Expand Down Expand Up @@ -386,7 +432,7 @@ const buildTree = (
tree = buildTreeDay("", operations);
expanded = expandTree(tree, 5, 0, 2);
} else {
tree = buildTreeInstanceID(operations);
tree = buildTreePlan(operations);
expanded = expandTree(tree, 5, 2, 4);
}
return { tree, expanded };
Expand Down

0 comments on commit ad5d396

Please sign in to comment.