-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Notification List with settings and selenced tabs
Fixes #2286
- Loading branch information
1 parent
1ade4f7
commit 469dec6
Showing
7 changed files
with
290 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { tables } from "@flanksource-ui/context/UserAccessContext/permissions"; | ||
import { | ||
BreadcrumbChild, | ||
BreadcrumbNav, | ||
BreadcrumbRoot | ||
} from "@flanksource-ui/ui/BreadcrumbNav"; | ||
import { Head } from "@flanksource-ui/ui/Head"; | ||
import { refreshButtonClickedTrigger } from "@flanksource-ui/ui/SlidingSideBar/SlidingSideBar"; | ||
import TabbedLinks from "@flanksource-ui/ui/Tabs/TabbedLinks"; | ||
import clsx from "clsx"; | ||
import { useAtom } from "jotai"; | ||
import { AiFillPlusCircle } from "react-icons/ai"; | ||
import ConfigSidebar from "../Configs/Sidebar/ConfigSidebar"; | ||
import { ErrorBoundary } from "../ErrorBoundary"; | ||
import { SearchLayout } from "../Layout/SearchLayout"; | ||
import { AuthorizationAccessCheck } from "../Permissions/AuthorizationAccessCheck"; | ||
|
||
const tabLinks = [ | ||
{ label: "Notifications", path: "/notifications" }, | ||
{ label: "Rules", path: "/notifications/rules" }, | ||
{ label: "Silenced Notifications", path: "/notifications/silenced" } | ||
]; | ||
|
||
type NotificationTabsLinksProps = { | ||
activeTab: "Notifications" | "Rules" | "Silenced Notifications"; | ||
children: React.ReactNode; | ||
refresh: () => void; | ||
isLoading: boolean; | ||
className?: string; | ||
setIsModalOpen?: (isOpen: boolean) => void; | ||
}; | ||
|
||
export default function NotificationTabsLinks({ | ||
activeTab, | ||
children, | ||
refresh = () => {}, | ||
isLoading, | ||
className, | ||
setIsModalOpen = () => {} | ||
}: NotificationTabsLinksProps) { | ||
const pageTitle = activeTab; | ||
|
||
const [, setRefreshButtonClickedTrigger] = useAtom( | ||
refreshButtonClickedTrigger | ||
); | ||
|
||
return ( | ||
<> | ||
<Head prefix={pageTitle} /> | ||
<SearchLayout | ||
title={ | ||
<BreadcrumbNav | ||
list={[ | ||
<BreadcrumbRoot key="notifications" link="/settings/jobs"> | ||
Notifications | ||
</BreadcrumbRoot>, | ||
...(activeTab === "Rules" | ||
? [ | ||
<BreadcrumbChild key="rules">Rules</BreadcrumbChild>, | ||
|
||
<AuthorizationAccessCheck | ||
resource={tables.notifications} | ||
action="write" | ||
key="add-notifications" | ||
> | ||
<button | ||
key="notifications-add" | ||
type="button" | ||
className="" | ||
onClick={() => setIsModalOpen(true)} | ||
> | ||
<AiFillPlusCircle size={32} className="text-blue-600" /> | ||
</button> | ||
</AuthorizationAccessCheck> | ||
] | ||
: []), | ||
...(activeTab === "Silenced Notifications" | ||
? [ | ||
<BreadcrumbChild key="silenced-notifications"> | ||
Silenced | ||
</BreadcrumbChild> | ||
] | ||
: []) | ||
]} | ||
/> | ||
} | ||
onRefresh={() => { | ||
setRefreshButtonClickedTrigger((prev) => prev + 1); | ||
refresh(); | ||
}} | ||
loading={isLoading} | ||
contentClass="p-0 h-full overflow-y-hidden" | ||
> | ||
<div className={`flex h-full flex-row`}> | ||
<div className="flex flex-1 flex-col"> | ||
<TabbedLinks | ||
activeTabName={activeTab} | ||
tabLinks={tabLinks} | ||
contentClassName={clsx( | ||
"bg-white border border-t-0 border-gray-300 flex-1 overflow-y-auto", | ||
className | ||
)} | ||
> | ||
<ErrorBoundary>{children}</ErrorBoundary> | ||
</TabbedLinks> | ||
</div> | ||
<ConfigSidebar /> | ||
</div> | ||
</SearchLayout> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useState } from "react"; | ||
import { | ||
useCreateNotification, | ||
useNotificationsSummaryQuery | ||
} from "../../api/query-hooks/useNotificationsQuery"; | ||
import { Modal } from "../../ui/Modal"; | ||
import NotificationsForm from "./NotificationsForm"; | ||
import NotificationsTable from "./NotificationsTable"; | ||
import { Notification } from "./notificationsTableColumns"; | ||
import NotificationTabsLinks from "./NotificationTabsLinks"; | ||
|
||
export default function NotificationRulesPage() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const { data, isLoading, refetch, isRefetching } = | ||
useNotificationsSummaryQuery({ | ||
keepPreviousData: true | ||
}); | ||
|
||
const { mutate: createNotification } = useCreateNotification(() => { | ||
refetch(); | ||
setIsOpen(false); | ||
}); | ||
|
||
const onSubmit = (notification: Partial<Notification>) => { | ||
createNotification(notification); | ||
}; | ||
|
||
const notifications = data?.data; | ||
|
||
return ( | ||
<> | ||
<NotificationTabsLinks | ||
activeTab={"Rules"} | ||
refresh={refetch} | ||
isLoading={false} | ||
setIsModalOpen={setIsOpen} | ||
> | ||
<div className="flex h-full w-full flex-1 flex-col p-6 pb-0"> | ||
<NotificationsTable | ||
notifications={notifications ?? []} | ||
isLoading={isLoading || isRefetching} | ||
refresh={refetch} | ||
/> | ||
</div> | ||
</NotificationTabsLinks> | ||
<Modal | ||
open={isOpen} | ||
onClose={() => setIsOpen(false)} | ||
title="Create Notification" | ||
bodyClass="flex flex-col w-full flex-1 h-full overflow-y-auto" | ||
> | ||
<NotificationsForm onSubmit={onSubmit} onDeleted={refetch} /> | ||
</Modal> | ||
</> | ||
); | ||
} |
Oops, something went wrong.