Skip to content

Commit

Permalink
fix(Browser history):
Browse files Browse the repository at this point in the history
- fixed an NPE when navigating to a different study via the URL
- exposed browser history navigation via a command
  • Loading branch information
jbocce committed Apr 24, 2023
1 parent dc61d87 commit 9a0911b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
14 changes: 14 additions & 0 deletions extensions/default/src/commandsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import findViewportsByPosition, {
} from './findViewportsByPosition';

import { ContextMenuProps } from './CustomizeableContextMenu/types';
import { NavigateHistory } from './types/commandModuleTypes';
import { history } from '@ohif/ui';

const { subscribeToNextViewportGridChange } = utils;

Expand Down Expand Up @@ -480,6 +482,13 @@ const commandsModule = ({
}
},

/**
* Exposes the browser history navigation used by OHIF.
*/
navigateHistory(historyArgs: NavigateHistory) {
history.navigate(historyArgs.to, historyArgs.options);
},

openDICOMTagViewer() {
const { activeViewportIndex, viewports } = viewportGridService.getState();
const activeViewportSpecificData = viewports[activeViewportIndex];
Expand Down Expand Up @@ -540,6 +549,11 @@ const commandsModule = ({
storeContexts: [],
options: {},
},
navigateHistory: {
commandFn: actions.navigateHistory,
storeContexts: [],
options: {},
},
nextStage: {
commandFn: actions.deltaStage,
storeContexts: [],
Expand Down
6 changes: 6 additions & 0 deletions extensions/default/src/types/commandModuleTypes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type NavigateHistory = {
to: string; // the URL to navigate to
options?: {
replace?: boolean; // replace or add/push to history?
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ function TrackedMeasurementsContextProvider(
activeViewport.displaySetInstanceUIDs[0]
);

if (!displaySet) {
return;
}

// If this is an SR produced by our SR SOPClassHandler,
// and it hasn't been loaded yet, do that now so we
// can check if it can be rehydrated or not.
Expand Down
1 change: 1 addition & 0 deletions platform/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"react-error-boundary": "^3.1.3",
"react-modal": "3.11.2",
"react-outside-click-handler": "^1.3.0",
"react-router-dom": "^6.8.1",
"react-select": "3.0.8",
"react-with-direction": "^1.3.1",
"swiper": "^8.4.2"
Expand Down
1 change: 1 addition & 0 deletions platform/ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ export { getIcon, ICONS, addIcon } from './components/Icon/getIcon';
export { BackgroundColor } from './pages/Colors/BackgroundColor';
export { ModalComponent } from './contextProviders/ModalComponent';
export { Types };
export { history } from './utils/history';
9 changes: 9 additions & 0 deletions platform/ui/src/utils/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NavigateFunction } from 'react-router';

type History = {
navigate: NavigateFunction;
};

export const history: History = {
navigate: null,
};
7 changes: 5 additions & 2 deletions platform/viewer/src/routes/Mode/Mode.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useState, useRef } from 'react';
import { useParams, useLocation } from 'react-router';
import { useParams, useLocation, useNavigate } from 'react-router';
import PropTypes from 'prop-types';
// TODO: DicomMetadataStore should be injected?
import { DicomMetadataStore, ServicesManager, utils } from '@ohif/core';
import { DragAndDropProvider, ImageViewerProvider } from '@ohif/ui';
import { DragAndDropProvider, ImageViewerProvider, history } from '@ohif/ui';
import { useQuery, useSearchParams } from '@hooks';
import ViewportGrid from '@components/ViewportGrid';
import Compose from './Compose';
Expand Down Expand Up @@ -105,6 +105,9 @@ export default function ModeRoute({
const locationRef = useRef(null);
const isMounted = useRef(false);

// Expose the react router dom navigation.
history.navigate = useNavigate();

if (location !== locationRef.current) {
layoutTemplateData.current = null;
locationRef.current = location;
Expand Down

0 comments on commit 9a0911b

Please sign in to comment.