Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d1f0c7e
New worker for iframe
DavidOnakDFO Feb 10, 2025
c516339
Update rendering code
DavidOnakDFO Feb 10, 2025
bcf9a32
Update rendering code again
DavidOnakDFO Feb 10, 2025
89ea115
Added print statment
DavidOnakDFO Feb 10, 2025
ab2a9f7
Added render condition for cavas ref existing
DavidOnakDFO Feb 10, 2025
ac83867
Added logging for canvas ref
DavidOnakDFO Feb 10, 2025
4f1476f
Added logging for canvas ref
DavidOnakDFO Feb 10, 2025
2714f34
Added logging for canvas ref
DavidOnakDFO Feb 10, 2025
a0de10b
Update Iframe.js
haydenDFO Feb 10, 2025
86ca232
Merge branch 'master' of https://pssi-prd-ocr-fm-rec-01.scm.dfo-sc2g-…
haydenDFO Feb 10, 2025
774da20
Added updated canvas check
DavidOnakDFO Feb 10, 2025
2d5cfe9
Merge branch 'master' of https://pssi-prd-ocr-fm-rec-01.scm.dfo-sc2g-…
haydenDFO Feb 10, 2025
1e59eb3
Update Iframe.js
haydenDFO Feb 10, 2025
7645ffc
Update Iframe.js
haydenDFO Feb 10, 2025
6d10193
Update Iframe.js
haydenDFO Feb 10, 2025
cf246ff
Update Iframe.js
haydenDFO Feb 10, 2025
1d81ef1
Update Iframe.js
haydenDFO Feb 10, 2025
cbd6952
Added updated canvas check
DavidOnakDFO Feb 10, 2025
0a7b048
Update Iframe.js
haydenDFO Feb 10, 2025
eddec54
Update Iframe.js
haydenDFO Feb 11, 2025
1757c64
Update Iframe.js
haydenDFO Feb 11, 2025
b3b4226
Update Iframe.js
haydenDFO Feb 11, 2025
86d1d8c
Update Iframe.js
haydenDFO Feb 11, 2025
a906137
Update Iframe.js
haydenDFO Feb 11, 2025
9353087
disable editable for original data view
haydenDFO Feb 11, 2025
4b02b34
fix original data view. add page reload after saving data.
haydenDFO Feb 11, 2025
76540ed
fix original view code
haydenDFO Feb 13, 2025
7ed6363
fix cancel edit to refresh; slide menu shadow style minor update
haydenDFO Feb 13, 2025
dbe24cb
fix max width to pdf
haydenDFO Feb 14, 2025
ad66be7
add editable to null field component. fix view json original data.
haydenDFO Feb 14, 2025
ec53ada
add null editable bg colour
haydenDFO Feb 14, 2025
c4f8787
Update HighlightColorSelector.js
haydenDFO Feb 14, 2025
bc9cae6
remove update form setting button
haydenDFO Feb 19, 2025
675234b
remove update form setting button
haydenDFO Feb 19, 2025
f61fe34
Improved error handeling
DavidOnak Feb 26, 2025
6b360c9
Selection box handeling and JSON view scroll
DavidOnak Feb 26, 2025
898cbb6
Fix file status retreival
DavidOnak Feb 26, 2025
03be89b
Updated readme with debugging note
DavidOnak Feb 26, 2025
7cf0a3c
Updated polygon box highlighting
DavidOnak Feb 26, 2025
2b23084
Fixed null field polygons with new delimitor
DavidOnak Feb 27, 2025
3357844
Added back Update Settings button (turns out we need it)
DavidOnakDFO Apr 17, 2025
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: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ Open [http://localhost:3000](http://localhost:3000) with your browser to see the

You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.

## Debugging
In order for the script to create individual polygon objects for all values in a nested object, a delimitor of ' -- ' is added. If any field name in a JSON file contains this demimitor, it will prevent the field from being updated.


1,297 changes: 1,232 additions & 65 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
},
"dependencies": {
"@azure/storage-blob": "^12.17.0",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@mui/material": "^6.4.6",
"@uiw/react-json-view": "^2.0.0-alpha.17",
"json-edit-react": "^1.8.1",
"next": "14.0.3",
Expand Down
27 changes: 26 additions & 1 deletion src/app/components/EditableField.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use client";
import styles from "./EditableField.module.css";
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
import { useState, useEffect, useRef } from "react";

const EditableField = ({
polygonKey,
Expand All @@ -8,11 +11,14 @@ const EditableField = ({
textAreaRefs,
handleUpdatePolygon,
editedPolygons,
highlightColor,
handleFocus = () => {},
handleBlur = () => {},
isReadOnly
}) => {

const [contentOld, setContentOld] = useState(content);

let flagStyle = '';
switch (flag) {
case 1:
Expand All @@ -27,7 +33,26 @@ const EditableField = ({
}

return (
<textarea
(content === 'selected' || content === 'unselected')?
<Select
sx={{
'&.Mui-focused .MuiOutlinedInput-notchedOutline': {
borderColor: highlightColor,
borderWidth: '1px',
}
}}
className={`${styles.dropdown} ${flagStyle}`}
ref={(ref) => (textAreaRefs.current[polygonKey] = ref)}
onFocus={()=>{handleFocus(polygonKey);}}
onBlur={handleBlur}
value={content}
onChange={(e) => handleUpdatePolygon(polygonKey, e.target.value)}
>
<MenuItem value={'unselected'}>unselected</MenuItem>
<MenuItem value={'selected'}>selected</MenuItem>
</Select>

:<textarea
onFocus={()=>{handleFocus(polygonKey);}}
onBlur={handleBlur}
ref={(ref) => (textAreaRefs.current[polygonKey] = ref)}
Expand Down
9 changes: 7 additions & 2 deletions src/app/components/EditableField.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
}

.flagged {
color: red;
color: red !important;
}

.edited {
color: green;
color: green !important;
}

.dropdown {
width: 100%;
height: 28px !important;
}
2 changes: 1 addition & 1 deletion src/app/components/NullField.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const NullField = ({
return polygon.map((row, rowIndex) =>
Object.entries(row).map(([nestedKey, nestedValue]) =>
renderNullField(
`${polygonKey} Row ${rowIndex+1} - ${nestedKey}`,
`${polygonKey} Row ${rowIndex+1} -- ${nestedKey}`,
nestedValue,
textAreaRefs
)
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Polygon = ({
return polygon.map((row, rowIndex) =>
Object.entries(row).map(([nestedKey, nestedValue]) =>
renderPolygon(
`${polygonKey} Row ${rowIndex+1} - ${nestedKey}`,
`${polygonKey} Row ${rowIndex+1} -- ${nestedKey}`,
nestedValue,
textAreaRefs
)
Expand Down Expand Up @@ -74,6 +74,7 @@ const Polygon = ({
polygonKey={polygonKey}
content={content}
flag={flag}
highlightColor={highlightColor}
textAreaRefs={textAreaRefs}
handleUpdatePolygon={handleUpdatePolygon}
editedPolygons={editedPolygons}
Expand Down
101 changes: 62 additions & 39 deletions src/app/components/homePage/FileNameList.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,68 @@ const FileNameList = ({ filesByFolder, fileStatus }) => {


//fetching the firle status
const asyncFetch = async () => {
setIsReload(true);
const Response = await fetch("/api/fileStatus", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(uniqueFolderNames),
});
if (!Response.ok) {
throw new Error(Response.statusText);
} else if (Response.status === 203) {
console.log("No data");
setIsReload(false);
} else {
const reader = Response.body.getReader();
const readData = async () => {
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
// `value` contains the chunk of data as a Uint8Array
const jsonString = new TextDecoder().decode(value);
// Parse the JSON string into an object
const dataObject = JSON.parse(jsonString);
fileStatus(dataObject);
setFileStatusJson(dataObject);
setIsReload(false);
}
} catch (error) {
console.error("Error reading response:", error);
} finally {
reader.releaseLock(); // Release the reader's lock when done
}
};

readData();
const asyncFetch = async () => {
// Prevent multiple simultaneous executions
if (isReload) return;

try {
setIsReload(true);

const response = await fetch("/api/fileStatus", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(uniqueFolderNames),
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
} else if (response.status === 203) {
console.log("No data");
setIsReload(false);
} else {
const reader = response.body.getReader();
const textDecoder = new TextDecoder();
let rawResponse = "";

const readData = async () => {
try {
let done = false;
while (!done) {
const { done: chunkDone, value } = await reader.read();
done = chunkDone;

if (value) {
rawResponse += textDecoder.decode(value, { stream: !done });
}
}

// Log the raw response for debugging
console.log("Raw response:", rawResponse);

// Attempt to parse the raw response
try {
const dataObject = JSON.parse(rawResponse);
fileStatus(dataObject);
setFileStatusJson(dataObject);
} catch (jsonError) {
console.error("JSON parse error:", jsonError);
console.error("Invalid JSON received:", rawResponse);
}
} catch (error) {
console.error("Error reading response:", error);
} finally {
reader.releaseLock();
setIsReload(false);
}
};

await readData();
}
} catch (error) {
console.error("Fetch error:", error);
setIsReload(false); // Ensure to reset the state even on error
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/files/Iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const Iframe = ({ fileName, folderName, pageWidth, json, polygonKeys, highlightC
if (coordsList && coordsList.every(coord => typeof coord === "object")) {
const coords = extractCoords(coordsList);
if (coords.every(coord => coord !== undefined)) {
const uniqueKey = `${rowKey} - ${columnKey}`;
const uniqueKey = `${rowKey} -- ${columnKey}`;
boxes.push({
key: uniqueKey,
coords: coords.map(coord => coord * DPI * scaleFactor),
Expand Down
2 changes: 1 addition & 1 deletion src/app/files/NullFieldList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const NullFieldList = ({ json, setHasNullField }) => {
return polygon.map((row, rowIndex) =>
Object.entries(row).map(([nestedKey, nestedValue]) =>
renderNullField(
`${key} Row ${rowIndex+1} - ${nestedKey}`,
`${key} Row ${rowIndex+1} -- ${nestedKey}`,
nestedValue
)
)
Expand Down
6 changes: 5 additions & 1 deletion src/app/files/PolygonList.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const PolygonList = ({
}, [json]);

const handleUpdatePolygon = (polygonKey, newValue) => {
console.log("PolygonKey: "+polygonKey)
console.log("New Value: "+newValue)
setEditedPolygons((prev) => new Set(prev).add(polygonKey));

const updatePolygon = (data, targetKeys) => {
Expand Down Expand Up @@ -137,8 +139,10 @@ const PolygonList = ({
return updatedData;
};

const keyList = polygonKey.split(" - ");
const keyList = polygonKey.split(" -- ");
console.log(keyList);
const updatedData = updatePolygon(json, keyList);
console.log(updatedData);

changeHandler(updatedData);
};
Expand Down
3 changes: 2 additions & 1 deletion src/app/files/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@
max-width: 480px;
height: 100%;
background-color: #fbf8f8;
padding: 20px;
padding: 20px;
overflow-y: auto;
transform: translateX(100%);
transition: transform 0.3s ease;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/viewJson/ViewJson.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.textarea {
max-width: 70vw;
margin-bottom: 100px;
margin-bottom: 25px;
}

.buttonWrap{
Expand Down
1 change: 0 additions & 1 deletion src/app/viewJson/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

align-items: center;
position: relative;

}
.note{
margin-top: 10px;
Expand Down