Skip to content

Commit

Permalink
feat: add activity bar to UI heading
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Dec 20, 2023
1 parent e57abbd commit f5c3e76
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/oplog/oplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (o *OpLog) Scan(onIncomplete func(op *v1.Operation)) error {
continue
}

if op.Status == v1.OperationStatus_STATUS_PENDING || op.Status == v1.OperationStatus_STATUS_SYSTEM_CANCELLED {
// remove pending operations.
if op.Status == v1.OperationStatus_STATUS_PENDING || op.Status == v1.OperationStatus_STATUS_SYSTEM_CANCELLED || op.Status == v1.OperationStatus_STATUS_USER_CANCELLED {
// remove pending or user cancelled operations.
o.deleteOperationHelper(tx, op.Id)
continue
} else if op.Status == v1.OperationStatus_STATUS_INPROGRESS {
Expand Down
41 changes: 41 additions & 0 deletions webui/src/components/ActivityBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useEffect, useState } from "react";
import { EOperation, detailsForOperation, displayTypeToString, getTypeForDisplay, subscribeToOperations, toEop, unsubscribeFromOperations } from "../state/oplog";
import { OperationEvent, OperationStatus } from "../../gen/ts/v1/operations.pb";
import { formatDuration } from "../lib/formatting";

export const ActivityBar = () => {
const [activeOperations, setActiveOperations] = useState<EOperation[]>([]);

useEffect(() => {
const callback = ({ operation, type }: OperationEvent) => {
if (!operation || !type) return;

setActiveOperations((ops) => {
ops = ops.filter((op) => op.id !== operation.id);
if (operation.status === OperationStatus.STATUS_INPROGRESS) {
ops.push(toEop(operation));
}
ops.sort((a, b) => b.parsedTime - a.parsedTime);
return ops;
});
}

subscribeToOperations(callback);

return () => {
unsubscribeFromOperations(callback);
}
});

const details = activeOperations.map((op) => {
return {
op: op,
details: detailsForOperation(op),
displayName: displayTypeToString(getTypeForDisplay(op)),
}
});

return <span>{details.map(details => {
return <>{details.displayName} in progress for plan {details.op.planId} to {details.op.repoId} for {formatDuration(details.details.duration)}</>
})}</span>
}
5 changes: 5 additions & 0 deletions webui/src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useShowModal } from "../components/ModalManager";
import { MainContentArea, useSetContent } from "./MainContentArea";
import { AddPlanModal } from "./AddPlanModal";
import { uiBuildVersion } from "../state/buildcfg";
import { ActivityBar } from "../components/ActivityBar";

const { Header, Sider } = Layout;

Expand Down Expand Up @@ -67,6 +68,10 @@ export const App: React.FC = () => {
<small style={{ color: "rgba(255,255,255,0.3)", fontSize: "0.6em" }}>
{uiBuildVersion}
</small>

<small style={{ fontSize: "0.6em", marginLeft: "30px" }}>
<ActivityBar />
</small>
</h1>
</Header>
<Layout>
Expand Down

0 comments on commit f5c3e76

Please sign in to comment.