Jon/sky 6375 alter how show all code works (#3445)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useLocation } from "react-router-dom";
|
||||
import type { WorkflowParameter } from "./types/workflowTypes";
|
||||
import { WorkflowApiResponse } from "@/routes/workflows/types/workflowTypes";
|
||||
|
||||
type Location = ReturnType<typeof useLocation>;
|
||||
|
||||
@@ -77,3 +78,49 @@ export const formatDuration = (duration: Duration): string => {
|
||||
return `${duration.second}s`;
|
||||
}
|
||||
};
|
||||
|
||||
export const getOrderedBlockLabels = (workflow?: WorkflowApiResponse) => {
|
||||
if (!workflow) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const blockLabels = workflow.workflow_definition.blocks.map(
|
||||
(block) => block.label,
|
||||
);
|
||||
|
||||
return blockLabels;
|
||||
};
|
||||
|
||||
const getCommentForBlockWithoutCode = (blockLabel: string) => {
|
||||
return `
|
||||
# block '${blockLabel}' code goes here
|
||||
`;
|
||||
};
|
||||
|
||||
export const getCode = (
|
||||
orderedBlockLabels: string[],
|
||||
blockScripts?: {
|
||||
[blockName: string]: string;
|
||||
},
|
||||
): string[] => {
|
||||
const blockCode: string[] = [];
|
||||
const startBlockCode = blockScripts?.__start_block__;
|
||||
|
||||
if (startBlockCode) {
|
||||
blockCode.push(startBlockCode);
|
||||
}
|
||||
|
||||
for (const blockLabel of orderedBlockLabels) {
|
||||
const code = blockScripts?.[blockLabel];
|
||||
|
||||
if (!code) {
|
||||
blockCode.push(getCommentForBlockWithoutCode(blockLabel));
|
||||
continue;
|
||||
}
|
||||
|
||||
blockCode.push(`${code}
|
||||
`);
|
||||
}
|
||||
|
||||
return blockCode;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user