Skip to content

Commit

Permalink
Merge pull request #812 from molgenis/fix/diskfull-message-always-shown
Browse files Browse the repository at this point in the history
fix: #811 correct typing on diskspace and check for NaN
  • Loading branch information
marikaris authored Oct 22, 2024
2 parents 44194cb + 49fd2ae commit e603d3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
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

0 comments on commit e603d3a

Please sign in to comment.