@tacoshell/shell 0.1.0 → 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/package.json +2 -2
- package/src/core/bus.ts +30 -6
- package/src/core/contrib.ts +70 -0
- package/src/core/csvfeature.ts +57 -0
- package/src/core/datasets.ts +100 -9
- package/src/core/indicators.ts +62 -0
- package/src/core/jobs.ts +37 -0
- package/src/core/nav.ts +6 -3
- package/src/core/page.ts +11 -1
- package/src/core/prefs.ts +5 -0
- package/src/core/services.ts +29 -12
- package/src/core/sessions.ts +23 -2
- package/src/core/text.ts +6 -0
- package/src/index.ts +2 -0
- package/src/styles.css +105 -2
- package/src/types.ts +23 -3
- package/src/ui/ActionModal.tsx +22 -0
- package/src/ui/App.tsx +14 -2
- package/src/ui/CsvFeature.tsx +151 -0
- package/src/ui/ItemFeature.tsx +39 -0
- package/src/ui/Rail.tsx +54 -8
- package/src/ui/RelatedMenu.tsx +57 -0
- package/src/ui/Sessions.tsx +4 -0
- package/src/ui/SidePanel.tsx +3 -1
- package/src/ui/ViewHost.tsx +39 -19
- package/src/ui/hooks.ts +9 -2
- package/src/ui/settings/Datasets.tsx +12 -2
- package/src/ui/settings/ReleaseNotes.tsx +84 -7
- package/src/ui/settings/Settings.tsx +36 -25
- package/src/ui/settings/SettingsTabs.tsx +63 -0
- package/src/ui/useContrib.ts +36 -0
package/src/core/services.ts
CHANGED
|
@@ -9,7 +9,7 @@ import * as store from './storage.ts';
|
|
|
9
9
|
import * as vault from './vault.ts';
|
|
10
10
|
|
|
11
11
|
const STATE_KEY = 'taco.services';
|
|
12
|
-
export interface ServiceState { enabled: boolean; mode: AuthMode; config: Record<string, string>; /** Current Session services appear in the header's Sessions menu unless the user hides them. */ hideFromSessions?: boolean; lastTest?: { ok: boolean; at: number; detail: string } }
|
|
12
|
+
export interface ServiceState { enabled: boolean; mode: AuthMode; config: Record<string, string>; /** Current Session services appear in the header's Sessions menu unless the user hides them. */ hideFromSessions?: boolean; lastTest?: { ok: boolean; /** ok = connected, warn = works with a caveat, error = failed. */ status?: 'ok' | 'warn' | 'error'; at: number; detail: string } }
|
|
13
13
|
|
|
14
14
|
let registry: Registry | undefined;
|
|
15
15
|
let impls: Record<string, ServiceImpl> = {};
|
|
@@ -40,15 +40,28 @@ export function fieldsFor(s: RegistryService, mode: AuthMode): FieldDecl[] {
|
|
|
40
40
|
apikey: [{ key: 'apiKey', label: 'API key', secret: true }],
|
|
41
41
|
basic: [{ key: 'username', label: 'Username' }, { key: 'password', label: 'Password or token', secret: true }],
|
|
42
42
|
oauth: [{ key: 'clientId', label: 'OAuth client ID' }],
|
|
43
|
+
none: [],
|
|
43
44
|
};
|
|
44
45
|
const out = [...declared];
|
|
45
46
|
for (const f of implied[mode]) if (!out.some((d) => d.key === f.key)) out.push(f);
|
|
46
47
|
return out;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
/** The non-secret field values in force: what the user saved, else the field's declared default. Secrets never appear here. */
|
|
51
|
+
export function configOf(s: RegistryService): Record<string, string> {
|
|
52
|
+
const st = stateOf(s);
|
|
53
|
+
const out: Record<string, string> = { ...st.config };
|
|
54
|
+
for (const f of fieldsFor(s, st.mode)) {
|
|
55
|
+
if (f.secret) { delete out[f.key]; continue; }
|
|
56
|
+
if (!out[f.key]?.trim() && f.default !== undefined) out[f.key] = f.default;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
export function isConfigured(s: RegistryService): boolean {
|
|
50
62
|
const st = stateOf(s);
|
|
51
|
-
const
|
|
63
|
+
const cfg = configOf(s);
|
|
64
|
+
const ok = fieldsFor(s, st.mode).every((f) => f.required === false || (f.secret ? vault.has(secretId(s, f.key)) : !!cfg[f.key]?.trim()));
|
|
52
65
|
return ok && (st.mode !== 'oauth' || vault.has(secretId(s, 'accessToken')));
|
|
53
66
|
}
|
|
54
67
|
|
|
@@ -61,6 +74,7 @@ const fill = (template: string, config: Record<string, string>) => template.repl
|
|
|
61
74
|
|
|
62
75
|
export function contextFor(s: RegistryService): ServiceContext {
|
|
63
76
|
const st = stateOf(s);
|
|
77
|
+
const impl = impls[serviceKey(s)];
|
|
64
78
|
const source = `${s.label} (${serviceKey(s)})`;
|
|
65
79
|
const slog = log.logger(source);
|
|
66
80
|
const secret = async (field: string) => {
|
|
@@ -68,9 +82,9 @@ export function contextFor(s: RegistryService): ServiceContext {
|
|
|
68
82
|
if (v === undefined) throw new Error(`${s.label}: "${field}" isn't set (Settings → Services → ${s.label}).`);
|
|
69
83
|
return v;
|
|
70
84
|
};
|
|
71
|
-
|
|
85
|
+
const ctx: ServiceContext = {
|
|
72
86
|
instance: { module: s.module, type: s.type, name: s.name },
|
|
73
|
-
config:
|
|
87
|
+
config: configOf(s),
|
|
74
88
|
authMode: st.mode,
|
|
75
89
|
secret,
|
|
76
90
|
log: slog,
|
|
@@ -80,9 +94,10 @@ export function contextFor(s: RegistryService): ServiceContext {
|
|
|
80
94
|
const headers = new Headers(init.headers);
|
|
81
95
|
let body = init.body;
|
|
82
96
|
if (init.json !== undefined) { headers.set('Content-Type', 'application/json'); body = JSON.stringify(init.json); }
|
|
83
|
-
if (
|
|
84
|
-
if (st.mode === '
|
|
85
|
-
if (st.mode === '
|
|
97
|
+
if (impl?.authorize) { for (const [k, v] of Object.entries(await impl.authorize(ctx))) headers.set(k, v); } // the service's own auth replaces the mode's
|
|
98
|
+
else if (st.mode === 'apikey') headers.set(s.apiKey?.header ?? 'Authorization', `${s.apiKey?.prefix ?? 'Bearer '}${await secret('apiKey')}`);
|
|
99
|
+
else if (st.mode === 'basic') headers.set('Authorization', `Basic ${btoa(`${st.config.username ?? ''}:${await secret('password')}`)}`);
|
|
100
|
+
else if (st.mode === 'oauth') headers.set('Authorization', `Bearer ${await oauthToken(s)}`);
|
|
86
101
|
const method = (init.method ?? 'GET').toUpperCase();
|
|
87
102
|
try {
|
|
88
103
|
const res = await fetch(url, { ...init, body, headers, credentials: st.mode === 'session' ? 'include' : 'omit' });
|
|
@@ -94,19 +109,21 @@ export function contextFor(s: RegistryService): ServiceContext {
|
|
|
94
109
|
}
|
|
95
110
|
},
|
|
96
111
|
};
|
|
112
|
+
return ctx;
|
|
97
113
|
}
|
|
98
114
|
|
|
99
|
-
export async function test(s: RegistryService): Promise<{ ok: boolean; detail: string }> {
|
|
115
|
+
export async function test(s: RegistryService): Promise<{ ok: boolean; status: 'ok' | 'warn' | 'error'; detail: string }> {
|
|
100
116
|
const impl = impls[serviceKey(s)];
|
|
101
|
-
let result: { ok: boolean; detail: string };
|
|
117
|
+
let result: { ok: boolean; status: 'ok' | 'warn' | 'error'; detail: string };
|
|
102
118
|
try {
|
|
103
119
|
const r = impl?.test ? await impl.test(contextFor(s)) : undefined;
|
|
104
|
-
|
|
120
|
+
const warn = r?.status === 'warn';
|
|
121
|
+
result = { ok: true, status: warn ? 'warn' : 'ok', detail: r?.detail ?? (r?.who ? `Connected as ${r.who}` : impl?.test ? 'Test passed' : 'No test defined by this service') };
|
|
105
122
|
} catch (e) {
|
|
106
|
-
result = { ok: false, detail: (e as Error).message };
|
|
123
|
+
result = { ok: false, status: 'error', detail: (e as Error).message };
|
|
107
124
|
}
|
|
108
125
|
await update(s, { lastTest: { ...result, at: Date.now() } });
|
|
109
|
-
log.add(result.ok ? 'info' : 'warn', `${s.label} (${serviceKey(s)}) test: ${result.detail}`, undefined, 'Settings › Services');
|
|
126
|
+
log.add(result.status === 'ok' ? 'info' : result.status === 'warn' ? 'warn' : 'warn', `${s.label} (${serviceKey(s)}) test: ${result.detail}`, undefined, 'Settings › Services');
|
|
110
127
|
return result;
|
|
111
128
|
}
|
|
112
129
|
|
package/src/core/sessions.ts
CHANGED
|
@@ -12,9 +12,15 @@ export interface SessionStatus { state: SessionState; who?: string; detail?: str
|
|
|
12
12
|
|
|
13
13
|
export const statuses = createStore<Record<string, SessionStatus>>({});
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Services that have a session to report and aren't turned off: those signed in with Current Session, and those with no HTTPS sign-in of their own
|
|
17
|
+
* (`auth: ["none"]`, e.g. a local bridge) that declare a `sessionRequirement`: they report their status with `session()`.
|
|
18
|
+
*/
|
|
16
19
|
export const sessionServices = (reg: Registry): RegistryService[] =>
|
|
17
|
-
reg.services.filter((s) =>
|
|
20
|
+
reg.services.filter((s) => {
|
|
21
|
+
const st = services.stateOf(s);
|
|
22
|
+
return st.enabled && ((s.auth.includes('session') && st.mode === 'session') || (s.auth.includes('none') && st.mode === 'none' && !!s.sessionRequirement));
|
|
23
|
+
});
|
|
18
24
|
|
|
19
25
|
/** The ones the menu shows: a user may hide a connected, active service from it (default: shown). */
|
|
20
26
|
export const shown = (reg: Registry) => sessionServices(reg).filter((s) => !services.stateOf(s).hideFromSessions);
|
|
@@ -70,3 +76,18 @@ async function defaultRun(s: RegistryService) {
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
export const checkAll = (reg: Registry) => Promise.all(sessionServices(reg).map((s) => check(s)));
|
|
79
|
+
|
|
80
|
+
/** Can the service re-establish its session itself (its `reauth()`)? The Sessions menu then offers "Sign in again". */
|
|
81
|
+
export const canReauth = (s: RegistryService) => !!services.implFor(s)?.reauth;
|
|
82
|
+
|
|
83
|
+
/** Runs the service's `reauth()`, then checks the session again. Returns an error message, or null when it ran (the check says whether it worked). */
|
|
84
|
+
export async function reauth(s: RegistryService): Promise<string | null> {
|
|
85
|
+
const impl = services.implFor(s);
|
|
86
|
+
if (!impl?.reauth) return 'This service has no way to sign in again from here.';
|
|
87
|
+
put(s, { ...statusOf(s), state: 'checking' });
|
|
88
|
+
let error: string | null = null;
|
|
89
|
+
try { await impl.reauth(services.contextFor(s)); log.add('info', `${s.label}: sign-in again finished`, undefined, 'Sessions'); }
|
|
90
|
+
catch (e) { error = (e as Error).message; log.add('warn', `${s.label}: sign-in again failed: ${error}`, undefined, 'Sessions'); }
|
|
91
|
+
await check(s);
|
|
92
|
+
return error;
|
|
93
|
+
}
|
package/src/core/text.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The first `max` characters by grapheme: emoji and other multi-code-unit characters count once. */
|
|
2
|
+
export function clipText(text: string, max: number): string {
|
|
3
|
+
const s = String(text ?? '');
|
|
4
|
+
const seg = typeof Intl !== 'undefined' && 'Segmenter' in Intl ? [...new Intl.Segmenter(undefined, { granularity: 'grapheme' }).segment(s)].map((x) => x.segment) : [...s];
|
|
5
|
+
return seg.slice(0, max).join('');
|
|
6
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { initSettings } from './core/prefs.ts';
|
|
|
8
8
|
import * as router from './core/router.ts';
|
|
9
9
|
import * as services from './core/services.ts';
|
|
10
10
|
import * as datasets from './core/datasets.ts';
|
|
11
|
+
import * as jobs from './core/jobs.ts';
|
|
11
12
|
import * as store from './core/storage.ts';
|
|
12
13
|
import * as vault from './core/vault.ts';
|
|
13
14
|
import { App } from './ui/App.tsx';
|
|
@@ -40,6 +41,7 @@ export async function boot(input: ShellInput) {
|
|
|
40
41
|
await initSettings({ idleLockMinutes: input.registry.settings.vault.idleLockMinutes, visibleLevels: input.registry.settings.activityLog.visibleLevels });
|
|
41
42
|
trackActivity();
|
|
42
43
|
datasets.startScheduler((module) => createFramework(module));
|
|
44
|
+
jobs.startJobs(input.registry, input.background ?? {}, (module, view) => createFramework(module, undefined, view));
|
|
43
45
|
router.start();
|
|
44
46
|
log.add('debug', `Started ${input.registry.app.displayName} ${input.registry.app.version} (${input.registry.modules.length} module(s))`, undefined, 'framework');
|
|
45
47
|
const root = document.getElementById('root')!;
|
package/src/styles.css
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
--taco-bg: #1e1f22; --taco-surface: #26272b; --taco-surface-2: #2f3035; --taco-surface-3: #383940; --taco-border: #3a3b41;
|
|
4
4
|
--taco-text: #e7e7ea; --taco-text-muted: #9b9ca3; --taco-text-faint: #6c6d74;
|
|
5
5
|
--taco-accent: #f0533f; --taco-primary: #006bff; --taco-primary-hover: #2a85ff;
|
|
6
|
-
--taco-success: #2fbf71; --taco-warning: #d9a03f; --taco-danger: #e5484d;
|
|
6
|
+
--taco-success: #2fbf71; --taco-warning: #d9a03f; --taco-danger: #e5484d; --taco-info: #2f7df6;
|
|
7
7
|
--taco-log-trace: #6c6d74; --taco-log-debug: #8a8b92; --taco-log-info: #9b9ca3; --taco-log-warn: #d9b43f; --taco-log-error: #f0801f; --taco-log-fatal: #e5484d;
|
|
8
8
|
--taco-radius-sm: 6px; --taco-radius-md: 8px; --taco-radius-lg: 12px;
|
|
9
9
|
--taco-font: "DM Sans", system-ui, sans-serif; --taco-font-mono: "JetBrains Mono", ui-monospace, monospace;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
--taco-bg: #ffffff; --taco-surface: #f6f8fa; --taco-surface-2: #eef1f4; --taco-surface-3: #e2e7ec; --taco-border: #d0d7de;
|
|
18
18
|
--taco-text: #1f2328; --taco-text-muted: #59636e; --taco-text-faint: #818b98;
|
|
19
19
|
--taco-primary: #1a6fdb; --taco-primary-hover: #1559b3;
|
|
20
|
-
--taco-success: #1a7f37; --taco-warning: #9a6700; --taco-danger: #cf222e;
|
|
20
|
+
--taco-success: #1a7f37; --taco-warning: #9a6700; --taco-danger: #cf222e; --taco-info: #1a6fdb;
|
|
21
21
|
--taco-log-trace: #818b98; --taco-log-debug: #6e7781; --taco-log-info: #59636e; --taco-log-warn: #bf8700; --taco-log-error: #d4580a; --taco-log-fatal: #cf222e;
|
|
22
22
|
color-scheme: light;
|
|
23
23
|
}
|
|
@@ -286,3 +286,106 @@ code.token { margin-right: 6px; }
|
|
|
286
286
|
.tab-more-menu { top: 100%; margin-top: 2px; }
|
|
287
287
|
.tabs-measure .tab { font-weight: 700; } /* measure at the bold width so the selected tab never overflows */
|
|
288
288
|
.subbar-actions { padding: 6px 0; }
|
|
289
|
+
|
|
290
|
+
/* ── Dataset refresh indicator (header): pulses between the selected color and disabled gray while a refresh runs ── */
|
|
291
|
+
.refresh-indicator { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 32px; font-size: 16px; animation: taco-refresh-pulse 1.4s ease-in-out infinite; }
|
|
292
|
+
@keyframes taco-refresh-pulse { 0%, 100% { color: var(--taco-primary); } 50% { color: var(--taco-text-faint); } }
|
|
293
|
+
@media (prefers-reduced-motion: reduce) { .refresh-indicator { animation-duration: 3s; } }
|
|
294
|
+
|
|
295
|
+
/* ── Indicator bubbles: 16 foreground/background pairs a theme can override; unspecified indicators pick one by a stable hash ── */
|
|
296
|
+
:root {
|
|
297
|
+
--taco-ind-1-bg: #e8c23a; --taco-ind-1-fg: #1b1b1b; --taco-ind-2-bg: #c4552a; --taco-ind-2-fg: #ffffff;
|
|
298
|
+
--taco-ind-3-bg: #c23b3b; --taco-ind-3-fg: #ffffff; --taco-ind-4-bg: #7b3fd1; --taco-ind-4-fg: #ffffff;
|
|
299
|
+
--taco-ind-5-bg: #3fb8c4; --taco-ind-5-fg: #0b1f22; --taco-ind-6-bg: #2f55d4; --taco-ind-6-fg: #ffffff;
|
|
300
|
+
--taco-ind-7-bg: #2fbf71; --taco-ind-7-fg: #08210f; --taco-ind-8-bg: #e86aa6; --taco-ind-8-fg: #2a0a1a;
|
|
301
|
+
--taco-ind-9-bg: #f0801f; --taco-ind-9-fg: #1f1000; --taco-ind-10-bg: #5b6b7b; --taco-ind-10-fg: #ffffff;
|
|
302
|
+
--taco-ind-11-bg: #9be15d; --taco-ind-11-fg: #14260a; --taco-ind-12-bg: #1f7a6d; --taco-ind-12-fg: #e8fffb;
|
|
303
|
+
--taco-ind-13-bg: #b8a4f5; --taco-ind-13-fg: #1c1240; --taco-ind-14-bg: #8a2b52; --taco-ind-14-fg: #ffe6f1;
|
|
304
|
+
--taco-ind-15-bg: #f5d9a0; --taco-ind-15-fg: #3a2606; --taco-ind-16-bg: #223a6b; --taco-ind-16-fg: #dbe7ff;
|
|
305
|
+
}
|
|
306
|
+
.rail-link { display: flex; align-items: center; gap: 6px; }
|
|
307
|
+
.rail-link .rail-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
308
|
+
.rail-group-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
|
|
309
|
+
/* A Featured feature with several views: toggle + link on one row, its views (3rd level) indented beneath */
|
|
310
|
+
.rail-parent { padding: 0 10px 0 2px; }
|
|
311
|
+
.rail-parent:hover { background: var(--taco-surface-2); }
|
|
312
|
+
.rail-parent.active { background: var(--taco-primary); color: #fff; }
|
|
313
|
+
.rail-parent-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 5px 0; color: inherit; }
|
|
314
|
+
.rail-parent-link:hover { text-decoration: none; }
|
|
315
|
+
.rail-toggle { flex: none; width: 20px; height: 24px; padding: 0; border: 0; background: none; color: inherit; font-size: 11px; }
|
|
316
|
+
.rail-toggle:hover:not(:disabled) { background: none; color: var(--taco-accent); }
|
|
317
|
+
.rail-child { padding-left: 30px; }
|
|
318
|
+
.bubbles { display: inline-flex; gap: 4px; flex: none; }
|
|
319
|
+
.bubble { min-width: 22px; height: 22px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; border-radius: 11px; font-size: 11px; font-weight: 700; line-height: 1; letter-spacing: 0; text-transform: none; }
|
|
320
|
+
.bubble.more { background: var(--taco-surface-3); color: var(--taco-text-muted); }
|
|
321
|
+
|
|
322
|
+
/* ── Feature types ── */
|
|
323
|
+
/* Framework-rendered features supply their own gutters (a GENERAL view gets them from its own .page): 24 px at the content edges. */
|
|
324
|
+
.item-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; align-items: start; min-height: 100%; }
|
|
325
|
+
.item-layout.no-rail { grid-template-columns: minmax(0, 1fr); }
|
|
326
|
+
.item-main { min-width: 0; padding: 8px 16px 32px 24px; }
|
|
327
|
+
.item-layout.no-rail .item-main { padding-right: 24px; }
|
|
328
|
+
/* The rail is 400 px in all, padding included: 16 px on its left, 24 px on its right. */
|
|
329
|
+
.item-rail { box-sizing: border-box; width: 400px; padding: 8px 24px 32px 16px; display: grid; gap: 14px; align-content: start; min-width: 0; }
|
|
330
|
+
.item-rail > section { min-width: 0; }
|
|
331
|
+
.rail-title { margin: 0 0 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--taco-text-muted); }
|
|
332
|
+
.action-btn { display: flex; align-items: center; gap: 8px; width: 100%; margin-bottom: 4px; height: 30px; justify-content: flex-start; font-size: 12px; }
|
|
333
|
+
.action-btn i { width: 16px; text-align: center; }
|
|
334
|
+
.modal.action-modal { width: min(760px, 94vw); max-height: 90vh; overflow: auto; }
|
|
335
|
+
.modal .close { position: absolute; top: 8px; right: 10px; height: 28px; width: 28px; padding: 0; border: 0; background: none; font-size: 20px; }
|
|
336
|
+
.csv-feature { box-sizing: border-box; min-width: 0; padding: 8px 24px 32px; }
|
|
337
|
+
.csv-feature .csv-upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
338
|
+
.csv-table { max-height: 55vh; overflow: auto; }
|
|
339
|
+
.csv-table table { border-collapse: collapse; width: 100%; }
|
|
340
|
+
.csv-table th, .csv-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--taco-border); position: relative; }
|
|
341
|
+
.csv-table thead th { position: sticky; top: 0; background: var(--taco-surface-2); z-index: 1; }
|
|
342
|
+
.csv-th { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
|
|
343
|
+
.csv-menu { left: 0; right: auto; top: 34px; max-height: 260px; overflow: auto; }
|
|
344
|
+
.csv-filter.on { border-color: var(--taco-primary); color: var(--taco-primary); }
|
|
345
|
+
.csv-status { width: 70px; text-align: center; }
|
|
346
|
+
.csv-table tr.row-ok td { background: color-mix(in srgb, var(--taco-success) 14%, transparent); }
|
|
347
|
+
.csv-table tr.row-warn td { background: color-mix(in srgb, var(--taco-warning) 18%, transparent); }
|
|
348
|
+
.csv-table tr.row-error td { background: color-mix(in srgb, var(--taco-danger) 18%, transparent); }
|
|
349
|
+
.csv-run { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
|
|
350
|
+
.csv-run .spacer { flex: 1; }
|
|
351
|
+
.csv-progress { display: inline-flex; align-items: center; gap: 8px; }
|
|
352
|
+
.modal.csv-confirm { width: min(560px, 94vw); }
|
|
353
|
+
.callout.warn { padding: 10px 12px; margin: 10px 0; border-radius: var(--taco-radius-md); border: 1px solid var(--taco-warning); background: color-mix(in srgb, var(--taco-warning) 16%, transparent); }
|
|
354
|
+
|
|
355
|
+
/* ── Related entries with a button ── */
|
|
356
|
+
.related-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
|
|
357
|
+
.related-row .menu-item { flex: 1; min-width: 0; display: block; padding: 0 8px; line-height: 30px; color: var(--taco-text); text-align: left; border-radius: var(--taco-radius-sm); }
|
|
358
|
+
.related-row .menu-item:hover { text-decoration: none; }
|
|
359
|
+
.rel-btn { flex: none; height: 24px; padding: 0 10px; font-size: 11px; }
|
|
360
|
+
/* `button:where(.x)` has the specificity of the plain `button` rule (and sits after it), so the type beats the default button look, while any styleClass
|
|
361
|
+
(one class) beats the type, and styleInline beats everything. Hover keeps the type's color. */
|
|
362
|
+
button:where(.rel-btn-success), button:where(.rel-btn-success):hover:not(:disabled) { background: var(--taco-success); border-color: var(--taco-success); color: #fff; }
|
|
363
|
+
button:where(.rel-btn-error), button:where(.rel-btn-error):hover:not(:disabled) { background: var(--taco-danger); border-color: var(--taco-danger); color: #fff; }
|
|
364
|
+
button:where(.rel-btn-info), button:where(.rel-btn-info):hover:not(:disabled) { background: var(--taco-info); border-color: var(--taco-info); color: #fff; }
|
|
365
|
+
button:where(.rel-btn-warn), button:where(.rel-btn-warn):hover:not(:disabled) { background: var(--taco-warning); border-color: var(--taco-warning); color: #1b1b1b; }
|
|
366
|
+
button:where([class*="rel-btn-"]):hover:not(:disabled) { filter: brightness(1.12); }
|
|
367
|
+
/* An ACTION modal appears after a beat, so one that does its work and calls framework.close() right away is never seen. */
|
|
368
|
+
.backdrop:has(.action-modal) { animation: taco-reveal 0s linear .18s backwards; }
|
|
369
|
+
@keyframes taco-reveal { from { opacity: 0; pointer-events: none; } to { opacity: 1; } }
|
|
370
|
+
|
|
371
|
+
/* Service settings: required marker, field help, test result colors */
|
|
372
|
+
.form-row .req { color: var(--taco-danger); }
|
|
373
|
+
.field-help { flex-basis: 100%; }
|
|
374
|
+
.test-ok { color: var(--taco-success); } .test-warn { color: var(--taco-warning); } .test-error { color: var(--taco-danger); }
|
|
375
|
+
|
|
376
|
+
/* Tabs inside a page (Settings → Release Notes | SBOM) and the SBOM table */
|
|
377
|
+
.page-tabs { display: flex; gap: 4px; margin: 4px 0 14px; border-bottom: 1px solid var(--taco-border); }
|
|
378
|
+
.page-tabs a { padding: 8px 14px; margin-bottom: -1px; border-bottom: 3px solid transparent; color: var(--taco-text-muted); font-weight: 500; }
|
|
379
|
+
.page-tabs a:hover { text-decoration: none; color: var(--taco-text); }
|
|
380
|
+
.page-tabs a.on { color: var(--taco-text); border-bottom-color: var(--taco-primary); font-weight: 700; }
|
|
381
|
+
.button-link { display: inline-flex; align-items: center; gap: 8px; height: var(--taco-field-height); padding: 0 14px; border-radius: var(--taco-radius-sm); background: var(--taco-primary); color: #fff; font-weight: 600; }
|
|
382
|
+
.button-link:hover { text-decoration: none; background: var(--taco-primary-hover); }
|
|
383
|
+
.sbom-table { width: 100%; border-collapse: collapse; }
|
|
384
|
+
.sbom-table th, .sbom-table td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--taco-border); vertical-align: top; }
|
|
385
|
+
.sbom-table th { position: sticky; top: 0; background: var(--taco-surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--taco-text-muted); }
|
|
386
|
+
.sbom-table code { word-break: break-all; }
|
|
387
|
+
|
|
388
|
+
.session-reauth { height: 22px; padding: 0 8px; font-size: 11px; margin-left: 6px; }
|
|
389
|
+
|
|
390
|
+
/* A Settings page's tab strip sits above its title, like a view's bar */
|
|
391
|
+
.settings-tabs { margin: 0; padding: 0 24px; }
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// The registry the CLI generates (`.taco/generated/registry.json`) and the shell reads. Keep in step with packages/cli/src/lib/build.ts.
|
|
2
2
|
|
|
3
|
-
export type AuthMode = 'session' | 'apikey' | 'basic' | 'oauth';
|
|
3
|
+
export type AuthMode = 'session' | 'apikey' | 'basic' | 'oauth' | 'none';
|
|
4
4
|
export type Bucket = 'featured' | 'tools' | 'services';
|
|
5
5
|
|
|
6
6
|
/** Font Awesome classes, or a bundled image (a data: URI embedded by the CLI). */
|
|
7
7
|
export type RegistryIcon = { fa: string } | { img: string };
|
|
8
8
|
|
|
9
|
-
export interface FieldDecl {
|
|
9
|
+
export interface FieldDecl {
|
|
10
|
+
key: string; label?: string; secret?: boolean; modes?: AuthMode[]; placeholder?: string; required?: boolean;
|
|
11
|
+
/** Non-secret fields only: used while the field is empty (e.g. a demo board id). Never for secrets. */
|
|
12
|
+
default?: string;
|
|
13
|
+
/** One line under the field. */
|
|
14
|
+
help?: string;
|
|
15
|
+
}
|
|
10
16
|
export interface TopicDecl { visibility?: 'public' | 'protected'; event?: boolean }
|
|
11
17
|
|
|
12
18
|
export interface RegistryService {
|
|
@@ -32,7 +38,15 @@ export interface RegistryView {
|
|
|
32
38
|
module: string;
|
|
33
39
|
name: string;
|
|
34
40
|
label: string;
|
|
35
|
-
viewType: string;
|
|
41
|
+
viewType: 'GENERAL' | 'CSV' | 'ITEM' | 'ITEMS' | 'ACTION' | string;
|
|
42
|
+
/** Shown in the left navigation and tabs. Default true, false for ACTION views. */
|
|
43
|
+
showInNavBars?: boolean;
|
|
44
|
+
/** Opted in to be asked for Related contributions (default false). */
|
|
45
|
+
related?: boolean;
|
|
46
|
+
/** ACTION views only: opted in to be asked for Actions contributions (default false). */
|
|
47
|
+
actions?: boolean;
|
|
48
|
+
/** A background job (`background` handler in the app entry) run while the app is open. */
|
|
49
|
+
background?: { everySeconds: number };
|
|
36
50
|
nav: { section?: 'home' | 'reports'; bucket: Bucket; group?: string; feature?: string };
|
|
37
51
|
helpText?: string;
|
|
38
52
|
/** Services this view needs (from its module's non-optional `uses`, or the view's own `requires`). */
|
|
@@ -64,6 +78,9 @@ export interface RegistryPanel {
|
|
|
64
78
|
requires: { type: string; name: string }[];
|
|
65
79
|
}
|
|
66
80
|
|
|
81
|
+
/** A tab a module adds to a core Settings page (ADR-072). */
|
|
82
|
+
export interface RegistrySettingsTab { module: string; name: string; label: string; into: string; icon?: RegistryIcon; order: number; requires: { type: string; name: string }[] }
|
|
83
|
+
|
|
67
84
|
/** A card (ADR-062): wired to page-context entries, shown on any view whose page context satisfies them. */
|
|
68
85
|
export interface RegistryCard { module: string; name: string; label: string; context: Record<string, string>; icon?: RegistryIcon; order: number; collapsed: boolean; requires: { type: string; name: string }[] }
|
|
69
86
|
|
|
@@ -80,6 +97,8 @@ export interface RegistryDataset {
|
|
|
80
97
|
writes: 'module' | 'public';
|
|
81
98
|
/** The developer's default refresh schedule (refreshable only); the user's choice, saved in the dataset state, wins. */
|
|
82
99
|
schedule?: { cron: string };
|
|
100
|
+
/** Refreshable only: the routine may load just what changed. */
|
|
101
|
+
incremental?: boolean;
|
|
83
102
|
}
|
|
84
103
|
|
|
85
104
|
/** Developer-shipped text the user may reword in Settings → Templates; an edit may only use the declared tokens. */
|
|
@@ -97,6 +116,7 @@ export interface Registry {
|
|
|
97
116
|
templates?: RegistryTemplate[];
|
|
98
117
|
panels?: RegistryPanel[];
|
|
99
118
|
cards?: RegistryCard[];
|
|
119
|
+
settingsTabs?: RegistrySettingsTab[];
|
|
100
120
|
gettingStartedText?: string;
|
|
101
121
|
releaseNotesText?: string;
|
|
102
122
|
sectionIcons?: Partial<Record<'home' | 'reports' | 'settings', RegistryIcon>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { Context } from '@tacoshell/sdk';
|
|
3
|
+
import { createFramework } from '../core/bus.ts';
|
|
4
|
+
import { createPage } from '../core/page.ts';
|
|
5
|
+
import type { RegistryView } from '../types.ts';
|
|
6
|
+
import { Icon } from './Icon.tsx';
|
|
7
|
+
import { ViewBody } from './ViewHost.tsx';
|
|
8
|
+
|
|
9
|
+
/** An ACTION feature, shown in a modal over the page that offered it. It gets its own page whose context is the contribution's plus `referrer`. */
|
|
10
|
+
export function ActionModal({ view, context, onClose }: { view: RegistryView; context: Context; onClose: () => void }) {
|
|
11
|
+
const page = useMemo(() => { const p = createPage(`${view.module}/${view.name}`, context); p.close = onClose; return p; }, [view, context]);
|
|
12
|
+
const framework = useMemo(() => createFramework(view.module, page), [view.module, page]);
|
|
13
|
+
return (
|
|
14
|
+
<div className="backdrop" onMouseDown={(e) => e.target === e.currentTarget && onClose()} onKeyDown={(e) => e.key === 'Escape' && onClose()}>
|
|
15
|
+
<div className="modal action-modal" role="dialog" aria-label={view.label} data-action={`${view.module}/${view.name}`}>
|
|
16
|
+
<button className="close" onClick={onClose} aria-label="Close">×</button>
|
|
17
|
+
<h2><Icon icon={view.icon} />{view.label}</h2>
|
|
18
|
+
<ViewBody view={view} page={page} framework={framework} />
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
package/src/ui/App.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { favorites, moveFavorite, settings, togglePanel, toggleFavorite, updateS
|
|
|
4
4
|
import * as router from '../core/router.ts';
|
|
5
5
|
import { currentPage } from '../core/page.ts';
|
|
6
6
|
import * as services from '../core/services.ts';
|
|
7
|
+
import * as datasets from '../core/datasets.ts';
|
|
7
8
|
import { dismiss, toast, toasts } from '../core/toasts.ts';
|
|
8
9
|
import * as vault from '../core/vault.ts';
|
|
9
10
|
import { viewKey, type RegistryView } from '../types.ts';
|
|
@@ -13,6 +14,7 @@ import { Rail, SettingsRail } from './Rail.tsx';
|
|
|
13
14
|
import { Configuration, GettingStarted, ServicePage, ServicesList, VaultAndData } from './settings/Settings.tsx';
|
|
14
15
|
import { DatasetsPage } from './settings/Datasets.tsx';
|
|
15
16
|
import { ReleaseNotesPage } from './settings/ReleaseNotes.tsx';
|
|
17
|
+
import { SettingsTabbed } from './settings/SettingsTabs.tsx';
|
|
16
18
|
import { TemplatesPage } from './settings/Templates.tsx';
|
|
17
19
|
import { comboOf, match } from '../core/hotkeys.ts';
|
|
18
20
|
import { appDefaultOf, startHash } from '../core/startpage.ts';
|
|
@@ -106,6 +108,15 @@ function NotifyBell({ locked }: { locked: boolean }) {
|
|
|
106
108
|
return <button className={`bar-btn icon-only ${on ? 'st-ok' : 'st-bad'}`} onClick={toggle} disabled={locked} title="Notifications" aria-label="Notifications" aria-pressed={on}><i className={`fa-solid ${on ? 'fa-bell' : 'fa-bell-slash'}`} /></button>;
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
/** A database icon that pulses (selected color ↔ disabled gray) while any dataset refreshes in the background, and is gone otherwise. */
|
|
112
|
+
function DatasetRefreshIcon() {
|
|
113
|
+
const ids = useStore(datasets.refreshingNow);
|
|
114
|
+
const progress = useStore(datasets.progressNow);
|
|
115
|
+
if (!ids.length) return null;
|
|
116
|
+
const names = ids.map((id) => { const [m, n] = [id.slice(0, id.lastIndexOf('/')), id.slice(id.lastIndexOf('/') + 1)]; return `${datasets.find(m, n)?.label ?? id}${progress[id]?.text ? `: ${progress[id].text}` : ''}`; });
|
|
117
|
+
return <span className="refresh-indicator" role="status" aria-label="Refreshing datasets" title={`Refreshing: ${names.join(', ')}`}><i className="fa-solid fa-database" /></span>;
|
|
118
|
+
}
|
|
119
|
+
|
|
109
120
|
function FullscreenButton() {
|
|
110
121
|
const [full, setFull] = useState(() => !!document.fullscreenElement);
|
|
111
122
|
useEffect(() => { const f = () => setFull(!!document.fullscreenElement); document.addEventListener('fullscreenchange', f); return () => document.removeEventListener('fullscreenchange', f); }, []);
|
|
@@ -186,8 +197,8 @@ export function App() {
|
|
|
186
197
|
body = view ? <ViewHost key={`${viewKey(view)}:${remount}`} view={view} /> : <div className="page"><h1>Not found</h1><p className="muted">No view {route.module}/{route.view} in this app.</p></div>;
|
|
187
198
|
if (view) help = { text: view.helpText, title: view.label };
|
|
188
199
|
} else if (route.page === 'settings') {
|
|
189
|
-
body = route.sub === 'getting-started' ? <GettingStarted /> : route.sub === 'configuration' ? <Configuration
|
|
190
|
-
: route.sub === 'datasets' ? <DatasetsPage
|
|
200
|
+
body = route.sub === 'getting-started' ? <GettingStarted /> : route.sub === 'configuration' ? <SettingsTabbed page="configuration" coreLabel="Configuration" tab={route.type}><Configuration /></SettingsTabbed> : route.sub === 'vault' ? <SettingsTabbed page="vault" coreLabel="Vault & Data" tab={route.type}><VaultAndData /></SettingsTabbed>
|
|
201
|
+
: route.sub === 'datasets' ? <SettingsTabbed page="datasets" coreLabel="Datasets" tab={route.type}><DatasetsPage /></SettingsTabbed> : route.sub === 'templates' ? <SettingsTabbed page="templates" coreLabel="Templates" tab={route.type}><TemplatesPage /></SettingsTabbed> : route.sub === 'release-notes' ? <ReleaseNotesPage tab={route.type ?? 'notes'} /> : route.type && route.name ? <ServicePage type={route.type} name={route.name} /> : <ServicesList />;
|
|
191
202
|
if (route.sub === 'services' && route.type && route.name) { const s = services.find(route.type, route.name); help = { text: s?.howToText, title: s?.label ?? 'Service' }; }
|
|
192
203
|
} else {
|
|
193
204
|
body = <Landing title={route.page === 'reports' ? 'Reports' : 'Home'} section={route.page === 'reports' ? nav.reports : nav.home} views={registry.views} />;
|
|
@@ -206,6 +217,7 @@ export function App() {
|
|
|
206
217
|
<a className="pill version" href={router.href.settings('release-notes')} title={`${registry.app.displayName} v${registry.app.version}: click for the release notes`}>v{registry.app.version}</a>
|
|
207
218
|
<SearchBar registry={registry} inputRef={searchRef} />
|
|
208
219
|
<div className="top-right">
|
|
220
|
+
<DatasetRefreshIcon />
|
|
209
221
|
<SessionsMenu registry={registry} />
|
|
210
222
|
<NotifyBell locked={vaultState === 'locked'} />
|
|
211
223
|
<VaultButton state={vaultState} onUnlock={() => setPrompt(true)} />
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { CsvFeatureDef, Framework, RowResult } from '@tacoshell/sdk';
|
|
3
|
+
import { BLANK, distinct, ICON, labelOf, normalizeResult, parseUpload, shownColumns, sleep, templateCsv, templateName, visibleIndexes, type CsvRow } from '../core/csvfeature.ts';
|
|
4
|
+
import { toast } from '../core/toasts.ts';
|
|
5
|
+
import type { RegistryView } from '../types.ts';
|
|
6
|
+
|
|
7
|
+
type Run = { queue: number[]; pos: number; state: 'idle' | 'running' | 'stopped' | 'done' };
|
|
8
|
+
|
|
9
|
+
/** Header cell with a checkbox dropdown of the column's values. Everything is ticked by default. */
|
|
10
|
+
function ColumnFilter({ label, values, excluded, onChange, disabled }: { label: string; values: string[]; excluded: ReadonlySet<string>; onChange: (next: Set<string>) => void; disabled: boolean }) {
|
|
11
|
+
const [open, setOpen] = useState(false);
|
|
12
|
+
const active = excluded.size > 0;
|
|
13
|
+
const toggle = (v: string) => { const n = new Set(excluded); if (n.has(v)) n.delete(v); else n.add(v); onChange(n); };
|
|
14
|
+
return (
|
|
15
|
+
<th>
|
|
16
|
+
<div className="csv-th"><span>{label}</span>
|
|
17
|
+
<button className={`bar-btn icon-only csv-filter${active ? ' on' : ''}`} disabled={disabled} aria-label={`Filter ${label}`} aria-expanded={open} onClick={() => setOpen(!open)}><i className="fa-solid fa-filter" /></button>
|
|
18
|
+
</div>
|
|
19
|
+
{open && (
|
|
20
|
+
<div className="filter-menu csv-menu" onMouseLeave={() => setOpen(false)}>
|
|
21
|
+
<div className="filter-row"><button onClick={() => onChange(new Set())}>Select all</button><button onClick={() => onChange(new Set(values))}>Select none</button></div>
|
|
22
|
+
{values.map((v) => <label key={v}><input type="checkbox" checked={!excluded.has(v)} onChange={() => toggle(v)} /> {v}</label>)}
|
|
23
|
+
</div>
|
|
24
|
+
)}
|
|
25
|
+
</th>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* CSV: upload (with a template download) → Preview table with a value filter per shown column → Process, after a confirmation that lists
|
|
31
|
+
* the feature's steps and warning. Every displayed row goes, one at a time, to the feature's `processRow` with progress, Stop and Resume (v2 FR-BULK-1).
|
|
32
|
+
*/
|
|
33
|
+
export function CsvFeature({ def, framework, view }: { def: CsvFeatureDef; framework: Framework; view: RegistryView }) {
|
|
34
|
+
const [file, setFile] = useState('');
|
|
35
|
+
const [rows, setRows] = useState<CsvRow[]>([]);
|
|
36
|
+
const [excluded, setExcluded] = useState<Record<string, Set<string>>>({});
|
|
37
|
+
const [results, setResults] = useState<Record<number, RowResult>>({});
|
|
38
|
+
const [run, setRun] = useState<Run>({ queue: [], pos: 0, state: 'idle' });
|
|
39
|
+
const [asking, setAsking] = useState(false);
|
|
40
|
+
const stopRef = useRef(false);
|
|
41
|
+
const runRef = useRef(run);
|
|
42
|
+
const releaseRef = useRef<(() => void)[]>([]);
|
|
43
|
+
const cols = shownColumns(def);
|
|
44
|
+
const options = useMemo(() => Object.fromEntries(cols.map((c) => [c.key, distinct(rows, c.key)])), [rows]);
|
|
45
|
+
const visible = useMemo(() => visibleIndexes(rows, excluded), [rows, excluded]);
|
|
46
|
+
const running = run.state === 'running';
|
|
47
|
+
const update = (next: Run) => { runRef.current = next; setRun(next); };
|
|
48
|
+
|
|
49
|
+
const releaseGuards = () => { releaseRef.current.forEach((r) => r()); releaseRef.current = []; };
|
|
50
|
+
const onFile = async (f: File | undefined) => {
|
|
51
|
+
if (!f) return;
|
|
52
|
+
const parsed = parseUpload(await f.text(), def);
|
|
53
|
+
framework.log.info(`CSV ${f.name}: ${parsed.rows.length} row(s)`);
|
|
54
|
+
for (const s of parsed.skipped) framework.log.warn(`Removed ${s}`);
|
|
55
|
+
if (parsed.problems.length) {
|
|
56
|
+
framework.log.error(`CSV rejected: ${f.name}`, parsed.problems.slice(0, 50));
|
|
57
|
+
toast(`CSV rejected: ${parsed.problems[0]}${parsed.problems.length > 1 ? ` (+${parsed.problems.length - 1} more, see the Activity Log)` : ''}`, 'error');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setFile(f.name); setRows(parsed.rows); setExcluded({}); setResults({}); update({ queue: [], pos: 0, state: 'idle' });
|
|
61
|
+
};
|
|
62
|
+
const download = () => {
|
|
63
|
+
const url = URL.createObjectURL(new Blob([templateCsv(def)], { type: 'text/csv' }));
|
|
64
|
+
const a = Object.assign(document.createElement('a'), { href: url, download: templateName(def, view.name) });
|
|
65
|
+
a.click(); URL.revokeObjectURL(url);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const go = async (from: Run) => {
|
|
69
|
+
stopRef.current = false;
|
|
70
|
+
update({ ...from, state: 'running' });
|
|
71
|
+
releaseGuards();
|
|
72
|
+
releaseRef.current.push(framework.guard.block(`A CSV run is going (${from.queue.length - from.pos} remaining)`));
|
|
73
|
+
let pos = from.pos, failed = 0;
|
|
74
|
+
while (pos < from.queue.length) {
|
|
75
|
+
if (stopRef.current) break; // Stop is checked before each row, so Resume continues with the next unprocessed one
|
|
76
|
+
const index = from.queue[pos];
|
|
77
|
+
let result: RowResult;
|
|
78
|
+
try { result = normalizeResult(await def.processRow(rows[index], { framework, index: pos, total: from.queue.length, log: framework.log })); }
|
|
79
|
+
catch (e) { result = { status: 'error', message: (e as Error).message }; }
|
|
80
|
+
if (result.status === 'error') failed++;
|
|
81
|
+
setResults((r) => ({ ...r, [index]: result }));
|
|
82
|
+
pos++;
|
|
83
|
+
update({ queue: from.queue, pos, state: 'running' });
|
|
84
|
+
if (def.delayMs && pos < from.queue.length) await sleep(def.delayMs);
|
|
85
|
+
}
|
|
86
|
+
releaseGuards();
|
|
87
|
+
const state = pos >= from.queue.length ? 'done' : 'stopped';
|
|
88
|
+
update({ queue: from.queue, pos, state });
|
|
89
|
+
framework.log[failed ? 'warn' : 'info'](state === 'done' ? `${def.processLabel ?? 'Process'} finished: ${from.queue.length - failed} of ${from.queue.length} without error` : `Stopped after ${pos} of ${from.queue.length} rows.`);
|
|
90
|
+
// After a Stop that left rows unprocessed, leaving is allowed but warned about: this page's tracking (and Resume) would be lost.
|
|
91
|
+
if (state === 'stopped') releaseRef.current.push(framework.guard.unsaved(() => runRef.current.state === 'stopped'));
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const start = () => { setAsking(false); setResults({}); void go({ queue: visible, pos: 0, state: 'running' }); };
|
|
95
|
+
const left = run.queue.length - run.pos;
|
|
96
|
+
const label = run.state === 'stopped' ? `Stopped — ${left} remaining` : left > 0 ? `${left} remaining` : 'Complete';
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div className="csv-feature" data-feature-type="CSV">
|
|
100
|
+
{def.intro && <p className="muted">{def.intro}</p>}
|
|
101
|
+
<div className="csv-upload card">
|
|
102
|
+
<input type="file" accept=".csv,text/csv" aria-label="CSV file" disabled={running} onChange={(e) => { void onFile(e.target.files?.[0]); e.target.value = ''; }} />
|
|
103
|
+
<button onClick={download}><i className="fa-solid fa-download" /> Download template</button>
|
|
104
|
+
{file && <span className="muted small">{file}: {rows.length} row(s)</span>}
|
|
105
|
+
</div>
|
|
106
|
+
{rows.length > 0 && (
|
|
107
|
+
<>
|
|
108
|
+
<h2>Preview <span className="muted small">{visible.length} of {rows.length} rows shown</span></h2>
|
|
109
|
+
<div className="table-wrap csv-table">
|
|
110
|
+
<table>
|
|
111
|
+
<thead><tr>{cols.map((c) => <ColumnFilter key={c.key} label={labelOf(c)} values={options[c.key]} excluded={excluded[c.key] ?? new Set()} disabled={running} onChange={(n) => setExcluded({ ...excluded, [c.key]: n })} />)}<th className="csv-status-col">Result</th></tr></thead>
|
|
112
|
+
<tbody>
|
|
113
|
+
{visible.map((i) => {
|
|
114
|
+
const r = results[i];
|
|
115
|
+
return (
|
|
116
|
+
<tr key={i} className={r ? `row-${r.status}` : undefined} data-row={i}>
|
|
117
|
+
{cols.map((c) => <td key={c.key}>{rows[i][c.key] || <span className="muted">{BLANK}</span>}</td>)}
|
|
118
|
+
<td className="csv-status" title={r?.message ?? ''}>{r ? ICON[r.status] : ''}</td>
|
|
119
|
+
</tr>
|
|
120
|
+
);
|
|
121
|
+
})}
|
|
122
|
+
</tbody>
|
|
123
|
+
</table>
|
|
124
|
+
</div>
|
|
125
|
+
<div className="csv-run">
|
|
126
|
+
<span className="spacer" />
|
|
127
|
+
{run.state !== 'idle' && (
|
|
128
|
+
<span className="csv-progress">
|
|
129
|
+
<progress max={run.queue.length || 1} value={run.pos} /><span className="muted small">{label}</span>
|
|
130
|
+
{running && <button onClick={() => { stopRef.current = true; }}>Stop</button>}
|
|
131
|
+
{run.state === 'stopped' && left > 0 && <button className="primary" onClick={() => void go(run)}>Resume</button>}
|
|
132
|
+
</span>
|
|
133
|
+
)}
|
|
134
|
+
<button className="primary" disabled={running || !visible.length} onClick={() => setAsking(true)}>{def.processLabel ?? 'Process'} ({visible.length})</button>
|
|
135
|
+
</div>
|
|
136
|
+
</>
|
|
137
|
+
)}
|
|
138
|
+
{asking && (
|
|
139
|
+
<div className="backdrop" onMouseDown={(e) => e.target === e.currentTarget && setAsking(false)} onKeyDown={(e) => e.key === 'Escape' && setAsking(false)}>
|
|
140
|
+
<div className="modal csv-confirm" role="alertdialog" aria-labelledby="csv-confirm-title">
|
|
141
|
+
<h2 id="csv-confirm-title">{def.confirm.title ?? `${def.processLabel ?? 'Process'} ${visible.length} row(s)?`}</h2>
|
|
142
|
+
<p className="muted">{visible.length} row(s) will be processed, one at a time. These steps happen for each row:</p>
|
|
143
|
+
<ol>{def.confirm.steps.map((s, i) => <li key={i}>{s}</li>)}</ol>
|
|
144
|
+
{def.confirm.warning && <div className="callout warn" role="note"><i className="fa-solid fa-triangle-exclamation" /> {def.confirm.warning}</div>}
|
|
145
|
+
<div className="actions"><button onClick={() => setAsking(false)}>Cancel</button><button className="primary" autoFocus onClick={start}>Confirm</button></div>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { Framework, ItemFeatureDef } from '@tacoshell/sdk';
|
|
3
|
+
import { actionProblem, targetContext } from '../core/contrib.ts';
|
|
4
|
+
import * as log from '../core/log.ts';
|
|
5
|
+
import type { Page } from '../core/page.ts';
|
|
6
|
+
import type { RegistryView } from '../types.ts';
|
|
7
|
+
import { ActionModal } from './ActionModal.tsx';
|
|
8
|
+
import { useContributions } from './useContrib.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* ITEM: a main pane (yours) and a fixed 300 px right rail: your Header, the framework's Actions, your Footer. Header and Footer are left out when
|
|
12
|
+
* not defined; Actions is left out when no feature contributes. Each Action is an ACTION feature that opens in a modal with this item's context as `referrer`.
|
|
13
|
+
*/
|
|
14
|
+
export function ItemFeature({ def, framework, page, context }: { def: ItemFeatureDef; framework: Framework; page: Page; context?: Record<string, unknown> }) {
|
|
15
|
+
const { items, exposed } = useContributions('actions', page);
|
|
16
|
+
// The modal's context is fixed when it opens, so what the page exposes later doesn't rebuild the action's page.
|
|
17
|
+
const [open, setOpen] = useState<{ view: RegistryView; context: Record<string, unknown> } | null>(null);
|
|
18
|
+
const { leftPane: Left, rightRailHeader: Header, rightRailFooter: Footer } = def;
|
|
19
|
+
const props = { framework, context };
|
|
20
|
+
const hasRail = !!Header || !!Footer || items.length > 0;
|
|
21
|
+
return (
|
|
22
|
+
<div className={`item-layout${hasRail ? '' : ' no-rail'}`}>
|
|
23
|
+
<div className="item-main"><Left {...props} /></div>
|
|
24
|
+
{hasRail && (
|
|
25
|
+
<aside className="item-rail" aria-label="Item rail">
|
|
26
|
+
{Header && <section className="rail-header" data-rail="header"><Header {...props} /></section>}
|
|
27
|
+
{items.length > 0 && (
|
|
28
|
+
<section className="rail-actions" data-rail="actions">
|
|
29
|
+
<h3 className="rail-title">Actions</h3>
|
|
30
|
+
{items.map((i) => <button key={i.id} className="action-btn" onClick={() => { const context = targetContext(i, exposed); const problem = actionProblem(i.view, context); if (problem) log.add('error', `Action "${i.label}": context for ${i.view.module}/${i.view.name} doesn't match its declaration (${problem})`, context, i.view.module); else setOpen({ view: i.view, context }); }}>{i.icon?.startsWith('fa-') ? <i className={i.icon} /> : null}<span>{i.label}</span></button>)}
|
|
31
|
+
</section>
|
|
32
|
+
)}
|
|
33
|
+
{Footer && <section className="rail-footer" data-rail="footer"><Footer {...props} /></section>}
|
|
34
|
+
</aside>
|
|
35
|
+
)}
|
|
36
|
+
{open && <ActionModal view={open.view} context={open.context} onClose={() => setOpen(null)} />}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|