16073: Display process io params from props, hide preview when lacking workflow mount
[arvados-workbench2.git] / src / views / process-panel / process-io-card.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React, { ReactElement, useState } from 'react';
6 import { Dispatch } from 'redux';
7 import {
8     StyleRulesCallback,
9     WithStyles,
10     withStyles,
11     Card,
12     CardHeader,
13     IconButton,
14     CardContent,
15     Tooltip,
16     Typography,
17     Tabs,
18     Tab,
19     Table,
20     TableHead,
21     TableBody,
22     TableRow,
23     TableCell,
24     Paper,
25     Grid,
26     Chip,
27     CircularProgress,
28 } from '@material-ui/core';
29 import { ArvadosTheme } from 'common/custom-theme';
30 import { CloseIcon, ImageIcon, InputIcon, ImageOffIcon, OutputIcon, MaximizeIcon } from 'components/icon/icon';
31 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
32 import {
33   BooleanCommandInputParameter,
34   CommandInputParameter,
35   CWLType,
36   Directory,
37   DirectoryArrayCommandInputParameter,
38   DirectoryCommandInputParameter,
39   EnumCommandInputParameter,
40   FileArrayCommandInputParameter,
41   FileCommandInputParameter,
42   FloatArrayCommandInputParameter,
43   FloatCommandInputParameter,
44   IntArrayCommandInputParameter,
45   IntCommandInputParameter,
46   isArrayOfType,
47   isPrimitiveOfType,
48   StringArrayCommandInputParameter,
49   StringCommandInputParameter,
50 } from "models/workflow";
51 import { CommandOutputParameter } from 'cwlts/mappings/v1.0/CommandOutputParameter';
52 import { File } from 'models/workflow';
53 import { getInlineFileUrl } from 'views-components/context-menu/actions/helpers';
54 import { AuthState } from 'store/auth/auth-reducer';
55 import mime from 'mime';
56 import { DefaultView } from 'components/default-view/default-view';
57 import { getNavUrl } from 'routes/routes';
58 import { Link as RouterLink } from 'react-router-dom';
59 import { Link as MuiLink } from '@material-ui/core';
60 import { InputCollectionMount } from 'store/processes/processes-actions';
61 import { connect } from 'react-redux';
62 import { RootState } from 'store/store';
63 import { ProcessOutputCollectionFiles } from './process-output-collection-files';
64 import { Process } from 'store/processes/process';
65 import { navigateTo } from 'store/navigation/navigation-action';
66
67 type CssRules =
68   | "card"
69   | "content"
70   | "title"
71   | "header"
72   | "avatar"
73   | "iconHeader"
74   | "tableWrapper"
75   | "tableRoot"
76   | "paramValue"
77   | "keepLink"
78   | "collectionLink"
79   | "imagePreview"
80   | "valArray"
81   | "emptyValue"
82   | "halfRow"
83   | "symmetricTabs"
84   | "imagePlaceholder"
85   | "rowWithPreview"
86   | "labelColumn";
87
88 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
89     card: {
90         height: '100%'
91     },
92     header: {
93         paddingTop: theme.spacing.unit,
94         paddingBottom: theme.spacing.unit,
95     },
96     iconHeader: {
97         fontSize: '1.875rem',
98         color: theme.customs.colors.green700,
99     },
100     avatar: {
101         alignSelf: 'flex-start',
102         paddingTop: theme.spacing.unit * 0.5
103     },
104     content: {
105         height: `calc(100% - ${theme.spacing.unit * 7}px - ${theme.spacing.unit * 1.5}px)`,
106         padding: theme.spacing.unit * 1.0,
107         paddingTop: theme.spacing.unit * 0.5,
108         '&:last-child': {
109             paddingBottom: theme.spacing.unit * 1,
110         }
111     },
112     title: {
113         overflow: 'hidden',
114         paddingTop: theme.spacing.unit * 0.5
115     },
116     tableWrapper: {
117         height: `calc(100% - ${theme.spacing.unit * 6}px)`,
118         overflow: 'auto',
119     },
120     tableRoot: {
121         width: '100%',
122         '& thead th': {
123             verticalAlign: 'bottom',
124             paddingBottom: '10px',
125         },
126         '& td, & th': {
127             paddingRight: '25px',
128         }
129     },
130     paramValue: {
131         display: 'flex',
132         alignItems: 'flex-start',
133         flexDirection: 'column',
134     },
135     keepLink: {
136         color: theme.palette.primary.main,
137         textDecoration: 'none',
138         overflowWrap: 'break-word',
139         cursor: 'pointer',
140     },
141     collectionLink: {
142         margin: '10px',
143         '& a': {
144             color: theme.palette.primary.main,
145             textDecoration: 'none',
146             overflowWrap: 'break-word',
147             cursor: 'pointer',
148         }
149     },
150     imagePreview: {
151         maxHeight: '15em',
152         maxWidth: '15em',
153         marginBottom: theme.spacing.unit,
154     },
155     valArray: {
156         display: 'flex',
157         gap: '10px',
158         flexWrap: 'wrap',
159         '& span': {
160             display: 'inline',
161         }
162     },
163     emptyValue: {
164         color: theme.customs.colors.grey500,
165     },
166     halfRow: {
167         '& td': {
168             borderBottom: 'none',
169         }
170     },
171     symmetricTabs: {
172         '& button': {
173             flexBasis: '0',
174         }
175     },
176     imagePlaceholder: {
177         width: '60px',
178         height: '60px',
179         display: 'flex',
180         alignItems: 'center',
181         justifyContent: 'center',
182         backgroundColor: '#cecece',
183         borderRadius: '10px',
184     },
185     rowWithPreview: {
186         verticalAlign: 'bottom',
187     },
188     labelColumn: {
189         minWidth: '120px',
190     },
191 });
192
193 export enum ProcessIOCardType {
194     INPUT = 'Inputs',
195     OUTPUT = 'Outputs',
196 }
197 export interface ProcessIOCardDataProps {
198     process: Process;
199     label: ProcessIOCardType;
200     params?: ProcessIOParameter[];
201     raw?: any;
202     mounts?: InputCollectionMount[];
203     outputUuid?: string;
204 }
205
206 export interface ProcessIOCardActionProps {
207     navigateTo: (uuid: string) => void;
208 }
209
210 const mapDispatchToProps = (dispatch: Dispatch): ProcessIOCardActionProps => ({
211     navigateTo: (uuid) => dispatch<any>(navigateTo(uuid)),
212 });
213
214 type ProcessIOCardProps = ProcessIOCardDataProps & ProcessIOCardActionProps & WithStyles<CssRules> & MPVPanelProps;
215
216 export const ProcessIOCard = withStyles(styles)(connect(null, mapDispatchToProps)(
217     ({ classes, label, params, raw, mounts, outputUuid, doHidePanel, doMaximizePanel, panelMaximized, panelName, process, navigateTo }: ProcessIOCardProps) => {
218         const [mainProcTabState, setMainProcTabState] = useState(0);
219         const handleMainProcTabChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
220             setMainProcTabState(value);
221         }
222
223         const [showImagePreview, setShowImagePreview] = useState(false);
224
225         const PanelIcon = label === ProcessIOCardType.INPUT ? InputIcon : OutputIcon;
226         const mainProcess = !process.containerRequest.requestingContainerUuid;
227
228         return <Card className={classes.card} data-cy="process-io-card">
229             <CardHeader
230                 className={classes.header}
231                 classes={{
232                     content: classes.title,
233                     avatar: classes.avatar,
234                 }}
235                 avatar={<PanelIcon className={classes.iconHeader} />}
236                 title={
237                     <Typography noWrap variant='h6' color='inherit'>
238                         {label}
239                     </Typography>
240                 }
241                 action={
242                     <div>
243                         { mainProcess && <Tooltip title={"Toggle Image Preview"} disableFocusListener>
244                             <IconButton data-cy="io-preview-image-toggle" onClick={() =>{setShowImagePreview(!showImagePreview)}}>{showImagePreview ? <ImageIcon /> : <ImageOffIcon />}</IconButton>
245                         </Tooltip> }
246                         { doMaximizePanel && !panelMaximized &&
247                         <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
248                             <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
249                         </Tooltip> }
250                         { doHidePanel &&
251                         <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
252                             <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
253                         </Tooltip> }
254                     </div>
255                 } />
256             <CardContent className={classes.content}>
257                 {mainProcess ?
258                     (<>
259                         {/* raw is undefined until params are loaded */}
260                         {raw === undefined && <Grid container item alignItems='center' justify='center'>
261                             <CircularProgress />
262                         </Grid>}
263                         {raw && Object.keys(raw).length > 0 &&
264                             <>
265                                 <Tabs value={mainProcTabState} onChange={handleMainProcTabChange} variant="fullWidth" className={classes.symmetricTabs}>
266                                     {/* params will be empty on processes without workflow definitions in mounts, so we only show raw */}
267                                     {(params && params.length) && <Tab label="Parameters" />}
268                                     <Tab label="JSON" />
269                                 </Tabs>
270                                 {(mainProcTabState === 0 && params && params.length > 0) && <div className={classes.tableWrapper}>
271                                         <ProcessIOPreview data={params} showImagePreview={showImagePreview} />
272                                     </div>}
273                                 {(mainProcTabState === 1 || !params || !(params.length > 0)) && <div className={classes.tableWrapper}>
274                                         <ProcessIORaw data={raw} />
275                                     </div>}
276                             </>}
277                         {raw && Object.keys(raw).length === 0 && <Grid container item alignItems='center' justify='center'>
278                             <DefaultView messages={["No parameters found"]} />
279                         </Grid>}
280                     </>) :
281                     // Subprocess
282                     (<>
283                         {((mounts && mounts.length) || outputUuid) ?
284                             <>
285                                 <Tabs value={0} variant="fullWidth" className={classes.symmetricTabs}>
286                                     {label === ProcessIOCardType.INPUT && <Tab label="Collections" />}
287                                     {label === ProcessIOCardType.OUTPUT && <Tab label="Collection" />}
288                                 </Tabs>
289                                 <div className={classes.tableWrapper}>
290                                     {label === ProcessIOCardType.INPUT && <ProcessInputMounts mounts={mounts || []} />}
291                                     {label === ProcessIOCardType.OUTPUT && <>
292                                         {outputUuid && <Typography className={classes.collectionLink}>
293                                             Output Collection: <MuiLink className={classes.keepLink} onClick={() => {navigateTo(outputUuid || "")}}>
294                                             {outputUuid}
295                                         </MuiLink></Typography>}
296                                         <ProcessOutputCollectionFiles isWritable={false} currentItemUuid={outputUuid} />
297                                     </>}
298                                 </div>
299                             </> :
300                             <Grid container item alignItems='center' justify='center'>
301                                 <DefaultView messages={["No collection(s) found"]} />
302                             </Grid>
303                         }
304                     </>)
305                 }
306             </CardContent>
307         </Card>;
308     }
309 ));
310
311 export type ProcessIOValue = {
312     display: ReactElement<any, any>;
313     imageUrl?: string;
314     collection?: ReactElement<any, any>;
315 }
316
317 export type ProcessIOParameter = {
318     id: string;
319     label: string;
320     value: ProcessIOValue[];
321 }
322
323 interface ProcessIOPreviewDataProps {
324     data: ProcessIOParameter[];
325     showImagePreview: boolean;
326 }
327
328 type ProcessIOPreviewProps = ProcessIOPreviewDataProps & WithStyles<CssRules>;
329
330 const ProcessIOPreview = withStyles(styles)(
331     ({ classes, data, showImagePreview }: ProcessIOPreviewProps) => {
332         const showLabel = data.some((param: ProcessIOParameter) => param.label);
333         return <Table className={classes.tableRoot} aria-label="Process IO Preview">
334             <TableHead>
335                 <TableRow>
336                     <TableCell>Name</TableCell>
337                     {showLabel && <TableCell className={classes.labelColumn}>Label</TableCell>}
338                     <TableCell>Value</TableCell>
339                     <TableCell>Collection</TableCell>
340                 </TableRow>
341             </TableHead>
342             <TableBody>
343                 {data.map((param: ProcessIOParameter) => {
344                     const firstVal = param.value.length > 0 ? param.value[0] : undefined;
345                     const rest = param.value.slice(1);
346                     const rowClass = rest.length > 0 ? classes.halfRow : undefined;
347
348                     return <>
349                         <TableRow className={rowClass} data-cy="process-io-param">
350                             <TableCell>
351                                 {param.id}
352                             </TableCell>
353                             {showLabel && <TableCell >{param.label}</TableCell>}
354                             <TableCell>
355                                 {firstVal && <ProcessValuePreview value={firstVal} showImagePreview={showImagePreview} />}
356                             </TableCell>
357                             <TableCell className={firstVal?.imageUrl ? classes.rowWithPreview : undefined}>
358                                 <Typography className={classes.paramValue}>
359                                     {firstVal?.collection}
360                                 </Typography>
361                             </TableCell>
362                         </TableRow>
363                         {rest.map((val, i) => (
364                             <TableRow className={(i < rest.length-1) ? rowClass : undefined}>
365                                 <TableCell />
366                                 {showLabel && <TableCell />}
367                                 <TableCell>
368                                     <ProcessValuePreview value={val} showImagePreview={showImagePreview} />
369                                 </TableCell>
370                                 <TableCell className={firstVal?.imageUrl ? classes.rowWithPreview : undefined}>
371                                     <Typography className={classes.paramValue}>
372                                         {val.collection}
373                                     </Typography>
374                                 </TableCell>
375                             </TableRow>
376                         ))}
377                     </>;
378                 })}
379             </TableBody>
380         </Table>;
381 });
382
383 interface ProcessValuePreviewProps {
384     value: ProcessIOValue;
385     showImagePreview: boolean;
386 }
387
388 const ProcessValuePreview = withStyles(styles)(
389     ({value, showImagePreview, classes}: ProcessValuePreviewProps & WithStyles<CssRules>) =>
390         <Typography className={classes.paramValue}>
391             {value.imageUrl && showImagePreview ? <img className={classes.imagePreview} src={value.imageUrl} alt="Inline Preview" /> : ""}
392             {value.imageUrl && !showImagePreview ? <ImagePlaceholder /> : ""}
393             <span className={classes.valArray}>
394                 {value.display}
395             </span>
396         </Typography>
397 )
398
399 interface ProcessIORawDataProps {
400     data: ProcessIOParameter[];
401 }
402
403 const ProcessIORaw = withStyles(styles)(
404     ({ data }: ProcessIORawDataProps) =>
405         <Paper elevation={0}>
406             <pre>
407                 {JSON.stringify(data, null, 2)}
408             </pre>
409         </Paper>
410 );
411
412 interface ProcessInputMountsDataProps {
413     mounts: InputCollectionMount[];
414 }
415
416 type ProcessInputMountsProps = ProcessInputMountsDataProps & WithStyles<CssRules>;
417
418 const ProcessInputMounts = withStyles(styles)(connect((state: RootState) => ({
419     auth: state.auth,
420 }))(({ mounts, classes, auth }: ProcessInputMountsProps & { auth: AuthState }) => (
421     <Table className={classes.tableRoot} aria-label="Process Input Mounts">
422         <TableHead>
423             <TableRow>
424                 <TableCell>Path</TableCell>
425                 <TableCell>Portable Data Hash</TableCell>
426             </TableRow>
427         </TableHead>
428         <TableBody>
429             {mounts.map(mount => (
430                 <TableRow key={mount.path}>
431                     <TableCell><pre>{mount.path}</pre></TableCell>
432                     <TableCell>
433                         <RouterLink to={getNavUrl(mount.pdh, auth)} className={classes.keepLink}>{mount.pdh}</RouterLink>
434                     </TableCell>
435                 </TableRow>
436             ))}
437         </TableBody>
438     </Table>
439 )));
440
441 type FileWithSecondaryFiles = {
442     secondaryFiles: File[];
443 }
444
445 export const getIOParamDisplayValue = (auth: AuthState, input: CommandInputParameter | CommandOutputParameter, pdh?: string): ProcessIOValue[] => {
446     switch (true) {
447         case isPrimitiveOfType(input, CWLType.BOOLEAN):
448             const boolValue = (input as BooleanCommandInputParameter).value;
449
450             return boolValue !== undefined &&
451                     !(Array.isArray(boolValue) && boolValue.length === 0) ?
452                 [{display: <pre>{String(boolValue)}</pre> }] :
453                 [{display: <EmptyValue />}];
454
455         case isPrimitiveOfType(input, CWLType.INT):
456         case isPrimitiveOfType(input, CWLType.LONG):
457             const intValue = (input as IntCommandInputParameter).value;
458
459             return intValue !== undefined &&
460                     // Missing values are empty array
461                     !(Array.isArray(intValue) && intValue.length === 0) ?
462                 [{display: <pre>{String(intValue)}</pre> }]
463                 : [{display: <EmptyValue />}];
464
465         case isPrimitiveOfType(input, CWLType.FLOAT):
466         case isPrimitiveOfType(input, CWLType.DOUBLE):
467             const floatValue = (input as FloatCommandInputParameter).value;
468
469             return floatValue !== undefined &&
470                     !(Array.isArray(floatValue) && floatValue.length === 0) ?
471                 [{display: <pre>{String(floatValue)}</pre> }]:
472                 [{display: <EmptyValue />}];
473
474         case isPrimitiveOfType(input, CWLType.STRING):
475             const stringValue = (input as StringCommandInputParameter).value || undefined;
476
477             return stringValue !== undefined &&
478                     !(Array.isArray(stringValue) && stringValue.length === 0) ?
479                 [{display: <pre>{stringValue}</pre> }] :
480                 [{display: <EmptyValue />}];
481
482         case isPrimitiveOfType(input, CWLType.FILE):
483             const mainFile = (input as FileCommandInputParameter).value;
484             // secondaryFiles: File[] is not part of CommandOutputParameter so we cast to access secondaryFiles
485             const secondaryFiles = ((mainFile as unknown) as FileWithSecondaryFiles)?.secondaryFiles || [];
486             const files = [
487                 ...(mainFile && !(Array.isArray(mainFile) && mainFile.length === 0) ? [mainFile] : []),
488                 ...secondaryFiles
489             ];
490
491             return files.length ?
492                 files.map(file => fileToProcessIOValue(file, auth, pdh)) :
493                 [{display: <EmptyValue />}];
494
495         case isPrimitiveOfType(input, CWLType.DIRECTORY):
496             const directory = (input as DirectoryCommandInputParameter).value;
497
498             return directory !== undefined &&
499                     !(Array.isArray(directory) && directory.length === 0) ?
500                 [directoryToProcessIOValue(directory, auth, pdh)] :
501                 [{display: <EmptyValue />}];
502
503         case typeof input.type === 'object' &&
504             !(input.type instanceof Array) &&
505             input.type.type === 'enum':
506             const enumValue = (input as EnumCommandInputParameter).value;
507
508             return enumValue !== undefined ?
509                 [{ display: <pre>{(input as EnumCommandInputParameter).value || ''}</pre> }] :
510                 [{display: <EmptyValue />}];
511
512         case isArrayOfType(input, CWLType.STRING):
513             const strArray = (input as StringArrayCommandInputParameter).value || [];
514             return strArray.length ?
515                 [{ display: <>{((input as StringArrayCommandInputParameter).value || []).map((val) => <Chip label={val} />)}</> }] :
516                 [{display: <EmptyValue />}];
517
518         case isArrayOfType(input, CWLType.INT):
519         case isArrayOfType(input, CWLType.LONG):
520             const intArray = (input as IntArrayCommandInputParameter).value || [];
521
522             return intArray.length ?
523                 [{ display: <>{((input as IntArrayCommandInputParameter).value || []).map((val) => <Chip label={val} />)}</> }] :
524                 [{display: <EmptyValue />}];
525
526         case isArrayOfType(input, CWLType.FLOAT):
527         case isArrayOfType(input, CWLType.DOUBLE):
528             const floatArray = (input as FloatArrayCommandInputParameter).value || [];
529
530             return floatArray.length ?
531                 [{ display: <>{floatArray.map((val) => <Chip label={val} />)}</> }] :
532                 [{display: <EmptyValue />}];
533
534         case isArrayOfType(input, CWLType.FILE):
535             const fileArrayMainFile = ((input as FileArrayCommandInputParameter).value || []);
536             const fileArraySecondaryFiles = fileArrayMainFile.map((file) => (
537                 ((file as unknown) as FileWithSecondaryFiles)?.secondaryFiles || []
538             )).reduce((acc: File[], params: File[]) => (acc.concat(params)), []);
539
540             const fileArrayFiles = [
541                 ...fileArrayMainFile,
542                 ...fileArraySecondaryFiles
543             ];
544
545             return fileArrayFiles.length ?
546                 fileArrayFiles.map(file => fileToProcessIOValue(file, auth, pdh)) :
547                 [{display: <EmptyValue />}];
548
549         case isArrayOfType(input, CWLType.DIRECTORY):
550             const directories = (input as DirectoryArrayCommandInputParameter).value || [];
551
552             return directories.length ?
553                 directories.map(directory => directoryToProcessIOValue(directory, auth, pdh)) :
554                 [{display: <EmptyValue />}];
555
556         default:
557             return [];
558     }
559 };
560
561 /*
562  * @returns keep url without keep: prefix
563  */
564 const getKeepUrl = (file: File | Directory, pdh?: string): string => {
565     const isKeepUrl = file.location?.startsWith('keep:') || false;
566     const keepUrl = isKeepUrl ?
567                         file.location?.replace('keep:', '') :
568                         pdh ? `${pdh}/${file.location}` : file.location;
569     return keepUrl || '';
570 };
571
572 interface KeepUrlProps {
573     auth: AuthState;
574     res: File | Directory;
575     pdh?: string;
576 }
577
578 const KeepUrlBase = withStyles(styles)(({auth, res, pdh, classes}: KeepUrlProps & WithStyles<CssRules>) => {
579     const keepUrl = getKeepUrl(res, pdh);
580     const pdhUrl = keepUrl ? keepUrl.split('/').slice(0, 1)[0] : '';
581     // Passing a pdh always returns a relative wb2 collection url
582     const pdhWbPath = getNavUrl(pdhUrl, auth);
583     return pdhUrl && pdhWbPath ?
584         <Tooltip title={"View collection in Workbench"}><RouterLink to={pdhWbPath} className={classes.keepLink}>{pdhUrl}</RouterLink></Tooltip> :
585         <></>;
586 });
587
588 const KeepUrlPath = withStyles(styles)(({auth, res, pdh, classes}: KeepUrlProps & WithStyles<CssRules>) => {
589     const keepUrl = getKeepUrl(res, pdh);
590     const keepUrlParts = keepUrl ? keepUrl.split('/') : [];
591     const keepUrlPath = keepUrlParts.length > 1 ? keepUrlParts.slice(1).join('/') : '';
592
593     const keepUrlPathNav = getKeepNavUrl(auth, res, pdh);
594     return keepUrlPath && keepUrlPathNav ?
595         <Tooltip title={"View in keep-web"}><a className={classes.keepLink} href={keepUrlPathNav} target="_blank" rel="noopener noreferrer">{keepUrlPath}</a></Tooltip> :
596         // Show No value for root collection io that lacks path part
597         <EmptyValue />;
598 });
599
600 const getKeepNavUrl = (auth: AuthState, file: File | Directory, pdh?: string): string => {
601     let keepUrl = getKeepUrl(file, pdh);
602     return (getInlineFileUrl(`${auth.config.keepWebServiceUrl}/c=${keepUrl}?api_token=${auth.apiToken}`, auth.config.keepWebServiceUrl, auth.config.keepWebInlineServiceUrl));
603 };
604
605 const getImageUrl = (auth: AuthState, file: File, pdh?: string): string => {
606     const keepUrl = getKeepUrl(file, pdh);
607     return getInlineFileUrl(`${auth.config.keepWebServiceUrl}/c=${keepUrl}?api_token=${auth.apiToken}`, auth.config.keepWebServiceUrl, auth.config.keepWebInlineServiceUrl);
608 };
609
610 const isFileImage = (basename?: string): boolean => {
611     return basename ? (mime.getType(basename) || "").startsWith('image/') : false;
612 };
613
614 const normalizeDirectoryLocation = (directory: Directory): Directory => {
615     if (!directory.location) {
616         return directory;
617     }
618     return {
619         ...directory,
620         location: (directory.location || '').endsWith('/') ? directory.location : directory.location + '/',
621     };
622 };
623
624 const directoryToProcessIOValue = (directory: Directory, auth: AuthState, pdh?: string): ProcessIOValue => {
625     const normalizedDirectory = normalizeDirectoryLocation(directory);
626     return {
627         display: <KeepUrlPath auth={auth} res={normalizedDirectory} pdh={pdh}/>,
628         collection: <KeepUrlBase auth={auth} res={normalizedDirectory} pdh={pdh}/>,
629     };
630 };
631
632 const fileToProcessIOValue = (file: File, auth: AuthState, pdh?: string): ProcessIOValue => {
633     return {
634         display: <KeepUrlPath auth={auth} res={file} pdh={pdh}/>,
635         imageUrl: isFileImage(file.basename) ? getImageUrl(auth, file, pdh) : undefined,
636         collection: <KeepUrlBase auth={auth} res={file} pdh={pdh}/>,
637     }
638 };
639
640 const EmptyValue = withStyles(styles)(
641     ({classes}: WithStyles<CssRules>) => <span className={classes.emptyValue}>No value</span>
642 );
643
644 const ImagePlaceholder = withStyles(styles)(
645     ({classes}: WithStyles<CssRules>) => <span className={classes.imagePlaceholder}><ImageIcon /></span>
646 );