Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typings): Enhance typing support with withAppTypes and custom services throughout OHIF #4090

Merged
merged 16 commits into from
May 8, 2024
3 changes: 1 addition & 2 deletions extensions/cornerstone/src/commandsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { callLabelAutocompleteDialog, showLabelAnnotationPopup } from './utils/c
import toggleImageSliceSync from './utils/imageSliceSync/toggleImageSliceSync';
import { getFirstAnnotationSelected } from './utils/measurementServiceMappings/utils/selection';
import getActiveViewportEnabledElement from './utils/getActiveViewportEnabledElement';
import { CornerstoneServices } from './types';
import toggleVOISliceSync from './utils/toggleVOISliceSync';

const toggleSyncFunctions = {
Expand All @@ -44,7 +43,7 @@ function commandsModule({
colorbarService,
hangingProtocolService,
syncGroupService,
} = servicesManager.services as CornerstoneServices;
} = servicesManager.services;

const { measurementServiceSource } = this;

Expand Down
11 changes: 10 additions & 1 deletion extensions/cornerstone/src/components/CinePlayer/CinePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ import { CinePlayer, useCine } from '@ohif/ui';
import { Enums, eventTarget, cache } from '@cornerstonejs/core';
import { Enums as StreamingEnums } from '@cornerstonejs/streaming-image-volume-loader';
import { useAppConfig } from '@state';
import { ServicesManager } from '@ohif/core';

function WrappedCinePlayer({ enabledVPElement, viewportId, servicesManager }) {
function WrappedCinePlayer({
enabledVPElement,
viewportId,
servicesManager,
}: {
enabledVPElement: HTMLElement;
viewportId: string;
servicesManager: ServicesManager;
}) {
const { customizationService, displaySetService, viewportGridService } = servicesManager.services;
const [{ isCineEnabled, cines }, cineService] = useCine();
const [newStackFrameRate, setNewStackFrameRate] = useState(24);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactNode } from 'react';
import { WindowLevelActionMenu } from './WindowLevelActionMenu';
import { ServicesManager } from '@ohif/core';

export function getWindowLevelActionMenu({
viewportId,
Expand All @@ -9,6 +10,8 @@ export function getWindowLevelActionMenu({
commandsManager,
verticalDirection,
horizontalDirection,
}: {
servicesManager: ServicesManager;
}): ReactNode {
const { customizationService } = servicesManager.services;

Expand Down
9 changes: 8 additions & 1 deletion extensions/cornerstone/src/getToolbarModule.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Enums } from '@cornerstonejs/tools';
import { CommandsManager, ServicesManager } from '@ohif/core';

const getToggledClassName = (isToggled: boolean) => {
return isToggled
? '!text-primary-active'
: '!text-common-bright hover:!bg-primary-dark hover:text-primary-light';
};

export default function getToolbarModule({ commandsManager, servicesManager }) {
export default function getToolbarModule({
commandsManager,
servicesManager,
}: {
commandsManager: CommandsManager;
servicesManager: ServicesManager;
}) {
const {
toolGroupService,
toolbarService,
Expand Down
4 changes: 2 additions & 2 deletions extensions/cornerstone/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const cornerstoneExtension: Types.Extensions.Extension = {
*/
id,

onModeEnter: ({ servicesManager }): void => {
onModeEnter: ({ servicesManager }: { servicesManager: ServicesManager }): void => {
const { cornerstoneViewportService, toolbarService, segmentationService } =
servicesManager.services;
toolbarService.registerEventForToolbarUpdate(cornerstoneViewportService, [
Expand All @@ -79,7 +79,7 @@ const cornerstoneExtension: Types.Extensions.Extension = {
]);
},

onModeExit: ({ servicesManager }): void => {
onModeExit: ({ servicesManager }: { servicesManager: ServicesManager }): void => {
const { cineService } = servicesManager.services;
// Empty out the image load and retrieval pools to prevent memory leaks
// on the mode exits
Expand Down
3 changes: 0 additions & 3 deletions extensions/cornerstone/src/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import nthLoader from './utils/nthLoader';
import interleaveTopToBottom from './utils/interleaveTopToBottom';
import initContextMenu from './initContextMenu';
import initDoubleClick from './initDoubleClick';
import { CornerstoneServices } from './types';
import initViewTiming from './utils/initViewTiming';
import { colormaps } from './utils/colormaps';

import { debounce } from 'lodash';

const { registerColormap } = csUtilities.colormap;

// TODO: Cypress tests are currently grabbing this from the window?
Expand Down
5 changes: 3 additions & 2 deletions extensions/cornerstone/src/initCineService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cache } from '@cornerstonejs/core';
import { utilities } from '@cornerstonejs/tools';
import { ServicesManager } from '@ohif/core';

function _getVolumesFromViewport(viewport) {
return viewport ? viewport.getActors().map(actor => cache.getVolume(actor.uid)) : [];
Expand All @@ -19,7 +20,7 @@ function _getVolumeFromViewport(viewport) {
* @param srcViewportIndex Source viewport index
* @returns array with viewport information.
*/
function _getSyncedViewports(servicesManager, srcViewportId) {
function _getSyncedViewports(servicesManager: ServicesManager, srcViewportId) {
const { viewportGridService, cornerstoneViewportService } = servicesManager.services;

const { viewports: viewportsStates } = viewportGridService.getState();
Expand Down Expand Up @@ -48,7 +49,7 @@ function _getSyncedViewports(servicesManager, srcViewportId) {
.map(({ viewportId }) => ({ viewportId }));
}

function initCineService(servicesManager) {
function initCineService(servicesManager: ServicesManager) {
const { cineService } = servicesManager.services;

const getSyncedViewports = viewportId => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { eventTarget } from '@cornerstonejs/core';
import { Enums, annotation } from '@cornerstonejs/tools';
import { DicomMetadataStore } from '@ohif/core';
import { DicomMetadataStore, ServicesManager } from '@ohif/core';
import { toolNames } from './initCornerstoneTools';
import { onCompletedCalibrationLine } from './tools/CalibrationLineTool';

Expand Down Expand Up @@ -178,7 +178,7 @@ const initMeasurementService = (
return csTools3DVer1MeasurementSource;
};

const connectToolsToMeasurementService = servicesManager => {
const connectToolsToMeasurementService = (servicesManager: ServicesManager) => {
const {
measurementService,
displaySetService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ToolGroupManager, Enums, Types } from '@cornerstonejs/tools';
import { eventTarget } from '@cornerstonejs/core';

import { Types as OhifTypes, pubSubServiceInterface } from '@ohif/core';
import { Types as OhifTypes, ServicesManager, pubSubServiceInterface } from '@ohif/core';
import getActiveViewportEnabledElement from '../../utils/getActiveViewportEnabledElement';

const EVENTS = {
Expand Down Expand Up @@ -33,14 +33,17 @@ export default class ToolGroupService {
};

serviceManager: any;
cornerstoneViewportService: any;
viewportGridService: any;
uiNotificationService: any;
private toolGroupIds: Set<string> = new Set();
/**
* Service-specific
*/
listeners: { [key: string]: Function[] };
EVENTS: { [key: string]: string };

constructor(serviceManager) {
constructor(serviceManager: ServicesManager) {
const { cornerstoneViewportService, viewportGridService, uiNotificationService } =
serviceManager.services;
this.cornerstoneViewportService = cornerstoneViewportService;
Expand Down
18 changes: 11 additions & 7 deletions extensions/cornerstone/src/types/CornerstoneServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import SegmentationService from '../services/SegmentationService';
import CornerstoneCacheService from '../services/CornerstoneCacheService';
import CornerstoneViewportService from '../services/ViewportService/CornerstoneViewportService';
import ViewportActionCornersService from '../services/ViewportActionCornersService/ViewportActionCornersService';
import ColorbarService from '../services/ColorbarService';

interface CornerstoneServices extends Types.Services {
cornerstoneViewportService: CornerstoneViewportService;
toolGroupService: ToolGroupService;
syncGroupService: SyncGroupService;
segmentationService: SegmentationService;
cornerstoneCacheService: CornerstoneCacheService;
viewportActionCornersService: ViewportActionCornersService;
declare global {
IbrahimCSAE marked this conversation as resolved.
Show resolved Hide resolved
interface CornerstoneServices extends Types.Services {
cornerstoneViewportService: CornerstoneViewportService;
toolGroupService: ToolGroupService;
syncGroupService: SyncGroupService;
segmentationService: SegmentationService;
cornerstoneCacheService: CornerstoneCacheService;
viewportActionCornersService: ViewportActionCornersService;
colorbarService: ColorbarService;
}
}

export default CornerstoneServices;
10 changes: 8 additions & 2 deletions platform/core/src/services/ServicesManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import log from './../log.js';
import Services from '../types/Services';
import CommandsManager from '../classes/CommandsManager';
import ExtensionManager from '../extensions/ExtensionManager';

export default class ServicesManager {
public services: Services = {};
public services: Services & CornerstoneServices = {};
IbrahimCSAE marked this conversation as resolved.
Show resolved Hide resolved
public registeredServiceNames: string[] = [];
private _commandsManager: CommandsManager;
private _extensionManager: ExtensionManager;
Expand Down Expand Up @@ -84,3 +83,10 @@ export default class ServicesManager {
});
}
}

// declare global for ServicesManager
declare global {
interface Window {
ServicesManager: ServicesManager;
}
}

This file was deleted.

Loading
Loading