-
Notifications
You must be signed in to change notification settings - Fork 3
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
Autoconversion Fixes #462
Autoconversion Fixes #462
Conversation
src/state/trajectory/logics.ts
Outdated
const convertFileLogic = createLogic({ | ||
process( | ||
deps: ReduxLogicDeps, | ||
dispatch: <T extends AnyAction>(action: T) => T, | ||
done | ||
) { | ||
const { getState } = deps; | ||
|
||
const { engineType, fileToConvert, fileName } = | ||
getConversionProcessingData(getState()); | ||
const fileContents: Record<string, any> = { | ||
fileContents: { fileContents: fileToConvert }, | ||
metaData: { trajectoryTitle: fileName }, | ||
}; | ||
dispatch( | ||
clearSimulariumFile({ | ||
newFile: true, | ||
}) | ||
); | ||
const controller = getSimulariumController(getState()); | ||
// convert the file | ||
dispatch( | ||
setConversionStatus({ | ||
status: CONVERSION_ACTIVE, | ||
}) | ||
); | ||
controller | ||
.convertAndLoadTrajectory( | ||
netConnectionSettings, | ||
fileContents, | ||
engineType | ||
) | ||
.catch((err: Error) => { | ||
console.error(err); | ||
}); | ||
done(); | ||
}, | ||
type: CONVERT_FILE, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the logic that actually sends the file to Octopus for conversion. Because we are already at /viewer
we are ready for Octopus to receive the converted file as soon as its ready.
{conversionStatus !== CONVERSION_INACTIVE && ( | ||
<ConversionForm /> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the conversion process doesn't have its own path, we are rendering the conversion form here in Simularium
because the viewer itself doesn't really need to know anything about conversion state, it just needs to handle the converted trajectory. Styling is also much easier here above the ViewerPanel
layout.
setError: (error: ViewerError) => void, | ||
rcRequest?: UploadRequestOption | ||
) => { | ||
try { | ||
const unpackedFileText = await fileToConvert.originFileObj.text(); | ||
receiveFileToConvert(unpackedFileText); | ||
const fileName = fileToConvert.name.replace(/\.[^/.]+$/, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? can you add a comment about what this regex selects for. You can also always use a named variable for your regex, like const whiteSpace = RegEX; string.replace(whiteSpace, "")
src/state/trajectory/logics.ts
Outdated
dispatch( | ||
clearSimulariumFile({ | ||
newFile: true, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like you wouldn't want to clear it out until you've received the converted file. Because if they cancel it they should go back to the previous trajectory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, just removing it seems to work well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only very small comments from me. I don't have the full perspective of how the app and octopus interact, but from what I understand this looks good!
src/index.tsx
Outdated
batch(() => { | ||
dispatch(setIsPlaying(false)); | ||
dispatch(setConversionStatus({ status: CONVERSION_NO_SERVER })); | ||
}); | ||
} else if (location.pathname === VIEWER_PATHNAME) { | ||
batch(() => { | ||
dispatch(setIsPlaying(false)); | ||
dispatch(setStatus({ status: VIEWER_EMPTY })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is this batch
call still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope!
src/containers/Simularium/index.tsx
Outdated
@@ -77,6 +85,7 @@ class App extends React.Component<AppProps, AppState> { | |||
public simulariumController: SimulariumController | undefined; | |||
private interactiveContent = React.createRef<HTMLDivElement>(); | |||
private endDragover = 0; | |||
private conversionCheckInterval: NodeJS.Timeout | null = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter warns this is unused. Will it be used later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, needs removing
}: ConversionProps): JSX.Element => { | ||
const [fileToConvert, setFileToConvert] = useState<UploadFile | null>(); | ||
const [engineSelected, setEngineSelected] = useState<boolean>(false); | ||
const [isProcessing, setIsProcessing] = useState<boolean>(false); | ||
const [serverDownModalOpen, setServerIsDownModalOpen] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (and not even one in the diff!): inconsistent names: serverDownModalOpen
vs setServer*Is*DownModalOpen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I think I now prefer serverErrorModalOpen anyway as it matches the modal component better
@@ -70,21 +71,28 @@ const ConversionForm = ({ | |||
receiveFileToConvert, | |||
initializeConversion, | |||
conversionStatus, | |||
convertFile, | |||
setConversionStatus, | |||
}: ConversionProps): JSX.Element => { | |||
const [fileToConvert, setFileToConvert] = useState<UploadFile | null>(); | |||
const [engineSelected, setEngineSelected] = useState<boolean>(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not technically part of this PR (so feel free to ignore me!), but this looks like derived state to me. engineSelected
tracks whether another component of state is set, and may become out of sync if not properly updated (e.g. engineSelected: false
while store.trajectory.processingData.engineType: "cytosim"
). This particular case is probably too simple to cause issues, but it still might be slightly better practice to select engineType
out of the store and null-check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, seems like this works and can remove the state variable:
const engineSelected = !!conversionProcessingData.engineType;
Co-authored-by: Cameron Fraser <53030214+frasercl@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
efc3f61
into
346-implement-production-autoconversion-ui
Problem
This is a somewhat large PR that solves three needs:
@interim17 did most of the work for this PR, @ascibisz helped with some debugging and happened to be the one to open the PR because she had the time to
Solution
Convert the file
Redux action/logic being triggered to send the file to Octopus. As always with redux there is much boiler plate, the action is in
convertFileLogic
which does the sending.Receive the converted file
To receive the file we need a configured viewer at the ready, so Joe refactored the routes so that the conversion form is just a component that is just visible in front of the viewer when the user opens it. This made some of the communication with Octopus simpler. We're always at
/viewer
ready to receive a file, and we handle navigation in and out of the conversion form withconversionState
.Errors
Alli then did some miscellaneous debugging, as well as switching the autoconversion feature branch to use octopus for everything, not just the autoconversion point. The infrastructure team is actively working on the octopus deployment, so rather than continuing to have a weird state of partially using octopus and partially using simularium-engine, we think it makes sense to have this feature branch ready to fully embrace octopus.