Skip to content

Commit 0ed2e78

Browse files
committed
Refactor(ui/storage): Extract storage row creation to helper function
1 parent a49251b commit 0ed2e78

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

src/public/js/ui/storage.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,39 +138,9 @@ PulseApp.ui.storage = (() => {
138138
}
139139

140140
const sortedNodeStorageData = sortNodeStorageData(nodeStorageData);
141-
142141
sortedNodeStorageData.forEach(store => {
143-
const row = document.createElement('tr');
144-
const isDisabled = store.enabled === 0 || store.active === 0;
145-
row.className = `transition-all duration-150 ease-out hover:bg-gray-100 dark:hover:bg-gray-700/60 hover:shadow-md hover:-translate-y-px ${isDisabled ? 'opacity-50 grayscale-[50%]' : ''}`;
146-
147-
const usagePercent = store.total > 0 ? (store.used / store.total) * 100 : 0;
148-
const usageTooltipText = `${PulseApp.utils.formatBytes(store.used)} / ${PulseApp.utils.formatBytes(store.total)} (${usagePercent.toFixed(1)}%)`;
149-
150-
const usageColorClass = PulseApp.utils.getUsageColor(usagePercent);
151-
const sharedIconTooltip = store.shared === 1 ? 'Shared across cluster' : 'Local to node';
152-
const sharedIcon = store.shared === 1 ? `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block text-green-600 dark:text-green-400"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>`
153-
: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block text-gray-400 dark:text-gray-500 opacity-50"><rect x="2" y="2" width="20" height="8" rx="2" ry="2"></rect><rect x="2" y="14" width="20" height="8" rx="2" ry="2"></rect><line x1="6" y1="6" x2="6.01" y2="6"></line><line x1="6" y1="18" x2="6.01" y2="18"></line></svg>`;
154-
155-
const contentTypes = (store.content || '').split(',').map(ct => ct.trim()).filter(ct => ct);
156-
contentTypes.sort();
157-
const contentBadges = contentTypes.map(ct => {
158-
const details = getContentBadgeDetails(ct);
159-
return `<span data-tooltip="${details.tooltip}" class="storage-tooltip-trigger inline-block ${details.badgeClass} rounded px-1.5 py-0.5 text-xs font-medium mr-1 cursor-default">${ct}</span>`;
160-
}).join('');
161-
162-
const usageBarHTML = PulseApp.utils.createProgressTextBarHTML(usagePercent, usageTooltipText, usageColorClass);
163-
164-
row.innerHTML = `
165-
<td class="p-1 px-2 whitespace-nowrap text-gray-900 dark:text-gray-100 font-medium">${store.storage || 'N/A'}</td>
166-
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300 text-xs flex items-center">${contentBadges || '-'}</td>
167-
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300">${store.type || 'N/A'}</td>
168-
<td class="p-1 px-2 whitespace-nowrap storage-tooltip-trigger cursor-default" data-tooltip="${sharedIconTooltip}">${sharedIcon}</td>
169-
<td class="p-1 px-2 text-gray-600 dark:text-gray-300 min-w-[250px]">${usageBarHTML}</td>
170-
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300">${PulseApp.utils.formatBytes(store.avail)}</td>
171-
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300">${PulseApp.utils.formatBytes(store.total)}</td>
172-
`;
173-
tbody.appendChild(row);
142+
const row = _createStorageRow(store);
143+
tbody.appendChild(row);
174144
});
175145
});
176146

@@ -179,7 +149,40 @@ PulseApp.ui.storage = (() => {
179149
contentDiv.appendChild(table);
180150
}
181151

152+
function _createStorageRow(store) {
153+
const row = document.createElement('tr');
154+
const isDisabled = store.enabled === 0 || store.active === 0;
155+
row.className = `transition-all duration-150 ease-out hover:bg-gray-100 dark:hover:bg-gray-700/60 hover:shadow-md hover:-translate-y-px ${isDisabled ? 'opacity-50 grayscale-[50%]' : ''}`;
156+
157+
const usagePercent = store.total > 0 ? (store.used / store.total) * 100 : 0;
158+
const usageTooltipText = `${PulseApp.utils.formatBytes(store.used)} / ${PulseApp.utils.formatBytes(store.total)} (${usagePercent.toFixed(1)}%)`;
159+
const usageColorClass = PulseApp.utils.getUsageColor(usagePercent);
160+
const usageBarHTML = PulseApp.utils.createProgressTextBarHTML(usagePercent, usageTooltipText, usageColorClass);
161+
162+
const sharedIconTooltip = store.shared === 1 ? 'Shared across cluster' : 'Local to node';
163+
const sharedIcon = store.shared === 1 ? `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block text-green-600 dark:text-green-400"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>`
164+
: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block text-gray-400 dark:text-gray-500 opacity-50"><rect x="2" y="2" width="20" height="8" rx="2" ry="2"></rect><rect x="2" y="14" width="20" height="8" rx="2" ry="2"></rect><line x1="6" y1="6" x2="6.01" y2="6"></line><line x1="6" y1="18" x2="6.01" y2="18"></line></svg>`;
165+
166+
const contentTypes = (store.content || '').split(',').map(ct => ct.trim()).filter(ct => ct);
167+
contentTypes.sort();
168+
const contentBadges = contentTypes.map(ct => {
169+
const details = getContentBadgeDetails(ct);
170+
return `<span data-tooltip="${details.tooltip}" class="storage-tooltip-trigger inline-block ${details.badgeClass} rounded px-1.5 py-0.5 text-xs font-medium mr-1 cursor-default">${ct}</span>`;
171+
}).join('');
172+
173+
row.innerHTML = `
174+
<td class="p-1 px-2 whitespace-nowrap text-gray-900 dark:text-gray-100 font-medium">${store.storage || 'N/A'}</td>
175+
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300 text-xs flex items-center">${contentBadges || '-'}</td>
176+
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300">${store.type || 'N/A'}</td>
177+
<td class="p-1 px-2 whitespace-nowrap storage-tooltip-trigger cursor-default" data-tooltip="${sharedIconTooltip}">${sharedIcon}</td>
178+
<td class="p-1 px-2 text-gray-600 dark:text-gray-300 min-w-[250px]">${usageBarHTML}</td>
179+
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300">${PulseApp.utils.formatBytes(store.avail)}</td>
180+
<td class="p-1 px-2 whitespace-nowrap text-gray-600 dark:text-gray-300">${PulseApp.utils.formatBytes(store.total)}</td>
181+
`;
182+
return row;
183+
}
184+
182185
return {
183186
updateStorageInfo
184187
};
185-
})();
188+
})();

0 commit comments

Comments
 (0)