fix(toggleOneUp): fixed one up for main tmtv layout (#3677)

This commit is contained in:
Joe Boccanfuso 2023-09-26 16:49:06 -04:00 committed by GitHub
parent 485cf037a1
commit 86f54d0d07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -371,6 +371,11 @@ const commandsModule = ({
// originally toggled to one up was the former active viewport. // originally toggled to one up was the former active viewport.
const viewportIdToUpdate = toggleOneUpViewportGridStore.activeViewportId; const viewportIdToUpdate = toggleOneUpViewportGridStore.activeViewportId;
// We are restoring the previous layout but taking into the account that
// the current one up viewport might have a new displaySet dragged and dropped on it.
// updatedViewportsViaHP below contains the viewports applicable to the HP that existed
// prior to the toggle to one-up - including the updated viewports if a display
// set swap were to have occurred.
const updatedViewportsViaHP = const updatedViewportsViaHP =
displaySetInstanceUIDs.length > 1 displaySetInstanceUIDs.length > 1
? [] ? []
@ -383,39 +388,25 @@ const commandsModule = ({
) )
.flat(); .flat();
// This findOrCreateViewport returns either one of the updatedViewports // findOrCreateViewport returns either one of the updatedViewportsViaHP
// returned from the HP service OR if there is not one from the HP service then // returned from the HP service OR if there is not one from the HP service then
// simply returns what was in the previous state. // simply returns what was in the previous state for a given position in the layout.
const findOrCreateViewport = (position: number) => { const findOrCreateViewport = (position: number, positionId: string) => {
// get the viewportId in the current state (since we are in the one-up layout) // Find the viewport for the given position prior to the toggle to one-up.
const currentOneUpViewport = Array.from(viewports.values())[0]; const preOneUpViewport = Array.from(toggleOneUpViewportGridStore.viewports.values()).find(
viewport => viewport.positionId === positionId
// we should restore the previous layout but take into the account the fact that
// the current one up viewport might have a new displaySet dragged and dropped on it
// so we should prioritize the current one in the old grid store layout viewports
const newViewports = Array.from(toggleOneUpViewportGridStore.viewports.values()).map(
viewport => {
if (viewport.viewportId === currentOneUpViewport.viewportId) {
return {
...currentOneUpViewport,
};
}
return viewport;
}
); );
// However, we also need to take into account that the current one up viewport // Use the viewport id from before the toggle to one-up to find any updates to the viewport.
// might have been part of a bigger hanging protocol layout, so going back const viewport = updatedViewportsViaHP.find(
// from one up we should apply those viewports as well. viewport => viewport.viewportId === preOneUpViewport.viewportId
return updatedViewportsViaHP.length > 1 && updatedViewportsViaHP[position] );
? {
viewportOptions, return viewport
displaySetOptions, ? // Use the applicable viewport from the HP updated viewports
...updatedViewportsViaHP[position], { viewportOptions, displaySetOptions, ...viewport }
} : // Use the previous viewport for the given position
: newViewports[position]; preOneUpViewport;
}; };
const layoutOptions = viewportGridService.getLayoutOptionsFromState( const layoutOptions = viewportGridService.getLayoutOptionsFromState(