Skip to content
Open
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
9 changes: 3 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { FIRESTORE_FIELDS } from "./constants/firebase";
import {
useCurrentRecipeData,
useJobId,
useJobLogs,
useOutputsDirectory,
useRunTime,
useSetJobId,
useSetJobLogs,
useSetPackingResults,
} from "./state/store";
import PackingInput from "./components/PackingInput";
Expand All @@ -26,9 +24,8 @@ const { Link } = Typography;

function App() {
const [jobStatus, setJobStatus] = useState<string>("");
const [jobLogs, setJobLogs] = useState<string>("");

const setJobLogs = useSetJobLogs();
const jobLogs = useJobLogs();
const setJobId = useSetJobId();
const jobId = useJobId();
const setPackingResults = useSetPackingResults();
Expand Down Expand Up @@ -100,6 +97,7 @@ function App() {
start = Date.now();
const response = await fetch(request);
setJobStatus(JOB_STATUS.SUBMITTED);
setJobLogs("");
const data = await response.json();
if (response.ok) {
setJobId(data.jobId);
Expand Down Expand Up @@ -142,16 +140,15 @@ function App() {
if (localJobStatus.status == JOB_STATUS.DONE) {
setPackingResults({
jobId: id,
jobLogs: "",
resultUrl: localJobStatus.result_path,
runTime: range,
outputDir: localJobStatus.outputs_directory,
edits: edits,
});
} else if (localJobStatus.status == JOB_STATUS.FAILED) {
setJobLogs(`Packing job failed: ${localJobStatus.error_message}`);
setPackingResults({
jobId: id,
jobLogs: `Packing job failed: ${localJobStatus.error_message}`,
resultUrl: "",
runTime: range,
outputDir: "",
Expand Down
1 change: 0 additions & 1 deletion src/state/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { EditableField, PackingResult } from "../types";
export const EMPTY_FIELDS: readonly EditableField[] = Object.freeze([]);
export const EMPTY_PACKING_RESULT: PackingResult = Object.freeze({
jobId: "",
jobLogs: "",
resultUrl: "",
runTime: 0,
outputDir: "",
Expand Down
20 changes: 0 additions & 20 deletions src/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type Actions = {
) => Promise<void>
) => Promise<void>;
setPackingResults: (results: PackingResult) => void;
setJobLogs: (logs: string) => void;
setJobId: (jobId: string) => void;
};

Expand Down Expand Up @@ -137,19 +136,6 @@ export const useRecipeStore = create<RecipeStore>()(
});
},

setJobLogs: (logs: string) => {
const currentRecipeId = get().selectedRecipeId;
set({
packingResults: {
...get().packingResults,
[currentRecipeId]: {
...get().packingResults[currentRecipeId],
jobLogs: logs,
},
},
});
},

setJobId: (jobId: string) => {
const currentRecipeId = get().selectedRecipeId;
set({
Expand Down Expand Up @@ -327,11 +313,6 @@ export const useRunTime = () => {
return results.runTime;
};

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

export const useJobId = () => {
const results = useCurrentPackingResult();
return results.jobId;
Expand Down Expand Up @@ -376,5 +357,4 @@ export const useGetOriginalValue = () =>
useRecipeStore((s) => s.getOriginalValue);
export const useSetPackingResults = () =>
useRecipeStore((s) => s.setPackingResults);
export const useSetJobLogs = () => useRecipeStore((s) => s.setJobLogs);
export const useSetJobId = () => useRecipeStore((s) => s.setJobId);
22 changes: 0 additions & 22 deletions src/test/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,6 @@ test("editing one recipe does not affect others", async () => {
expect(result.current.getCurrentValue(path)).toBe(newValue1);
});

test("setJobLogs updates job logs for current recipe", async () => {
const { result } = renderHook(() => useRecipeStore());

const recipeId = INITIAL_RECIPE_ID;
await result.current.selectRecipe(recipeId);

const logs = "Some Error Message";

act(() => {
result.current.setJobLogs(logs);
});

expect(result.current.packingResults[recipeId].jobLogs).toBe(logs);

for (const recipeId of Object.keys(result.current.inputOptions)) {
if (recipeId !== INITIAL_RECIPE_ID) {
// No other job logs should have been updated to `logs`
expect(result.current.packingResults[recipeId]?.jobLogs).not.toBe(logs);
}
}
});

test("setJobId updates job ID for current recipe", async () => {
const { result } = renderHook(() => useRecipeStore());

Expand Down
1 change: 0 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export type JobStatusObject = {

export type PackingResult = {
jobId: string;
jobLogs: string;
resultUrl: string;
runTime: number;
outputDir: string;
Expand Down