@svadmin/ui 0.129.0 → 0.131.0
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/app.css +403 -0
- package/dist/app.theme.css +403 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AccessRevocationMatrix.svelte +425 -0
- package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
- package/dist/components/AudioVisualInspector.svelte +458 -0
- package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
- package/dist/components/AuditSnapshotCapture.svelte +328 -0
- package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
- package/dist/components/CannedResponsePicker.svelte +257 -0
- package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
- package/dist/components/ContentModerationCenter.svelte +166 -0
- package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
- package/dist/components/ContractClauseDiffViewer.svelte +566 -0
- package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
- package/dist/components/DataImportPipeline.svelte +577 -0
- package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
- package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
- package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
- package/dist/components/ElectronicSealInspector.svelte +450 -0
- package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
- package/dist/components/FeatureFlagStudio.svelte +583 -0
- package/dist/components/FeatureFlagStudio.svelte.d.ts +12 -0
- package/dist/components/FieldMappingBuilder.svelte +393 -0
- package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
- package/dist/components/GatewayRouteEditor.svelte +493 -0
- package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
- package/dist/components/HotkeysHelpModal.svelte +286 -0
- package/dist/components/HotkeysHelpModal.svelte.d.ts +21 -0
- package/dist/components/I18nStudio.svelte +635 -0
- package/dist/components/I18nStudio.svelte.d.ts +23 -0
- package/dist/components/IpAccessRuleEditor.svelte +290 -0
- package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
- package/dist/components/IpWhitelistDrawer.svelte +94 -0
- package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
- package/dist/components/MediaGallery.svelte +575 -0
- package/dist/components/MediaGallery.svelte.d.ts +34 -0
- package/dist/components/NotificationCenter.svelte +20 -1
- package/dist/components/NotificationCenter.svelte.d.ts +2 -0
- package/dist/components/NotificationDrawer.svelte +242 -0
- package/dist/components/NotificationDrawer.svelte.d.ts +40 -0
- package/dist/components/PrintDocument.svelte +95 -0
- package/dist/components/PrintDocument.svelte.d.ts +10 -0
- package/dist/components/PrintPreviewModal.svelte +52 -0
- package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
- package/dist/components/PrintTemplateDesigner.svelte +280 -0
- package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
- package/dist/components/RateLimitPolicyPanel.svelte +369 -0
- package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
- package/dist/components/ResizableSplitter.svelte +246 -0
- package/dist/components/ResizableSplitter.svelte.d.ts +18 -0
- package/dist/components/SensitiveWordAuditor.svelte +368 -0
- package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
- package/dist/components/ServiceDeskTicketCard.svelte +297 -0
- package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
- package/dist/components/ShiftScheduler.svelte +490 -0
- package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
- package/dist/components/SslCertificateMonitorCard.svelte +309 -0
- package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
- package/dist/components/SsoConnectionStudio.svelte +784 -0
- package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
- package/dist/components/StepUpAuthModal.svelte +448 -0
- package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
- package/dist/components/TrafficTopologyInspector.svelte +361 -0
- package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
- package/dist/components/ip-access-rules.d.ts +24 -0
- package/dist/components/ip-access-rules.js +110 -0
- package/dist/components/moderation-utils.d.ts +45 -0
- package/dist/components/moderation-utils.js +74 -0
- package/dist/components/print-document.d.ts +3 -0
- package/dist/components/print-document.js +65 -0
- package/dist/components/print-utils.d.ts +44 -0
- package/dist/components/print-utils.js +68 -0
- package/dist/components/retention-utils.d.ts +31 -0
- package/dist/components/retention-utils.js +38 -0
- package/dist/components/sso-connection-presets.d.ts +2 -0
- package/dist/components/sso-connection-presets.js +59 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -1
- package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
- package/dist/components/useFeatureFlag.d.svelte.ts +1 -0
- package/dist/components/useFeatureFlag.svelte.d.ts +45 -0
- package/dist/components/useFeatureFlag.svelte.js +94 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +53 -0
- package/package.json +5 -4
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import * as Dialog from './ui/dialog/index.js';
|
|
4
|
+
import type { FeatureFlag, FeatureFlagContext, FeatureFlagRegistry } from './useFeatureFlag.svelte.js';
|
|
5
|
+
import {
|
|
6
|
+
evaluateFeatureFlag,
|
|
7
|
+
cloneFeatureFlag,
|
|
8
|
+
createFeatureFlagRegistry,
|
|
9
|
+
} from './useFeatureFlag.svelte.js';
|
|
10
|
+
|
|
11
|
+
export interface FeatureFlagStudioProps {
|
|
12
|
+
flags?: FeatureFlag[];
|
|
13
|
+
registry?: FeatureFlagRegistry;
|
|
14
|
+
class?: string;
|
|
15
|
+
showSimulator?: boolean;
|
|
16
|
+
onChange?: (flag: FeatureFlag) => void;
|
|
17
|
+
onKillSwitchTriggered?: (flag: FeatureFlag) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
flags = [],
|
|
22
|
+
registry = createFeatureFlagRegistry(),
|
|
23
|
+
class: className = '',
|
|
24
|
+
showSimulator = true,
|
|
25
|
+
onChange,
|
|
26
|
+
onKillSwitchTriggered,
|
|
27
|
+
}: FeatureFlagStudioProps = $props();
|
|
28
|
+
|
|
29
|
+
// Internal reactive state
|
|
30
|
+
let flagList = $derived(flags.map(cloneFeatureFlag));
|
|
31
|
+
const idPrefix = $props.id();
|
|
32
|
+
let searchQuery = $state<string>('');
|
|
33
|
+
let statusFilter = $state<'ALL' | 'ENABLED' | 'DISABLED' | 'KILL_SWITCH'>('ALL');
|
|
34
|
+
let selectedTag = $state<string>('ALL');
|
|
35
|
+
|
|
36
|
+
// Kill Switch Confirmation Modal state
|
|
37
|
+
let killSwitchTarget = $state<FeatureFlag | null>(null);
|
|
38
|
+
|
|
39
|
+
// New / Edit Flag Dialog state
|
|
40
|
+
let isEditing = $state<boolean>(false);
|
|
41
|
+
let editKey = $state<string>('');
|
|
42
|
+
let editName = $state<string>('');
|
|
43
|
+
let editDescription = $state<string>('');
|
|
44
|
+
let editPercentage = $state<number | undefined>(100);
|
|
45
|
+
let editTags = $state<string>('');
|
|
46
|
+
let editWhitelist = $state<string>('');
|
|
47
|
+
|
|
48
|
+
// Simulator state
|
|
49
|
+
let simFlagKey = $state<string>('');
|
|
50
|
+
let simUserId = $state<string>('user_123');
|
|
51
|
+
let simTenantId = $state<string>('tenant_alpha');
|
|
52
|
+
let simRole = $state<string>('admin');
|
|
53
|
+
|
|
54
|
+
// 只写入显式传入或本实例拥有的注册表,不污染其他组件树。
|
|
55
|
+
$effect(() => {
|
|
56
|
+
const values = flagList;
|
|
57
|
+
const target = registry;
|
|
58
|
+
untrack(() => target.replace(values));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Extract all unique tags
|
|
62
|
+
const allTags = $derived.by(() => {
|
|
63
|
+
const set = new Set<string>();
|
|
64
|
+
for (const flag of flagList) {
|
|
65
|
+
if (flag.tags) {
|
|
66
|
+
for (const t of flag.tags) set.add(t);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Array.from(set);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
$effect(() => {
|
|
73
|
+
if (selectedTag !== 'ALL' && !allTags.includes(selectedTag)) selectedTag = 'ALL';
|
|
74
|
+
if (simFlagKey && !flagList.some(flag => flag.key === simFlagKey)) simFlagKey = '';
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Filtered flag list
|
|
78
|
+
const filteredFlags = $derived.by(() => {
|
|
79
|
+
return flagList.filter((flag) => {
|
|
80
|
+
// Status filter
|
|
81
|
+
if (statusFilter === 'ENABLED' && (!flag.enabled || flag.killSwitch)) return false;
|
|
82
|
+
if (statusFilter === 'DISABLED' && (flag.enabled || flag.killSwitch)) return false;
|
|
83
|
+
if (statusFilter === 'KILL_SWITCH' && !flag.killSwitch) return false;
|
|
84
|
+
|
|
85
|
+
// Tag filter
|
|
86
|
+
if (selectedTag !== 'ALL' && (!flag.tags || !flag.tags.includes(selectedTag))) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Search query
|
|
91
|
+
if (searchQuery.trim()) {
|
|
92
|
+
const query = searchQuery.toLowerCase();
|
|
93
|
+
const matchKey = flag.key.toLowerCase().includes(query);
|
|
94
|
+
const matchName = flag.name.toLowerCase().includes(query);
|
|
95
|
+
const matchDesc = flag.description ? flag.description.toLowerCase().includes(query) : false;
|
|
96
|
+
if (!matchKey && !matchName && !matchDesc) return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return true;
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Simulation result calculation
|
|
104
|
+
const simResult = $derived.by((): { enabled: boolean; reason: string } => {
|
|
105
|
+
if (!simFlagKey) return { enabled: false, reason: 'No flag selected' };
|
|
106
|
+
const flag = flagList.find((f) => f.key === simFlagKey);
|
|
107
|
+
if (!flag) return { enabled: false, reason: 'Flag not found' };
|
|
108
|
+
|
|
109
|
+
const ctx: FeatureFlagContext = {
|
|
110
|
+
...(simUserId.trim() ? { userId: simUserId.trim() } : {}),
|
|
111
|
+
...(simTenantId.trim() ? { tenantId: simTenantId.trim() } : {}),
|
|
112
|
+
...(simRole.trim() ? { role: simRole.trim() } : {}),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (flag.killSwitch) {
|
|
116
|
+
return { enabled: false, reason: 'Kill Switch is ACTIVE (Emergency Disabled)' };
|
|
117
|
+
}
|
|
118
|
+
if (!flag.enabled) {
|
|
119
|
+
return { enabled: false, reason: 'Flag is globally DISABLED' };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const res = evaluateFeatureFlag(flag, ctx);
|
|
123
|
+
if (res) {
|
|
124
|
+
return { enabled: true, reason: 'Matched rules or inside rollout percentage' };
|
|
125
|
+
}
|
|
126
|
+
return { enabled: false, reason: 'Outside rollout percentage or rule mismatch' };
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
function updateFlag(flag: FeatureFlag, updates: Partial<FeatureFlag>): FeatureFlag {
|
|
130
|
+
const next = cloneFeatureFlag({ ...flag, ...updates, updatedAt: new Date().toISOString() });
|
|
131
|
+
flagList = flagList.map(value => value.key === next.key ? next : value);
|
|
132
|
+
registry.set(next);
|
|
133
|
+
onChange?.(cloneFeatureFlag(next));
|
|
134
|
+
return next;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function toggleFlagEnabled(flag: FeatureFlag) {
|
|
138
|
+
updateFlag(flag, { enabled: !flag.enabled });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function updatePercentage(flag: FeatureFlag, value: number) {
|
|
142
|
+
if (Number.isFinite(value) && value >= 0 && value <= 100) updateFlag(flag, { percentage: value });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function triggerKillSwitch(flag: FeatureFlag) {
|
|
146
|
+
if (!flag.killSwitch) killSwitchTarget = flag;
|
|
147
|
+
else updateFlag(flag, { killSwitch: false });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function confirmKillSwitch() {
|
|
151
|
+
const flag = flagList.find(value => value.key === killSwitchTarget?.key);
|
|
152
|
+
if (flag) {
|
|
153
|
+
const next = updateFlag(flag, { killSwitch: true });
|
|
154
|
+
onKillSwitchTriggered?.(cloneFeatureFlag(next));
|
|
155
|
+
}
|
|
156
|
+
killSwitchTarget = null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function openCreateModal() {
|
|
160
|
+
isEditing = true;
|
|
161
|
+
editKey = '';
|
|
162
|
+
editName = '';
|
|
163
|
+
editDescription = '';
|
|
164
|
+
editPercentage = 100;
|
|
165
|
+
editTags = '';
|
|
166
|
+
editWhitelist = '';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const invalidCreate = $derived(!editKey.trim() || !editName.trim()
|
|
170
|
+
|| editPercentage === undefined || !Number.isFinite(editPercentage)
|
|
171
|
+
|| editPercentage < 0 || editPercentage > 100
|
|
172
|
+
|| flagList.some(flag => flag.key === editKey.trim()));
|
|
173
|
+
|
|
174
|
+
function saveFlag() {
|
|
175
|
+
if (invalidCreate || editPercentage === undefined) return;
|
|
176
|
+
|
|
177
|
+
const tags = editTags
|
|
178
|
+
.split(',')
|
|
179
|
+
.map((t) => t.trim())
|
|
180
|
+
.filter(Boolean);
|
|
181
|
+
|
|
182
|
+
const whitelist = editWhitelist
|
|
183
|
+
.split(',')
|
|
184
|
+
.map((w) => w.trim())
|
|
185
|
+
.filter(Boolean);
|
|
186
|
+
|
|
187
|
+
const newFlag: FeatureFlag = {
|
|
188
|
+
key: editKey.trim(),
|
|
189
|
+
name: editName.trim(),
|
|
190
|
+
description: editDescription.trim(),
|
|
191
|
+
enabled: true,
|
|
192
|
+
percentage: editPercentage,
|
|
193
|
+
...(tags.length > 0 ? { tags: [...new Set(tags)] } : {}),
|
|
194
|
+
...(whitelist.length > 0 ? { rules: [{ field: 'userId', operator: 'in' as const, values: [...new Set(whitelist)] }] } : {}),
|
|
195
|
+
updatedAt: new Date().toISOString(),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
flagList = [...flagList, newFlag];
|
|
199
|
+
registry.set(newFlag);
|
|
200
|
+
onChange?.(cloneFeatureFlag(newFlag));
|
|
201
|
+
isEditing = false;
|
|
202
|
+
}
|
|
203
|
+
</script>
|
|
204
|
+
|
|
205
|
+
<div
|
|
206
|
+
class="flex flex-col gap-6 rounded-lg border border-border bg-card p-6 text-card-foreground shadow-sm {className}"
|
|
207
|
+
data-svadmin-component="FeatureFlagStudio"
|
|
208
|
+
>
|
|
209
|
+
<!-- Header Bar -->
|
|
210
|
+
<div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between border-b border-border pb-4">
|
|
211
|
+
<div>
|
|
212
|
+
<h2 class="text-xl font-bold tracking-tight text-foreground flex items-center gap-2">
|
|
213
|
+
<svg class="h-6 w-6 text-primary" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
214
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 21v-4m0 0V5a2 2 0 012-2h6.5l1 1H21l-3 6 3 6h-8.5l-1-1H5a2 2 0 00-2 2zm9-13.5V9" />
|
|
215
|
+
</svg>
|
|
216
|
+
Feature Flag Studio
|
|
217
|
+
</h2>
|
|
218
|
+
<p class="text-xs text-muted-foreground mt-1">
|
|
219
|
+
Manage feature toggles, percentage rollout, and emergency kill switches.
|
|
220
|
+
</p>
|
|
221
|
+
</div>
|
|
222
|
+
<div class="flex items-center gap-3">
|
|
223
|
+
<button
|
|
224
|
+
type="button"
|
|
225
|
+
class="inline-flex items-center justify-center rounded-md bg-primary px-3.5 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:opacity-90 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary transition-colors"
|
|
226
|
+
onclick={openCreateModal}
|
|
227
|
+
>
|
|
228
|
+
<svg class="mr-1.5 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
229
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
|
|
230
|
+
</svg>
|
|
231
|
+
New Feature Flag
|
|
232
|
+
</button>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<!-- Search & Filter Controls -->
|
|
237
|
+
<div class="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
|
238
|
+
<div class="flex flex-1 items-center gap-3">
|
|
239
|
+
<div class="relative w-full max-w-sm">
|
|
240
|
+
<input
|
|
241
|
+
type="text"
|
|
242
|
+
aria-label="Search feature flags"
|
|
243
|
+
placeholder="Search by flag key, name or description..."
|
|
244
|
+
bind:value={searchQuery}
|
|
245
|
+
data-size="compact" class="svadmin-input"
|
|
246
|
+
/>
|
|
247
|
+
</div>
|
|
248
|
+
<select
|
|
249
|
+
aria-label="Filter by status"
|
|
250
|
+
bind:value={statusFilter}
|
|
251
|
+
data-size="compact" class="svadmin-select svadmin-select--inline"
|
|
252
|
+
>
|
|
253
|
+
<option value="ALL">All Status</option>
|
|
254
|
+
<option value="ENABLED">Enabled</option>
|
|
255
|
+
<option value="DISABLED">Disabled</option>
|
|
256
|
+
<option value="KILL_SWITCH">Kill Switch Active</option>
|
|
257
|
+
</select>
|
|
258
|
+
{#if allTags.length > 0}
|
|
259
|
+
<select
|
|
260
|
+
aria-label="Filter by tag"
|
|
261
|
+
bind:value={selectedTag}
|
|
262
|
+
data-size="compact" class="svadmin-select svadmin-select--inline"
|
|
263
|
+
>
|
|
264
|
+
<option value="ALL">All Tags</option>
|
|
265
|
+
{#each allTags as tag (tag)}
|
|
266
|
+
<option value={tag}>{tag}</option>
|
|
267
|
+
{/each}
|
|
268
|
+
</select>
|
|
269
|
+
{/if}
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
|
|
273
|
+
<!-- Flag Cards Grid -->
|
|
274
|
+
<div class="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
|
275
|
+
{#if filteredFlags.length === 0}
|
|
276
|
+
<div class="col-span-full rounded-lg border border-dashed border-border p-8 text-center text-xs text-muted-foreground">
|
|
277
|
+
No feature flags matched the current filter.
|
|
278
|
+
</div>
|
|
279
|
+
{:else}
|
|
280
|
+
{#each filteredFlags as flag (flag.key)}
|
|
281
|
+
<div
|
|
282
|
+
class="relative flex flex-col justify-between rounded-lg border border-border bg-card p-4 shadow-sm transition-all hover:border-border/80 {flag.killSwitch ? 'border-destructive/60 bg-destructive/5' : ''}"
|
|
283
|
+
>
|
|
284
|
+
<div>
|
|
285
|
+
<div class="flex items-start justify-between gap-3">
|
|
286
|
+
<div class="flex-1">
|
|
287
|
+
<div class="flex items-center gap-2">
|
|
288
|
+
<span class="font-semibold text-sm text-foreground">{flag.name}</span>
|
|
289
|
+
{#if flag.killSwitch}
|
|
290
|
+
<span class="inline-flex items-center rounded-full bg-destructive/10 px-2 py-0.5 text-[10px] font-semibold text-destructive">
|
|
291
|
+
KILL SWITCH ACTIVE
|
|
292
|
+
</span>
|
|
293
|
+
{:else if flag.enabled}
|
|
294
|
+
<span class="inline-flex items-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary">
|
|
295
|
+
ACTIVE
|
|
296
|
+
</span>
|
|
297
|
+
{:else}
|
|
298
|
+
<span class="inline-flex items-center rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground">
|
|
299
|
+
INACTIVE
|
|
300
|
+
</span>
|
|
301
|
+
{/if}
|
|
302
|
+
</div>
|
|
303
|
+
<div class="mt-0.5 font-mono text-xs text-muted-foreground">{flag.key}</div>
|
|
304
|
+
{#if flag.description}
|
|
305
|
+
<p class="mt-2 text-xs text-muted-foreground line-clamp-2">{flag.description}</p>
|
|
306
|
+
{/if}
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
<!-- Main On/Off Switch -->
|
|
310
|
+
<div class="flex items-center gap-2">
|
|
311
|
+
<button
|
|
312
|
+
type="button"
|
|
313
|
+
role="switch"
|
|
314
|
+
aria-label={`Enable ${flag.name}`}
|
|
315
|
+
aria-checked={flag.enabled && !flag.killSwitch}
|
|
316
|
+
disabled={flag.killSwitch}
|
|
317
|
+
class="relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 {flag.enabled && !flag.killSwitch ? 'bg-primary' : 'bg-muted'}"
|
|
318
|
+
onclick={() => toggleFlagEnabled(flag)}
|
|
319
|
+
>
|
|
320
|
+
<span
|
|
321
|
+
class="pointer-events-none inline-block h-4 w-4 transform rounded-full bg-background shadow-lg ring-0 transition duration-200 ease-in-out {flag.enabled && !flag.killSwitch ? 'translate-x-4' : 'translate-x-0'}"
|
|
322
|
+
></span>
|
|
323
|
+
</button>
|
|
324
|
+
</div>
|
|
325
|
+
</div>
|
|
326
|
+
|
|
327
|
+
<!-- Rollout Percentage Slider -->
|
|
328
|
+
<div class="mt-4 border-t border-border/60 pt-3">
|
|
329
|
+
<div class="flex items-center justify-between text-xs">
|
|
330
|
+
<span class="text-muted-foreground">Gradual Rollout:</span>
|
|
331
|
+
<span class="font-mono font-medium text-foreground">{flag.percentage ?? 100}%</span>
|
|
332
|
+
</div>
|
|
333
|
+
<input
|
|
334
|
+
aria-label={`Rollout percentage for ${flag.name}`}
|
|
335
|
+
type="range"
|
|
336
|
+
min="0"
|
|
337
|
+
max="100"
|
|
338
|
+
step="5"
|
|
339
|
+
value={flag.percentage ?? 100}
|
|
340
|
+
disabled={flag.killSwitch || !flag.enabled}
|
|
341
|
+
oninput={(e) => updatePercentage(flag, Number((e.target as HTMLInputElement).value))}
|
|
342
|
+
class="mt-1.5 w-full accent-primary disabled:opacity-50"
|
|
343
|
+
/>
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
<!-- Tags & Rules Badge -->
|
|
347
|
+
{#if flag.tags && flag.tags.length > 0}
|
|
348
|
+
<div class="mt-3 flex flex-wrap gap-1.5">
|
|
349
|
+
{#each flag.tags as tag, index (`${tag}:${index}`)}
|
|
350
|
+
<span class="inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground">
|
|
351
|
+
#{tag}
|
|
352
|
+
</span>
|
|
353
|
+
{/each}
|
|
354
|
+
</div>
|
|
355
|
+
{/if}
|
|
356
|
+
</div>
|
|
357
|
+
|
|
358
|
+
<!-- Bottom Actions Bar -->
|
|
359
|
+
<div class="mt-4 flex items-center justify-between border-t border-border/60 pt-3 text-xs">
|
|
360
|
+
<span class="text-[10px] text-muted-foreground">
|
|
361
|
+
Updated: {flag.updatedAt ? new Date(flag.updatedAt).toLocaleTimeString() : 'Never'}
|
|
362
|
+
</span>
|
|
363
|
+
<div class="flex items-center gap-2">
|
|
364
|
+
<button
|
|
365
|
+
type="button"
|
|
366
|
+
class="inline-flex items-center rounded px-2 py-1 text-[11px] font-medium transition-colors {flag.killSwitch ? 'bg-muted text-foreground hover:bg-muted/80' : 'bg-destructive/10 text-destructive hover:bg-destructive/20'}"
|
|
367
|
+
onclick={() => triggerKillSwitch(flag)}
|
|
368
|
+
>
|
|
369
|
+
{flag.killSwitch ? 'Revoke Kill Switch' : 'Trigger Kill Switch'}
|
|
370
|
+
</button>
|
|
371
|
+
</div>
|
|
372
|
+
</div>
|
|
373
|
+
</div>
|
|
374
|
+
{/each}
|
|
375
|
+
{/if}
|
|
376
|
+
</div>
|
|
377
|
+
|
|
378
|
+
<!-- Interactive Context Playground / Simulator -->
|
|
379
|
+
{#if showSimulator}
|
|
380
|
+
<div class="mt-6 rounded-lg border border-border bg-muted/30 p-5">
|
|
381
|
+
<div class="flex items-center gap-2 border-b border-border pb-3">
|
|
382
|
+
<svg class="h-4 w-4 text-primary" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
383
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
384
|
+
</svg>
|
|
385
|
+
<h3 class="text-sm font-semibold text-foreground">Feature Flag Evaluation Simulator</h3>
|
|
386
|
+
</div>
|
|
387
|
+
<div class="mt-4 grid grid-cols-1 gap-4 sm:grid-cols-4">
|
|
388
|
+
<div>
|
|
389
|
+
<label for={`${idPrefix}-target-flag`} class="block text-xs font-medium text-muted-foreground">Target Flag</label>
|
|
390
|
+
<select
|
|
391
|
+
id={`${idPrefix}-target-flag`}
|
|
392
|
+
bind:value={simFlagKey}
|
|
393
|
+
data-size="compact" class="mt-1 svadmin-select"
|
|
394
|
+
>
|
|
395
|
+
<option value="">Select a flag...</option>
|
|
396
|
+
{#each flagList as flag (flag.key)}
|
|
397
|
+
<option value={flag.key}>{flag.name} ({flag.key})</option>
|
|
398
|
+
{/each}
|
|
399
|
+
</select>
|
|
400
|
+
</div>
|
|
401
|
+
<div>
|
|
402
|
+
<label for={`${idPrefix}-user-id`} class="block text-xs font-medium text-muted-foreground">User ID</label>
|
|
403
|
+
<input
|
|
404
|
+
id={`${idPrefix}-user-id`}
|
|
405
|
+
type="text"
|
|
406
|
+
bind:value={simUserId}
|
|
407
|
+
placeholder="e.g. user_99"
|
|
408
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
409
|
+
/>
|
|
410
|
+
</div>
|
|
411
|
+
<div>
|
|
412
|
+
<label for={`${idPrefix}-tenant-id`} class="block text-xs font-medium text-muted-foreground">Tenant ID</label>
|
|
413
|
+
<input
|
|
414
|
+
id={`${idPrefix}-tenant-id`}
|
|
415
|
+
type="text"
|
|
416
|
+
bind:value={simTenantId}
|
|
417
|
+
placeholder="e.g. tenant_pro"
|
|
418
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
419
|
+
/>
|
|
420
|
+
</div>
|
|
421
|
+
<div>
|
|
422
|
+
<label for={`${idPrefix}-role`} class="block text-xs font-medium text-muted-foreground">User Role</label>
|
|
423
|
+
<input
|
|
424
|
+
id={`${idPrefix}-role`}
|
|
425
|
+
type="text"
|
|
426
|
+
bind:value={simRole}
|
|
427
|
+
placeholder="e.g. admin"
|
|
428
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
429
|
+
/>
|
|
430
|
+
</div>
|
|
431
|
+
</div>
|
|
432
|
+
|
|
433
|
+
<div class="mt-4 flex items-center justify-between rounded-md border border-border bg-background p-3">
|
|
434
|
+
<div class="flex items-center gap-3">
|
|
435
|
+
<span class="text-xs font-medium text-muted-foreground">Simulation Result:</span>
|
|
436
|
+
{#if simResult.enabled}
|
|
437
|
+
<span class="inline-flex items-center rounded-full bg-primary/10 px-2.5 py-0.5 text-xs font-bold text-primary">
|
|
438
|
+
ENABLED (TRUE)
|
|
439
|
+
</span>
|
|
440
|
+
{:else}
|
|
441
|
+
<span class="inline-flex items-center rounded-full bg-muted px-2.5 py-0.5 text-xs font-bold text-muted-foreground">
|
|
442
|
+
DISABLED (FALSE)
|
|
443
|
+
</span>
|
|
444
|
+
{/if}
|
|
445
|
+
</div>
|
|
446
|
+
<span class="text-xs text-muted-foreground">{simResult.reason}</span>
|
|
447
|
+
</div>
|
|
448
|
+
</div>
|
|
449
|
+
{/if}
|
|
450
|
+
|
|
451
|
+
<!-- Kill Switch Confirmation Dialog -->
|
|
452
|
+
<Dialog.Root open={killSwitchTarget !== null} onOpenChange={(open) => { if (!open) killSwitchTarget = null; }}>
|
|
453
|
+
<Dialog.Content data-svadmin-component="FeatureFlagStudioKillSwitchDialog" closeOnOverlayClick={false}>
|
|
454
|
+
{#if killSwitchTarget}
|
|
455
|
+
<div class="flex items-center gap-3">
|
|
456
|
+
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-destructive/10 text-destructive">
|
|
457
|
+
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
458
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
|
459
|
+
</svg>
|
|
460
|
+
</div>
|
|
461
|
+
<div>
|
|
462
|
+
<Dialog.Title>Emergency Kill Switch Confirmation</Dialog.Title>
|
|
463
|
+
<p class="text-xs text-muted-foreground">This is a high-risk operational action.</p>
|
|
464
|
+
</div>
|
|
465
|
+
</div>
|
|
466
|
+
<Dialog.Description class="mt-4">
|
|
467
|
+
Are you sure you want to activate the emergency kill switch for <strong class="text-foreground">{killSwitchTarget.name}</strong> (<code class="text-destructive">{killSwitchTarget.key}</code>)?
|
|
468
|
+
This disables this feature in the current preview. Save the configuration in your application to apply it.
|
|
469
|
+
</Dialog.Description>
|
|
470
|
+
<div class="mt-6 flex justify-end gap-3">
|
|
471
|
+
<button
|
|
472
|
+
type="button"
|
|
473
|
+
class="rounded-md border border-input bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted"
|
|
474
|
+
onclick={() => (killSwitchTarget = null)}
|
|
475
|
+
>
|
|
476
|
+
Cancel
|
|
477
|
+
</button>
|
|
478
|
+
<button
|
|
479
|
+
type="button"
|
|
480
|
+
class="rounded-md bg-destructive px-3.5 py-1.5 text-xs font-medium text-destructive-foreground shadow hover:bg-destructive/90"
|
|
481
|
+
onclick={confirmKillSwitch}
|
|
482
|
+
>
|
|
483
|
+
Confirm Kill Switch
|
|
484
|
+
</button>
|
|
485
|
+
</div>
|
|
486
|
+
{/if}
|
|
487
|
+
</Dialog.Content>
|
|
488
|
+
</Dialog.Root>
|
|
489
|
+
|
|
490
|
+
<!-- Create Flag Modal -->
|
|
491
|
+
<Dialog.Root bind:open={isEditing}>
|
|
492
|
+
<Dialog.Content closeOnOverlayClick={false}>
|
|
493
|
+
<Dialog.Title>Create Feature Flag</Dialog.Title>
|
|
494
|
+
<Dialog.Description>Define a new toggle and set rollout percentage.</Dialog.Description>
|
|
495
|
+
|
|
496
|
+
<div class="mt-4 space-y-3">
|
|
497
|
+
<div>
|
|
498
|
+
<label for={`${idPrefix}-edit-key`} class="block text-xs font-medium text-foreground">Flag Key (Unique)</label>
|
|
499
|
+
<input
|
|
500
|
+
id={`${idPrefix}-edit-key`}
|
|
501
|
+
type="text"
|
|
502
|
+
bind:value={editKey}
|
|
503
|
+
placeholder="e.g. enable_beta_checkout"
|
|
504
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
505
|
+
/>
|
|
506
|
+
{#if flagList.some(flag => flag.key === editKey.trim())}
|
|
507
|
+
<p role="status" class="mt-1 text-xs text-destructive">This flag key already exists.</p>
|
|
508
|
+
{/if}
|
|
509
|
+
</div>
|
|
510
|
+
<div>
|
|
511
|
+
<label for={`${idPrefix}-edit-name`} class="block text-xs font-medium text-foreground">Display Name</label>
|
|
512
|
+
<input
|
|
513
|
+
id={`${idPrefix}-edit-name`}
|
|
514
|
+
type="text"
|
|
515
|
+
bind:value={editName}
|
|
516
|
+
placeholder="e.g. Beta Checkout V2"
|
|
517
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
518
|
+
/>
|
|
519
|
+
</div>
|
|
520
|
+
<div>
|
|
521
|
+
<label for={`${idPrefix}-edit-description`} class="block text-xs font-medium text-foreground">Description</label>
|
|
522
|
+
<textarea
|
|
523
|
+
id={`${idPrefix}-edit-description`}
|
|
524
|
+
bind:value={editDescription}
|
|
525
|
+
rows="2"
|
|
526
|
+
placeholder="Explain the purpose of this flag..."
|
|
527
|
+
class="mt-1 svadmin-textarea"
|
|
528
|
+
></textarea>
|
|
529
|
+
</div>
|
|
530
|
+
<div>
|
|
531
|
+
<label for={`${idPrefix}-edit-percentage`} class="block text-xs font-medium text-foreground">Initial Rollout Percentage (0% - 100%)</label>
|
|
532
|
+
<input
|
|
533
|
+
id={`${idPrefix}-edit-percentage`}
|
|
534
|
+
type="number"
|
|
535
|
+
min="0"
|
|
536
|
+
max="100"
|
|
537
|
+
bind:value={editPercentage}
|
|
538
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
539
|
+
/>
|
|
540
|
+
</div>
|
|
541
|
+
<div>
|
|
542
|
+
<label for={`${idPrefix}-edit-whitelist`} class="block text-xs font-medium text-foreground">User Whitelist (Comma separated User IDs)</label>
|
|
543
|
+
<input
|
|
544
|
+
id={`${idPrefix}-edit-whitelist`}
|
|
545
|
+
type="text"
|
|
546
|
+
bind:value={editWhitelist}
|
|
547
|
+
placeholder="user_1, user_2, admin_test"
|
|
548
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
549
|
+
/>
|
|
550
|
+
<p class="mt-1 text-xs text-muted-foreground">Matching users bypass the rollout percentage. Use 0% for whitelist-only access.</p>
|
|
551
|
+
</div>
|
|
552
|
+
<div>
|
|
553
|
+
<label for={`${idPrefix}-edit-tags`} class="block text-xs font-medium text-foreground">Tags (Comma separated)</label>
|
|
554
|
+
<input
|
|
555
|
+
id={`${idPrefix}-edit-tags`}
|
|
556
|
+
type="text"
|
|
557
|
+
bind:value={editTags}
|
|
558
|
+
placeholder="checkout, experiment, billing"
|
|
559
|
+
data-size="compact" class="mt-1 svadmin-input"
|
|
560
|
+
/>
|
|
561
|
+
</div>
|
|
562
|
+
</div>
|
|
563
|
+
|
|
564
|
+
<div class="mt-6 flex justify-end gap-3">
|
|
565
|
+
<button
|
|
566
|
+
type="button"
|
|
567
|
+
class="rounded-md border border-input bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted"
|
|
568
|
+
onclick={() => (isEditing = false)}
|
|
569
|
+
>
|
|
570
|
+
Cancel
|
|
571
|
+
</button>
|
|
572
|
+
<button
|
|
573
|
+
type="button"
|
|
574
|
+
class="rounded-md bg-primary px-3.5 py-1.5 text-xs font-medium text-primary-foreground shadow hover:opacity-90"
|
|
575
|
+
disabled={invalidCreate}
|
|
576
|
+
onclick={saveFlag}
|
|
577
|
+
>
|
|
578
|
+
Save Flag
|
|
579
|
+
</button>
|
|
580
|
+
</div>
|
|
581
|
+
</Dialog.Content>
|
|
582
|
+
</Dialog.Root>
|
|
583
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FeatureFlag, FeatureFlagRegistry } from './useFeatureFlag.svelte.js';
|
|
2
|
+
export interface FeatureFlagStudioProps {
|
|
3
|
+
flags?: FeatureFlag[];
|
|
4
|
+
registry?: FeatureFlagRegistry;
|
|
5
|
+
class?: string;
|
|
6
|
+
showSimulator?: boolean;
|
|
7
|
+
onChange?: (flag: FeatureFlag) => void;
|
|
8
|
+
onKillSwitchTriggered?: (flag: FeatureFlag) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const FeatureFlagStudio: import("svelte").Component<FeatureFlagStudioProps, {}, "">;
|
|
11
|
+
type FeatureFlagStudio = ReturnType<typeof FeatureFlagStudio>;
|
|
12
|
+
export default FeatureFlagStudio;
|