Skip to content

Commit 6e2bfcf

Browse files
committed
feat: enhance dataset size display and selection panel functionality
- Add functionality to calculate and format total file size for selected datasets. - Update UI to display total size alongside the count of selected datasets. - Refactor existing methods to improve clarity and maintainability in size calculations. - Introduce new utility methods for file size formatting and total size calculation from datasets.
1 parent 2fc7f43 commit 6e2bfcf

5 files changed

Lines changed: 131 additions & 20 deletions

File tree

docs/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ <h1 class="header-title">RoboCOIN-DataManager</h1>
8888
<span class="stat-inline">
8989
<span class="stat-label">Filtered:</span>
9090
<strong id="filteredCount">0</strong>
91+
<span id="filteredInfo"> repos</span>
9192
</span>
9293
<span class="stat-inline">
9394
<span class="stat-label">Selected:</span>
9495
<strong id="selectedCount">0</strong>
96+
<span id="selectedInfo"> repos</span>
9597
</span>
9698
</div>
9799
</div>

docs/js/app.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,18 @@ class Application {
153153
const searchQuery = document.getElementById('searchBox')?.value || '';
154154
const filteredDatasets = this.filterManager.applyFilters(searchQuery);
155155

156+
// Get selected datasets array from selectedDatasets Set
157+
const selectedDatasetsArray = Array.from(this.selectedDatasets)
158+
.map(path => dataManager.datasetMap.get(path))
159+
.filter(ds => ds !== undefined);
160+
156161
// Update counts
157-
this.uiUtils.updateCounts(filteredDatasets.length, this.selectedDatasets.size);
162+
this.uiUtils.updateCounts(
163+
filteredDatasets.length,
164+
this.selectedDatasets.size,
165+
filteredDatasets,
166+
selectedDatasetsArray
167+
);
158168

159169
// Update filter counts in UI
160170
this.updateFilterCounts(filteredDatasets);

docs/js/modules/config.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,46 @@ class ConfigManager {
316316
return null;
317317
}
318318

319+
/**
320+
* Format file size from bytes to human-readable string (GB or TB)
321+
* @param {number} totalBytes - Total size in bytes
322+
* @returns {string} Formatted size string (e.g., "1.5GB" or "0.3TB")
323+
*/
324+
static formatFileSize(totalBytes) {
325+
const TB = 1e12;
326+
const GB = 1e9;
327+
const useTB = totalBytes >= TB;
328+
const value = useTB ? (totalBytes / TB) : (totalBytes / GB);
329+
const formatted = (Math.round(value * 10) / 10).toFixed(1);
330+
const unit = useTB ? 'TB' : 'GB';
331+
return `${formatted}${unit}`;
332+
}
333+
334+
/**
335+
* Calculate total size in bytes from an array of datasets
336+
* @param {Dataset[]} datasets - Array of datasets
337+
* @returns {number|null} Total size in bytes, or null if no valid sizes found
338+
*/
339+
static calculateTotalSizeFromDatasets(datasets) {
340+
if (!datasets || datasets.length === 0) {
341+
return null;
342+
}
343+
344+
let totalBytes = 0;
345+
let hasValidSize = false;
346+
347+
for (const ds of datasets) {
348+
const size = ds?.datasetSize ?? ds?.raw?.dataset_size;
349+
const bytes = this.parseDatasetSizeToBytes(size);
350+
if (bytes !== null) {
351+
totalBytes += bytes;
352+
hasValidSize = true;
353+
}
354+
}
355+
356+
return hasValidSize ? totalBytes : null;
357+
}
358+
319359
/**
320360
* Build the required storage comment for a list of datasets.
321361
* Rules:
@@ -335,24 +375,16 @@ class ConfigManager {
335375
return '# Required storage: ---GB/TB.\n# Disk usage may be larger.';
336376
}
337377

338-
let totalBytes = 0;
339-
for (const path of datasetPaths) {
340-
const ds = datasetMap.get(path);
341-
const size = ds?.datasetSize ?? ds?.raw?.dataset_size;
342-
const bytes = this.parseDatasetSizeToBytes(size);
343-
if (bytes === null) {
344-
return '# Required storage: ---GB/TB.\n# Disk usage may be larger.';
345-
}
346-
totalBytes += bytes;
378+
// Build datasets array from paths
379+
const datasets = datasetPaths.map(path => datasetMap.get(path)).filter(ds => ds !== undefined);
380+
const totalBytes = this.calculateTotalSizeFromDatasets(datasets);
381+
382+
if (totalBytes === null) {
383+
return '# Required storage: ---GB/TB.\n# Disk usage may be larger.';
347384
}
348-
349-
const TB = 1e12;
350-
const GB = 1e9;
351-
const useTB = totalBytes >= TB;
352-
const value = useTB ? (totalBytes / TB) : (totalBytes / GB);
353-
const formatted = (Math.round(value * 10) / 10).toFixed(1);
354-
const unit = useTB ? 'TB' : 'GB';
355-
return `# Required storage: ${formatted}${unit}.\n# Disk usage may be larger.`;
385+
386+
const formattedSize = this.formatFileSize(totalBytes);
387+
return `# Required storage: ${formattedSize}.\n# Disk usage may be larger.`;
356388
}
357389

358390
/**

docs/js/modules/selection-panel.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,44 @@ export class SelectionPanelManager {
5757
this._sortedPathsCache = null;
5858
}
5959

60+
/**
61+
* Calculate and format total file size for selected datasets
62+
* @returns {string} Formatted size string (e.g., " repos, 1.5GB")
63+
*/
64+
_calculateSelectedTotalSize() {
65+
if (this.selectedDatasets.size === 0) {
66+
return ' repos';
67+
}
68+
69+
// Build datasets array from selected paths
70+
const datasets = Array.from(this.selectedDatasets)
71+
.map(path => this.datasetMap.get(path))
72+
.filter(ds => ds !== undefined);
73+
74+
const totalBytes = ConfigManager.calculateTotalSizeFromDatasets(datasets);
75+
76+
if (totalBytes === null) {
77+
return ' repos';
78+
}
79+
80+
const formattedSize = ConfigManager.formatFileSize(totalBytes);
81+
return ` repos, ${formattedSize}`;
82+
}
83+
6084
/**
6185
* Update selection panel with virtual scrolling
6286
*/
6387
updateSelectionPanel() {
64-
document.getElementById('selectedCount').textContent = this.selectedDatasets.size;
88+
const selectedCountEl = document.getElementById('selectedCount');
89+
const selectedInfoEl = document.getElementById('selectedInfo');
90+
91+
if (selectedCountEl) {
92+
selectedCountEl.textContent = this.selectedDatasets.size;
93+
}
94+
95+
if (selectedInfoEl) {
96+
selectedInfoEl.textContent = this._calculateSelectedTotalSize();
97+
}
6598

6699
const list = document.getElementById('selectionList');
67100
if (!list) return;

docs/js/modules/ui-utils.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,51 @@ export class UIUtils {
244244
}
245245
}
246246

247+
/**
248+
* Calculate and format total file size for datasets
249+
* @param {Dataset[]} datasets - Array of datasets
250+
* @returns {string} Formatted size string (e.g., " repos, 1.5GB")
251+
*/
252+
calculateTotalSize(datasets) {
253+
if (!datasets || datasets.length === 0) {
254+
return ' repos';
255+
}
256+
257+
const totalBytes = ConfigManager.calculateTotalSizeFromDatasets(datasets);
258+
259+
if (totalBytes === null) {
260+
return ' repos';
261+
}
262+
263+
const formattedSize = ConfigManager.formatFileSize(totalBytes);
264+
return ` repos, ${formattedSize}`;
265+
}
266+
247267
/**
248268
* Update counts display
249269
* @param {number} filteredCount - Filtered datasets count
250270
* @param {number} selectedCount - Selected datasets count
271+
* @param {Dataset[]} [filteredDatasets] - Optional filtered datasets array for size calculation
272+
* @param {Dataset[]} [selectedDatasets] - Optional selected datasets array for size calculation
251273
*/
252-
updateCounts(filteredCount, selectedCount) {
274+
updateCounts(filteredCount, selectedCount, filteredDatasets = null, selectedDatasets = null) {
253275
const filteredEl = document.getElementById('filteredCount');
254276
const selectedEl = document.getElementById('selectedCount');
277+
const filteredInfoEl = document.getElementById('filteredInfo');
278+
const selectedInfoEl = document.getElementById('selectedInfo');
255279

256280
if (filteredEl) filteredEl.textContent = filteredCount;
257281
if (selectedEl) selectedEl.textContent = selectedCount;
282+
283+
// Calculate and display total file size for filtered datasets
284+
if (filteredInfoEl) {
285+
filteredInfoEl.textContent = this.calculateTotalSize(filteredDatasets);
286+
}
287+
288+
// Calculate and display total file size for selected datasets
289+
if (selectedInfoEl) {
290+
selectedInfoEl.textContent = this.calculateTotalSize(selectedDatasets);
291+
}
258292
}
259293

260294
/**

0 commit comments

Comments
 (0)