1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { ReactElement, memo } from "react";
6 import { Dispatch } from "redux";
26 } from "@material-ui/core";
27 import { ArvadosTheme } from "common/custom-theme";
28 import { CloseIcon, InputIcon, OutputIcon, MaximizeIcon, UnMaximizeIcon, InfoIcon } from "components/icon/icon";
29 import { MPVPanelProps } from "components/multi-panel-view/multi-panel-view";
31 BooleanCommandInputParameter,
32 CommandInputParameter,
35 DirectoryArrayCommandInputParameter,
36 DirectoryCommandInputParameter,
37 EnumCommandInputParameter,
38 FileArrayCommandInputParameter,
39 FileCommandInputParameter,
40 FloatArrayCommandInputParameter,
41 FloatCommandInputParameter,
42 IntArrayCommandInputParameter,
43 IntCommandInputParameter,
46 StringArrayCommandInputParameter,
47 StringCommandInputParameter,
49 } from "models/workflow";
50 import { CommandOutputParameter } from "cwlts/mappings/v1.0/CommandOutputParameter";
51 import { File } from "models/workflow";
52 import { getInlineFileUrl } from "views-components/context-menu/actions/helpers";
53 import { AuthState } from "store/auth/auth-reducer";
54 import mime from "mime";
55 import { DefaultView } from "components/default-view/default-view";
56 import { getNavUrl } from "routes/routes";
57 import { Link as RouterLink } from "react-router-dom";
58 import { Link as MuiLink } from "@material-ui/core";
59 import { InputCollectionMount } from "store/processes/processes-actions";
60 import { connect } from "react-redux";
61 import { RootState } from "store/store";
62 import { ProcessOutputCollectionFiles } from "./process-output-collection-files";
63 import { Process } from "store/processes/process";
64 import { navigateTo } from "store/navigation/navigation-action";
65 import classNames from "classnames";
66 import { DefaultVirtualCodeSnippet } from "components/default-code-snippet/default-virtual-code-snippet";
67 import { KEEP_URL_REGEX } from "models/resource";
68 import { FixedSizeList } from 'react-window';
69 import AutoSizer from "react-virtualized-auto-sizer";
70 import { LinkProps } from "@material-ui/core/Link";
71 import { ConditionalTabs } from "components/conditional-tabs/conditional-tabs";
82 | "paramTableCellText"
93 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
98 paddingTop: theme.spacing.unit,
102 fontSize: "1.875rem",
103 color: theme.customs.colors.greyL,
106 alignSelf: "flex-start",
107 paddingTop: theme.spacing.unit * 0.5,
111 height: `calc(100% - ${theme.spacing.unit * 6}px)`,
112 padding: theme.spacing.unit * 1.0,
115 paddingBottom: theme.spacing.unit * 1,
121 paddingTop: theme.spacing.unit * 0.5,
122 color: theme.customs.colors.greyD,
123 fontSize: "1.875rem",
125 // Applies to table tab and collection table content
128 maxHeight: `calc(100% - ${theme.spacing.unit * 6}px)`,
130 // Use flexbox to keep scrolling at the virtual list level
132 flexDirection: "column",
133 alignItems: "stretch", // Stretches output collection to full width
137 // Param table virtual list styles
140 flexDirection: "column",
146 padding: "4px 25px 10px",
150 height: "100vh", // Must be constrained by panel maxHeight
152 // Flex header/body rows
153 "& thead tr, & > tbody tr": {
155 // Flex header/body cells
162 // Column width overrides
163 "& th:nth-of-type(1), & td:nth-of-type(1)": {
166 "& th:nth-last-of-type(1), & td:nth-last-of-type(1)": {
175 padding: "2px 25px 2px",
178 flexDirection: "row",
179 alignItems: "center",
180 whiteSpace: "nowrap",
184 // Param value cell typography styles
185 paramTableCellText: {
188 // Every cell contents requires a wrapper for the ellipsis
189 // since adding ellipses to an anchor element parent results in misaligned tooltip
192 textOverflow: "ellipsis",
197 textOverflow: "ellipsis",
203 verticalAlign: "bottom",
204 paddingBottom: "10px",
207 paddingRight: "25px",
212 height: `calc(100% - ${theme.spacing.unit * 6}px)`,
215 color: theme.palette.primary.main,
216 textDecoration: "none",
217 // Overflow wrap for mounts table
218 overflowWrap: "break-word",
221 // Output collection tab link
225 color: theme.palette.primary.main,
226 textDecoration: "none",
227 overflowWrap: "break-word",
235 color: theme.customs.colors.grey700,
239 borderBottom: "none",
241 paddingBottom: "2px",
252 wordWrap: "break-word",
256 export enum ProcessIOCardType {
257 INPUT = "Input Parameters",
258 OUTPUT = "Output Parameters",
260 export interface ProcessIOCardDataProps {
262 label: ProcessIOCardType;
263 params: ProcessIOParameter[] | null;
265 mounts?: InputCollectionMount[];
267 forceShowParams?: boolean;
270 type ProcessIOCardProps = ProcessIOCardDataProps & WithStyles<CssRules> & MPVPanelProps;
272 export const ProcessIOCard = withStyles(styles)(
287 }: ProcessIOCardProps) => {
288 const PanelIcon = label === ProcessIOCardType.INPUT ? InputIcon : OutputIcon;
289 const mainProcess = !(process && process!.containerRequest.requestingContainerUuid);
290 const showParamTable = mainProcess || forceShowParams;
292 const loading = raw === null || raw === undefined || params === null;
294 const hasRaw = !!(raw && Object.keys(raw).length > 0);
295 const hasParams = !!(params && params.length > 0);
296 // isRawLoaded allows subprocess panel to display raw even if it's {}
297 const isRawLoaded = !!(raw && Object.keys(raw).length >= 0);
300 const hasInputMounts = !!(label === ProcessIOCardType.INPUT && mounts && mounts.length);
301 const hasOutputCollecton = !!(label === ProcessIOCardType.OUTPUT && outputUuid);
302 // Subprocess should not show loading if hasOutputCollection or hasInputMounts
303 const subProcessLoading = loading && !hasOutputCollecton && !hasInputMounts;
307 className={classes.card}
308 data-cy="process-io-card"
311 className={classes.header}
313 content: classes.title,
314 avatar: classes.avatar,
316 avatar={<PanelIcon className={classes.iconHeader} />}
328 {doUnMaximizePanel && panelMaximized && (
330 title={`Unmaximize ${panelName || "panel"}`}
333 <IconButton onClick={doUnMaximizePanel}>
338 {doMaximizePanel && !panelMaximized && (
340 title={`Maximize ${panelName || "panel"}`}
343 <IconButton onClick={doMaximizePanel}>
350 title={`Close ${panelName || "panel"}`}
354 disabled={panelMaximized}
355 onClick={doHidePanel}
364 <CardContent className={classes.content}>
367 {/* raw is undefined until params are loaded */}
378 {/* Once loaded, either raw or params may still be empty
379 * Raw when all params are empty
380 * Params when raw is provided by containerRequest properties but workflow mount is absent for preview
382 {!loading && (hasRaw || hasParams) && (
385 className={classes.symmetricTabs}
388 // params will be empty on processes without workflow definitions in mounts, so we only show raw
391 content: <ProcessIOPreview
393 valueLabel={forceShowParams ? "Default value" : "Value"}
397 show: !forceShowParams,
399 content: <ProcessIORaw data={raw} />,
402 show: hasOutputCollecton,
404 content: <ProcessOutputCollection outputUuid={outputUuid} />,
409 {!loading && !hasRaw && !hasParams && (
416 <DefaultView messages={["No parameters found"]} />
423 {subProcessLoading ? (
432 ) : !subProcessLoading && (hasInputMounts || hasOutputCollecton || isRawLoaded) ? (
435 className={classes.symmetricTabs}
438 show: hasInputMounts,
439 label: "Collections",
440 content: <ProcessInputMounts mounts={mounts || []} />,
443 show: hasOutputCollecton,
445 content: <ProcessOutputCollection outputUuid={outputUuid} />,
450 content: <ProcessIORaw data={raw} />,
461 <DefaultView messages={["No data to display"]} />
472 export type ProcessIOValue = {
473 display: ReactElement<any, any>;
475 collection?: ReactElement<any, any>;
479 export type ProcessIOParameter = {
482 value: ProcessIOValue;
485 interface ProcessIOPreviewDataProps {
486 data: ProcessIOParameter[];
491 type ProcessIOPreviewProps = ProcessIOPreviewDataProps & WithStyles<CssRules>;
493 const ProcessIOPreview = memo(
494 withStyles(styles)(({ data, valueLabel, hidden, classes }: ProcessIOPreviewProps) => {
495 const showLabel = data.some((param: ProcessIOParameter) => param.label);
497 const hasMoreValues = (index: number) => (
498 data[index+1] && !isMainRow(data[index+1])
501 const isMainRow = (param: ProcessIOParameter) => (
503 ((param.id || param.label) &&
504 !param.value.secondary)
507 const RenderRow = ({index, style}) => {
508 const param = data[index];
511 [classes.noBorderRow]: hasMoreValues(index),
516 className={classNames(rowClasses)}
517 data-cy={isMainRow(param) ? "process-io-param" : ""}>
519 <Tooltip title={param.id}>
520 <Typography className={classes.paramTableCellText}>
527 {showLabel && <TableCell>
528 <Tooltip title={param.label}>
529 <Typography className={classes.paramTableCellText}>
542 <Typography className={classes.paramTableCellText}>
543 {/** Collection is an anchor so doesn't require wrapper element */}
544 {param.value.collection}
550 return <div className={classes.tableWrapper} hidden={hidden}>
552 className={classes.paramTableRoot}
553 aria-label="Process IO Preview"
557 <TableCell>Name</TableCell>
558 {showLabel && <TableCell>Label</TableCell>}
559 <TableCell>{valueLabel}</TableCell>
560 <TableCell>Collection</TableCell>
565 {({ height, width }) =>
568 itemCount={data.length}
582 interface ProcessValuePreviewProps {
583 value: ProcessIOValue;
586 const ProcessValuePreview = withStyles(styles)(({ value, classes }: ProcessValuePreviewProps & WithStyles<CssRules>) => (
587 <Typography className={classNames(classes.paramTableCellText, value.secondary && classes.secondaryVal)}>
592 interface ProcessIORawDataProps {
593 data: ProcessIOParameter[];
597 const ProcessIORaw = withStyles(styles)(({ data, hidden, classes }: ProcessIORawDataProps & WithStyles<CssRules>) => (
598 <div className={classes.jsonWrapper} hidden={hidden}>
599 <Paper elevation={0} style={{minWidth: "100%", height: "100%"}}>
600 <DefaultVirtualCodeSnippet
601 lines={JSON.stringify(data, null, 2).split('\n')}
609 interface ProcessInputMountsDataProps {
610 mounts: InputCollectionMount[];
614 type ProcessInputMountsProps = ProcessInputMountsDataProps & WithStyles<CssRules>;
616 const ProcessInputMounts = withStyles(styles)(
617 connect((state: RootState) => ({
619 }))(({ mounts, hidden, classes, auth }: ProcessInputMountsProps & { auth: AuthState }) => (
621 className={classes.mountsTableRoot}
622 aria-label="Process Input Mounts"
627 <TableCell>Path</TableCell>
628 <TableCell>Portable Data Hash</TableCell>
632 {mounts.map(mount => (
633 <TableRow key={mount.path}>
635 <pre>{mount.path}</pre>
639 to={getNavUrl(mount.pdh, auth)}
640 className={classes.keepLink}
652 export interface ProcessOutputCollectionActionProps {
653 navigateTo: (uuid: string) => void;
656 const mapNavigateToProps = (dispatch: Dispatch): ProcessOutputCollectionActionProps => ({
657 navigateTo: uuid => dispatch<any>(navigateTo(uuid)),
660 type ProcessOutputCollectionProps = {outputUuid: string | undefined, hidden?: boolean} & ProcessOutputCollectionActionProps & WithStyles<CssRules>;
662 const ProcessOutputCollection = withStyles(styles)(connect(null, mapNavigateToProps)(({ outputUuid, hidden, navigateTo, classes }: ProcessOutputCollectionProps) => (
663 <div className={classes.tableWrapper} hidden={hidden}>
666 <Typography className={classes.collectionLink}>
667 Output Collection:{" "}
669 className={classes.keepLink}
671 navigateTo(outputUuid || "");
678 <ProcessOutputCollectionFiles
680 currentItemUuid={outputUuid}
686 type FileWithSecondaryFiles = {
687 secondaryFiles: File[];
690 export const getIOParamDisplayValue = (auth: AuthState, input: CommandInputParameter | CommandOutputParameter, pdh?: string): ProcessIOValue[] => {
692 case isPrimitiveOfType(input, CWLType.BOOLEAN):
693 const boolValue = (input as BooleanCommandInputParameter).value;
694 return boolValue !== undefined && !(Array.isArray(boolValue) && boolValue.length === 0)
695 ? [{ display: <PrimitiveTooltip data={boolValue}>{renderPrimitiveValue(boolValue, false)}</PrimitiveTooltip> }]
696 : [{ display: <EmptyValue /> }];
698 case isPrimitiveOfType(input, CWLType.INT):
699 case isPrimitiveOfType(input, CWLType.LONG):
700 const intValue = (input as IntCommandInputParameter).value;
701 return intValue !== undefined &&
702 // Missing values are empty array
703 !(Array.isArray(intValue) && intValue.length === 0)
704 ? [{ display: <PrimitiveTooltip data={intValue}>{renderPrimitiveValue(intValue, false)}</PrimitiveTooltip> }]
705 : [{ display: <EmptyValue /> }];
707 case isPrimitiveOfType(input, CWLType.FLOAT):
708 case isPrimitiveOfType(input, CWLType.DOUBLE):
709 const floatValue = (input as FloatCommandInputParameter).value;
710 return floatValue !== undefined && !(Array.isArray(floatValue) && floatValue.length === 0)
711 ? [{ display: <PrimitiveTooltip data={floatValue}>{renderPrimitiveValue(floatValue, false)}</PrimitiveTooltip> }]
712 : [{ display: <EmptyValue /> }];
714 case isPrimitiveOfType(input, CWLType.STRING):
715 const stringValue = (input as StringCommandInputParameter).value || undefined;
716 return stringValue !== undefined && !(Array.isArray(stringValue) && stringValue.length === 0)
717 ? [{ display: <PrimitiveTooltip data={stringValue}>{renderPrimitiveValue(stringValue, false)}</PrimitiveTooltip> }]
718 : [{ display: <EmptyValue /> }];
720 case isPrimitiveOfType(input, CWLType.FILE):
721 const mainFile = (input as FileCommandInputParameter).value;
722 // secondaryFiles: File[] is not part of CommandOutputParameter so we cast to access secondaryFiles
723 const secondaryFiles = (mainFile as unknown as FileWithSecondaryFiles)?.secondaryFiles || [];
724 const files = [...(mainFile && !(Array.isArray(mainFile) && mainFile.length === 0) ? [mainFile] : []), ...secondaryFiles];
725 const mainFilePdhUrl = mainFile ? getResourcePdhUrl(mainFile, pdh) : "";
727 ? files.map((file, i) => fileToProcessIOValue(file, i > 0, auth, pdh, i > 0 ? mainFilePdhUrl : ""))
728 : [{ display: <EmptyValue /> }];
730 case isPrimitiveOfType(input, CWLType.DIRECTORY):
731 const directory = (input as DirectoryCommandInputParameter).value;
732 return directory !== undefined && !(Array.isArray(directory) && directory.length === 0)
733 ? [directoryToProcessIOValue(directory, auth, pdh)]
734 : [{ display: <EmptyValue /> }];
736 case getEnumType(input) !== null:
737 const enumValue = (input as EnumCommandInputParameter).value;
738 return enumValue !== undefined && enumValue ? [{ display: <PrimitiveTooltip data={enumValue}>{enumValue}</PrimitiveTooltip> }] : [{ display: <EmptyValue /> }];
740 case isArrayOfType(input, CWLType.STRING):
741 const strArray = (input as StringArrayCommandInputParameter).value || [];
742 return strArray.length ? [{ display: <PrimitiveArrayTooltip data={strArray}>{strArray.map(val => renderPrimitiveValue(val, true))}</PrimitiveArrayTooltip> }] : [{ display: <EmptyValue /> }];
744 case isArrayOfType(input, CWLType.INT):
745 case isArrayOfType(input, CWLType.LONG):
746 const intArray = (input as IntArrayCommandInputParameter).value || [];
747 return intArray.length ? [{ display: <PrimitiveArrayTooltip data={intArray}>{intArray.map(val => renderPrimitiveValue(val, true))}</PrimitiveArrayTooltip> }] : [{ display: <EmptyValue /> }];
749 case isArrayOfType(input, CWLType.FLOAT):
750 case isArrayOfType(input, CWLType.DOUBLE):
751 const floatArray = (input as FloatArrayCommandInputParameter).value || [];
752 return floatArray.length ? [{ display: <PrimitiveArrayTooltip data={floatArray}>{floatArray.map(val => renderPrimitiveValue(val, true))}</PrimitiveArrayTooltip> }] : [{ display: <EmptyValue /> }];
754 case isArrayOfType(input, CWLType.FILE):
755 const fileArrayMainFiles = (input as FileArrayCommandInputParameter).value || [];
756 const firstMainFilePdh = fileArrayMainFiles.length > 0 && fileArrayMainFiles[0] ? getResourcePdhUrl(fileArrayMainFiles[0], pdh) : "";
758 // Convert each main and secondaryFiles into array of ProcessIOValue preserving ordering
759 let fileArrayValues: ProcessIOValue[] = [];
760 for (let i = 0; i < fileArrayMainFiles.length; i++) {
761 const secondaryFiles = (fileArrayMainFiles[i] as unknown as FileWithSecondaryFiles)?.secondaryFiles || [];
762 fileArrayValues.push(
763 // Pass firstMainFilePdh to secondary files and every main file besides the first to hide pdh if equal
764 ...(fileArrayMainFiles[i] ? [fileToProcessIOValue(fileArrayMainFiles[i], false, auth, pdh, i > 0 ? firstMainFilePdh : "")] : []),
765 ...secondaryFiles.map(file => fileToProcessIOValue(file, true, auth, pdh, firstMainFilePdh))
769 return fileArrayValues.length ? fileArrayValues : [{ display: <EmptyValue /> }];
771 case isArrayOfType(input, CWLType.DIRECTORY):
772 const directories = (input as DirectoryArrayCommandInputParameter).value || [];
773 return directories.length ? directories.map(directory => directoryToProcessIOValue(directory, auth, pdh)) : [{ display: <EmptyValue /> }];
776 return [{ display: <UnsupportedValue /> }];
780 interface PrimitiveTooltipProps {
781 data: boolean | number | string;
784 const PrimitiveTooltip = (props: React.PropsWithChildren<PrimitiveTooltipProps>) => (
785 <Tooltip title={typeof props.data !== 'object' ? String(props.data) : ""}>
786 <pre>{props.children}</pre>
790 interface PrimitiveArrayTooltipProps {
794 const PrimitiveArrayTooltip = (props: React.PropsWithChildren<PrimitiveArrayTooltipProps>) => (
795 <Tooltip title={props.data.join(', ')}>
796 <span>{props.children}</span>
801 const renderPrimitiveValue = (value: any, asChip: boolean) => {
802 const isObject = typeof value === "object";
807 label={String(value)}
808 style={{marginRight: "10px"}}
814 return asChip ? <UnsupportedValueChip /> : <UnsupportedValue />;
819 * @returns keep url without keep: prefix
821 const getKeepUrl = (file: File | Directory, pdh?: string): string => {
822 const isKeepUrl = file.location?.startsWith("keep:") || false;
823 const keepUrl = isKeepUrl ? file.location?.replace("keep:", "") : pdh ? `${pdh}/${file.location}` : file.location;
824 return keepUrl || "";
827 interface KeepUrlProps {
829 res: File | Directory;
833 const getResourcePdhUrl = (res: File | Directory, pdh?: string): string => {
834 const keepUrl = getKeepUrl(res, pdh);
835 return keepUrl ? keepUrl.split("/").slice(0, 1)[0] : "";
838 const KeepUrlBase = withStyles(styles)(({ auth, res, pdh, classes }: KeepUrlProps & WithStyles<CssRules>) => {
839 const pdhUrl = getResourcePdhUrl(res, pdh);
840 // Passing a pdh always returns a relative wb2 collection url
841 const pdhWbPath = getNavUrl(pdhUrl, auth);
842 return pdhUrl && pdhWbPath ? (
843 <Tooltip title={<>View collection in Workbench<br />{pdhUrl}</>}>
846 className={classes.keepLink}
856 const KeepUrlPath = withStyles(styles)(({ auth, res, pdh, classes }: KeepUrlProps & WithStyles<CssRules>) => {
857 const keepUrl = getKeepUrl(res, pdh);
858 const keepUrlParts = keepUrl ? keepUrl.split("/") : [];
859 const keepUrlPath = keepUrlParts.length > 1 ? keepUrlParts.slice(1).join("/") : "";
861 const keepUrlPathNav = getKeepNavUrl(auth, res, pdh);
862 return keepUrlPathNav ? (
863 <Tooltip classes={{tooltip: classes.wrapTooltip}} title={<>View in keep-web<br />{keepUrlPath || "/"}</>}>
865 className={classes.keepLink}
866 href={keepUrlPathNav}
868 rel="noopener noreferrer"
878 const getKeepNavUrl = (auth: AuthState, file: File | Directory, pdh?: string): string => {
879 let keepUrl = getKeepUrl(file, pdh);
880 return getInlineFileUrl(
881 `${auth.config.keepWebServiceUrl}/c=${keepUrl}?api_token=${auth.apiToken}`,
882 auth.config.keepWebServiceUrl,
883 auth.config.keepWebInlineServiceUrl
887 const getImageUrl = (auth: AuthState, file: File, pdh?: string): string => {
888 const keepUrl = getKeepUrl(file, pdh);
889 return getInlineFileUrl(
890 `${auth.config.keepWebServiceUrl}/c=${keepUrl}?api_token=${auth.apiToken}`,
891 auth.config.keepWebServiceUrl,
892 auth.config.keepWebInlineServiceUrl
896 const isFileImage = (basename?: string): boolean => {
897 return basename ? (mime.getType(basename) || "").startsWith("image/") : false;
900 const isFileUrl = (location?: string): boolean =>
901 !!location && !KEEP_URL_REGEX.exec(location) && (location.startsWith("http://") || location.startsWith("https://"));
903 const normalizeDirectoryLocation = (directory: Directory): Directory => {
904 if (!directory.location) {
909 location: (directory.location || "").endsWith("/") ? directory.location : directory.location + "/",
913 const directoryToProcessIOValue = (directory: Directory, auth: AuthState, pdh?: string): ProcessIOValue => {
914 if (isExternalValue(directory)) {
915 return { display: <UnsupportedValue /> };
918 const normalizedDirectory = normalizeDirectoryLocation(directory);
923 res={normalizedDirectory}
930 res={normalizedDirectory}
937 type MuiLinkWithTooltipProps = WithStyles<CssRules> & React.PropsWithChildren<LinkProps>;
939 const MuiLinkWithTooltip = withStyles(styles)((props: MuiLinkWithTooltipProps) => (
940 <Tooltip title={props.title} classes={{tooltip: props.classes.wrapTooltip}}>
947 const fileToProcessIOValue = (file: File, secondary: boolean, auth: AuthState, pdh: string | undefined, mainFilePdh: string): ProcessIOValue => {
948 if (isExternalValue(file)) {
949 return { display: <UnsupportedValue /> };
952 if (isFileUrl(file.location)) {
959 title={file.location}
962 </MuiLinkWithTooltip>
968 const resourcePdh = getResourcePdhUrl(file, pdh);
978 imageUrl: isFileImage(file.basename) ? getImageUrl(auth, file, pdh) : undefined,
980 resourcePdh !== mainFilePdh ? (
992 const isExternalValue = (val: any) => Object.keys(val).includes("$import") || Object.keys(val).includes("$include");
994 export const EmptyValue = withStyles(styles)(({ classes }: WithStyles<CssRules>) => <span className={classes.emptyValue}>No value</span>);
996 const UnsupportedValue = withStyles(styles)(({ classes }: WithStyles<CssRules>) => <span className={classes.emptyValue}>Cannot display value</span>);
998 const UnsupportedValueChip = withStyles(styles)(({ classes }: WithStyles<CssRules>) => (
1001 label={"Cannot display value"}