Skip to content

Commit 4d048f1

Browse files
Merge pull request #122 from ImagingDataCommons/update/slim
Update slim to lts upstream
2 parents 8e64e10 + f3600d1 commit 4d048f1

File tree

6 files changed

+214
-83
lines changed

6 files changed

+214
-83
lines changed

src/App.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ interface AppProps {
158158

159159
interface AppState {
160160
clients: { [sopClassUID: string]: DicomWebManager }
161+
defaultClients: { [sopClassUID: string]: DicomWebManager }
161162
user?: User
162163
isLoading: boolean
163164
redirectTo?: string
@@ -249,13 +250,16 @@ class App extends React.Component<AppProps, AppState> {
249250
message.config({ duration: 5 })
250251
this.addGcpSecondaryAnnotationServer(props.config)
251252

253+
const defaultClients = _createClientMapping({
254+
baseUri,
255+
gcpBaseUrl: props.config.gcpBaseUrl ?? 'https://healthcare.googleapis.com/v1',
256+
settings: props.config.servers,
257+
onError: this.handleDICOMwebError
258+
})
259+
252260
this.state = {
253-
clients: _createClientMapping({
254-
baseUri,
255-
gcpBaseUrl: props.config.gcpBaseUrl ?? 'https://healthcare.googleapis.com/v1',
256-
settings: props.config.servers,
257-
onError: this.handleDICOMwebError
258-
}),
261+
clients: defaultClients,
262+
defaultClients,
259263
isLoading: true,
260264
wasAuthSuccessful: false
261265
}
@@ -290,6 +294,11 @@ class App extends React.Component<AppProps, AppState> {
290294

291295
handleServerSelection ({ url }: { url: string }): void {
292296
console.info('select DICOMweb server: ', url)
297+
if (url === '' || window.localStorage.getItem('slim_server_selection_mode') === 'default') {
298+
this.setState({ clients: this.state.defaultClients })
299+
return
300+
}
301+
window.localStorage.setItem('slim_selected_server', url)
293302
const tmpClient = new DicomWebManager({
294303
baseUri: '',
295304
settings: [{
@@ -334,11 +343,11 @@ class App extends React.Component<AppProps, AppState> {
334343
}
335344
const storedPath = window.localStorage.getItem('slim_path')
336345
const storedSearch = window.localStorage.getItem('slim_search')
337-
if (storedPath != null) {
346+
if (storedPath !== null && storedPath !== '') {
338347
const currentPath = window.location.pathname
339348
if (storedPath !== currentPath) {
340349
let path = storedPath
341-
if (storedSearch != null) {
350+
if (storedSearch !== null && storedSearch !== '') {
342351
path += storedSearch
343352
}
344353
window.location.href = path
@@ -384,10 +393,17 @@ class App extends React.Component<AppProps, AppState> {
384393

385394
componentDidMount (): void {
386395
const path = window.localStorage.getItem('slim_path')
387-
if (path == null) {
396+
if (path === null || path === '') {
388397
window.localStorage.setItem('slim_path', window.location.pathname)
389398
window.localStorage.setItem('slim_search', window.location.search)
390399
}
400+
401+
// Restore cached server selection if it exists
402+
const cachedServerUrl = window.localStorage.getItem('slim_selected_server')
403+
if (cachedServerUrl !== null && cachedServerUrl !== '') {
404+
this.handleServerSelection({ url: cachedServerUrl })
405+
}
406+
391407
this.signIn()
392408
}
393409

@@ -454,6 +470,7 @@ class App extends React.Component<AppProps, AppState> {
454470
showServerSelectionButton={false}
455471
appConfig={this.props.config}
456472
clients={this.state.clients}
473+
defaultClients={this.state.defaultClients}
457474
/>
458475
<Layout.Content style={layoutContentStyle}>
459476
<FaSpinner />
@@ -485,6 +502,8 @@ class App extends React.Component<AppProps, AppState> {
485502
onUserLogout={isLogoutPossible ? onLogout : undefined}
486503
showServerSelectionButton={enableServerSelection}
487504
appConfig={this.props.config}
505+
clients={this.state.clients}
506+
defaultClients={this.state.defaultClients}
488507
/>
489508
<Layout.Content style={layoutContentStyle}>
490509
{worklist}
@@ -504,6 +523,8 @@ class App extends React.Component<AppProps, AppState> {
504523
onUserLogout={isLogoutPossible ? onLogout : undefined}
505524
showServerSelectionButton={enableServerSelection}
506525
appConfig={this.props.config}
526+
clients={this.state.clients}
527+
defaultClients={this.state.defaultClients}
507528
/>
508529
<Layout.Content style={layoutContentStyle}>
509530
<ParametrizedCaseViewer
@@ -528,6 +549,8 @@ class App extends React.Component<AppProps, AppState> {
528549
onUserLogout={isLogoutPossible ? onLogout : undefined}
529550
showServerSelectionButton={enableServerSelection}
530551
appConfig={this.props.config}
552+
clients={this.state.clients}
553+
defaultClients={this.state.defaultClients}
531554
/>
532555
<Layout.Content style={layoutContentStyle}>
533556
<ParametrizedCaseViewer
@@ -552,6 +575,8 @@ class App extends React.Component<AppProps, AppState> {
552575
onUserLogout={isLogoutPossible ? onLogout : undefined}
553576
showServerSelectionButton={enableServerSelection}
554577
appConfig={this.props.config}
578+
clients={this.state.clients}
579+
defaultClients={this.state.defaultClients}
555580
/>
556581
Logged out
557582
</Layout>

src/components/CaseViewer.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ interface ReferencedSlideResult {
4444
metadata: NaturalizedInstance
4545
}
4646

47+
const findSeriesSlide = (slides: Slide[], seriesInstanceUID: string): Slide | undefined => {
48+
return slides.find((slide: Slide) => {
49+
return slide.seriesInstanceUIDs.find((uid: string) => {
50+
return uid === seriesInstanceUID
51+
})
52+
})
53+
}
54+
4755
function ParametrizedSlideViewer ({
4856
clients,
4957
slides,
@@ -68,13 +76,17 @@ function ParametrizedSlideViewer ({
6876
}): JSX.Element | null {
6977
const { studyInstanceUID = '', seriesInstanceUID = '' } = useParams<{ studyInstanceUID: string, seriesInstanceUID: string }>()
7078
const location = useLocation()
71-
const [selectedSlide, setSelectedSlide] = useState(slides.find((slide: Slide) => {
72-
return slide.seriesInstanceUIDs.find((uid: string) => {
73-
return uid === seriesInstanceUID
74-
})
75-
}))
79+
80+
const [selectedSlide, setSelectedSlide] = useState(findSeriesSlide(slides, seriesInstanceUID))
7681
const [derivedDataset, setDerivedDataset] = useState<NaturalizedInstance | null>(null)
7782

83+
useEffect(() => {
84+
const seriesSlide = findSeriesSlide(slides, seriesInstanceUID)
85+
if (seriesSlide !== null) {
86+
setSelectedSlide(seriesSlide)
87+
}
88+
}, [seriesInstanceUID, slides])
89+
7890
useEffect(() => {
7991
const findReferencedSlide = async ({ clients, studyInstanceUID, seriesInstanceUID }: {
8092
clients: { [key: string]: DicomWebManager }
@@ -119,9 +131,9 @@ function ParametrizedSlideViewer ({
119131
}
120132
})
121133

122-
if (selectedSlide == null) {
134+
if (selectedSlide === null || selectedSlide === undefined) {
123135
void findReferencedSlide({ clients, studyInstanceUID, seriesInstanceUID }).then((result: ReferencedSlideResult | null) => {
124-
if (result != null) {
136+
if (result !== null) {
125137
setSelectedSlide(result.slide)
126138
setDerivedDataset(result.metadata)
127139
}
@@ -139,6 +151,7 @@ function ParametrizedSlideViewer ({
139151
presentationStateUID = undefined
140152
}
141153
}
154+
142155
let viewer = null
143156
if (selectedSlide != null) {
144157
viewer = (

0 commit comments

Comments
 (0)