Skip to content

Commit

Permalink
feat: Notification silence new fields (#2447)
Browse files Browse the repository at this point in the history
* rearrange columns in notification silence list

* feat: add name to the silence form

* feat: display resource and the filter in the same column

* feat: add indefinitely option to duration picker

* feat: config hard parents

* feat: rearrange columns and don't use Age component

* feat: different form for notification silences

* feat: show attributes in the silence form

* feat: multiple selection of attributes and change tag display
  • Loading branch information
adityathebe authored Feb 14, 2025
1 parent cf0987a commit 8899739
Show file tree
Hide file tree
Showing 21 changed files with 691 additions and 73 deletions.
10 changes: 10 additions & 0 deletions src/api/query-hooks/useCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getHealthCheckByID } from "../services/check";
import { useQuery } from "@tanstack/react-query";

export function useCheckDetail(id: string) {
return useQuery({
queryKey: ["check", id],
queryFn: () => getHealthCheckByID(id),
select: (data) => data?.data
});
}
10 changes: 10 additions & 0 deletions src/api/query-hooks/useComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getTopologyByID } from "../services/topology";
import { useQuery } from "@tanstack/react-query";

export function useComponentDetail(id: string) {
return useQuery({
queryKey: ["component", id],
queryFn: () => getTopologyByID(id),
select: (data) => data?.data
});
}
18 changes: 17 additions & 1 deletion src/api/query-hooks/useConfigRelationshipsQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSearchParams } from "react-router-dom";
import { getAConfigRelationships } from "../services/configs";
import { ConfigItem } from "../types/configs";

export default function useConfigRelationshipsQuery(id: string | undefined) {
export function useConfigRelationshipsQuery(id: string | undefined) {
const [searchParams] = useSearchParams();
const hideDeleted = useHideDeletedConfigs();
const tag = searchParams.get("tag") ?? undefined;
Expand Down Expand Up @@ -82,3 +82,19 @@ export default function useConfigRelationshipsQuery(id: string | undefined) {
select: (data) => transformConfigRelationships(data ?? [])
});
}

export function useConfigHardParents(id: string) {
return useQuery({
queryKey: ["config", "relationships", id],
queryFn: () =>
getAConfigRelationships({
configId: id!,
type_filter: "incoming",
hideDeleted: true,
relation: "hard"
}),
enabled: id !== undefined,
keepPreviousData: true,
select: (data) => data ?? []
});
}
10 changes: 10 additions & 0 deletions src/api/services/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IncidentCommander } from "../axios";
import { HealthCheck } from "../types/health";

export const getHealthCheckByID = async (checkID: string) => {
if (checkID === "") {
return Promise.resolve({ data: [] }); // Ensure consistent return type
}

return IncidentCommander.get<HealthCheck[]>(`/checks?id=eq.${checkID}`);
};
4 changes: 4 additions & 0 deletions src/api/services/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ export const getAConfigRelationships = async ({
health,
status
}: GetAConfigRelationshipsParams) => {
if (configId === "") {
return null;
}

const searchParams = new URLSearchParams();
searchParams.append("config_id", configId);
searchParams.append("include_deleted_configs", `${!hideDeleted}`);
Expand Down
4 changes: 4 additions & 0 deletions src/api/services/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export const silenceNotification = async (
export const updateNotificationSilence = async (
data: Omit<NotificationSilenceItem, "created_at">
) => {
if (data.until === "indefinitely") {
data["until"] = null;
}

const res = await IncidentCommander.patch(
`/notification_silences?id=eq.${data.id}`,
data
Expand Down
5 changes: 5 additions & 0 deletions src/api/services/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ComponentTemplateItem,
Topology
} from "../types/topology";
import { AxiosResponse } from "axios";

Check warning on line 25 in src/api/services/topology.ts

View workflow job for this annotation

GitHub Actions / eslint

'AxiosResponse' is defined but never used

interface IParam {
id?: string;
Expand Down Expand Up @@ -216,6 +217,10 @@ export const getTopologyNameByID = (topologyID: string) => {
};

export const getTopologyByID = async (topologyID: string) => {
if (topologyID === "") {
return Promise.resolve({ data: [] }); // Ensure consistent return type
}

return IncidentCommander.get<Topology[]>(`/components?id=eq.${topologyID}`);
};

Expand Down
1 change: 1 addition & 0 deletions src/api/types/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ConfigItem extends Timestamped, Avatar, Agent, Costs {
external_id?: string;
config_class?: string;
type: string;
path?: string;
changes?: number;
analysis?: Record<string, any>;
tags?: Record<string, any>;
Expand Down
11 changes: 7 additions & 4 deletions src/api/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ export type NotificationRules = {

export type SilenceNotificationResponse = {
id: string;
name: string;
filter?: string;
selectors?: string;
component_id?: string;
config_id?: string;
check_id?: string;
canary_id?: string;
from: string;
until: string;
until: string | null;
description?: string;
recursive?: boolean;
namespace?: string;
error?: string;
source?: "source1" | "source2" | "source3";
source?: "KubernetesCRD" | "UI";
};

export type NotificationSendHistory = {
Expand Down Expand Up @@ -87,18 +89,19 @@ export type NotificationSendHistoryApiResponse = NotificationSendHistory & {

export type NotificationSilenceItem = {
id: string;
name: string;
namespace: string;
description?: string;
filter?: string;
error?: string;
from: string;
until: string;
until: string | null;
recursive?: boolean;
config_id?: string;
check_id?: string;
canary_id?: string;
component_id?: string;
source?: "source1" | "source2" | "source3";
source?: "KubernetesCRD" | "UI";
created_by?: string;
created_at: string;
updated_at: string;
Expand Down
8 changes: 4 additions & 4 deletions src/components/Notifications/NotificationTabsLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ export default function NotificationTabsLinks({
action="write"
key="add-notifications"
>
<Link
key="notifications-silenced-add"
<button
key="notifications-add"
type="button"
className=""
to="/notifications/silences/add"
onClick={() => setIsModalOpen(true)}
>
<AiFillPlusCircle
size={32}
className="text-blue-600"
/>
</Link>
</button>
</AuthorizationAccessCheck>
])
]
Expand Down
Loading

0 comments on commit 8899739

Please sign in to comment.