Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@ import { getJobStatus, addRecipe } from "./utils/firebase";
import { getFirebaseRecipe, jsonToString } from "./utils/recipeLoader";
import { getSubmitPackingUrl, JOB_STATUS } from "./constants/aws";
import { FIRESTORE_FIELDS } from "./constants/firebase";
import { SIMULARIUM_EMBED_URL } from "./constants/urls";
import { useResultUrl, useSetResultUrl } from "./state/store";
import {
useJobId,
useJobLogs,
useOutputsDirectory,
useRunTime,
useSetJobId,
useSetJobLogs,
useSetPackingResults,
} from "./state/store";
import PackingInput from "./components/PackingInput";
import Viewer from "./components/Viewer";
import StatusBar from "./components/StatusBar";
import { EMPTY_PACKING_RESULTS } from "./state/constants";

import "./App.css";

const { Header, Content, Sider, Footer } = Layout;
const { Link } = Typography;

function App() {
const [jobId, setJobId] = useState("");
const [jobStatus, setJobStatus] = useState("");
const [jobLogs, setJobLogs] = useState<string>("");
const [outputDir, setOutputDir] = useState<string>("");
const [runTime, setRunTime] = useState<number>(0);
const resultUrl = useResultUrl();
const setResultUrl = useSetResultUrl();
const [jobStatus, setJobStatus] = useState<string>("");
const setJobLogs = useSetJobLogs();
const jobLogs = useJobLogs();
const setJobId = useSetJobId();
const jobId = useJobId();
const setPackingResults = useSetPackingResults();
const runTime = useRunTime();
const outputDir = useOutputsDirectory();

let start = 0;

Expand All @@ -31,11 +41,7 @@ function App() {
}

const resetState = () => {
setJobId("");
setJobStatus("");
setJobLogs("");
setResultUrl("");
setRunTime(0);
setPackingResults({ ...EMPTY_PACKING_RESULTS });
};

const recipeHasChanged = async (
Expand Down Expand Up @@ -136,12 +142,22 @@ function App() {
}
}
const range = (Date.now() - start) / 1000;
setRunTime(range);
if (localJobStatus.status == JOB_STATUS.DONE) {
setResultUrl(localJobStatus.result_path);
setOutputDir(localJobStatus.outputs_directory);
setPackingResults({
jobId: id,
jobLogs: "",
resultUrl: localJobStatus.result_path,
runTime: range,
outputDir: localJobStatus.outputs_directory,
});
} else if (localJobStatus.status == JOB_STATUS.FAILED) {
setJobLogs(localJobStatus.error_message);
setPackingResults({
jobId: id,
jobLogs: `Packing job failed: ${localJobStatus.error_message}`,
resultUrl: "",
runTime: range,
outputDir: "",
});
Comment on lines +154 to +160
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

The jobLogs field is being set in the FAILED case but left empty in the DONE case (line 148). This inconsistency means successful jobs lose their logs. Consider preserving the existing jobLogs value or fetching/storing logs for successful jobs as well.

Copilot uses AI. Check for mistakes.
}
};

Expand All @@ -164,7 +180,7 @@ function App() {
<PackingInput startPacking={startPacking} />
</Sider>
<Content className="content-container">
<Viewer resultUrl={resultUrl ? SIMULARIUM_EMBED_URL + resultUrl : ""} />
<Viewer />
</Content>
</Layout>
<Footer className="footer">
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Select } from "antd";
import { map } from "lodash-es";
import { Dictionary, PackingInputs } from "../../types";
import { Dictionary, RecipeManifest } from "../../types";

interface DropdownProps {
placeholder: string;
defaultValue?: string;
options: Dictionary<PackingInputs>;
options: Dictionary<RecipeManifest>;
onChange: (value: string) => void;
}

Expand Down
17 changes: 9 additions & 8 deletions src/components/Viewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { SIMULARIUM_EMBED_URL } from "../../constants/urls";
import { useResultUrl } from "../../state/store";
import "./style.css";

interface ViewerProps {
resultUrl: string;
}

