Skip to content

Commit 8af64a7

Browse files
authored
Merge pull request #1354 from dodona-edu/fix/webui-server-bugs
Fix bugs in server web UI
2 parents c6fbd19 + 6be6444 commit 8af64a7

File tree

12 files changed

+78
-49
lines changed

12 files changed

+78
-49
lines changed

api/shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ pkgs ? import <nixpkgs> { }, system ? builtins.currentSystem, ... }:
22
let
3-
dev = fetchTarball "https://github.com/chvp/devshell/archive/main.tar.gz";
3+
dev = fetchTarball "https://github.com/numtide/devshell/archive/main.tar.gz";
44
devshell = pkgs.devshell or (import dev { inherit system; });
55
ruby = pkgs.ruby_3_2;
66
in

flake.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
devshell = {
1212
url = "github:numtide/devshell";
1313
inputs = {
14-
systems.follows = "systems";
1514
nixpkgs.follows = "nixpkgs";
15+
flake-utils.follows = "flake-utils";
1616
};
1717
};
1818
};

web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"dev": "vite",
14-
"dev:server": "VITE_MODE=server vite",
14+
"dev:server": "VITE_API_URL=http://localhost:3000 VITE_MODE=server vite",
1515
"build": "vue-tsc --noEmit && vite build",
1616
"build:server": "VITE_MODE=server vite build",
1717
"preview": "vite preview",

