Skip to content

Commit c6bd4b6

Browse files
committed
wip: Updated mfpc progress display
1 parent 709987b commit c6bd4b6

File tree

7 files changed

+148
-88
lines changed

7 files changed

+148
-88
lines changed

src/renderer/src/components/renderers/ReactComponentRenderer.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ const componentTypeRenderers = {
100100
renderComponent(componentSlot, <MicrofilePlusInstallationCheckDisplay {...props} />);
101101
},
102102
"process-status-table": (componentSlot) => {
103-
const props = { tableId: componentSlot.id };
103+
const tableId = componentSlot.id;
104+
const tableTitle = componentSlot.getAttribute("data-table-title");
105+
const props = { tableId: tableId, tableTitle: tableTitle };
104106
renderComponent(componentSlot, <ProcessStatusTable {...props} />);
105107
},
106108
};

src/renderer/src/components/tables/processStatusTable/index.jsx

+41-44
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,53 @@
1-
import { Table, Text, Loader, ScrollArea } from "@mantine/core";
1+
import { Card, Text, Loader, Progress, Group, Center } from "@mantine/core";
22
import { IconCheck } from "@tabler/icons-react";
33
import { useEffect, useRef } from "react";
44
import useGlobalStore from "../../../stores/globalStore";
55

6-
const ProcessStatusTable = ({ tableId }) => {
7-
const rowData = useGlobalStore((state) => state.processStatusTableData[tableId]) || [];
8-
const scrollAreaRef = useRef(null);
6+
const ProcessStatusTable = ({ tableId, tableTitle }) => {
7+
const { currentTask, taskProgress } =
8+
useGlobalStore((state) => state.progressElementData[tableId]) || {};
99

10-
const progressComponents = {
11-
loading: <Loader my="sm" />,
12-
success: <IconCheck color="green" stroke={3} />,
13-
};
14-
15-
const generateProgressDisplay = (progress) =>
16-
progressComponents[progress] || <Text>{progress}</Text>;
17-
18-
const rows = rowData.map((row) => (
19-
<tr key={row.rowId}>
20-
<td>
21-
<Text>{row.status}</Text>
22-
</td>
23-
<td style={{ textAlign: "center" }}>{generateProgressDisplay(row.progress)}</td>
24-
</tr>
25-
));
10+
console.log("currentTask", currentTask);
11+
console.log("taskProgress", taskProgress);
2612

27-
useEffect(() => {
28-
// Scroll to the bottom of the table when rowData changes
29-
if (scrollAreaRef.current) {
30-
scrollAreaRef.current.scrollTo({
31-
top: scrollAreaRef.current.scrollHeight,
32-
behavior: "smooth",
33-
});
34-
}
35-
}, [rowData]);
13+
const isNumberBetween0and100 = (num) => {
14+
return num > 0 && num < 100;
15+
};
3616

17+
console.log("isNumberBetween0and100", isNumberBetween0and100(taskProgress));
3718
return (
38-
<Table stickyHeader withTableBorder captionSide="top">
39-
<Table.Caption>
40-
<Text fw={700} size="xl">
41-
Process Status Table
19+
<Card
20+
withBorder
21+
radius="md"
22+
padding="lg"
23+
bg="var(--mantine-color-body)"
24+
style={{ width: "100%" }}
25+
>
26+
<Center mt="0px">
27+
<Text size="lg" fw={700}>
28+
{tableTitle}
29+
</Text>
30+
</Center>
31+
<Group>
32+
<Text size="lg" fw={500}>
33+
Task Progress:
4234
</Text>
43-
</Table.Caption>
44-
<ScrollArea h={400} viewportRef={scrollAreaRef} style={{ width: "100%" }}>
45-
<Table.Thead>
46-
<Table.Tr>
47-
<Table.Th>Status</Table.Th>
48-
<Table.Th style={{ textAlign: "center" }}>Progress</Table.Th>
49-
</Table.Tr>
50-
</Table.Thead>
51-
<Table.Tbody>{rows}</Table.Tbody>
52-
</ScrollArea>
53-
</Table>
35+
</Group>
36+
<Progress
37+
value={taskProgress}
38+
mt="md"
39+
size="lg"
40+
radius="xl"
41+
color={taskProgress === 0 ? "gray" : "blue"}
42+
animated={isNumberBetween0and100(taskProgress)}
43+
/>
44+
<Text size="lg" fw={500}>
45+
{taskProgress}% complete
46+
</Text>
47+
<Text size="md" fw={300}>
48+
{currentTask}
49+
</Text>
50+
</Card>
5451
);
5552
};
5653

src/renderer/src/scripts/advanced-features/compare-local-remote-dataset.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ while (!window.baseHtmlLoaded) {
44
}
55

66
import api from "../others/api/api";
7-
import { addRows, removeRows } from "../../stores/slices/tableDataSlice";
7+
import { addRows, removeRows } from "../../stores/slices/tableDataSlice.js";
88
import { clientError } from "../others/http-error-handler/error-handler";
99
import { swalConfirmAction, swalShowError, swalShowInfo } from "../utils/swal-utils";
1010

src/renderer/src/scripts/guided-mode/guided-curate-dataset.js

+68-39
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ import {
5353
import { clearBioLucidaCredentials } from "../../stores/slices/authSlice";
5454
import { setMicroFilePlusInstalledStatus } from "../../stores/slices/backgroundServicesSlice";
5555
import {
56-
addOrUpdateProcessStatusRow,
57-
removeProcessStatusRows,
58-
} from "../../stores/slices/tableDataSlice";
56+
setProgressElementData,
57+
removeProgressElementData,
58+
} from "../../stores/slices/progressElementSlice.js";
5959

6060
import "bootstrap-select";
6161
// import DragSort from '@yaireo/dragsort'
@@ -15858,11 +15858,10 @@ const hideDatasetMetadataGenerationTableRows = (destination) => {
1585815858
}
1585915859
};
1586015860
const convertMicroscopyImagesViaMfPlus = async () => {
15861-
addOrUpdateProcessStatusRow(
15862-
"guided-div-microscopy-image-conversion-status-table",
15863-
"microfileplus-installation-status",
15861+
setProgressElementData(
15862+
"guided-progress-display-microscopy-image-conversion",
1586415863
"Making sure MicroFile+ is installed",
15865-
"loading"
15864+
0
1586615865
);
1586715866
// wait for 10000 seconds
1586815867
await new Promise((resolve) => setTimeout(resolve, 5000));
@@ -15875,55 +15874,85 @@ const convertMicroscopyImagesViaMfPlus = async () => {
1587515874
`SODA was unable to detect MicroFile+ on your machine. Please install MicroFile+ and try again.`
1587615875
);
1587715876
}
15878-
addOrUpdateProcessStatusRow(
15879-
"guided-div-microscopy-image-conversion-status-table",
15880-
"microfileplus-installation-status",
15881-
"SODA detected MicroFile+ installation!",
15882-
"success"
15883-
);
15877+
1588415878
console.log("Converting microscopy images via MicroFilePlus");
1588515879
const microscopyImagesToConvert = window.sodaJSONObj["confirmed-microscopy-images"];
1588615880
const microscopyImagesToConvertCount = microscopyImagesToConvert.length;
1588715881

1588815882
let imageConvertedCount = 1;
1588915883
for await (const image of microscopyImagesToConvert) {
1589015884
console.log(`Converting image: ${image.filePath}`);
15891-
addOrUpdateProcessStatusRow(
15892-
"guided-div-microscopy-image-conversion-status-table",
15893-
`microscopy-image-conversion-progress-count`,
15894-
`Converting and adding metadata to images`,
15895-
`${imageConvertedCount}/${microscopyImagesToConvert.length}`
15885+
15886+
const progressPercentage = Math.round(
15887+
(imageConvertedCount / microscopyImagesToConvertCount) * 100
1589615888
);
15897-
addOrUpdateProcessStatusRow(
15898-
"guided-div-microscopy-image-conversion-status-table",
15899-
`${image.filePath}-conversion-status`,
15889+
15890+
setProgressElementData(
15891+
"guided-progress-display-microscopy-image-conversion",
1590015892
`Converting image: ${image.filePath}`,
15901-
"loading"
15893+
progressPercentage
1590215894
);
15903-
// wait for 1 second
15895+
// wait for 5 second
1590415896
await new Promise((resolve) => setTimeout(resolve, 1000));
15905-
addOrUpdateProcessStatusRow(
15906-
"guided-div-microscopy-image-conversion-status-table",
15907-
`${image.filePath}-conversion-status`,
15908-
`Successfully converted image: ${image.filePath}`,
15909-
"success"
15910-
);
15897+
1591115898
imageConvertedCount++;
1591215899
}
1591315900

15914-
addOrUpdateProcessStatusRow(
15915-
"guided-div-microscopy-image-conversion-status-table",
15916-
"Converting microscopy images with MicroFile+",
15917-
`0/${microscopyImagesToConvertCount}`
15901+
setProgressElementData(
15902+
"guided-progress-display-microscopy-image-conversion",
15903+
"Microscopy images successfully converted",
15904+
100
1591815905
);
15919-
// wait for 10000 seconds
15920-
await new Promise((resolve) => setTimeout(resolve, 10000000));
1592115906
};
1592215907

1592315908
const uploadMicroscopyImagesToBioLucida = async () => {
15909+
setProgressElementData(
15910+
"guided-progress-display-microscopy-image-conversion",
15911+
"Making sure MicroFile+ is installed",
15912+
0
15913+
);
15914+
// wait for 10000 seconds
15915+
await new Promise((resolve) => setTimeout(resolve, 5000));
15916+
// Ensure that MicroFile+ is installed on the user's machine
15917+
const req = await client.get("/image_processing/is_microfileplus_installed");
15918+
const { status: microFilePlusIsInstalled } = req.data;
15919+
15920+
if (!microFilePlusIsInstalled) {
15921+
throw new Error(
15922+
`SODA was unable to detect MicroFile+ on your machine. Please install MicroFile+ and try again.`
15923+
);
15924+
}
15925+
1592415926
console.log("Converting microscopy images via MicroFilePlus");
15925-
// wait for 10 seconds
15926-
await new Promise((resolve) => setTimeout(resolve, 10000));
15927+
const microscopyImagesToConvert = window.sodaJSONObj["confirmed-microscopy-images"];
15928+
const microscopyImagesToConvertCount = microscopyImagesToConvert.length;
15929+
15930+
let imageConvertedCount = 1;
15931+
for await (const image of microscopyImagesToConvert) {
15932+
console.log(`Converting image: ${image.filePath}`);
15933+
15934+
const progressPercentage = Math.round(
15935+
(imageConvertedCount / microscopyImagesToConvertCount) * 100
15936+
);
15937+
15938+
setProgressElementData(
15939+
"guided-progress-display-microscopy-image-conversion",
15940+
`Converting image: ${image.filePath}`,
15941+
progressPercentage
15942+
);
15943+
// wait for 5 second
15944+
await new Promise((resolve) => setTimeout(resolve, 1000));
15945+
15946+
imageConvertedCount++;
15947+
}
15948+
15949+
setProgressElementData(
15950+
"guided-progress-display-microscopy-image-conversion",
15951+
"Microscopy images successfully converted",
15952+
100
15953+
);
15954+
// wait for 10000 seconds
15955+
await new Promise((resolve) => setTimeout(resolve, 10000000));
1592715956
};
1592815957

1592915958
const guidedPennsieveDatasetUpload = async () => {
@@ -15949,12 +15978,12 @@ const guidedPennsieveDatasetUpload = async () => {
1594915978
}
1595015979

1595115980
// Display the MicroFilePlus conversion status table
15952-
window.unHideAndSmoothScrollToElement("guided-div-microscopy-image-conversion-status-table");
15981+
window.unHideAndSmoothScrollToElement("guided-progress-display-microscopy-image-conversion");
1595315982

1595415983
await convertMicroscopyImagesViaMfPlus();
1595515984

1595615985
//Display the BioLucida Image upload table
15957-
window.unHideAndSmoothScrollToElement("guided-div-biolucida-image-upload-status-table");
15986+
window.unHideAndSmoothScrollToElement("guided-progress-display-biolucida-image-upload");
1595815987
await uploadMicroscopyImagesToBioLucida();
1595915988

1596015989
// sleep for 20 seconds

src/renderer/src/sections/guided_mode/guided_curate_dataset.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -5636,12 +5636,13 @@ <h1 class="text-sub-step-title">Generating your dataset on Pennsieve</h1>
56365636
<div
56375637
class="guided--section hidden mt-lg guided-upload-table"
56385638
data-component-type="process-status-table"
5639-
id="guided-div-microscopy-image-conversion-status-table"
5639+
data-table-title="Converting Microscopy Images using MicroFile+"
5640+
id="guided-progress-display-microscopy-image-conversion"
56405641
></div>
56415642
<div
56425643
class="guided--section hidden mt-lg guided-upload-table"
56435644
data-component-type="process-status-table"
5644-
id="guided-div-biolucida-image-upload-status-table"
5645+
id="guided-progress-display-biolucida-image-upload"
56455646
></div>
56465647
<div
56475648
class="guided--section hidden mt-lg guided-upload-table"

src/renderer/src/stores/globalStore.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { microscopyImageSlice } from "./slices/microscopyImageSlice";
77
import { authSlice } from "./slices/authSlice";
88
import { microscopyImageMetadataSlice } from "./slices/microscopyImageMetadataSlice";
99
import { bioLucidaSlice } from "./slices/bioLucidaSlice";
10-
import { singleColumnTableSlice } from "./slices/tableDataSlice";
10+
import { singleColumnTableSlice } from "./slices/tableDataSlice.js";
1111
import { backgroundServicesSlice } from "./slices/backgroundServicesSlice";
12+
import { progressElementSlice } from "./slices/progressElementSlice";
1213

1314
const useGlobalStore = create(
1415
immer((...a) => ({
@@ -21,6 +22,7 @@ const useGlobalStore = create(
2122
...bioLucidaSlice(...a),
2223
...singleColumnTableSlice(...a),
2324
...backgroundServicesSlice(...a),
25+
...progressElementSlice(...a),
2426
}))
2527
);
2628

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import useGlobalStore from "../globalStore"; // Import the global state store
2+
import { produce } from "immer"; // produce makes working with nested state modifications easier
3+
4+
export const progressElementSlice = (set) => ({
5+
progressElementData: {},
6+
});
7+
8+
export const setProgressElementData = (progressElementId, currentTask, taskProgress) => {
9+
useGlobalStore.setState(
10+
produce((state) => {
11+
// Initialize the array if it does not exist
12+
if (!state.progressElementData[progressElementId]) {
13+
state.progressElementData[progressElementId] = {};
14+
}
15+
16+
// Update the progress of the current task
17+
state.progressElementData[progressElementId]["currentTask"] = currentTask;
18+
state.progressElementData[progressElementId]["taskProgress"] = taskProgress;
19+
})
20+
);
21+
};
22+
23+
export const removeProgressElementData = (progressElementId) => {
24+
useGlobalStore.setState(
25+
produce((state) => {
26+
state.progressElementData[progressElementId] = {};
27+
})
28+
);
29+
};

0 commit comments

Comments
 (0)