diff --git a/src/components/instance/functions/manage/applicationsEditor/EditorMenu.js b/src/components/instance/functions/manage/applicationsEditor/EditorMenu.js index 452e9232c..757f4e556 100644 --- a/src/components/instance/functions/manage/applicationsEditor/EditorMenu.js +++ b/src/components/instance/functions/manage/applicationsEditor/EditorMenu.js @@ -52,10 +52,10 @@ export default function EditorMenu({ children }) { {children.map( (child) => child && ( -
  • +
  • {child}
  • - ), + ) )} ); diff --git a/src/components/instance/functions/manage/applicationsEditor/FileMenu.js b/src/components/instance/functions/manage/applicationsEditor/FileMenu.js index b55a8489d..25d5afe80 100644 --- a/src/components/instance/functions/manage/applicationsEditor/FileMenu.js +++ b/src/components/instance/functions/manage/applicationsEditor/FileMenu.js @@ -51,10 +51,10 @@ function FileMenu({ children }) { {children.map( (child) => child && ( -
  • +
  • {child}
  • - ), + ) )} ); diff --git a/src/functions/api/instance/getComponents.js b/src/functions/api/instance/getComponents.js index cfd7461f0..4b248ea97 100644 --- a/src/functions/api/instance/getComponents.js +++ b/src/functions/api/instance/getComponents.js @@ -9,7 +9,7 @@ function addMetadata(fileTree, path, rootDir, readOnly = false) { if (path === rootDir) { fileTree.path = rootDir; - fileTree.key = crypto.randomUUID(); + fileTree.key = crypto.randomUUID?.() ?? Math.random().toString().slice(2); } for (const entry of fileTree.entries) { @@ -24,7 +24,7 @@ function addMetadata(fileTree, path, rootDir, readOnly = false) { const [, project] = newPath.split('/'); entry.project = project; entry.path = newPath; - entry.key = crypto.randomUUID(); + entry.key = crypto.randomUUID?.() ?? Math.random().toString().slice(2); entry.readOnly = readOnly || !!entry.package; addMetadata(entry, newPath, rootDir, entry.readOnly); diff --git a/src/functions/api/instance/updateSystemInfo.js b/src/functions/api/instance/updateSystemInfo.js index 8e4181806..e476f0de2 100644 --- a/src/functions/api/instance/updateSystemInfo.js +++ b/src/functions/api/instance/updateSystemInfo.js @@ -4,18 +4,15 @@ import instanceState from '../../state/instanceState'; const B2GB1000 = 1000000000; // for mac disk and transfer const B2GB1024 = 1073741824; // for non-mac disk -export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo, skip=[] }) => { - +export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo, skip = [] }) => { // skip attributes added because network and disk currently expensive instance ops // provides more fine-grained control over which items are cached. - const systemAttributes = ['network','disk','cpu','memory','system']; + const systemAttributes = ['network', 'disk', 'cpu', 'memory', 'system']; const result = await queryInstance({ operation: { operation: 'system_information', - attributes: skip?.length ? - systemAttributes.filter(attr => !skip.includes(attr)) : - systemAttributes, + attributes: skip?.length ? systemAttributes.filter((attr) => !skip.includes(attr)) : systemAttributes, }, auth, url, @@ -52,76 +49,56 @@ export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo, }); } - // MEMORY - const totalMemory = skip.includes('memory') ? - parseFloat(cachedSystemInfo.totalMemory) : - result.memory.total / B2GB1024; - const usedMemory = skip.includes('memory') ? - parseFloat(cachedSystemInfo.usedMemory) : - result.memory.active / B2GB1024; - const freeMemory = skip.includes('memory') ? - parseFloat(cachedSystemInfo.freeMemory) : - result.memory.available / B2GB1024; - const memoryStatus = skip.includes('memory') ? - cachedSystemInfo.memoryStatus : - freeMemory / totalMemory < 0.1 ? - 'danger' : - freeMemory / totalMemory < 0.25 ? 'warning' : 'success'; + const totalMemory = skip.includes('memory') ? parseFloat(cachedSystemInfo.totalMemory) : result.memory.total / B2GB1024; + const usedMemory = skip.includes('memory') ? parseFloat(cachedSystemInfo.usedMemory) : result.memory.active / B2GB1024; + const freeMemory = skip.includes('memory') ? parseFloat(cachedSystemInfo.freeMemory) : result.memory.available / B2GB1024; + const memoryStatus = skip.includes('memory') + ? cachedSystemInfo.memoryStatus + : freeMemory / totalMemory < 0.1 + ? 'danger' + : freeMemory / totalMemory < 0.25 + ? 'warning' + : 'success'; // DISK - const totalDisk = skip.includes('disk') ? - parseFloat(cachedSystemInfo.totalDisk) : - result.system.platform === 'darwin' ? - result.disk.size[0].size / B2GB1000 : - !is_local ? - result.disk.size.find((disk) => disk.mount === '/home/ubuntu/hdb').size / B2GB1024 : - result.disk.size[0].size / B2GB1024; - - const usedDisk = skip.includes('disk') ? - parseFloat(cachedSystemInfo.usedDisk) : - result.system.platform === 'darwin' ? - result.disk.size.reduce((a, b) => a + b.used, 0) / B2GB1000 : - !is_local ? - result.disk.size.find((disk) => disk.mount === '/home/ubuntu/hdb').used / B2GB1024 : - result.disk.size.reduce((a, b) => a + b.used, 0) / B2GB1024; - - const freeDisk = skip.includes('disk') ? - parseFloat(cachedSystemInfo.freeDisk) : - totalDisk - usedDisk; - - const diskStatus = skip.includes('disk') ? - cachedSystemInfo.diskStatus : - freeDisk / totalDisk < 0.1 ? - 'danger' : freeDisk / totalDisk < 0.25 ? - 'warning' : 'success'; + const totalDisk = skip.includes('disk') + ? parseFloat(cachedSystemInfo.totalDisk) + : result.system.platform === 'darwin' + ? result.disk.size?.[0].size / B2GB1000 + : !is_local + ? result.disk.size?.find((disk) => disk.mount === '/home/ubuntu/hdb').size / B2GB1024 + : result.disk.size?.[0].size / B2GB1024; + + const usedDisk = skip.includes('disk') + ? parseFloat(cachedSystemInfo.usedDisk) + : result.system.platform === 'darwin' + ? result.disk.size?.reduce((a, b) => a + b.used, 0) / B2GB1000 + : !is_local + ? result.disk.size?.find((disk) => disk.mount === '/home/ubuntu/hdb').used / B2GB1024 + : result.disk.size?.reduce((a, b) => a + b.used, 0) / B2GB1024; + + const freeDisk = skip.includes('disk') ? parseFloat(cachedSystemInfo.freeDisk) : totalDisk - usedDisk; + + const diskStatus = skip.includes('disk') ? cachedSystemInfo.diskStatus : freeDisk / totalDisk < 0.1 ? 'danger' : freeDisk / totalDisk < 0.25 ? 'warning' : 'success'; // CPU - const cpuInfo = skip.includes('cpu') ? - cachedSystemInfo.cpuInfo : `${result.cpu.manufacturer} ${result.cpu.brand}`; - const cpuCores = skip.includes('cpu') ? - cachedSystemInfo.cpuCores : `${result.cpu.physicalCores} physical / ${result.cpu.cores} virtual`; - const cpuLoad = skip.includes('cpu') ? - parseFloat(cachedSystemInfo.cpuLoad) : result.cpu.current_load.currentLoad || result.cpu.current_load.currentload || 0; - const cpuStatus = skip.includes('cpu') ? - cachedSystemInfo.cpuStatus : - cpuLoad > 90 ? - 'danger' : cpuLoad > 75 ? - 'warning' : 'success'; + const cpuInfo = skip.includes('cpu') ? cachedSystemInfo.cpuInfo : `${result.cpu.manufacturer} ${result.cpu.brand}`; + const cpuCores = skip.includes('cpu') ? cachedSystemInfo.cpuCores : `${result.cpu.physicalCores} physical / ${result.cpu.cores} virtual`; + const cpuLoad = skip.includes('cpu') ? parseFloat(cachedSystemInfo.cpuLoad) : result.cpu.current_load.currentLoad || result.cpu.current_load.currentload || 0; + const cpuStatus = skip.includes('cpu') ? cachedSystemInfo.cpuStatus : cpuLoad > 90 ? 'danger' : cpuLoad > 75 ? 'warning' : 'success'; // NETWORK - const networkTransferred = skip.includes('network') ? - parseFloat(cachedSystemInfo.networkTransferred) : - result.network.stats.reduce((a, b) => a + b.tx_bytes, 0) / B2GB1000; - const networkReceived = skip.includes('network') ? - parseFloat(cachedSystemInfo.networkReceived) : - result.network.stats.reduce((a, b) => a + b.rx_bytes, 0) / B2GB1000; - const networkLatency = skip.includes('network') ? - parseFloat(cachedSystemInfo.networkLatency) : - result.network.latency.ms; - const networkLatencyStatus = skip.includes('network') ? - parseFloat(cachedSystemInfo.networkLatencyStatus) : - networkLatency > 1000 ? 'danger' : networkLatency > 500 ? 'warning' : 'success'; + const networkTransferred = skip.includes('network') ? parseFloat(cachedSystemInfo.networkTransferred) : result.network.stats.reduce((a, b) => a + b.tx_bytes, 0) / B2GB1000; + const networkReceived = skip.includes('network') ? parseFloat(cachedSystemInfo.networkReceived) : result.network.stats.reduce((a, b) => a + b.rx_bytes, 0) / B2GB1000; + const networkLatency = skip.includes('network') ? parseFloat(cachedSystemInfo.networkLatency) : result.network.latency.ms; + const networkLatencyStatus = skip.includes('network') + ? parseFloat(cachedSystemInfo.networkLatencyStatus) + : networkLatency > 1000 + ? 'danger' + : networkLatency > 500 + ? 'warning' + : 'success'; const systemInfo = { totalMemory: totalMemory?.toFixed(2), @@ -145,5 +122,4 @@ export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo, return instanceState.update((s) => { s.systemInfo = systemInfo; }); - };