Skip to content

Commit

Permalink
feat: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Feb 19, 2024
1 parent 26bb757 commit 7ff1ad7
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 21 deletions.
3 changes: 1 addition & 2 deletions keep-ui/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ type RootLayoutProps = {
export default async function RootLayout({ children }: RootLayoutProps) {
return (
<html lang="en" className={`bg-gray-50 ${mulish.className}`}>
<body className="h-screen grid grid-cols-[250px_auto]">
<body className="h-screen flex flex-col lg:grid lg:grid-cols-[250px_auto] lg:grid-rows-1">
<NextAuthProvider>
{/* @ts-expect-error Server Component */}
<Navbar />
{/* https://discord.com/channels/752553802359505017/1068089513253019688/1117731746922893333 */}
<main className="flex flex-col col-start-2 p-4 overflow-auto">
Expand Down
2 changes: 1 addition & 1 deletion keep-ui/components/navbar/ConfigureLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ConfigureLinks = ({ session }: ConfigureLinksProps) => {
</li>
<li>
<LinkWithIcon href="/workflows" icon={LuWorkflow}>
Worksflows
Workflows
</LinkWithIcon>
</li>
</ul>
Expand Down
59 changes: 59 additions & 0 deletions keep-ui/components/navbar/Menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use client";

import { Fragment, ReactNode, useEffect } from "react";
import { Popover } from "@headlessui/react";
import { Icon } from "@tremor/react";
import { AiOutlineMenu, AiOutlineClose } from "react-icons/ai";
import { usePathname } from "next/navigation";

type CloseMenuOnRouteChangeProps = {
closeMenu: () => void;
};

const CloseMenuOnRouteChange = ({ closeMenu }: CloseMenuOnRouteChangeProps) => {
const pathname = usePathname();

useEffect(() => {
closeMenu();
}, [pathname, closeMenu]);

return null;
};

type MenuButtonProps = {
children: ReactNode;
};

export const Menu = ({ children }: MenuButtonProps) => {
return (
<Popover as={Fragment}>
{({ close: closeMenu }) => (
<>
<div className="p-3 w-full block lg:hidden">
<Popover.Button className="p-1 hover:bg-gray-200 font-medium rounded-lg hover:text-orange-500 focus:ring focus:ring-orange-300">
<Icon icon={AiOutlineMenu} color="orange" />
</Popover.Button>
</div>

<aside className="bg-gray-50 col-span-1 border-r border-gray-300 h-full hidden lg:block">
<nav className="flex flex-col h-full">{children}</nav>
</aside>

<CloseMenuOnRouteChange closeMenu={closeMenu} />
<Popover.Panel
className="bg-gray-50 col-span-1 border-r border-gray-300 z-50 h-screen fixed inset-0"
as="nav"
>
<div className="p-3 fixed top-0 right-0 ">
<Popover.Button className="p-1 hover:bg-gray-200 font-medium rounded-lg hover:text-orange-500 focus:ring focus:ring-orange-300">
<Icon icon={AiOutlineClose} color="orange" />
</Popover.Button>
</div>

{children}
</Popover.Panel>
</>
)}
</Popover>
);
};
23 changes: 11 additions & 12 deletions keep-ui/components/navbar/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ import { AnalyseLinks } from "components/navbar/AnalyseLinks";
import { LearnLinks } from "components/navbar/LearnLinks";
import { UserInfo } from "components/navbar/UserInfo";
import { InitPostHog } from "components/navbar/InitPostHog";
import { Menu } from "components/navbar/Menu";

export default async function NavbarInner() {
const session = await getServerSession();

return (
<>
<InitPostHog />
<aside className="bg-gray-50 col-span-1 border-r border-gray-300 h-full">
<nav className="flex flex-col h-full">
<div className="flex-1 h-full">
<Search />
<div className="pt-6 space-y-4">
<AnalyseLinks />
<ConfigureLinks session={session} />
<LearnLinks />
</div>
<Menu>
<div className="flex-1 h-full">
<Search />
<div className="pt-6 space-y-4">
<AnalyseLinks />
<ConfigureLinks session={session} />
<LearnLinks />
</div>
</div>

<UserInfo session={session} />
</nav>
</aside>
<UserInfo session={session} />
</Menu>
</>
);
}
3 changes: 2 additions & 1 deletion keep/api/models/alert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import logging
from enum import Enum
from typing import Any, Dict
Expand Down Expand Up @@ -71,7 +72,7 @@ class AlertDto(BaseModel):
@validator("fingerprint", pre=True, always=True)
def assign_fingerprint_if_none(cls, fingerprint, values):
if fingerprint is None:
return values.get("name", "")
return hashlib.sha256(values.get("name").encode()).hexdigest()
return fingerprint

@validator("deleted", pre=True, always=True)
Expand Down
16 changes: 12 additions & 4 deletions keep/providers/sentry_provider/sentry_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,19 @@ def _format_alert(event: dict) -> AlertDto | list[AlertDto]:
)
# map severity and status to keep's format
severity = event.pop("level", tags_as_dict.get("level", "")).lower()
severity = SentryProvider.SEVERITIES_MAP.get(
severity, AlertSeverity.INFO
)
severity = SentryProvider.SEVERITIES_MAP.get(severity, AlertSeverity.INFO)
status = event.get("action")
status = SentryProvider.STATUS_MAP.get(status, AlertStatus.FIRING)

# https://docs.sentry.io/product/integrations/integration-platform/webhooks/issue-alerts/#dataeventissue_url
url = event_data.pop("url", None)
if "issue_url" in event_data:
url = event_data["issue_url"]
elif "web_url" in event_data:
url = event_data["web_url"]
elif "url" in tags_as_dict:
url = tags_as_dict["url"]

logger.info("Formatted Sentry alert", extra={"event": event})
return AlertDto(
id=event_data.pop("event_id"),
Expand All @@ -236,7 +244,7 @@ def _format_alert(event: dict) -> AlertDto | list[AlertDto]:
description=event.get("culprit", ""),
pushed=True,
severity=severity,
url=event_data.pop("url", tags_as_dict.pop("url", event.get("url", None))),
url=url,
fingerprint=event.get("id"),
tags=tags_as_dict,
)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_alert_dto.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import hashlib

from keep.api.models.alert import AlertDto


Expand All @@ -20,4 +22,4 @@ def test_alert_dto_fingerprint_none():
event_id="1234",
url="https://www.google.com/search?q=open+source+alert+management",
)
assert alert_dto.fingerprint == name
assert alert_dto.fingerprint == hashlib.sha256(name.encode()).hexdigest()

0 comments on commit 7ff1ad7

Please sign in to comment.