web/src/api/stores/api.store.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ export const useApiStore = defineStore("api", () => {
6868
// Re-hydrate the API stores when the anonymous value changes.
6969
watch(isAnonymous, () => fileStore.anonymize());
7070
// Re-hydrate the API stores when the url value changes.
71-
watch(dataUrl, () => hydrate());
71+
watch(dataUrl, () => {
72+
if (dataUrl) {
73+
hydrate();
74+
}
75+
});
7276

7377
return {
7478
url: dataUrl,

web/src/components/clustering/ClustersTable.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const maxWidth = computed(() => {
123123
124124
// When a row is clicked.
125125
const rowClicked = (e: Event, value: any): void => {
126-
router.push({ name: "Cluster", params: { clusterId: value.item.id } });
126+
router.push({ name: "Cluster", params: { clusterId: String(value.item.id) } });
127127
};
128128
</script>
129129

web/src/components/upload/UploadFormCard.vue

+16-7
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,21 @@ const acceptRules = [
9595
const uploadProgress = shallowRef(25);
9696
9797
// Report
98-
const reportActiveId = shallowRef<string>();
99-
const reportActive = computed(() =>
100-
reports.getReportById(reportActiveId.value)
101-
);
102-
const reportRoute = computed(() =>
103-
reports.getReportRouteById(reportActiveId.value)
104-
);
98+
const reportActiveId = shallowRef<string | undefined>();
99+
const reportActive = computed(() => {
100+
if (reportActiveId.value) {
101+
return reports.getReportById(reportActiveId.value);
102+
} else {
103+
return undefined;
104+
}
105+
});
106+
const reportRoute = computed(() => {
107+
if (reportActiveId.value) {
108+
return reports.getReportRouteById(reportActiveId.value);
109+
} else {
110+
return undefined;
111+
}
112+
});
105113
106114
// Clear the form.
107115
const clearForm = (): void => {
@@ -276,6 +284,7 @@ watch(
276284
},
277285
{
278286
immediate: true,
287+
deep: true,
279288
}
280289
);
281290
</script>

web/src/components/upload/UploadsTable.vue

+8-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ const items = computed(() =>
4747
}))
4848
);
4949
50-
const selectedReportId = ref<string>();
51-
const selectedReport = computed(() =>
52-
reports.getReportById(selectedReportId.value)
53-
);
50+
const selectedReportId = ref<string | undefined>();
51+
const selectedReport = computed(() => {
52+
if (selectedReportId.value) {
53+
return reports.getReportById(selectedReportId.value)
54+
} else {
55+
return undefined;
56+
}
57+
});
5458
5559
const infoDialog = ref(false);
5660
const deleteDialog = ref(false);

web/src/composables/useAppMode.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export function useAppMode() {
1313
// URL to the report.
1414
const reportUrl = computed(() => {
1515
if (import.meta.env.VITE_MODE === "server") {
16-
return reports.getReportUrlById(reports.currentReport?.reportId);
16+
if (reports.currentReport) {
17+
return reports.getReportUrlById(reports.currentReport.reportId);
18+
} else {
19+
return undefined;
20+
}
1721
} else {
1822
return DATA_URL;
1923
}
@@ -22,7 +26,7 @@ export function useAppMode() {
2226
// URL to the data.
2327
const dataUrl = computed(() => {
2428
if (import.meta.env.VITE_MODE === "server") {
25-
return `${reportUrl.value}/data`;
29+
return reportUrl.value ? `${reportUrl.value}/data` : undefined;
2630
} else {
2731
return DATA_URL;
2832
}

web/src/router/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const routes = [
4949
component: () => import("@/views/analysis/clusters.vue"),
5050
},
5151
{
52-
path: "/clusters/:clusterId",
52+
path: "clusters/:clusterId",
5353
name: "Cluster",
5454
component: () => import("@/views/analysis/cluster.vue"),
5555
},
@@ -85,4 +85,5 @@ const router = createRouter({
8585
routes,
8686
});
8787

88+
8889
export default router;

web/src/stores/reports.store.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { UploadReport } from "@/types/uploads/UploadReport";
2-
import { useLocalStorage } from "@vueuse/core";
3-
import { defineStore } from "pinia";
4-
import { computed, onMounted } from "vue";
5-
import { useRoute } from "vue-router";
1+
import {UploadReport} from "@/types/uploads/UploadReport";
2+
import {useLocalStorage} from "@vueuse/core";
3+
import {defineStore} from "pinia";
4+
import {computed, onMounted} from "vue";
5+
import {useRoute} from "vue-router";
66
import slugify from "slugify";
7-
import axios, { AxiosError } from "axios";
7+
import axios, {AxiosError} from "axios";
88

99
export const useReportsStore = defineStore("reports", () => {
1010
// List of uploaded reports in localstorage.
@@ -41,17 +41,17 @@ export const useReportsStore = defineStore("reports", () => {
4141
}
4242

4343
// Get a report in the list by reportId.
44-
function getReportById(reportId: string | undefined) {
44+
function getReportById(reportId: string) {
4545
return reports.value.find((r) => r.reportId === reportId);
4646
}
4747

4848
// Get a report in the list by referenceId.
49-
function getReportByReferenceId(referenceId: string | undefined) {
49+
function getReportByReferenceId(referenceId: string) {
5050
return reports.value.find((r) => r.referenceId === referenceId);
5151
}
5252

5353
// Get the route for a given report id.
54-
function getReportRouteById(reportId: string | undefined) {
54+
function getReportRouteById(reportId: string) {
5555
const report = getReportById(reportId);
5656

5757
// If no report is found, return the home page.
@@ -64,28 +64,28 @@ export const useReportsStore = defineStore("reports", () => {
6464
return {
6565
name: "Overview",
6666
params: {
67-
referenceId: report?.referenceId,
67+
referenceId: report.referenceId,
6868
},
6969
};
7070
}
7171

7272
// Get the share route for a given report id.
73-
function getReportShareRouteById(reportId: string | undefined) {
73+
function getReportShareRouteById(reportId: string) {
7474
return {
7575
name: "Share",
7676
params: {
77-
reportId: reportId ?? "",
77+
reportId: reportId,
7878
},
7979
};
8080
}
8181

8282
// Delete a report by reportId.
83-
function deleteReportById(reportId: string | undefined) {
83+
function deleteReportById(reportId: string) {
8484
reports.value = reports.value.filter((r) => r.reportId !== reportId);
8585
}
8686

8787
// Get the URL for a given report id.
88-
const getReportUrlById = (reportId: string | undefined) => {
88+
const getReportUrlById = (reportId: string) => {
8989
return `${import.meta.env.VITE_API_URL}/reports/${reportId}`;
9090
};
9191

@@ -117,8 +117,14 @@ export const useReportsStore = defineStore("reports", () => {
117117
const route = useRoute();
118118
const currentReport = computed(() => {
119119
const reportId = route.params.reportId as string | undefined;
120+
if (reportId) {
121+
return getReportById(reportId);
122+
}
120123
const referenceId = route.params.referenceId as string | undefined;
121-
return getReportById(reportId) ?? getReportByReferenceId(referenceId);
124+
if (referenceId) {
125+
return getReportByReferenceId(referenceId);
126+
}
127+
return undefined;
122128
});
123129

124130
return {

web/src/views/upload/share.vue

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,20 @@ onMounted(async () => {
1919
2020
// If the report reference does not exist, generate a new one.
2121
if (!report) {
22+
2223
try {
2324
// Fetch the report from the server.
24-
const response = await axios.get(reports.getReportUrlById(reportId));
25+
const url = reports.getReportUrlById(reportId);
26+
const response = await axios.get(url);
2527
const data = response.data;
26-
2728
// Create the uploaded report.
2829
const report: Partial<UploadReport> = {
2930
reportId,
3031
date: data["created_at"] ?? new Date().toISOString(),
3132
name: data["name"] ?? "Report",
3233
status: data["status"],
33-
statusUrl: data["url"],
34-
response: data["response"],
34+
statusUrl: url,
35+
response: response,
3536
isFromSharing: true,
3637
};
3738
@@ -42,9 +43,9 @@ onMounted(async () => {
4243
return;
4344
}
4445
}
45-
46+
const reportRoute = reports.getReportRouteById(reportId);
4647
// Go to the report.
47-
router.push(reports.getReportRouteById(reportId));
48+
router.push(reportRoute);
4849
});
4950
</script>
5051

0 commit comments

Comments
 (0)