refactor: improve storage handling, UI feedback, and defaults

- Update default admin email to admin@datastack.dev
- Improve storage flush logic with partial success handling
- Enhance CSV download reliability using fetch and Blob
- Adjust simulator protocol resolution and timing
- Fix date range filtering in data API query
This commit is contained in:
Team Dark Devil committed 2026-11-19 00:42:38 +06:00
1 parent 40a6855724
commit 3ad9b1d4d2
17 files changed
+281 -78

No files matched your search

+1 -1
View File
@@ -102,7 +102,7 @@ export function AdminLogin({
label="Email"
type="email"
autoComplete="username"
placeholder="admin@example.com"
placeholder="admin@datastack.dev"
value={email}
onChange={(event) => setEmail(event.target.value)}
compact
+1 -1
View File
@@ -81,7 +81,7 @@ export function AdminSetup({
label="Admin email"
type="email"
autoComplete="username"
placeholder="admin@example.com"
placeholder="admin@datastack.dev"
value={email}
onChange={(event) => setEmail(event.target.value)}
compact
+21 -4
View File
@@ -198,10 +198,27 @@ export function ExportWorkspace() {
);
};
const downloadFile = (file: StorageFile) => {
window.location.assign(
`/api/export?clientId=${encodeURIComponent(file.clientId)}&filename=${encodeURIComponent(file.filename)}`
);
const downloadFile = async (file: StorageFile) => {
const url = `/api/export?clientId=${encodeURIComponent(file.clientId)}&filename=${encodeURIComponent(file.filename)}`;
try {
const res = await fetch(url, { cache: 'no-store' });
if (!res.ok) {
const errorJson = await res.json().catch(() => ({}));
error('Download Failed', errorJson.error || 'Requested CSV file could not be exported.');
return;
}
const blob = await res.blob();
const objectUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = objectUrl;
a.download = file.filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(objectUrl);
} catch (err: unknown) {
error('Download Failed', err instanceof Error ? err.message : 'Export download error');
}
};
const rangeChanged = (setter: (value: string) => void, value: string) => {
+1 -1
View File
@@ -12,7 +12,7 @@ export const SdkSection: React.FC = () => (
<span className="text-[var(--text-faint)]"># Auto-loads config.datastack.py from project root</span>{'\n'}
<span className="text-[var(--text)]">from datastack import DataStack</span>{'\n\n'}
<span className="text-[var(--text)]">client = DataStack()</span>{'\n'}
<span className="text-[var(--text)]">client.send({'{'}<span className="text-[var(--accent)]">&quot;event&quot;</span>: <span className="text-[var(--accent)]">&quot;package_received&quot;</span>{'}'})</span>{'\n'}
<span className="text-[var(--text)]">client.send({'{'}<span className="text-[var(--accent)]">&quot;event_type&quot;</span>: <span className="text-[var(--accent)]">&quot;sensor_telemetry&quot;</span>, <span className="text-[var(--accent)]">&quot;temperature&quot;</span>: 24.8, <span className="text-[var(--accent)]">&quot;status&quot;</span>: <span className="text-[var(--accent)]">&quot;NOMINAL&quot;</span>{'}'})</span>{'\n'}
<span className="text-[var(--text)]">client.send_file(<span className="text-[var(--accent)]">&quot;telemetry_batch.csv&quot;</span>)</span>{'\n'}
<span className="text-[var(--text)]">client.disconnect()</span>
</CodeBlock>
+20 -5
View File
@@ -82,8 +82,11 @@ export function SettingsWorkspace() {
const probeSocketServer = useCallback(async (port: number) => {
setSocketStatus('checking');
const isLocalDev = window.location.port === '3000';
const httpHost = isLocalDev
const isLocalHost =
window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1' ||
window.location.port === '3000';
const httpHost = isLocalHost
? `${window.location.hostname}:${port}`
: window.location.host;
const healthUrl = `${window.location.protocol}//${httpHost}/health`;
@@ -95,15 +98,27 @@ export function SettingsWorkspace() {
});
setSocketStatus(response.ok ? 'online' : 'offline');
} catch {
setSocketStatus('offline');
// In remote/preview environments where Port 4000 is proxied through web API or reverse proxy, probe /api/health
try {
const fallbackRes = await fetch('/api/health', {
cache: 'no-store',
signal: AbortSignal.timeout(1500),
});
setSocketStatus(fallbackRes.ok ? 'online' : 'offline');
} catch {
setSocketStatus('offline');
}
}
}, []);
useEffect(() => {
setBaseUrl(window.location.origin);
const isLocalDev = window.location.port === '3000';
const isLocalHost =
window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1' ||
window.location.port === '3000';
const socketProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
const socketHost = isLocalDev
const socketHost = isLocalHost
? `${window.location.hostname}:${serverPort}`
: window.location.host;
setWebSocketUrl(`${socketProtocol}://${socketHost}`);