const Viewer = (props: ViewerProps): JSX.Element => {
const { resultUrl } = props;
const Viewer = (): JSX.Element => {
const resultUrl = useResultUrl();
return (
<div className="viewer-container">
<iframe className="simularium-embed" src={resultUrl} />
<iframe
className="simularium-embed"
src={`${SIMULARIUM_EMBED_URL}${resultUrl}`}
/>
</div>
);
};

export default Viewer;
export default Viewer;
11 changes: 11 additions & 0 deletions src/state/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { EditableField, PackingResults } from "../types";

// stable/frozen empty array to prevent re-renders
export const EMPTY_FIELDS: readonly EditableField[] = Object.freeze([]);
export const EMPTY_PACKING_RESULTS: PackingResults = Object.freeze({
jobId: "",
jobLogs: "",
resultUrl: "",
runTime: 0,
outputDir: "",
});
95 changes: 78 additions & 17 deletions src/state/store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { create } from "zustand";
import { subscribeWithSelector } from "zustand/middleware";
import { get as lodashGet, set as lodashSet } from "lodash-es";
import { PackingInputs } from "../types";
import { PackingResults, RecipeManifest } from "../types";
import { getFirebaseRecipe, jsonToString } from "../utils/recipeLoader";
import { getPackingInputsDict } from "../utils/firebase";
import { EMPTY_PACKING_RESULTS } from "./constants";

export interface RecipeData {
id: string;
Expand All @@ -14,8 +15,9 @@ export interface RecipeData {

export interface RecipeState {
selectedRecipeId: string;
inputOptions: Record<string, PackingInputs>;
inputOptions: Record<string, RecipeManifest>;
recipes: Record<string, RecipeData>;
packingResults: PackingResults;
Copy link
Contributor

@ascibisz ascibisz Nov 7, 2025

Choose a reason for hiding this comment

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

I think ideally we want packingResults to be a Record<string, PackingResults>, with recipeId as the key, so that when a user navigates back to a recipe that they previously ran, the results of that last run are displayed rather than the pre-computed results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I was thinking about that, maybe good to have in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

export interface UIState {
Expand Down Expand Up @@ -43,7 +45,9 @@ type Actions = {
recipeString: string
) => Promise<void>
) => Promise<void>;
setResultUrl: (url: string) => void;
setPackingResults: (results: PackingResults) => void;
setJobLogs: (logs: string) => void;
setJobId: (jobId: string) => void;
};

export type RecipeStore = RecipeState & UIState & Actions;
Expand All @@ -56,6 +60,7 @@ const initialState: RecipeState & UIState = {
recipes: {},
isLoading: false,
isPacking: false,
packingResults: { ...EMPTY_PACKING_RESULTS },
};

export const useRecipeStore = create<RecipeStore>()(
Expand Down Expand Up @@ -115,6 +120,8 @@ export const useRecipeStore = create<RecipeStore>()(
},

selectRecipe: async (recipeId) => {
get().setPackingResults({ ...EMPTY_PACKING_RESULTS });
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: part of why I froze this object was so avoid triggering re-renders if we use EMPTY_PACKING_RESULTS when that's already in state.

Won't be a big deal either way, but in a case like this the spread creates a new object, so subscribers will re-render, even if packing results were already empty before calling selectRecipe. At least I think so.


const sel = get().inputOptions[recipeId];
if (!sel) return;

Expand All @@ -127,22 +134,27 @@ export const useRecipeStore = create<RecipeStore>()(
}
},

setPackingResults: (results: PackingResults) => {
set({ packingResults: results });
},

setResultUrl: (url: string) => {
const { inputOptions, selectedRecipeId } = get();
const sel = inputOptions[selectedRecipeId];
if (!sel) return;
setJobLogs: (logs: string) => {
set({
inputOptions: {
...get().inputOptions,
[selectedRecipeId]: {
...sel,
result_path: url,
},
packingResults: {
...get().packingResults,
jobLogs: logs,
},
});
},

setJobId: (jobId: string) => {
set({
packingResults: {
...get().packingResults,
jobId: jobId,
},
});
},

updateRecipeString: (recipeId, newString) => {
set((s) => {
Expand Down Expand Up @@ -234,12 +246,13 @@ export const useRecipeStore = create<RecipeStore>()(
}))
);

// tiny helpers/selectors (all derived — not stored)
// simple selectors
export const useSelectedRecipeId = () =>
useRecipeStore((s) => s.selectedRecipeId);
export const useCurrentRecipeString = () =>
useRecipeStore((s) => s.recipes[s.selectedRecipeId]?.currentString ?? "");
export const useInputOptions = () => useRecipeStore((s) => s.inputOptions);

export const useIsLoading = () => useRecipeStore((s) => s.isLoading);
export const useIsPacking = () => useRecipeStore((s) => s.isPacking);
export const useFieldsToDisplay = () =>
Expand All @@ -248,8 +261,53 @@ export const useIsCurrentRecipeModified = () =>
useRecipeStore((s) => s.recipes[s.selectedRecipeId]?.isModified ?? false);
export const useGetOriginalValue = () =>
useRecipeStore((s) => s.getOriginalValue);
export const useResultUrl = () =>
useRecipeStore((s) => s.inputOptions[s.selectedRecipeId]?.result_path);
const usePackingResults = () => useRecipeStore((s) => s.packingResults);

// compound selectors

const useCurrentRecipeManifest = () => {
const selectedRecipeId = useSelectedRecipeId();
const inputOptions = useInputOptions();
if (!selectedRecipeId) return undefined;
return inputOptions[selectedRecipeId];
};
const useDefaultResultPath = () => {
const manifest = useCurrentRecipeManifest();
return manifest?.defaultResultPath || "";
};

export const useRunTime = () => {
const results = usePackingResults();
return results.runTime;
};

export const useJobLogs = () => {
const results = usePackingResults();
return results.jobLogs;
};

export const useJobId = () => {
const results = usePackingResults();
return results.jobId;
};

export const useOutputsDirectory = () => {
const results = usePackingResults();
return results.outputDir;
};

export const useResultUrl = () => {
const results = usePackingResults();
const currentRecipeId = useSelectedRecipeId();
const defaultResultPath = useDefaultResultPath();
let path = "";
if (results.resultUrl) {
path = results.resultUrl;
} else if (currentRecipeId) {
path = defaultResultPath;
}
return path;
};

// action selectors (stable identities)
export const useLoadInputOptions = () =>
Expand All @@ -265,4 +323,7 @@ export const useRestoreRecipeDefault = () =>
export const useStartPacking = () => useRecipeStore((s) => s.startPacking);
export const useGetCurrentValue = () =>
useRecipeStore((s) => s.getCurrentValue);
export const useSetResultUrl = () => useRecipeStore((s) => s.setResultUrl);
export const useSetPackingResults = () =>
useRecipeStore((s) => s.setPackingResults);
export const useSetJobLogs = () => useRecipeStore((s) => s.setJobLogs);
export const useSetJobId = () => useRecipeStore((s) => s.setJobId);
12 changes: 10 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export interface Dictionary<T> {
[Key: string]: T;
}

export type PackingInputs = {
export type RecipeManifest = {
name?: string;
config: string;
recipe: string;
result_path?: string;
defaultResultPath?: string;
editable_fields?: EditableField[];
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use camel case here?

};

Expand All @@ -31,6 +31,14 @@ export type JobStatusObject = {
result_path: string;
};

export type PackingResults = {
jobId: string;
jobLogs: string;
resultUrl: string;
runTime: number;
outputDir: string;
};

export type EditableField = {
id: string;
name: string;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "../constants/firebase";
import {
FirestoreDoc,
PackingInputs,
RecipeManifest,
Dictionary,
EditableField,
JobStatusObject,
Expand Down Expand Up @@ -163,11 +163,11 @@ const getEditableFieldsList = async (
return docs;
};

const getPackingInputsDict = async (): Promise<Dictionary<PackingInputs>> => {
const getPackingInputsDict = async (): Promise<Dictionary<RecipeManifest>> => {
const docs = await getAllDocsFromCollection(
FIRESTORE_COLLECTIONS.PACKING_INPUTS
);
const inputsDict: Dictionary<PackingInputs> = {};
const inputsDict: Dictionary<RecipeManifest> = {};
for (const doc of docs) {
const displayName = doc[FIRESTORE_FIELDS.NAME];
const config = doc[FIRESTORE_FIELDS.CONFIG];
Expand All @@ -182,7 +182,7 @@ const getPackingInputsDict = async (): Promise<Dictionary<PackingInputs>> => {
[FIRESTORE_FIELDS.CONFIG]: config,
[FIRESTORE_FIELDS.RECIPE]: recipe,
[FIRESTORE_FIELDS.EDITABLE_FIELDS]: editableFields,
[FIRESTORE_FIELDS.RESULT_PATH]: result,
defaultResultPath: result,
};
}
}
Expand Down