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

Autoconversion Fixes #462

Conversation

ascibisz
Copy link
Contributor

@ascibisz ascibisz commented Feb 2, 2024

Problem

This is a somewhat large PR that solves three needs:

  1. Need to send the file to Octopus to get it converted.
  2. Receive the converted file from Octopus.
  3. Front end errors arising from switching backends.

@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 with conversionState.

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.

interim17 and others added 30 commits January 5, 2024 12:24
Comment on lines 545 to 584
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,
});

Copy link
Contributor

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.

Comment on lines +221 to +223
{conversionStatus !== CONVERSION_INACTIVE && (
<ConversionForm />
)}
Copy link
Contributor

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.

Base automatically changed from fix/react-bump to 346-implement-production-autoconversion-ui February 21, 2024 22:20
@ascibisz ascibisz requested a review from meganrm February 22, 2024 00:21
@ascibisz ascibisz marked this pull request as ready for review February 22, 2024 00:21
@ascibisz ascibisz removed the request for review from toloudis February 22, 2024 00:22
@ascibisz ascibisz changed the title Misc Autoconversion Debugging Autoconversion Fixes Feb 23, 2024
setError: (error: ViewerError) => void,
rcRequest?: UploadRequestOption
) => {
try {
const unpackedFileText = await fileToConvert.originFileObj.text();
receiveFileToConvert(unpackedFileText);
const fileName = fileToConvert.name.replace(/\.[^/.]+$/, "");
Copy link
Contributor

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, "")

dispatch(
clearSimulariumFile({
newFile: true,
})
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

@frasercl frasercl left a 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
Comment on lines 37 to 38
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 }));
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope!

@@ -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;
Copy link
Contributor

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?

Copy link
Contributor

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] =
Copy link
Contributor

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

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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;

@interim17 interim17 requested a review from frasercl March 20, 2024 20:52
Copy link
Contributor

@frasercl frasercl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@interim17 interim17 merged commit efc3f61 into 346-implement-production-autoconversion-ui Mar 22, 2024
5 checks passed
@interim17 interim17 deleted the feature/convert-file-no-routing branch March 22, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants