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
15 changes: 9 additions & 6 deletions src/components/StatusBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ const StatusBar = (props: StatusBarProps): JSX.Element => {
return () => window.removeEventListener("blur", onBlur);
}, [isShareOpen]);

const downloadResults = async (jobId: string) => {
const jobSucceeded = jobStatus == JOB_STATUS.DONE;
const buttonsEnabled = !jobStatus || jobSucceeded;
const canDownload = buttonsEnabled && !!outputDir;
const canShare = buttonsEnabled && !!shareUrl;

const downloadResults = async () => {
setIsDownloading(true);
await downloadOutputs(jobId, outputDir);
setIsDownloading(false);
};

const jobSucceeded = jobStatus == JOB_STATUS.DONE;

const shareResultUrl = (
<Space.Compact style={{ display: "flex", width: 400 }}>
<Input value={shareUrl} readOnly style={{ flex: 1 }} />
Expand Down Expand Up @@ -71,9 +74,9 @@ const StatusBar = (props: StatusBarProps): JSX.Element => {
<div className="status-bar-actions">
<Button
{...statusBarButtonProps}
onClick={() => downloadResults(jobId)}
onClick={downloadResults}
loading={isDownloading}
disabled={!jobSucceeded}
disabled={!canDownload}
icon={<DownloadOutlined style={{ fontSize: 18 }} />}
>
Download packing result
Expand All @@ -88,7 +91,7 @@ const StatusBar = (props: StatusBarProps): JSX.Element => {
>
<Button
{...statusBarButtonProps}
disabled={!shareUrl}
disabled={!canShare}
icon={<ShareAltOutlined style={{ fontSize: 18 }} />}
>
Share
Expand Down
1 change: 1 addition & 0 deletions src/constants/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const FIRESTORE_FIELDS = {
CONFIG: "config",
EDITABLE_FIELDS: "editable_fields",
RESULT_PATH: "result_path",
OUTPUTS_DIRECTORY: "outputs_directory",
} as const;

export const RETENTION_POLICY = {
Expand Down
9 changes: 8 additions & 1 deletion src/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,16 @@ export const useJobId = () => {
return results.jobId;
};

const useDefaultOutputDir = () => {
const manifest = useCurrentRecipeManifest();
const recipe = useCurrentRecipeData();
return (recipe && manifest?.defaultOutputDir) || "";
};

Comment on lines +321 to +326
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when no job runs, falls back to the initial recipe outputs

export const useOutputsDirectory = () => {
const results = useCurrentPackingResult();
return results.outputDir;
const defaultOutputDir = useDefaultOutputDir();
return results.outputDir || defaultOutputDir;
};

export const useResultUrl = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Document {
config?: string;
editable_fields?: string[];
result_path?: string;
outputs_directory?: string;
}

export type FirestoreDoc = Document & {
Expand All @@ -23,6 +24,7 @@ export interface RecipeManifest {
displayName: string;
editableFieldIds: string[];
defaultResultPath?: string;
defaultOutputDir?: string;
}

export interface RecipeData {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ export const downloadOutputs = async (jobId: string, outputsDir?: string) => {
const jobStatus = await getJobStatus(jobId);
outputsDir = jobStatus?.outputs_directory ?? "";
}
await downloadOutputsFromS3(outputsDir, jobId);
// use jobId when an edited recipe packing completes. For an example recipe, grab the last part of the s3 path as the zip name
const zipName = jobId || outputsDir.split("/").filter(Boolean).pop() || "output";
await downloadOutputsFromS3(outputsDir, zipName);
}
2 changes: 2 additions & 0 deletions src/utils/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const getRecipeManifestFromFirebase = async (): Promise<
const recipeId = doc[FIRESTORE_FIELDS.RECIPE];
const editableFieldIds = doc[FIRESTORE_FIELDS.EDITABLE_FIELDS];
const defaultResultPath = doc[FIRESTORE_FIELDS.RESULT_PATH] || "";
const defaultOutputDir = doc[FIRESTORE_FIELDS.OUTPUTS_DIRECTORY] || "";

if (displayName && config && recipeId) {
inputsDict[recipeId] = {
Expand All @@ -173,6 +174,7 @@ const getRecipeManifestFromFirebase = async (): Promise<
displayName,
editableFieldIds: editableFieldIds || [],
defaultResultPath,
defaultOutputDir,
};
}
}
Expand Down