Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const compat = new FlatCompat({
export default [...fixupConfigRules(
compat.extends("react-app", "airbnb", "plugin:jsx-a11y/recommended", "prettier"),
), {
// root: true,
plugins: {
"jsx-a11y": fixupPluginRules(jsxA11Y),
prettier
Expand All @@ -40,7 +41,7 @@ export default [...fixupConfigRules(
"no-underscore-dangle": ["warn", {
allow: ["_kmq", "_kmk"],
}],

"no-unsafe-optional-chaining": 0,
"jsx-a11y/label-has-associated-control": 0,
"react/jsx-no-bind": 0,

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harperdb-studio",
"version": "4.5.6",
"version": "4.5.7",
"description": "A UI for HarperDB",
"deploymentUrl": "studio.harperdb.io",
"private": true,
Expand All @@ -10,9 +10,9 @@
"start": "HTTPS=true SSL_CRT_FILE=./.cert/cert.pem SSL_KEY_FILE=./.cert/key.pem react-scripts start",
"start:local": "REACT_APP_LOCALSTUDIO=true HTTPS=true SSL_CRT_FILE=./.cert/cert.pem SSL_KEY_FILE=./.cert/key.pem react-scripts start",
"docker": "HTTPS=false react-scripts start",
"build:stage": "GENERATE_SOURCEMAP=false PUBLIC_URL=https://dbjxbnqel2bw9.cloudfront.net react-scripts build",
"build:prod": "GENERATE_SOURCEMAP=false PUBLIC_URL=https://ds5zz9rfvzuta.cloudfront.net react-scripts build",
"build:local": "BUILD_PATH=./build-local GENERATE_SOURCEMAP=false REACT_APP_LOCALSTUDIO=true react-scripts build",
"build:stage": "DISABLE_ESLINT_PLUGIN=true GENERATE_SOURCEMAP=false PUBLIC_URL=https://dbjxbnqel2bw9.cloudfront.net react-scripts build",
"build:prod": "DISABLE_ESLINT_PLUGIN=true GENERATE_SOURCEMAP=false PUBLIC_URL=https://ds5zz9rfvzuta.cloudfront.net react-scripts build",
"build:local": "DISABLE_ESLINT_PLUGIN=true BUILD_PATH=./build-local GENERATE_SOURCEMAP=false REACT_APP_LOCALSTUDIO=true react-scripts build",
"lint-dev": "eslint --fix src && npx stylelint --fix \"src/**/*.scss\"",
"lint-prod": "eslint --fix src"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export default function EditorMenu({ children }) {
{children.map(
(child) =>
child && (
<li className="editor-menu-item" key={crypto.randomUUID()}>
<li className="editor-menu-item" key={crypto.randomUUID?.() ?? Math.random().toString().slice(2)}>
{child}
</li>
),
)
)}
</ul>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function FileMenu({ children }) {
{children.map(
(child) =>
child && (
<li className="file-menu-item" key={crypto.randomUUID()}>
<li className="file-menu-item" key={crypto.randomUUID?.() ?? Math.random().toString().slice(2)}>
{child}
</li>
),
)
)}
</ul>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/instances/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useEffect, useState, useCallback } from 'react';
import React, { useEffect, useCallback } from 'react';
import { Row } from 'reactstrap';
import { useParams, useNavigate } from 'react-router-dom';
import { useStoreState } from 'pullstate';
import { useAlert } from 'react-alert';
import useAsyncEffect from 'use-async-effect';
import useInterval from 'use-interval';

import config from '../../config';
Expand Down Expand Up @@ -43,6 +42,7 @@ function InstancesIndex() {

useEffect(() => {
refreshInstances();
// eslint-disable-next-line
}, [auth, customer_id, products, regions, subscriptions]);

useEffect(() => {
Expand All @@ -52,7 +52,7 @@ function InstancesIndex() {
alert.error('You have been removed from this organization');
navigate('/');
}
}, [action, alert, isOrgUser]);
}, [action, alert, isOrgUser, navigate]);

useEffect(() => {
if (auth && customer_id) {
Expand Down
4 changes: 0 additions & 4 deletions src/components/instances/list/CardFront.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,12 @@ function CardFront({ compute_stack_id, instance_id, url, status, instance_name,
setProcessing(true);

const registrationResult = await handleInstanceRegistration({
auth,
customer_id,
instanceAuth,
url,
is_local,
is_ssl,
cloud_provider,
instance_id,
compute_stack_id,
compute,
instance_name,
status: instanceData.status,
});
Expand Down
4 changes: 2 additions & 2 deletions src/functions/api/instance/getComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
116 changes: 46 additions & 70 deletions src/functions/api/instance/updateSystemInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -145,5 +122,4 @@ export default async ({ auth, url, signal, refresh, is_local, cachedSystemInfo,
return instanceState.update((s) => {
s.systemInfo = systemInfo;
});

};
2 changes: 1 addition & 1 deletion src/functions/instances/handleInstanceRegistration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import registrationInfo from '../api/instance/registrationInfo';
import handleCloudInstanceUsernameChange from './handleCloudInstanceUsernameChange';

export default async ({ auth, customer_id, instanceAuth, url, is_local, is_ssl, cloud_provider, instance_id, compute_stack_id, compute, status }) => {
export default async ({ instanceAuth, url, is_local, is_ssl, cloud_provider, instance_id, status }) => {
try {
let registration = await registrationInfo({ auth: instanceAuth, url });

Expand Down