Skip to content

Commit 30bbe67

Browse files
Fixed cache button is not reachable issue when the image preview file… (#65)
* Fixed cache button is not a reachable issue when the image preview files are loaded, yaml file load error issue * linter edits --------- Co-authored-by: mansouralawi <[email protected]>
1 parent a57ae0d commit 30bbe67

File tree

6 files changed

+9348
-14621
lines changed

6 files changed

+9348
-14621
lines changed

client/package-lock.json

Lines changed: 9290 additions & 14571 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"antd": "^5.18.1",
1212
"axios": "^1.7.2",
1313
"buffer": "^6.0.3",
14-
"electron": "^27.3.11",
14+
"electron": "^31.2.1",
1515
"js-yaml": "^4.1.0",
1616
"localforage": "^1.10.0",
1717
"nth-check": "^2.1.1",

client/src/components/Dragger.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// global FileReader
2-
import React, { useContext, useState } from 'react'
2+
import React, { useContext, useState, useEffect } from 'react'
33
import { Button, Input, message, Modal, Space, Upload } from 'antd'
44
import { InboxOutlined } from '@ant-design/icons'
55
import { AppContext } from '../contexts/GlobalContext'
@@ -123,42 +123,31 @@ export function Dragger () {
123123
try {
124124
const buffer = new Uint8Array(event.target.result)
125125
console.log('Buffer length: ', buffer.length) // Log buffer length in bytes
126-
127126
const tiffPages = UTIF.decode(buffer)
128-
129127
// Check if tiffPages array is not empty
130128
if (tiffPages.length === 0) throw new Error('No TIFF pages found')
131-
132129
const firstPage = tiffPages[0]
133-
console.log('First page before decoding:', firstPage) // Log first page object before decodin
134-
130+
console.log('First page before decoding:', firstPage) // Log first page object before decoding
135131
// Ensure the firstPage has necessary tags before decoding
136132
if (!firstPage.t256 || !firstPage.t257) throw new Error('First page is missing essential tags (width and height)')
137-
138133
UTIF.decodeImage(buffer, firstPage) // firstPage before and after decoding, the result is same.
139134
console.log('TIFF first page after decoding: ', firstPage) // Log the first page object
140-
141135
// Extract width and height from the TIFF tags
142136
const width = firstPage.t256 ? firstPage.t256[0] : 0
143137
const height = firstPage.t257 ? firstPage.t257[0] : 0
144-
145138
// Check if width and height are valid
146139
if (width > 0 && height > 0) {
147140
const rgba = UTIF.toRGBA8(firstPage) // Uint8Array with RGBA pixels
148-
149141
// Create a canvas to draw the TIFF image
150142
const canvas = document.createElement('canvas')
151143
const ctx = canvas.getContext('2d')
152144
canvas.width = width
153145
canvas.height = height
154146
const imageData = ctx.createImageData(width, height)
155-
156147
imageData.data.set(rgba)
157148
ctx.putImageData(imageData, 0, 0)
158-
159149
const dataURL = canvas.toDataURL()
160150
console.log('Canvas data URL:', dataURL)
161-
162151
callback(dataURL)
163152
} else {
164153
console.error('TIFF image has invalid dimensions:', { width, height })
@@ -193,9 +182,22 @@ export function Dragger () {
193182
}
194183
}
195184

185+
// Solved the "clear the cache" button for image loading is not reachable when the image preview files are loaded.
196186
const listItemStyle = {
197-
width: '185px'
187+
display: 'inline-block',
188+
width: '185px',
189+
height: 'auto',
190+
verticalAlign: 'top'
198191
}
192+
useEffect(() => {
193+
// Get all elements with the class name "ant-upload-list-item-container"
194+
const uploadListItemContainers = document.querySelectorAll('.ant-upload-list-item-container')
195+
196+
// Apply styles to each element
197+
uploadListItemContainers.forEach((element) => {
198+
Object.assign(element.style, listItemStyle)
199+
})
200+
})
199201

200202
// when click or drag file to this area to upload, below function will be deployed.
201203
const handleBeforeUpload = (file) => {
@@ -236,7 +238,7 @@ export function Dragger () {
236238
Click or drag file to this area to upload
237239
</p>
238240
</Upload.Dragger>
239-
<Button type='default' onClick={handleClearCache}>
241+
<Button type='default' style={{ width: '185px' }} onClick={handleClearCache}>
240242
Clear File Cache
241243
</Button>
242244
<Modal

client/src/components/YamlFileUploader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// global FileReader
1+
// global FileReader
22
import React, { Fragment, useContext, useEffect, useState } from 'react'
33
import { Button, Col, message, Row, Slider, Upload } from 'antd'
44
import { UploadOutlined } from '@ant-design/icons'
@@ -111,7 +111,9 @@ const YamlFileUploader = (props) => {
111111
reader.onload = (e) => {
112112
try {
113113
const contents = e.target.result
114+
console.log('File contents:', contents)
114115
const yamlData = yaml.load(contents)
116+
console.log('Parsed YAML data:', yamlData)
115117

116118
if (type === 'training') {
117119
context.setTrainingConfig(
@@ -142,14 +144,18 @@ const YamlFileUploader = (props) => {
142144
)
143145

144146
context.setInferenceConfig(
145-
yaml.safeDump(yamlData, { indent: 2 }).replace(/^\s*\n/gm, '')
147+
// yaml.safeDump(yamlData, { indent: 2 }).replace(/^\s*\n/gm, '')
148+
yaml.dump(yamlData, { indent: 2 }).replace(/^\s*\n/gm, '')
149+
// yaml.safeDump has been removed in js-yaml version 4.
150+
// Solved 'Error reading YAML file' issue.
146151
)
147152
// these are for slider
148153
YAMLContext.setNumGPUs(yamlData.SYSTEM.NUM_GPUS)
149154
YAMLContext.setNumCPUs(yamlData.SYSTEM.NUM_CPUS)
150155
YAMLContext.setLearningRate(yamlData.SOLVER.BASE_LR)
151156
YAMLContext.setSolverSamplesPerBatch(yamlData.SOLVER.SAMPLES_PER_BATCH)
152157
} catch (error) {
158+
console.error('Error reading YAML file: ', error) // Add this line to log the error
153159
message.error('Error reading YAML file.')
154160
}
155161
}

client/src/views/Views.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,36 +87,36 @@ function Views () {
8787
minWidth: '90vw'
8888
}}
8989
>
90-
{isLoading ? (
91-
<div>Loading the viewer ...</div>
92-
) : (
93-
<React.Fragment>
94-
<Sider
90+
{isLoading
91+
? (<div>Loading the viewer ...</div>)
92+
: (
93+
<>
94+
<Sider
9595
// collapsible
96-
collapsed={collapsed}
97-
onCollapse={(value) => setCollapsed(value)}
98-
theme='light'
99-
collapsedWidth='0'
100-
>
101-
<DataLoader fetchNeuroglancerViewer={fetchNeuroglancerViewer} />
102-
</Sider>
103-
<Layout className='site-layout'>
104-
<Content
105-
style={{
106-
margin: '0 16px'
107-
}}
96+
collapsed={collapsed}
97+
onCollapse={(value) => setCollapsed(value)}
98+
theme='light'
99+
collapsedWidth='0'
108100
>
109-
<Menu
110-
onClick={onClick}
111-
selectedKeys={[current]}
112-
mode='horizontal'
113-
items={items}
114-
/>
115-
{renderMenu()}
116-
</Content>
117-
</Layout>
118-
</React.Fragment>
119-
) }
101+
<DataLoader fetchNeuroglancerViewer={fetchNeuroglancerViewer} />
102+
</Sider>
103+
<Layout className='site-layout'>
104+
<Content
105+
style={{
106+
margin: '0 16px'
107+
}}
108+
>
109+
<Menu
110+
onClick={onClick}
111+
selectedKeys={[current]}
112+
mode='horizontal'
113+
items={items}
114+
/>
115+
{renderMenu()}
116+
</Content>
117+
</Layout>
118+
</>
119+
)}
120120
</Layout>
121121
)
122122
}

client/src/views/Visualization.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function Visualization (props) {
5050
// Refresh the viewer URL by adding a refresh request token to it
5151
// The refresh request token is only for node.js to force refresh the element
5252
// The appended token will be ignored when rendering
53-
return {...viewer, viewer: viewer.viewer + '?refresh=' + new Date().getTime() }
53+
return { ...viewer, viewer: viewer.viewer + '?refresh=' + new Date().getTime() }
5454
}
5555
return viewer
5656
})
@@ -73,9 +73,9 @@ function Visualization (props) {
7373
<span>
7474
{viewer.title}
7575
<Button
76-
type='link'
77-
icon={<ReloadOutlined />}
78-
onClick={() => refreshViewer(viewer.key)}
76+
type='link'
77+
icon={<ReloadOutlined />}
78+
onClick={() => refreshViewer(viewer.key)}
7979
/>
8080

8181
</span>

0 commit comments

Comments
 (0)