Skip to content

Commit

Permalink
feat: add indefinitely option to duration picker
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Feb 10, 2025
1 parent c332f68 commit 2030000
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
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
4 changes: 2 additions & 2 deletions src/api/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type SilenceNotificationResponse = {
check_id?: string;
canary_id?: string;
from: string;
until: string;
until: string | null;
description?: string;
recursive?: boolean;
namespace?: string;
Expand Down Expand Up @@ -94,7 +94,7 @@ export type NotificationSilenceItem = {
filter?: string;
error?: string;
from: string;
until: string;
until: string | null;
recursive?: boolean;
config_id?: string;
check_id?: string;
Expand Down
1 change: 1 addition & 0 deletions src/components/Notifications/SilenceNotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const silenceNotificationListColumns: MRT_ColumnDef<NotificationSilenceItemApiRe
className={clsx(isExpired && "line-through")}
from={from}
to={until}
displayType={"duration"}
></Age>
{isExpired && <span className="pl-1 text-red-500">Expired</span>}
</span>
Expand Down
11 changes: 8 additions & 3 deletions src/ui/Age/Age.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ dayjs.extend(LocalizedFormat);
type AgeProps = {
className?: string;
from?: Date | string;
to?: Date | string;
to?: Date | string | null;
suffix?: boolean;
// duration handles null "to" time differently.
displayType?: "age" | "duration";
};

export default function Age({
className = "",
from,
to,
suffix = false
suffix = false,
displayType = "age"
}: AgeProps) {
if (isEmpty(from)) {
return null;
Expand All @@ -36,7 +39,9 @@ export default function Age({
data-tooltip-id={`age-tooltip-${_from.local().fromNow(!suffix)}`}
className={className}
>
{_from.local().fromNow(!suffix)}
{displayType === "duration"
? "Indefinitely"
: _from.local().fromNow(!suffix)}
</span>
<Tooltip
id={`age-tooltip-${_from.local().fromNow(!suffix)}`}
Expand Down
5 changes: 5 additions & 0 deletions src/ui/Dates/TimeRangePicker/TimeRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export function TimeRangePicker({
if (currentRange?.type === "absolute") {
return `${currentRange.from} - ${currentRange.to}`;
}

if (!currentRange?.display) {
return "Indefinitely";
}

return currentRange?.display;
}, [currentRange]);

Expand Down
5 changes: 5 additions & 0 deletions src/ui/Dates/TimeRangePicker/rangeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export const rangeOptionsCategories: RangeOptionsCategory[] = [
name: "Relative time ranges",
type: "future",
options: [
{
type: "relative",
display: "Indefinitely",
range: "indefinitely"
},
{
type: "relative",
display: "5 minutes",
Expand Down

0 comments on commit 2030000

Please sign in to comment.