@clef-sh/ui 0.1.15-beta.97 → 0.1.15
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/dist/client/assets/index-C4tsbWst.js +26 -0
- package/dist/client/index.html +1 -1
- package/dist/client-lib/components/MatrixGrid.d.ts +3 -1
- package/dist/client-lib/components/MatrixGrid.d.ts.map +1 -1
- package/dist/client-lib/components/SyncPanel.d.ts +8 -0
- package/dist/client-lib/components/SyncPanel.d.ts.map +1 -0
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/api.js +83 -4
- package/dist/server/api.js.map +1 -1
- package/package.json +1 -1
- package/src/client/App.tsx +2 -16
- package/src/client/components/MatrixGrid.tsx +179 -145
- package/src/client/components/SyncPanel.test.tsx +138 -0
- package/src/client/components/SyncPanel.tsx +217 -0
- package/src/client/screens/BackendScreen.tsx +0 -1
- package/src/client/screens/MatrixView.tsx +24 -2
- package/src/client/screens/NamespaceEditor.test.tsx +24 -24
- package/src/client/screens/NamespaceEditor.tsx +28 -62
- package/dist/client/assets/index-rBYybJbt.js +0 -26
|
@@ -9,6 +9,8 @@ export interface MatrixGridProps {
|
|
|
9
9
|
environments: Array<{ name: string }>;
|
|
10
10
|
matrixStatuses: MatrixStatus[];
|
|
11
11
|
onNamespaceClick?: (ns: string) => void;
|
|
12
|
+
onSyncClick?: (ns: string) => void;
|
|
13
|
+
syncingNs?: string | null;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
function getStatusType(status: MatrixStatus): string {
|
|
@@ -38,6 +40,8 @@ export function MatrixGrid({
|
|
|
38
40
|
environments,
|
|
39
41
|
matrixStatuses,
|
|
40
42
|
onNamespaceClick,
|
|
43
|
+
onSyncClick,
|
|
44
|
+
syncingNs,
|
|
41
45
|
}: MatrixGridProps) {
|
|
42
46
|
return (
|
|
43
47
|
<div
|
|
@@ -98,168 +102,198 @@ export function MatrixGrid({
|
|
|
98
102
|
</div>
|
|
99
103
|
|
|
100
104
|
{/* Namespace rows */}
|
|
101
|
-
{namespaces.map((ns, i) =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
onKeyDown={(e) => {
|
|
109
|
-
if (e.key === "Enter") onNamespaceClick?.(ns.name);
|
|
110
|
-
}}
|
|
111
|
-
style={{
|
|
112
|
-
display: "grid",
|
|
113
|
-
gridTemplateColumns: `180px ${environments.map(() => "1fr").join(" ")}`,
|
|
114
|
-
borderBottom: i < namespaces.length - 1 ? `1px solid ${theme.border}` : "none",
|
|
115
|
-
cursor: onNamespaceClick ? "pointer" : "default",
|
|
116
|
-
transition: "background 0.1s",
|
|
117
|
-
}}
|
|
118
|
-
onMouseEnter={(e) => {
|
|
119
|
-
(e.currentTarget as HTMLElement).style.background = theme.surfaceHover;
|
|
120
|
-
}}
|
|
121
|
-
onMouseLeave={(e) => {
|
|
122
|
-
(e.currentTarget as HTMLElement).style.background = "transparent";
|
|
123
|
-
}}
|
|
124
|
-
>
|
|
125
|
-
{/* Namespace label */}
|
|
105
|
+
{namespaces.map((ns, i) => {
|
|
106
|
+
const nsCells = matrixStatuses.filter((s) => s.cell.namespace === ns.name);
|
|
107
|
+
const hasDrift = nsCells.some((s) =>
|
|
108
|
+
s.issues.some((issue) => issue.type === "missing_keys"),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
return (
|
|
126
112
|
<div
|
|
113
|
+
key={ns.name}
|
|
114
|
+
data-testid={`matrix-row-${ns.name}`}
|
|
115
|
+
role="button"
|
|
116
|
+
tabIndex={0}
|
|
117
|
+
onClick={() => onNamespaceClick?.(ns.name)}
|
|
118
|
+
onKeyDown={(e) => {
|
|
119
|
+
if (e.key === "Enter") onNamespaceClick?.(ns.name);
|
|
120
|
+
}}
|
|
127
121
|
style={{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
display: "grid",
|
|
123
|
+
gridTemplateColumns: `180px ${environments.map(() => "1fr").join(" ")}`,
|
|
124
|
+
borderBottom: i < namespaces.length - 1 ? `1px solid ${theme.border}` : "none",
|
|
125
|
+
cursor: onNamespaceClick ? "pointer" : "default",
|
|
126
|
+
transition: "background 0.1s",
|
|
127
|
+
}}
|
|
128
|
+
onMouseEnter={(e) => {
|
|
129
|
+
(e.currentTarget as HTMLElement).style.background = theme.surfaceHover;
|
|
130
|
+
}}
|
|
131
|
+
onMouseLeave={(e) => {
|
|
132
|
+
(e.currentTarget as HTMLElement).style.background = "transparent";
|
|
132
133
|
}}
|
|
133
134
|
>
|
|
134
|
-
|
|
135
|
+
{/* Namespace label */}
|
|
136
|
+
<div
|
|
135
137
|
style={{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
padding: "16px 20px",
|
|
139
|
+
display: "flex",
|
|
140
|
+
alignItems: "center",
|
|
141
|
+
gap: 10,
|
|
139
142
|
}}
|
|
140
143
|
>
|
|
141
|
-
|
|
142
|
-
</span>
|
|
143
|
-
<span
|
|
144
|
-
style={{
|
|
145
|
-
fontFamily: theme.mono,
|
|
146
|
-
fontSize: 13,
|
|
147
|
-
fontWeight: 600,
|
|
148
|
-
color: theme.text,
|
|
149
|
-
}}
|
|
150
|
-
>
|
|
151
|
-
{ns.name}
|
|
152
|
-
</span>
|
|
153
|
-
</div>
|
|
154
|
-
|
|
155
|
-
{/* Environment cells */}
|
|
156
|
-
{environments.map((env) => {
|
|
157
|
-
const cellStatus = matrixStatuses.find(
|
|
158
|
-
(s) => s.cell.namespace === ns.name && s.cell.environment === env.name,
|
|
159
|
-
);
|
|
160
|
-
const statusType = cellStatus ? getStatusType(cellStatus) : "ok";
|
|
161
|
-
const keyCount = cellStatus?.keyCount ?? 0;
|
|
162
|
-
const lastMod = cellStatus?.lastModified
|
|
163
|
-
? formatDate(
|
|
164
|
-
cellStatus.lastModified instanceof Date
|
|
165
|
-
? cellStatus.lastModified
|
|
166
|
-
: new Date(cellStatus.lastModified as unknown as string),
|
|
167
|
-
)
|
|
168
|
-
: "never";
|
|
169
|
-
const missingKeyCount = cellStatus
|
|
170
|
-
? new Set(
|
|
171
|
-
cellStatus.issues
|
|
172
|
-
.filter((i) => i.type === "missing_keys" && i.key)
|
|
173
|
-
.map((i) => i.key),
|
|
174
|
-
).size
|
|
175
|
-
: 0;
|
|
176
|
-
const warnKeyCount = cellStatus
|
|
177
|
-
? cellStatus.issues.filter((i) => i.type === "schema_warning").length
|
|
178
|
-
: 0;
|
|
179
|
-
const cellPending = cellStatus?.pendingCount ?? 0;
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
<div
|
|
183
|
-
key={env.name}
|
|
144
|
+
<span
|
|
184
145
|
style={{
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
flexDirection: "column",
|
|
189
|
-
gap: 5,
|
|
146
|
+
fontFamily: theme.mono,
|
|
147
|
+
fontSize: 11,
|
|
148
|
+
color: theme.textDim,
|
|
190
149
|
}}
|
|
191
150
|
>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
151
|
+
//
|
|
152
|
+
</span>
|
|
153
|
+
<span
|
|
154
|
+
style={{
|
|
155
|
+
fontFamily: theme.mono,
|
|
156
|
+
fontSize: 13,
|
|
157
|
+
fontWeight: 600,
|
|
158
|
+
color: theme.text,
|
|
159
|
+
flex: 1,
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
{ns.name}
|
|
163
|
+
</span>
|
|
164
|
+
{hasDrift && syncingNs !== ns.name && onSyncClick && (
|
|
165
|
+
<button
|
|
166
|
+
data-testid={`sync-btn-${ns.name}`}
|
|
167
|
+
onClick={(e) => {
|
|
168
|
+
e.stopPropagation();
|
|
169
|
+
onSyncClick(ns.name);
|
|
170
|
+
}}
|
|
171
|
+
style={{
|
|
172
|
+
fontFamily: theme.sans,
|
|
173
|
+
fontSize: 10,
|
|
174
|
+
fontWeight: 600,
|
|
175
|
+
color: theme.accent,
|
|
176
|
+
background: `${theme.accent}18`,
|
|
177
|
+
border: `1px solid ${theme.accent}33`,
|
|
178
|
+
borderRadius: 4,
|
|
179
|
+
padding: "2px 8px",
|
|
180
|
+
cursor: "pointer",
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
Sync
|
|
184
|
+
</button>
|
|
185
|
+
)}
|
|
186
|
+
</div>
|
|
187
|
+
|
|
188
|
+
{/* Environment cells */}
|
|
189
|
+
{environments.map((env) => {
|
|
190
|
+
const cellStatus = matrixStatuses.find(
|
|
191
|
+
(s) => s.cell.namespace === ns.name && s.cell.environment === env.name,
|
|
192
|
+
);
|
|
193
|
+
const statusType = cellStatus ? getStatusType(cellStatus) : "ok";
|
|
194
|
+
const keyCount = cellStatus?.keyCount ?? 0;
|
|
195
|
+
const lastMod = cellStatus?.lastModified
|
|
196
|
+
? formatDate(
|
|
197
|
+
cellStatus.lastModified instanceof Date
|
|
198
|
+
? cellStatus.lastModified
|
|
199
|
+
: new Date(cellStatus.lastModified as unknown as string),
|
|
200
|
+
)
|
|
201
|
+
: "never";
|
|
202
|
+
const missingKeyCount = cellStatus
|
|
203
|
+
? new Set(
|
|
204
|
+
cellStatus.issues
|
|
205
|
+
.filter((i) => i.type === "missing_keys" && i.key)
|
|
206
|
+
.map((i) => i.key),
|
|
207
|
+
).size
|
|
208
|
+
: 0;
|
|
209
|
+
const warnKeyCount = cellStatus
|
|
210
|
+
? cellStatus.issues.filter((i) => i.type === "schema_warning").length
|
|
211
|
+
: 0;
|
|
212
|
+
const cellPending = cellStatus?.pendingCount ?? 0;
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<div
|
|
216
|
+
key={env.name}
|
|
217
|
+
style={{
|
|
218
|
+
padding: "14px 20px",
|
|
219
|
+
borderLeft: `1px solid ${theme.border}`,
|
|
220
|
+
display: "flex",
|
|
221
|
+
flexDirection: "column",
|
|
222
|
+
gap: 5,
|
|
223
|
+
}}
|
|
224
|
+
>
|
|
225
|
+
<div style={{ display: "flex", alignItems: "center", gap: 7 }}>
|
|
226
|
+
<StatusDot status={statusType} />
|
|
234
227
|
<span
|
|
235
228
|
style={{
|
|
236
229
|
fontFamily: theme.mono,
|
|
237
|
-
fontSize:
|
|
238
|
-
color: theme.
|
|
239
|
-
background: `${theme.accent}18`,
|
|
240
|
-
border: `1px solid ${theme.accent}33`,
|
|
241
|
-
borderRadius: 3,
|
|
242
|
-
padding: "1px 5px",
|
|
230
|
+
fontSize: 11,
|
|
231
|
+
color: theme.textMuted,
|
|
243
232
|
}}
|
|
244
233
|
>
|
|
245
|
-
{
|
|
234
|
+
{keyCount} keys
|
|
246
235
|
</span>
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
236
|
+
{missingKeyCount > 0 && (
|
|
237
|
+
<span
|
|
238
|
+
style={{
|
|
239
|
+
fontFamily: theme.mono,
|
|
240
|
+
fontSize: 10,
|
|
241
|
+
color: theme.red,
|
|
242
|
+
background: theme.redDim,
|
|
243
|
+
border: `1px solid ${theme.red}33`,
|
|
244
|
+
borderRadius: 3,
|
|
245
|
+
padding: "1px 5px",
|
|
246
|
+
}}
|
|
247
|
+
>
|
|
248
|
+
-{missingKeyCount} missing
|
|
249
|
+
</span>
|
|
250
|
+
)}
|
|
251
|
+
{warnKeyCount > 0 && (
|
|
252
|
+
<span
|
|
253
|
+
style={{
|
|
254
|
+
fontFamily: theme.mono,
|
|
255
|
+
fontSize: 10,
|
|
256
|
+
color: theme.yellow,
|
|
257
|
+
background: theme.yellowDim,
|
|
258
|
+
border: `1px solid ${theme.yellow}33`,
|
|
259
|
+
borderRadius: 3,
|
|
260
|
+
padding: "1px 5px",
|
|
261
|
+
}}
|
|
262
|
+
>
|
|
263
|
+
{warnKeyCount} warn
|
|
264
|
+
</span>
|
|
265
|
+
)}
|
|
266
|
+
{cellPending > 0 && (
|
|
267
|
+
<span
|
|
268
|
+
style={{
|
|
269
|
+
fontFamily: theme.mono,
|
|
270
|
+
fontSize: 10,
|
|
271
|
+
color: theme.accent,
|
|
272
|
+
background: `${theme.accent}18`,
|
|
273
|
+
border: `1px solid ${theme.accent}33`,
|
|
274
|
+
borderRadius: 3,
|
|
275
|
+
padding: "1px 5px",
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
{cellPending} pending
|
|
279
|
+
</span>
|
|
280
|
+
)}
|
|
281
|
+
</div>
|
|
282
|
+
<div
|
|
283
|
+
style={{
|
|
284
|
+
fontFamily: theme.mono,
|
|
285
|
+
fontSize: 10,
|
|
286
|
+
color: theme.textDim,
|
|
287
|
+
}}
|
|
288
|
+
>
|
|
289
|
+
{lastMod}
|
|
290
|
+
</div>
|
|
257
291
|
</div>
|
|
258
|
-
|
|
259
|
-
)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
)
|
|
292
|
+
);
|
|
293
|
+
})}
|
|
294
|
+
</div>
|
|
295
|
+
);
|
|
296
|
+
})}
|
|
263
297
|
</div>
|
|
264
298
|
);
|
|
265
299
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen, fireEvent, act } from "@testing-library/react";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
4
|
+
import { SyncPanel } from "./SyncPanel";
|
|
5
|
+
|
|
6
|
+
const mockFetch = jest.fn();
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
global.fetch = mockFetch;
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
delete (global as Record<string, unknown>).fetch;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("SyncPanel", () => {
|
|
16
|
+
it("fetches preview on mount and shows missing keys", async () => {
|
|
17
|
+
mockFetch.mockResolvedValueOnce({
|
|
18
|
+
ok: true,
|
|
19
|
+
json: () =>
|
|
20
|
+
Promise.resolve({
|
|
21
|
+
cells: [
|
|
22
|
+
{
|
|
23
|
+
namespace: "payments",
|
|
24
|
+
environment: "production",
|
|
25
|
+
missingKeys: ["API_KEY"],
|
|
26
|
+
isProtected: true,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
totalKeys: 1,
|
|
30
|
+
hasProtectedEnvs: true,
|
|
31
|
+
}),
|
|
32
|
+
} as Response);
|
|
33
|
+
|
|
34
|
+
await act(async () => {
|
|
35
|
+
render(<SyncPanel namespace="payments" onComplete={jest.fn()} onCancel={jest.fn()} />);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(screen.getByTestId("sync-preview-list")).toBeInTheDocument();
|
|
39
|
+
expect(screen.getByText(/API_KEY/)).toBeInTheDocument();
|
|
40
|
+
expect(screen.getByText(/protected/i)).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("shows 'all in sync' when plan has 0 keys", async () => {
|
|
44
|
+
mockFetch.mockResolvedValueOnce({
|
|
45
|
+
ok: true,
|
|
46
|
+
json: () => Promise.resolve({ cells: [], totalKeys: 0, hasProtectedEnvs: false }),
|
|
47
|
+
} as Response);
|
|
48
|
+
|
|
49
|
+
await act(async () => {
|
|
50
|
+
render(<SyncPanel namespace="payments" onComplete={jest.fn()} onCancel={jest.fn()} />);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(screen.getByTestId("sync-in-sync")).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("calls /api/sync on execute and shows done state", async () => {
|
|
57
|
+
mockFetch
|
|
58
|
+
.mockResolvedValueOnce({
|
|
59
|
+
ok: true,
|
|
60
|
+
json: () =>
|
|
61
|
+
Promise.resolve({
|
|
62
|
+
cells: [
|
|
63
|
+
{
|
|
64
|
+
namespace: "payments",
|
|
65
|
+
environment: "staging",
|
|
66
|
+
missingKeys: ["SECRET"],
|
|
67
|
+
isProtected: false,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
totalKeys: 1,
|
|
71
|
+
hasProtectedEnvs: false,
|
|
72
|
+
}),
|
|
73
|
+
} as Response)
|
|
74
|
+
.mockResolvedValueOnce({
|
|
75
|
+
ok: true,
|
|
76
|
+
json: () =>
|
|
77
|
+
Promise.resolve({
|
|
78
|
+
success: true,
|
|
79
|
+
result: {
|
|
80
|
+
modifiedCells: ["payments/staging"],
|
|
81
|
+
scaffoldedKeys: { "payments/staging": ["SECRET"] },
|
|
82
|
+
totalKeysScaffolded: 1,
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
} as Response);
|
|
86
|
+
|
|
87
|
+
const onComplete = jest.fn();
|
|
88
|
+
await act(async () => {
|
|
89
|
+
render(<SyncPanel namespace="payments" onComplete={onComplete} onCancel={jest.fn()} />);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await act(async () => {
|
|
93
|
+
fireEvent.click(screen.getByTestId("sync-execute-btn"));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
expect(screen.getByTestId("sync-done")).toBeInTheDocument();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("shows error on preview failure", async () => {
|
|
100
|
+
mockFetch.mockResolvedValueOnce({
|
|
101
|
+
ok: false,
|
|
102
|
+
json: () => Promise.resolve({ error: "Something went wrong" }),
|
|
103
|
+
} as Response);
|
|
104
|
+
|
|
105
|
+
await act(async () => {
|
|
106
|
+
render(<SyncPanel namespace="payments" onComplete={jest.fn()} onCancel={jest.fn()} />);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect(screen.getByText(/Something went wrong/)).toBeInTheDocument();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("calls onCancel when cancel is clicked", async () => {
|
|
113
|
+
mockFetch.mockResolvedValueOnce({
|
|
114
|
+
ok: true,
|
|
115
|
+
json: () =>
|
|
116
|
+
Promise.resolve({
|
|
117
|
+
cells: [
|
|
118
|
+
{
|
|
119
|
+
namespace: "payments",
|
|
120
|
+
environment: "staging",
|
|
121
|
+
missingKeys: ["KEY"],
|
|
122
|
+
isProtected: false,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
totalKeys: 1,
|
|
126
|
+
hasProtectedEnvs: false,
|
|
127
|
+
}),
|
|
128
|
+
} as Response);
|
|
129
|
+
|
|
130
|
+
const onCancel = jest.fn();
|
|
131
|
+
await act(async () => {
|
|
132
|
+
render(<SyncPanel namespace="payments" onComplete={jest.fn()} onCancel={onCancel} />);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
fireEvent.click(screen.getByTestId("sync-cancel-btn"));
|
|
136
|
+
expect(onCancel).toHaveBeenCalled();
|
|
137
|
+
});
|
|
138
|
+
});
|