fix(segmentationService): prevent no representation crash (#5495)

This commit is contained in:
Pedro Köhler 2025-10-15 08:32:27 -03:00 committed by GitHub
parent a1c6b5f3ec
commit 3137aed017
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 18 deletions

View File

@ -2482,7 +2482,7 @@ describe('SegmentationService', () => {
type: representations[0].type,
});
expect(service.getSegmentationRepresentations).toHaveBeenCalledTimes(2);
expect(service.getSegmentationRepresentations).toHaveBeenCalledTimes(1);
expect(service.getSegmentationRepresentations).toHaveBeenCalledWith(viewportId, {
segmentationId: representations[0].segmentationId,
type: representations[0].type,
@ -2511,20 +2511,20 @@ describe('SegmentationService', () => {
false
);
});
});
describe('setSegmentationRepresentationVisibility', () => {
it('should early return if the representation is not found', () => {
jest.spyOn(service, 'getSegmentationRepresentations').mockReturnValueOnce(representations);
jest.spyOn(cstSegmentation.state, 'getSegmentationRepresentations').mockReturnValueOnce([]);
jest
.spyOn(cstSegmentation.config.visibility, 'getHiddenSegmentIndices')
.mockReturnValue(new Set());
jest.spyOn(service, 'getSegmentationRepresentations').mockReturnValueOnce([]);
jest.spyOn(console, 'debug').mockReturnValue(undefined);
jest.spyOn(cstSegmentation.config.visibility, 'setSegmentationRepresentationVisibility');
service.toggleSegmentationRepresentationVisibility(viewportId, {
segmentationId: representations[0].segmentationId,
type: representations[0].type,
});
service['_setSegmentationRepresentationVisibility'](
viewportId,
representations[0].segmentationId,
representations[0].type,
true
);
expect(console.debug).toHaveBeenCalledTimes(1);
expect(console.debug).toHaveBeenCalledWith(

View File

@ -1756,22 +1756,16 @@ class SegmentationService extends PubSubService {
segmentationId: string,
type: csToolsEnums.SegmentationRepresentations
): void => {
const representations = this.getSegmentationRepresentations(viewportId, {
segmentationId,
type,
});
const representation = representations[0];
const segmentsHidden = cstSegmentation.config.visibility.getHiddenSegmentIndices(viewportId, {
segmentationId,
type: representation.type,
type,
});
const currentVisibility = segmentsHidden.size === 0;
this._setSegmentationRepresentationVisibility(
viewportId,
segmentationId,
representation.type,
type,
!currentVisibility
);
};