Skip to content

Commit 1c5caf1

Browse files
authored
Tasks indicator for the current branch (#4873)
* add pulse component * add tasks link with status indicator * fix indicator * update tooltip
1 parent c39f92c commit 1c5caf1

File tree

6 files changed

+80
-1
lines changed

6 files changed

+80
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { classNames } from "@/utils/common";
2+
3+
interface PulseProps {
4+
className?: string;
5+
}
6+
7+
export function Pulse({ className }: PulseProps) {
8+
return (
9+
<span className={classNames("absolute flex h-2 w-2", className)}>
10+
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-custom-blue-500 opacity-75"></span>
11+
<span className="relative inline-flex rounded-full h-2 w-2 bg-custom-blue-700"></span>
12+
</span>
13+
);
14+
}

frontend/app/src/config/constants.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const NUMBER_POOL_OBJECT = "CoreNumberPool";
6565

6666
export const TASK_OBJECT = "InfrahubTask";
6767

68+
export const TASKS_STATUS_OBJECT = "InfrahubTaskBranchStatus";
69+
6870
export const ADMIN_ROLES = ["admin"];
6971

7072
export const MENU_EXCLUDELIST = [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { gql } from "@apollo/client";
2+
3+
export const TASKS_STATUS = gql`
4+
query TASKS_STATUS($branch: String!) {
5+
InfrahubTaskBranchStatus(branch: $branch){
6+
count
7+
}
8+
}
9+
`;
Lines changed: 4 additions & 0 deletions
Loading

frontend/app/src/screens/layout/header.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import InfrahubLogo from "@/images/infrahub-logo.svg";
44
import BreadcrumbNavigation from "@/screens/layout/breadcrumb-navigation/breadcrumb-navigation";
55
import { constructPath } from "@/utils/fetch";
66
import { Link } from "react-router-dom";
7+
import { TaskStatus } from "./tasks-status";
78

89
export default function Header() {
910
return (
@@ -16,7 +17,11 @@ export default function Header() {
1617

1718
<BranchSelector />
1819

19-
<BreadcrumbNavigation />
20+
<div className="flex-1">
21+
<BreadcrumbNavigation />
22+
</div>
23+
24+
<TaskStatus />
2025
</header>
2126
);
2227
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ButtonWithTooltip } from "@/components/buttons/button-primitive";
2+
import { Pulse } from "@/components/ui/pulse";
3+
import { Spinner } from "@/components/ui/spinner";
4+
import { TASKS_STATUS_OBJECT } from "@/config/constants";
5+
import { TASKS_STATUS } from "@/graphql/queries/tasks/getTasksStatus";
6+
import useQuery from "@/hooks/useQuery";
7+
import { ReactComponent as TasksStatusIcon } from "@/images/icons/tasks-status.svg";
8+
import { currentBranchAtom } from "@/state/atoms/branches.atom";
9+
import { constructPath } from "@/utils/fetch";
10+
import { Icon } from "@iconify-icon/react";
11+
import { useAtomValue } from "jotai";
12+
import { Link } from "react-router-dom";
13+
14+
export function TaskStatus() {
15+
const branch = useAtomValue(currentBranchAtom);
16+
17+
const { error, loading, data } = useQuery(TASKS_STATUS, {
18+
variables: { branch: branch?.name },
19+
pollInterval: 1000,
20+
});
21+
22+
if (error) {
23+
return <Icon icon="mdi:error-outline" className="text-red-500" />;
24+
}
25+
26+
const count = data && data[TASKS_STATUS_OBJECT]?.count;
27+
28+
return (
29+
<Link to={constructPath("/tasks")}>
30+
<ButtonWithTooltip
31+
size="square"
32+
variant="ghost"
33+
className="h-8 w-8 bg-neutral-50 border border-neutral-200 rounded-lg relative"
34+
tooltipEnabled
35+
tooltipContent={"Tasks"}
36+
>
37+
{loading && <Spinner />}
38+
39+
{!loading && <TasksStatusIcon />}
40+
41+
{!loading && count > 0 && <Pulse className="right-[6.5px] bottom-[6.5px]" />}
42+
</ButtonWithTooltip>
43+
</Link>
44+
);
45+
}

0 commit comments

Comments
 (0)