Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #811 correct typing on diskspace and check for NaN #812

Merged
merged 1 commit into from
Oct 22, 2024
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
6 changes: 3 additions & 3 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { defineComponent, onMounted, ref, Ref } from "vue";
import { getPrincipal, getVersion, logout, getFreeDiskSpace, getPermissions } from "@/api/api";
import { useRouter } from "vue-router";
import { ApiError } from "@/helpers/errors";
import { diskSpaceBelowThreshold, convertBytes } from "@/helpers/utils";
import { diskSpaceBelowThreshold, convertBytes, isEmpty } from "@/helpers/utils";

export default defineComponent({
name: "ArmadilloPortal",
Expand All @@ -55,7 +55,7 @@ export default defineComponent({
const username: Ref<string> = ref("");
const version: Ref<string> = ref("");
const router = useRouter();
const diskSpace: Ref<string> = ref("");
const diskSpace: Ref<number> = ref(NaN);

onMounted(() => {
loadUser();
Expand Down Expand Up @@ -121,7 +121,7 @@ export default defineComponent({
},
diskSpaceMessage() {
return `Disk space low (${
this.diskSpace === "" ? "" : convertBytes(this.diskSpace)
isEmpty(this.diskSpace) ? "" : convertBytes(this.diskSpace)
} remaining). Saving workspaces may not be possible and users risk losing workspace data. Either allocate more space or remove saved workspaces.`;
},
},
Expand Down
4 changes: 2 additions & 2 deletions ui/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ export async function createLinkFile(
return postJson(`/storage/projects/${viewProject}/objects/link`, data);
}

export async function getFreeDiskSpace() {
export async function getFreeDiskSpace(): Promise<number> {
return get("/actuator/metrics/disk.free").then((data) => {
return data.measurements[0].value;
return Number(data.measurements[0].value);
});
}
4 changes: 2 additions & 2 deletions ui/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ export function encodeUriComponent(component: string) {
}

export function diskSpaceBelowThreshold(diskSpace: number): boolean {
return diskSpace < 2147483648;
return !isEmpty(diskSpace)? diskSpace < 2147483648 : false;
}

export function isEmpty(variable: any): boolean {
// function will return true if empty string, empty object or empty array, else false
if (variable === undefined || variable === null || variable === '') {
if (variable === undefined || variable === null || variable === '' || Number.isNaN(variable)) {
return true;
} else if(typeof(variable) === 'object') {
if (Array.isArray(variable)) {
Expand Down
10 changes: 10 additions & 0 deletions ui/tests/unit/helpers/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ describe("utils", () => {
const actual = diskSpaceBelowThreshold(9214748364);
expect(actual).toEqual(false);
});

it("Return false", () => {
const actual = diskSpaceBelowThreshold(NaN);
expect(actual).toEqual(false);
});
});

describe("isEmpty", () => {
Expand Down Expand Up @@ -375,6 +380,11 @@ describe("utils", () => {
const actual = isEmpty(0);
expect(actual).toEqual(false);
});

it("Returns true when NaN", () => {
const actual = isEmpty(NaN);
expect(actual).toEqual(true);
});
});
});

Expand Down
Loading