-
Notifications
You must be signed in to change notification settings - Fork 1
Hamza/feature/retry budget alerts #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6ee9366
Recompute pagination pages when the result count changes
hamzahalq 3e7d9b7
Show budget usage and alert routing as one subscriptions table
hamzahalq 7c09b22
Show a subscription's retry failures in an expandable row
hamzahalq 532b6d7
Stop failed writes from looking like successes, and confirm resets
hamzahalq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,19 @@ | ||
| // A rejected write comes back as either a validation map — { CODE: ["what went wrong"] } — or a | ||
| // problem detail. This pulls the first human sentence out of whichever it is. | ||
| // | ||
| // The middleware already toasts failures, but it toasts the raw JSON, which tells a reader nothing | ||
| // they can act on. A form that knows why its save was refused can say so where the reader is | ||
| // looking. | ||
| export const apiErrorMessage = (error: unknown, fallback: string): string => { | ||
| const data = (error as { data?: unknown } | undefined)?.data; | ||
|
|
||
| if (typeof data === "string" && data.trim()) return data; | ||
|
|
||
| if (data && typeof data === "object") | ||
| for (const value of Object.values(data as Record<string, unknown>)) { | ||
| if (typeof value === "string" && value.trim()) return value; | ||
| if (Array.isArray(value) && typeof value[0] === "string" && value[0].trim()) return value[0]; | ||
| } | ||
|
|
||
| return fallback; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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,128 @@ | ||
| import React from "react"; | ||
| import AdapterEditor from "src/components/Subscriptions/AdapterEditor"; | ||
| import { | ||
| RetryAlertMode, | ||
| pairsFromRecord, | ||
| recordFromPairs | ||
| } from "src/types/retryPolicies"; | ||
|
|
||
| export interface RetryAlertValue { | ||
| alertMode: RetryAlertMode | ||
| alertHandlerId?: string | null | ||
| alertHandlerProperties?: Record<string, string> | null | ||
| } | ||
|
|
||
| interface Props { | ||
| value: RetryAlertValue | ||
| onChange: (value: RetryAlertValue) => void | ||
| /** What "Inherit" resolves to at the level above, e.g. "the policy default". */ | ||
| inheritedFrom: string | ||
| /** The handler that level uses, so inheriting can be described rather than just named. */ | ||
| inheritedHandlerId?: string | null | ||
| inheritedProperties?: Record<string, string> | null | ||
| title?: string | ||
| } | ||
|
|
||
| /** | ||
| * True when this level claims to send but names nothing to send with. Both callers check it before | ||
| * saving: the API refuses this too, so without the check the save fails for a reason the form never | ||
| * got to explain. | ||
| */ | ||
| export const alertIsIncomplete = ( | ||
| // Widened rather than taking RetryAlertValue: a group carries the same two fields with alertMode | ||
| // optional, and both levels ask this same question. | ||
| value: { alertMode?: RetryAlertMode, alertHandlerId?: string | null }) => | ||
| (value.alertMode ?? RetryAlertMode.Inherit) === RetryAlertMode.Send && !value.alertHandlerId; | ||
|
|
||
| const modes: { mode: RetryAlertMode, label: string }[] = [ | ||
| {mode: RetryAlertMode.Inherit, label: "Inherit"}, | ||
| {mode: RetryAlertMode.Send, label: "Send via…"}, | ||
| {mode: RetryAlertMode.Silent, label: "Silent"}, | ||
| ]; | ||
|
|
||
| // A level that overrides REPLACES the level above rather than merging into it, so choosing | ||
| // "Send via…" means re-entering the handler and every property it needs. That is what the | ||
| // "copy from" button is for — otherwise the api key gets retyped by hand and eventually typo'd. | ||
| const RetryAlertEditor: React.FC<Props> = ({ | ||
| value, | ||
| onChange, | ||
| inheritedFrom, | ||
| inheritedHandlerId, | ||
| inheritedProperties, | ||
| title = "Budget exhausted alert" | ||
| }) => { | ||
|
|
||
| const mode = value.alertMode ?? RetryAlertMode.Inherit; | ||
|
|
||
| const setMode = (next: RetryAlertMode) => { | ||
| // Leaving Send behind drops its handler, so a level that no longer sends cannot keep | ||
| // stale config that the UI would still show. | ||
| if (next === RetryAlertMode.Send) | ||
| onChange({...value, alertMode: next}); | ||
| else | ||
| onChange({alertMode: next, alertHandlerId: null, alertHandlerProperties: null}); | ||
| }; | ||
|
|
||
| const copyFromInherited = () => onChange({ | ||
| alertMode: RetryAlertMode.Send, | ||
| alertHandlerId: inheritedHandlerId, | ||
| alertHandlerProperties: inheritedProperties ?? {} | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-2"> | ||
| <h3 className="text-sm tracking-wide text-gray-700 font-semibold uppercase">{title}</h3> | ||
|
|
||
| <div className="flex flex-row gap-2"> | ||
| {modes.map(m => ( | ||
| <button key={m.mode} type="button" | ||
| onClick={() => setMode(m.mode)} | ||
| className={`px-3 py-1 rounded text-sm border transition ${mode === m.mode | ||
| ? "bg-primary-600 text-white border-primary-600" | ||
| : "bg-white text-gray-600 border-gray-300 hover:border-primary-400"}`}> | ||
| {m.label} | ||
| </button> | ||
| ))} | ||
| </div> | ||
|
|
||
| {mode === RetryAlertMode.Inherit && | ||
| <p className="text-xs text-gray-500"> | ||
| {inheritedHandlerId | ||
| ? <>Uses {inheritedFrom} — <span className="font-mono">{inheritedHandlerId}</span>.</> | ||
| : <>Follows {inheritedFrom}, which currently sends no alert.</>} | ||
| </p>} | ||
|
|
||
| {mode === RetryAlertMode.Silent && | ||
| <p className="text-xs text-gray-500"> | ||
| Sends nothing, even when {inheritedFrom} defines an alert. | ||
| </p>} | ||
|
|
||
| {mode === RetryAlertMode.Send && <> | ||
| <div className="flex flex-row items-center justify-between gap-2"> | ||
| <p className="text-xs text-gray-500"> | ||
| Replaces {inheritedFrom} entirely — set the handler and all of its properties here. | ||
| </p> | ||
| {inheritedHandlerId && | ||
| <button type="button" onClick={copyFromInherited} | ||
| className="shrink-0 text-xs text-primary-600 hover:underline"> | ||
| Copy from {inheritedFrom} | ||
| </button>} | ||
| </div> | ||
| {!value.alertHandlerId && | ||
| <p className="text-xs text-amber-700"> | ||
| Choose a handler — until then this level sends nothing, and saving is blocked. | ||
| </p>} | ||
| <AdapterEditor title="Alert handler" type="handlers" | ||
| value={value.alertHandlerId} | ||
| onChange={(v) => onChange({...value, alertHandlerId: v})} | ||
| props={pairsFromRecord(value.alertHandlerProperties)} | ||
| onPropsChange={(p) => onChange({ | ||
| ...value, | ||
| alertHandlerProperties: recordFromPairs(p) | ||
| })}/> | ||
| </>} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default RetryAlertEditor; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.