mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Eng-council sweep: export hygiene, dead code, helper dedup, declare vega-expression
This commit is contained in:
@@ -14,9 +14,16 @@
|
||||
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
import { datasetReference, tabularRows, type DataSource, type Dataset } from '@core/dataset';
|
||||
import {
|
||||
cellText,
|
||||
datasetReference,
|
||||
tabularRows,
|
||||
type DataSource,
|
||||
type Dataset,
|
||||
} from '@core/dataset';
|
||||
import { detectFormat, detectFormatFromUrl, type DataFormat } from '@core/format-detection';
|
||||
import { datasetUsageCounts, snippetsReferencingDataset } from '@core/relationships';
|
||||
import { humanizeBytes } from '@core/storage-estimate';
|
||||
import { closeModal, openModal, resnapshot } from '../modals/ModalCoordinator';
|
||||
import { fetchRemoteData } from '../infrastructure/remote-data';
|
||||
import { remoteFetchErrorMessage } from '../services/remote-data-errors';
|
||||
@@ -38,15 +45,6 @@ function formatLabel(format: DataFormat): string {
|
||||
return format === 'topojson' ? 'TopoJSON' : format.toUpperCase();
|
||||
}
|
||||
|
||||
/** Human-readable byte size (B / KB / MB). */
|
||||
function humanBytes(bytes: number): string {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
const kb = bytes / 1024;
|
||||
if (kb < 1024) return `${kb < 10 ? kb.toFixed(1) : Math.round(kb)} KB`;
|
||||
const mb = kb / 1024;
|
||||
return `${mb < 10 ? mb.toFixed(1) : Math.round(mb)} MB`;
|
||||
}
|
||||
|
||||
const SOURCE_OPTIONS: ReadonlyArray<SegmentedOption<DataSource>> = [
|
||||
{ value: 'inline', label: 'Inline' },
|
||||
{ value: 'url', label: 'URL' },
|
||||
@@ -55,14 +53,6 @@ const SOURCE_OPTIONS: ReadonlyArray<SegmentedOption<DataSource>> = [
|
||||
/** Rows shown in the tabular preview before truncating (spec §05 → Detail Panel). */
|
||||
const PREVIEW_ROW_LIMIT = 50;
|
||||
|
||||
/** One table cell's text: blank for empty, the string as-is, else JSON (numbers,
|
||||
* booleans, nested values). Avoids `String()` on objects ("[object Object]"). */
|
||||
function cellText(value: unknown): string {
|
||||
if (value == null) return '';
|
||||
if (typeof value === 'string') return value;
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
|
||||
export function DatasetsModal() {
|
||||
const datasets = useDatasetStore(useShallow((s) => s.datasets));
|
||||
const view = useDatasetStore((s) => s.view);
|
||||
@@ -137,7 +127,7 @@ function DatasetListItem({
|
||||
if (unfetched) parts.push('not fetched');
|
||||
else if (dataset.rowCount !== null) parts.push(`${dataset.rowCount} rows`);
|
||||
parts.push(formatLabel(dataset.format));
|
||||
if (!unfetched) parts.push(humanBytes(dataset.size));
|
||||
if (!unfetched) parts.push(humanizeBytes(dataset.size));
|
||||
|
||||
return (
|
||||
<li className={`${styles.item} ${active ? styles.itemActive : ''}`}>
|
||||
@@ -324,7 +314,7 @@ function DatasetDetail({
|
||||
</div>
|
||||
<div>
|
||||
<dt>Size</dt>
|
||||
<dd>{dataset.data == null ? 'N/A' : humanBytes(dataset.size)}</dd>
|
||||
<dd>{dataset.data == null ? 'N/A' : humanizeBytes(dataset.size)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export type IconName =
|
||||
| 'status-info'; // Carbon InformationFilled
|
||||
|
||||
/** Carbon icon scale (arch 09 §5.3). 16px (sm) is the default, paired to 14px body. */
|
||||
export type IconSize = 'sm' | 'md' | 'lg' | 'xl';
|
||||
type IconSize = 'sm' | 'md' | 'lg' | 'xl';
|
||||
|
||||
/** Inner SVG geometry per glyph, on Carbon's 0 0 32 32 grid. fill comes from CSS. */
|
||||
const GLYPHS: Record<IconName, ReactNode> = {
|
||||
|
||||
Reference in New Issue
Block a user