@stapel/alerts-react 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -0
- package/LICENSE +21 -0
- package/MODULE.md +140 -0
- package/README.md +147 -0
- package/dist/analytics/events.d.ts +29 -0
- package/dist/analytics/events.d.ts.map +1 -0
- package/dist/analytics/events.js +28 -0
- package/dist/analytics/events.js.map +1 -0
- package/dist/api/alertsApi.d.ts +84 -0
- package/dist/api/alertsApi.d.ts.map +1 -0
- package/dist/api/alertsApi.js +127 -0
- package/dist/api/alertsApi.js.map +1 -0
- package/dist/api/generated/schema.d.ts +453 -0
- package/dist/api/generated/schema.d.ts.map +1 -0
- package/dist/api/generated/schema.js +2 -0
- package/dist/api/generated/schema.js.map +1 -0
- package/dist/api/types.d.ts +78 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +44 -0
- package/dist/api/types.js.map +1 -0
- package/dist/default/FixIssueDialog.d.ts +15 -0
- package/dist/default/FixIssueDialog.d.ts.map +1 -0
- package/dist/default/FixIssueDialog.js +67 -0
- package/dist/default/FixIssueDialog.js.map +1 -0
- package/dist/default/IssueDetail.d.ts +10 -0
- package/dist/default/IssueDetail.d.ts.map +1 -0
- package/dist/default/IssueDetail.js +83 -0
- package/dist/default/IssueDetail.js.map +1 -0
- package/dist/default/IssueFilterBar.d.ts +21 -0
- package/dist/default/IssueFilterBar.d.ts.map +1 -0
- package/dist/default/IssueFilterBar.js +86 -0
- package/dist/default/IssueFilterBar.js.map +1 -0
- package/dist/default/IssuesFeed.d.ts +10 -0
- package/dist/default/IssuesFeed.d.ts.map +1 -0
- package/dist/default/IssuesFeed.js +137 -0
- package/dist/default/IssuesFeed.js.map +1 -0
- package/dist/default/MuteIssueDialog.d.ts +19 -0
- package/dist/default/MuteIssueDialog.d.ts.map +1 -0
- package/dist/default/MuteIssueDialog.js +72 -0
- package/dist/default/MuteIssueDialog.js.map +1 -0
- package/dist/default/index.d.ts +32 -0
- package/dist/default/index.d.ts.map +1 -0
- package/dist/default/index.js +26 -0
- package/dist/default/index.js.map +1 -0
- package/dist/default/labels.d.ts +40 -0
- package/dist/default/labels.d.ts.map +1 -0
- package/dist/default/labels.js +94 -0
- package/dist/default/labels.js.map +1 -0
- package/dist/default/layout.d.ts +32 -0
- package/dist/default/layout.d.ts.map +1 -0
- package/dist/default/layout.js +44 -0
- package/dist/default/layout.js.map +1 -0
- package/dist/default/types.d.ts +27 -0
- package/dist/default/types.d.ts.map +1 -0
- package/dist/default/types.js +2 -0
- package/dist/default/types.js.map +1 -0
- package/dist/flows/errors.d.ts +12 -0
- package/dist/flows/errors.d.ts.map +1 -0
- package/dist/flows/errors.js +13 -0
- package/dist/flows/errors.js.map +1 -0
- package/dist/flows/registry.d.ts +22 -0
- package/dist/flows/registry.d.ts.map +1 -0
- package/dist/flows/registry.js +20 -0
- package/dist/flows/registry.js.map +1 -0
- package/dist/headless/AlertsProvider.d.ts +19 -0
- package/dist/headless/AlertsProvider.d.ts.map +1 -0
- package/dist/headless/AlertsProvider.js +15 -0
- package/dist/headless/AlertsProvider.js.map +1 -0
- package/dist/i18n/errorsMap.d.ts +10 -0
- package/dist/i18n/errorsMap.d.ts.map +1 -0
- package/dist/i18n/errorsMap.js +20 -0
- package/dist/i18n/errorsMap.js.map +1 -0
- package/dist/i18n/es.d.ts +20 -0
- package/dist/i18n/es.d.ts.map +1 -0
- package/dist/i18n/es.js +152 -0
- package/dist/i18n/es.js.map +1 -0
- package/dist/i18n/generated/errors.es.gen.d.ts +9 -0
- package/dist/i18n/generated/errors.es.gen.d.ts.map +1 -0
- package/dist/i18n/generated/errors.es.gen.js +57 -0
- package/dist/i18n/generated/errors.es.gen.js.map +1 -0
- package/dist/i18n/generated/errors.gen.d.ts +323 -0
- package/dist/i18n/generated/errors.gen.d.ts.map +1 -0
- package/dist/i18n/generated/errors.gen.js +165 -0
- package/dist/i18n/generated/errors.gen.js.map +1 -0
- package/dist/i18n/generated/errors.ru.gen.d.ts +9 -0
- package/dist/i18n/generated/errors.ru.gen.d.ts.map +1 -0
- package/dist/i18n/generated/errors.ru.gen.js +57 -0
- package/dist/i18n/generated/errors.ru.gen.js.map +1 -0
- package/dist/i18n/keys.d.ts +164 -0
- package/dist/i18n/keys.d.ts.map +1 -0
- package/dist/i18n/keys.js +300 -0
- package/dist/i18n/keys.js.map +1 -0
- package/dist/i18n/ru.d.ts +27 -0
- package/dist/i18n/ru.d.ts.map +1 -0
- package/dist/i18n/ru.js +159 -0
- package/dist/i18n/ru.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/model/context.d.ts +11 -0
- package/dist/model/context.d.ts.map +1 -0
- package/dist/model/context.js +16 -0
- package/dist/model/context.js.map +1 -0
- package/dist/model/issues.d.ts +103 -0
- package/dist/model/issues.d.ts.map +1 -0
- package/dist/model/issues.js +230 -0
- package/dist/model/issues.js.map +1 -0
- package/dist/model/queryKeys.d.ts +11 -0
- package/dist/model/queryKeys.d.ts.map +1 -0
- package/dist/model/queryKeys.js +32 -0
- package/dist/model/queryKeys.js.map +1 -0
- package/dist/model/refusals.d.ts +25 -0
- package/dist/model/refusals.d.ts.map +1 -0
- package/dist/model/refusals.js +73 -0
- package/dist/model/refusals.js.map +1 -0
- package/dist/model/runtime.d.ts +51 -0
- package/dist/model/runtime.d.ts.map +1 -0
- package/dist/model/runtime.js +29 -0
- package/dist/model/runtime.js.map +1 -0
- package/dist/model/status.d.ts +60 -0
- package/dist/model/status.d.ts.map +1 -0
- package/dist/model/status.js +116 -0
- package/dist/model/status.js.map +1 -0
- package/dist/nav/manifest.d.ts +43 -0
- package/dist/nav/manifest.d.ts.map +1 -0
- package/dist/nav/manifest.js +36 -0
- package/dist/nav/manifest.js.map +1 -0
- package/llms.txt +84 -0
- package/manifest.json +694 -0
- package/nav-manifest.json +46 -0
- package/package.json +119 -0
- package/src/analytics/events.ts +29 -0
- package/src/analytics/generated/events.json +7 -0
- package/src/api/alertsApi.ts +259 -0
- package/src/api/generated/schema.ts +455 -0
- package/src/api/types.ts +113 -0
- package/src/default/FixIssueDialog.tsx +158 -0
- package/src/default/IssueDetail.tsx +431 -0
- package/src/default/IssueFilterBar.tsx +197 -0
- package/src/default/IssuesFeed.tsx +343 -0
- package/src/default/MuteIssueDialog.tsx +186 -0
- package/src/default/index.ts +37 -0
- package/src/default/labels.ts +113 -0
- package/src/default/layout.ts +52 -0
- package/src/default/types.ts +27 -0
- package/src/flows/errors.ts +16 -0
- package/src/flows/registry.ts +32 -0
- package/src/headless/AlertsProvider.tsx +20 -0
- package/src/i18n/errorsMap.ts +31 -0
- package/src/i18n/es.ts +181 -0
- package/src/i18n/generated/errors.es.gen.ts +63 -0
- package/src/i18n/generated/errors.gen.ts +196 -0
- package/src/i18n/generated/errors.json +370 -0
- package/src/i18n/generated/errors.ru.gen.ts +63 -0
- package/src/i18n/keys.ts +341 -0
- package/src/i18n/ru.ts +188 -0
- package/src/index.ts +152 -0
- package/src/model/context.tsx +28 -0
- package/src/model/issues.ts +311 -0
- package/src/model/queryKeys.ts +41 -0
- package/src/model/refusals.ts +82 -0
- package/src/model/runtime.ts +80 -0
- package/src/model/status.ts +179 -0
- package/src/nav/manifest.ts +76 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<MuteIssueDialog>` — known, accepted, and deliberately not notified about.
|
|
3
|
+
*
|
|
4
|
+
* ── Muting stops the notifications, not the recording ─────────────────────
|
|
5
|
+
*
|
|
6
|
+
* That sentence is in the body, first, because it is the one thing people get
|
|
7
|
+
* wrong about a mute: occurrences keep arriving, the count keeps rising, and
|
|
8
|
+
* the row keeps its place on the board. A person who believed otherwise would
|
|
9
|
+
* mute a rising fatal thinking they had parked it.
|
|
10
|
+
*
|
|
11
|
+
* ── "No deadline" is offered, and warned about ────────────────────────────
|
|
12
|
+
*
|
|
13
|
+
* `muted_until` is nullable upstream, so an indefinite mute is a real state
|
|
14
|
+
* and hiding it would only produce the 2099 date somebody types instead. It is
|
|
15
|
+
* the last option, not the first, and choosing it says what it costs: nothing
|
|
16
|
+
* will ever bring this back on its own.
|
|
17
|
+
*
|
|
18
|
+
* ── The patch is the deadline ─────────────────────────────────────────────
|
|
19
|
+
*
|
|
20
|
+
* `muted_until` on its own is a mute; the store infers the status from it.
|
|
21
|
+
* `useIssueStatus().mute` always sends the key — `null` for "forever" — see
|
|
22
|
+
* `model/status.ts`.
|
|
23
|
+
*/
|
|
24
|
+
import { useState } from "react";
|
|
25
|
+
import type { ReactElement } from "react";
|
|
26
|
+
import { Flex, Input, Radio, Typography } from "antd";
|
|
27
|
+
import { spacing } from "@stapel/tokens";
|
|
28
|
+
import { ErrorAlert, SkinButton, SkinDialog } from "@stapel/tokens-antd/skin";
|
|
29
|
+
import { useFormat, useT } from "@stapel/core";
|
|
30
|
+
import type { IssueLevel } from "../api/types.js";
|
|
31
|
+
import { useIssueStatus } from "../model/status.js";
|
|
32
|
+
import { ALERTS_I18N_KEYS } from "../i18n/keys.js";
|
|
33
|
+
import { DIALOG_ACTION_BAR_STYLE } from "./layout.js";
|
|
34
|
+
import type { ThemeModeProp } from "./types.js";
|
|
35
|
+
|
|
36
|
+
/** How long a mute lasts. `forever` sends an explicit `null`. */
|
|
37
|
+
export type MuteWindow = "day" | "week" | "month" | "forever";
|
|
38
|
+
|
|
39
|
+
const WINDOW_SECONDS: Readonly<Record<Exclude<MuteWindow, "forever">, number>> =
|
|
40
|
+
{
|
|
41
|
+
day: 24 * 60 * 60,
|
|
42
|
+
week: 7 * 24 * 60 * 60,
|
|
43
|
+
month: 30 * 24 * 60 * 60,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The instant a window means, taken from the clock at the moment of the choice. */
|
|
47
|
+
export function mutedUntilFor(
|
|
48
|
+
span: MuteWindow,
|
|
49
|
+
now: Date = new Date()
|
|
50
|
+
): string | null {
|
|
51
|
+
if (span === "forever") return null;
|
|
52
|
+
return new Date(now.getTime() + WINDOW_SECONDS[span] * 1000).toISOString();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface MuteIssueDialogProps extends ThemeModeProp {
|
|
56
|
+
readonly open: boolean;
|
|
57
|
+
readonly onClose: () => void;
|
|
58
|
+
readonly issueId: string;
|
|
59
|
+
/** The row's level — the analytics prop only; it never reaches the wire. */
|
|
60
|
+
readonly level?: IssueLevel;
|
|
61
|
+
/** Called after the store has saved the mute. */
|
|
62
|
+
readonly onMuted?: () => void;
|
|
63
|
+
readonly testId?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function MuteIssueDialog(props: MuteIssueDialogProps): ReactElement {
|
|
67
|
+
const t = useT();
|
|
68
|
+
const testId = props.testId ?? "alerts-mute";
|
|
69
|
+
return (
|
|
70
|
+
<SkinDialog
|
|
71
|
+
open={props.open}
|
|
72
|
+
onClose={props.onClose}
|
|
73
|
+
title={t(ALERTS_I18N_KEYS.muteTitle)}
|
|
74
|
+
dismissLabel={t(ALERTS_I18N_KEYS.dismiss)}
|
|
75
|
+
data-testid={testId}
|
|
76
|
+
>
|
|
77
|
+
{/* The body exists only while the dialog is open, so the window, the
|
|
78
|
+
note and the mutation's error are dropped together on close. */}
|
|
79
|
+
{props.open ? <MuteIssueForm {...props} testId={testId} /> : null}
|
|
80
|
+
</SkinDialog>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function MuteIssueForm(
|
|
85
|
+
props: MuteIssueDialogProps & { readonly testId: string }
|
|
86
|
+
): ReactElement {
|
|
87
|
+
const t = useT();
|
|
88
|
+
const fmt = useFormat();
|
|
89
|
+
const { testId } = props;
|
|
90
|
+
const { mute } = useIssueStatus();
|
|
91
|
+
const [span, setSpan] = useState<MuteWindow>("week");
|
|
92
|
+
const [note, setNote] = useState("");
|
|
93
|
+
|
|
94
|
+
const until = mutedUntilFor(span);
|
|
95
|
+
|
|
96
|
+
const submit = (): void => {
|
|
97
|
+
mute.mutate(
|
|
98
|
+
{
|
|
99
|
+
issueId: props.issueId,
|
|
100
|
+
mutedUntil: mutedUntilFor(span),
|
|
101
|
+
...(note.trim().length > 0 ? { note: note.trim() } : {}),
|
|
102
|
+
...(props.level !== undefined ? { level: props.level } : {}),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
onSuccess: () => {
|
|
106
|
+
props.onMuted?.();
|
|
107
|
+
props.onClose();
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Flex vertical gap={spacing[3]}>
|
|
115
|
+
<Typography.Text type="secondary">
|
|
116
|
+
{t(ALERTS_I18N_KEYS.muteBody)}
|
|
117
|
+
</Typography.Text>
|
|
118
|
+
|
|
119
|
+
<Flex vertical gap={spacing[1]}>
|
|
120
|
+
<Typography.Text strong>{t(ALERTS_I18N_KEYS.muteUntil)}</Typography.Text>
|
|
121
|
+
<Radio.Group
|
|
122
|
+
value={span}
|
|
123
|
+
data-testid={`${testId}-window`}
|
|
124
|
+
onChange={(event) => setSpan(event.target.value as MuteWindow)}
|
|
125
|
+
>
|
|
126
|
+
<Radio value="day" data-testid={`${testId}-window-day`}>
|
|
127
|
+
{t(ALERTS_I18N_KEYS.muteDay)}
|
|
128
|
+
</Radio>
|
|
129
|
+
<Radio value="week" data-testid={`${testId}-window-week`}>
|
|
130
|
+
{t(ALERTS_I18N_KEYS.muteWeek)}
|
|
131
|
+
</Radio>
|
|
132
|
+
<Radio value="month" data-testid={`${testId}-window-month`}>
|
|
133
|
+
{t(ALERTS_I18N_KEYS.muteMonth)}
|
|
134
|
+
</Radio>
|
|
135
|
+
<Radio value="forever" data-testid={`${testId}-window-forever`}>
|
|
136
|
+
{t(ALERTS_I18N_KEYS.muteForever)}
|
|
137
|
+
</Radio>
|
|
138
|
+
</Radio.Group>
|
|
139
|
+
{until === null ? (
|
|
140
|
+
<Typography.Text type="warning" data-testid={`${testId}-forever`}>
|
|
141
|
+
{t(ALERTS_I18N_KEYS.muteForeverHint)}
|
|
142
|
+
</Typography.Text>
|
|
143
|
+
) : (
|
|
144
|
+
<Typography.Text type="secondary" data-testid={`${testId}-until`}>
|
|
145
|
+
{fmt.timestamp(until) ?? t(ALERTS_I18N_KEYS.none)}
|
|
146
|
+
</Typography.Text>
|
|
147
|
+
)}
|
|
148
|
+
</Flex>
|
|
149
|
+
|
|
150
|
+
<Flex vertical gap={spacing[1]}>
|
|
151
|
+
<Typography.Text strong>{t(ALERTS_I18N_KEYS.muteNote)}</Typography.Text>
|
|
152
|
+
<Input.TextArea
|
|
153
|
+
value={note}
|
|
154
|
+
rows={2}
|
|
155
|
+
aria-label={t(ALERTS_I18N_KEYS.muteNote)}
|
|
156
|
+
placeholder={t(ALERTS_I18N_KEYS.muteNoteHint)}
|
|
157
|
+
data-testid={`${testId}-note`}
|
|
158
|
+
onChange={(event) => setNote(event.target.value)}
|
|
159
|
+
/>
|
|
160
|
+
</Flex>
|
|
161
|
+
|
|
162
|
+
<ErrorAlert testId={`${testId}-failed`} thrown={mute.error} variant="inline" />
|
|
163
|
+
|
|
164
|
+
<Flex gap={spacing[2]} justify="end" style={DIALOG_ACTION_BAR_STYLE}>
|
|
165
|
+
<SkinButton
|
|
166
|
+
data-testid={`${testId}-cancel`}
|
|
167
|
+
data-analytics="none"
|
|
168
|
+
data-analytics-reason="dismissing a dialog decides nothing about the issue"
|
|
169
|
+
onClick={props.onClose}
|
|
170
|
+
>
|
|
171
|
+
{t(ALERTS_I18N_KEYS.cancel)}
|
|
172
|
+
</SkinButton>
|
|
173
|
+
<SkinButton
|
|
174
|
+
type="primary"
|
|
175
|
+
loading={mute.isPending}
|
|
176
|
+
data-testid={`${testId}-submit`}
|
|
177
|
+
data-analytics="none"
|
|
178
|
+
data-analytics-reason="alerts.issue.muted is emitted by the model layer on success"
|
|
179
|
+
onClick={submit}
|
|
180
|
+
>
|
|
181
|
+
{t(ALERTS_I18N_KEYS.muteSubmit)}
|
|
182
|
+
</SkinButton>
|
|
183
|
+
</Flex>
|
|
184
|
+
</Flex>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@stapel/alerts-react/default` — the pair's default AntD skin (§54: a pair
|
|
3
|
+
* ships a FEATURE, not only a bag). A separate entry point, so a host that
|
|
4
|
+
* brings its own visuals never pulls `antd` or the token bridge into its
|
|
5
|
+
* bundle; importing this subpath is the opt-in.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import { IssuesFeed } from "@stapel/alerts-react/default";
|
|
9
|
+
* // under the pair's <AlertsProvider> + core's <I18nProvider>:
|
|
10
|
+
* <IssuesFeed issueHref={(id) => `/admin/alerts/${id}`} />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* The two screens are `IssuesFeed` and `IssueDetail` — the two the nav
|
|
14
|
+
* manifest routes to. Everything under them is exported as well, because a
|
|
15
|
+
* host that builds its own operations layout should be able to mount the
|
|
16
|
+
* filter bar or the fix dialog beside its own chrome rather than
|
|
17
|
+
* re-implementing either.
|
|
18
|
+
*/
|
|
19
|
+
export { IssuesFeed } from "./IssuesFeed.js";
|
|
20
|
+
export type { IssuesFeedProps } from "./IssuesFeed.js";
|
|
21
|
+
export { IssueDetail } from "./IssueDetail.js";
|
|
22
|
+
export type { IssueDetailProps } from "./IssueDetail.js";
|
|
23
|
+
export { IssueFilterBar, sinceFor } from "./IssueFilterBar.js";
|
|
24
|
+
export type { IssueFilterBarProps, SincePreset } from "./IssueFilterBar.js";
|
|
25
|
+
export { FixIssueDialog } from "./FixIssueDialog.js";
|
|
26
|
+
export type { FixIssueDialogProps } from "./FixIssueDialog.js";
|
|
27
|
+
export { MuteIssueDialog, mutedUntilFor } from "./MuteIssueDialog.js";
|
|
28
|
+
export type { MuteIssueDialogProps, MuteWindow } from "./MuteIssueDialog.js";
|
|
29
|
+
export {
|
|
30
|
+
levelKey,
|
|
31
|
+
levelFamily,
|
|
32
|
+
kindKey,
|
|
33
|
+
statusKey,
|
|
34
|
+
statusFamily,
|
|
35
|
+
} from "./labels.js";
|
|
36
|
+
export { TRACE_BLOCK_STYLE, DIALOG_ACTION_BAR_STYLE } from "./layout.js";
|
|
37
|
+
export type { ThemeModeProp, IssueNavigationProps } from "./types.js";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire enum → i18n key, and wire enum → status FAMILY, one table per axis.
|
|
3
|
+
*
|
|
4
|
+
* Every table has the same fallback shape, and the fallback is the point: all
|
|
5
|
+
* three enums can gain a member in a backend minor, and a `switch` with no
|
|
6
|
+
* default would render a raw wire token (`silenced`, `critical`) at an
|
|
7
|
+
* operator — or, worse, fall into the wrong colour and paint a new fatal
|
|
8
|
+
* green. An unrecognised value renders the "unknown ({x})" copy in the neutral
|
|
9
|
+
* family, which is honest and still says exactly what the server sent.
|
|
10
|
+
*
|
|
11
|
+
* The families come from `@stapel/tokens-antd`'s `StatusTag` vocabulary
|
|
12
|
+
* (§ the skin registry): five families for the whole fleet, so "this failed"
|
|
13
|
+
* is the same red here as everywhere else a host draws a failure.
|
|
14
|
+
*/
|
|
15
|
+
import type { StatusFamily } from "@stapel/tokens-antd/skin";
|
|
16
|
+
import { ALERTS_I18N_KEYS } from "../i18n/keys.js";
|
|
17
|
+
|
|
18
|
+
/** Copy for a severity. */
|
|
19
|
+
export function levelKey(level: string): string {
|
|
20
|
+
switch (level) {
|
|
21
|
+
case "debug":
|
|
22
|
+
return ALERTS_I18N_KEYS.levelDebug;
|
|
23
|
+
case "info":
|
|
24
|
+
return ALERTS_I18N_KEYS.levelInfo;
|
|
25
|
+
case "warning":
|
|
26
|
+
return ALERTS_I18N_KEYS.levelWarning;
|
|
27
|
+
case "error":
|
|
28
|
+
return ALERTS_I18N_KEYS.levelError;
|
|
29
|
+
case "fatal":
|
|
30
|
+
return ALERTS_I18N_KEYS.levelFatal;
|
|
31
|
+
default:
|
|
32
|
+
return ALERTS_I18N_KEYS.levelUnknown;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The status family a severity belongs to.
|
|
38
|
+
*
|
|
39
|
+
* `fatal` and `error` are both the error family and that is deliberate: a
|
|
40
|
+
* sixth colour for "worse than red" would be a colour nobody can read faster
|
|
41
|
+
* than red. What separates them is the WORD, and the feed sorts by level so
|
|
42
|
+
* the fatals are already at the top of their service.
|
|
43
|
+
*/
|
|
44
|
+
export function levelFamily(level: string): StatusFamily {
|
|
45
|
+
switch (level) {
|
|
46
|
+
case "fatal":
|
|
47
|
+
case "error":
|
|
48
|
+
return "error";
|
|
49
|
+
case "warning":
|
|
50
|
+
return "warning";
|
|
51
|
+
case "info":
|
|
52
|
+
return "info";
|
|
53
|
+
default:
|
|
54
|
+
return "neutral";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Copy for where an occurrence came from. */
|
|
59
|
+
export function kindKey(kind: string): string {
|
|
60
|
+
switch (kind) {
|
|
61
|
+
case "exception":
|
|
62
|
+
return ALERTS_I18N_KEYS.kindException;
|
|
63
|
+
case "log":
|
|
64
|
+
return ALERTS_I18N_KEYS.kindLog;
|
|
65
|
+
case "dlq":
|
|
66
|
+
return ALERTS_I18N_KEYS.kindDlq;
|
|
67
|
+
case "monitoring":
|
|
68
|
+
return ALERTS_I18N_KEYS.kindMonitoring;
|
|
69
|
+
case "manual":
|
|
70
|
+
return ALERTS_I18N_KEYS.kindManual;
|
|
71
|
+
default:
|
|
72
|
+
return ALERTS_I18N_KEYS.kindUnknown;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Copy for where an issue is in its life. */
|
|
77
|
+
export function statusKey(status: string): string {
|
|
78
|
+
switch (status) {
|
|
79
|
+
case "new":
|
|
80
|
+
return ALERTS_I18N_KEYS.statusNew;
|
|
81
|
+
case "fixed":
|
|
82
|
+
return ALERTS_I18N_KEYS.statusFixed;
|
|
83
|
+
case "regressed":
|
|
84
|
+
return ALERTS_I18N_KEYS.statusRegressed;
|
|
85
|
+
case "muted":
|
|
86
|
+
return ALERTS_I18N_KEYS.statusMuted;
|
|
87
|
+
default:
|
|
88
|
+
return ALERTS_I18N_KEYS.statusUnknown;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The status family a tracker status belongs to.
|
|
94
|
+
*
|
|
95
|
+
* `regressed` is the ERROR family while `new` is only a warning, and that is
|
|
96
|
+
* the one judgement in this table: a bug somebody already closed and which
|
|
97
|
+
* came back anyway is worse news than a bug nobody has looked at, because it
|
|
98
|
+
* means a fix that was believed did not hold.
|
|
99
|
+
*/
|
|
100
|
+
export function statusFamily(status: string): StatusFamily {
|
|
101
|
+
switch (status) {
|
|
102
|
+
case "fixed":
|
|
103
|
+
return "success";
|
|
104
|
+
case "regressed":
|
|
105
|
+
return "error";
|
|
106
|
+
case "new":
|
|
107
|
+
return "warning";
|
|
108
|
+
case "muted":
|
|
109
|
+
return "neutral";
|
|
110
|
+
default:
|
|
111
|
+
return "neutral";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geometries this skin owns, lifted to named constants rather than
|
|
3
|
+
* spelled inline. All of them are element-width decisions, not viewport ones:
|
|
4
|
+
* a traceback keeps its shape wherever a host mounts it, including inside a
|
|
5
|
+
* narrow drawer that is nobody's breakpoint.
|
|
6
|
+
*/
|
|
7
|
+
import type { CSSProperties } from "react";
|
|
8
|
+
import { cssVar, fontSize, radii, spacing } from "@stapel/tokens";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A traceback or a context blob is arbitrary text — one long line in it must
|
|
12
|
+
* scroll INSIDE the block, never widen the page. `overflowX: auto` on the
|
|
13
|
+
* `<pre>` is what keeps a phone from horizontally scrolling the whole issue
|
|
14
|
+
* screen because one frame carried a 300-character path.
|
|
15
|
+
*
|
|
16
|
+
* `maxHeight` matters here more than in the pairs this pattern came from: a
|
|
17
|
+
* Python traceback from a Django request is routinely sixty frames, and three
|
|
18
|
+
* of them in a row would push every control on the screen below the fold.
|
|
19
|
+
*/
|
|
20
|
+
export const TRACE_BLOCK_STYLE: CSSProperties = {
|
|
21
|
+
overflowX: "auto",
|
|
22
|
+
overflowY: "auto",
|
|
23
|
+
maxHeight: "24rem",
|
|
24
|
+
margin: 0,
|
|
25
|
+
padding: spacing[3],
|
|
26
|
+
borderRadius: radii.md,
|
|
27
|
+
fontSize: fontSize.sm.fontSize,
|
|
28
|
+
lineHeight: `${String(fontSize.sm.lineHeight)}px`,
|
|
29
|
+
// No background/colour: the `<pre>` inherits the surface it is dropped into,
|
|
30
|
+
// which is the skin surface `SkinTheme` painted. A colour here would fight
|
|
31
|
+
// the theme in exactly one of the two modes.
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The action row at the foot of a dialog, pinned to the bottom of the
|
|
36
|
+
* dialog's own scroll box.
|
|
37
|
+
*
|
|
38
|
+
* A bottom sheet is a fixed slice of the viewport and these bodies are long —
|
|
39
|
+
* the mute dialog is four presets, a date and a note. Left in the flow, the
|
|
40
|
+
* one control somebody opened the sheet to press sits below an invisible fold.
|
|
41
|
+
*
|
|
42
|
+
* It is NOT `SkinDialog`'s `footer` slot: antd memoises that slot, so a button
|
|
43
|
+
* whose gate opens once a field is filled keeps rendering the state it had on
|
|
44
|
+
* the dialog's first frame.
|
|
45
|
+
*/
|
|
46
|
+
export const DIALOG_ACTION_BAR_STYLE: CSSProperties = {
|
|
47
|
+
position: "sticky",
|
|
48
|
+
bottom: 0,
|
|
49
|
+
zIndex: 1,
|
|
50
|
+
background: cssVar("surface-overlay"),
|
|
51
|
+
paddingBlock: spacing[3],
|
|
52
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The props every skin component in this package shares.
|
|
3
|
+
*
|
|
4
|
+
* `mode` is OPTIONAL and has no default here on purpose: the shared
|
|
5
|
+
* `SkinTheme` (`@stapel/tokens-antd/skin`) follows the host's theme when
|
|
6
|
+
* nobody overrides it, and a `mode = "light"` default in a pair is how a dark
|
|
7
|
+
* host ends up with one white rectangle in the middle of its app.
|
|
8
|
+
*/
|
|
9
|
+
export interface ThemeModeProp {
|
|
10
|
+
readonly mode?: "light" | "dark";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* How a screen in this pair reaches one issue.
|
|
15
|
+
*
|
|
16
|
+
* This package owns no router. A host that has one passes `issueHref` and the
|
|
17
|
+
* rows become real links — middle-clickable, copyable, and the thing somebody
|
|
18
|
+
* pastes into a chat beside `alerts:<id>`. A host without one passes
|
|
19
|
+
* `onOpenIssue` and gets a button. Neither given, the row still renders and
|
|
20
|
+
* simply offers no way in, which is honest: a dead control would be worse.
|
|
21
|
+
*/
|
|
22
|
+
export interface IssueNavigationProps {
|
|
23
|
+
/** `(issueId) => href` for the host's route to the issue screen. */
|
|
24
|
+
readonly issueHref?: (issueId: string) => string;
|
|
25
|
+
/** Called with the issue id when a row is activated. */
|
|
26
|
+
readonly onOpenIssue?: (issueId: string) => void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { toFlowError as coreToFlowError } from "@stapel/core";
|
|
2
|
+
import type { FlowError } from "@stapel/core";
|
|
3
|
+
|
|
4
|
+
export type { FlowError } from "@stapel/core";
|
|
5
|
+
export { isErrorCode } from "@stapel/core";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Fold any thrown value into a {@link FlowError} using this pair's own
|
|
9
|
+
* module-scoped fallback key (`alerts.error.unknown`, an en string in
|
|
10
|
+
* {@link alertsI18nBundleEn}) so a non-`StapelApiError` fault still renders
|
|
11
|
+
* real copy rather than a raw key. The primitive lives in `@stapel/core`
|
|
12
|
+
* (frontend-core-architecture §4b); this wrapper only pins the fallback.
|
|
13
|
+
*/
|
|
14
|
+
export function toFlowError(error: unknown): FlowError {
|
|
15
|
+
return coreToFlowError(error, "alerts.error.unknown");
|
|
16
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-flow registry shim (slim wave §21/S3). stapel-alerts annotates no
|
|
3
|
+
* `@flow_step` — its `docs/flows.json` is an empty array, so `gen:flows` skips
|
|
4
|
+
* emission for this pair (no `flows/generated/` scaffolding at all). This
|
|
5
|
+
* hand-written shim preserves the pair's public flow-registry surface at its
|
|
6
|
+
* zero-flow shape.
|
|
7
|
+
*
|
|
8
|
+
* When the backend annotates flows, `pnpm gen:flows` emits
|
|
9
|
+
* `./generated/flows.gen.ts` again — replace these exports with re-exports
|
|
10
|
+
* from it (the shapes match by construction) and delete this file.
|
|
11
|
+
*/
|
|
12
|
+
export const ALERTS_FLOWS = {} as const;
|
|
13
|
+
|
|
14
|
+
/** Canonical flow ids present in flows.json (none yet — see above). */
|
|
15
|
+
export type AlertsFlowId = keyof typeof ALERTS_FLOWS;
|
|
16
|
+
|
|
17
|
+
export type AlertsFlowSpec = (typeof ALERTS_FLOWS)[AlertsFlowId];
|
|
18
|
+
|
|
19
|
+
export interface FlowEndpoint {
|
|
20
|
+
readonly method: string;
|
|
21
|
+
readonly path: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** All HTTP endpoints a flow touches, in step order (for the contract test / MSW). */
|
|
25
|
+
export function flowEndpoints(id: AlertsFlowId): readonly FlowEndpoint[] {
|
|
26
|
+
// Same widened body as the generated registry's — valid for the zero-flow
|
|
27
|
+
// shape AND correct once flows exist.
|
|
28
|
+
const spec = ALERTS_FLOWS[id] as
|
|
29
|
+
| { readonly steps: readonly { readonly endpoints: readonly FlowEndpoint[] }[] }
|
|
30
|
+
| undefined;
|
|
31
|
+
return spec ? spec.steps.flatMap((s) => s.endpoints) : [];
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { ModuleProvider } from "../model/context.js";
|
|
3
|
+
import type { AlertsRuntime } from "../model/runtime.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides the wired {@link AlertsRuntime} to every alerts hook and screen
|
|
7
|
+
* below it. Bring your own visual shell — this component renders nothing of
|
|
8
|
+
* its own. (Core's `createModuleContext` provider, bound to this pair — slim
|
|
9
|
+
* wave §21/S2.)
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const runtime = createAlertsRuntime({ baseUrl: "/alerts/api/v1/" });
|
|
13
|
+
* // give runtime.client to core's <StapelConfigProvider config={{ client }}>
|
|
14
|
+
* <AlertsProvider runtime={runtime}>{app}</AlertsProvider>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const AlertsProvider: (props: {
|
|
18
|
+
runtime: AlertsRuntime;
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}) => ReactElement = ModuleProvider;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pair's error map (frontend-standard §4 checklist #7, frontend-core §2.5):
|
|
3
|
+
* the generated `code → { status, params, remediation, en }` catalog plus a
|
|
4
|
+
* tiny `explain()` lookup. Backs the manifest `errors` block and gives hosts a
|
|
5
|
+
* mechanical UX branch beside `t(code, params)`. The map itself is generated
|
|
6
|
+
* from the backend registry (`pnpm gen:errors`); this file only adds the
|
|
7
|
+
* lookup helper and re-exports the public surface.
|
|
8
|
+
*/
|
|
9
|
+
import { ALERTS_ERRORS } from "./generated/errors.gen.js";
|
|
10
|
+
import type { Remediation } from "./generated/errors.gen.js";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
ALERTS_ERRORS,
|
|
14
|
+
ALERTS_ERROR_CODES,
|
|
15
|
+
alertsErrorBundleEn,
|
|
16
|
+
} from "./generated/errors.gen.js";
|
|
17
|
+
export type {
|
|
18
|
+
AlertsErrorCode,
|
|
19
|
+
AlertsErrorSpec,
|
|
20
|
+
Remediation,
|
|
21
|
+
} from "./generated/errors.gen.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a backend error code to its remediation hint, or `undefined` for a
|
|
25
|
+
* code this module doesn't know (e.g. a cross-cutting `stapel.http.*`
|
|
26
|
+
* fallback). Zero guessing at runtime — a static lookup over the generated map.
|
|
27
|
+
*/
|
|
28
|
+
export function explainAlertsError(code: string): Remediation | undefined {
|
|
29
|
+
return (ALERTS_ERRORS as Record<string, { remediation: Remediation }>)[code]
|
|
30
|
+
?.remediation;
|
|
31
|
+
}
|