84a9ca6d4c53cd6b345bae17b40e820dce186b5a
[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                         {params === undefined && <Grid container item alignItems='center' justify='center'>
260                             <CircularProgress />
261                         </Grid>}
262                         {params && params.length > 0 &&
263                             <>
264                                 <Tabs value={mainProcTabState} onChange={handleMainProcTabChange} variant="fullWidth" className={classes.symmetricTabs}>
265                                     <Tab label="Parameters" />
266                                     <Tab label="JSON" />
267                                 </Tabs>
268                                 {mainProcTabState === 0 && <div className={classes.tableWrapper}>
269                                         <ProcessIOPreview data={params} showImagePreview={showImagePreview} />
270                                     </div>}
271                                 {mainProcTabState === 1 && <div className={classes.tableWrapper}>
272                                         <ProcessIORaw data={raw || params} />
273                                     </div>}
274                             </>}
275                         {params && params.length === 0 && <Grid container item alignItems='center' justify='center'>
276                             <DefaultView messages={["No parameters found"]} />
277                         </Grid>}
278                     </>) :
279                     // Subprocess
280                     (<>
281                         {((mounts && mounts.length) || outputUuid) ?
282                             <>
283                                 <Tabs value={0} variant="fullWidth" className={classes.symmetricTabs}>
284                                     {label === ProcessIOCardType.INPUT && <Tab label="Collections" />}
285                                     {label === ProcessIOCardType.OUTPUT && <Tab label="Collection" />}
286                                 </Tabs>
287                                 <div className={classes.tableWrapper}>
288                                     {label === ProcessIOCardType.INPUT && <ProcessInputMounts mounts={mounts || []} />}
289                                     {label === ProcessIOCardType.OUTPUT && <>
290                                         {outputUuid && <Typography className={classes.collectionLink}>
291                                             Output Collection: <MuiLink className={classes.keepLink} onClick={() => {navigateTo(outputUuid || "")}}>
292                                             {outputUuid}
293                                         </MuiLink></Typography>}
294                                         <ProcessOutputCollectionFiles isWritable={false} currentItemUuid={outputUuid} />
295                                     </>}
296                                 </div>
297                             </> :
298                             <Grid container item alignItems='center' justify='center'>
299                                 <DefaultView messages={["No collection(s) found"]} />
300                             </Grid>
301                         }
302                     </>)
303                 }
304             </CardContent>
305         </Card>;
306     }
307 ));
308
309 export type ProcessIOValue = {
310     display: ReactElement<any, any>;
311     imageUrl?: string;
312     collection?: ReactElement<any, any>;
313 }
314
315 export type ProcessIOParameter = {
316     id: string;
317     label: string;
318     value: ProcessIOValue[];
319 }
320
321 interface ProcessIOPreviewDataProps {
322     data: ProcessIOParameter[];
323     showImagePreview: boolean;
324 }
325
326 type ProcessIOPreviewProps = ProcessIOPreviewDataProps & WithStyles<CssRules>;
327
328 const ProcessIOPreview = withStyles(styles)(
329     ({ classes, data, showImagePreview }: ProcessIOPreviewProps) => {
330         const showLabel = data.some((param: ProcessIOParameter) => param.label);
331         return <Table className={classes.tableRoot} aria-label="Process IO Preview">
332             <TableHead>
333                 <TableRow>
334                     <TableCell>Name</TableCell>
335                     {showLabel && <TableCell className={classes.labelColumn}>Label</TableCell>}
336                     <TableCell>Value</TableCell>
337                     <TableCell>Collection</TableCell>
338                 </TableRow>
339             </TableHead>
340             <TableBody>
341                 {data.map((param: ProcessIOParameter) => {
342                     const firstVal = param.value.length > 0 ? param.value[0] : undefined;
343                     const rest = param.value.slice(1);
344                     const rowClass = rest.length > 0 ? classes.halfRow : undefined;
345
346                     return <>
347                         <TableRow className={rowClass} data-cy="process-io-param">
348                             <TableCell>
349                                 {param.id}
350                             </TableCell>
351                             {showLabel && <TableCell >{param.label}</TableCell>}
352                             <TableCell>
353                                 {firstVal && <ProcessValuePreview value={firstVal} showImagePreview={showImagePreview} />}
354                             </TableCell>
355                             <TableCell className={firstVal?.imageUrl ? classes.rowWithPreview : undefined}>
356                                 <Typography className={classes.paramValue}>
357                                     {firstVal?.collection}
358                                 </Typography>
359                             </TableCell>
360                         </TableRow>
361                         {rest.map((val, i) => (
362                             <TableRow className={(i < rest.length-1) ? rowClass : undefined}>
363                                 <TableCell />
364                                 {showLabel && <TableCell />}
365                                 <TableCell>
366                                     <ProcessValuePreview value={val} showImagePreview={showImagePreview} />
367                                 </TableCell>
368                                 <TableCell className={firstVal?.imageUrl ? classes.rowWithPreview : undefined}>
369                                     <Typography className={classes.paramValue}>
370                                         {val.collection}
371                                     </Typography>
372                                 </TableCell>
373                             </TableRow>
374                         ))}
375                     </>;
376                 })}
377             </TableBody>
378         </Table>;
379 });
380
381 interface ProcessValuePreviewProps {
382     value: ProcessIOValue;
383     showImagePreview: boolean;
384 }
385
386 const ProcessValuePreview = withStyles(styles)(
387     ({value, showImagePreview, classes}: ProcessValuePreviewProps & WithStyles<CssRules>) =>
388         <Typography className={classes.paramValue}>
389             {value.imageUrl && showImagePreview ? <img className={classes.imagePreview} src={value.imageUrl} alt="Inline Preview" /> : ""}
390             {value.imageUrl && !showImagePreview ? <ImagePlaceholder /> : ""}
391             <span className={classes.valArray}>
392                 {value.display}
393             </span>
394         </Typography>
395 )
396
397 interface ProcessIORawDataProps {
398     data: ProcessIOParameter[];
399 }
400
401 const ProcessIORaw = withStyles(styles)(
402     ({ data }: ProcessIORawDataProps) =>
403         <Paper elevation={0}>
404             <pre>
405                 {JSON.stringify(data, null, 2)}
406             </pre>
407         </Paper>
408 );
409
410 interface ProcessInputMountsDataProps {
411     mounts: InputCollectionMount[];
412 }
413
414 type ProcessInputMountsProps = ProcessInputMountsDataProps & WithStyles<CssRules>;
415
416 const ProcessInputMounts = withStyles(styles)(connect((state: RootState) => ({
417     auth: state.auth,
418 }))(({ mounts, classes, auth }: ProcessInputMountsProps & { auth: AuthState }) => (
419     <Table className={classes.tableRoot} aria-label="Process Input Mounts">
420         <TableHead>
421             <TableRow>
422                 <TableCell>Path</TableCell>
423                 <TableCell>Portable Data Hash</TableCell>
424             </TableRow>
425         </TableHead>
426         <TableBody>
427             {mounts.map(mount => (
428                 <TableRow key={mount.path}>
429                     <TableCell><pre>{mount.path}</pre></TableCell>
430                     <TableCell>
431                         <RouterLink to={getNavUrl(mount.pdh, auth)} className={classes.keepLink}>{mount.pdh}</RouterLink>
432                     </TableCell>
433                 </TableRow>
434             ))}
435         </TableBody>
436     </Table>
437 )));
438
439 type FileWithSecondaryFiles = {
440     secondaryFiles: File[];
441 }
442
443 export const getIOParamDisplayValue = (auth: AuthState, input: CommandInputParameter | CommandOutputParameter, pdh?: string): ProcessIOValue[] => {
444     switch (true) {
445         case isPrimitiveOfType(input, CWLType.BOOLEAN):
446             const boolValue = (input as BooleanCommandInputParameter).value;
447
448             return boolValue !== undefined &&
449                     !(Array.isArray(boolValue) && boolValue.length === 0) ?
450                 [{display: <pre>{String(boolValue)}</pre> }] :
451                 [{display: <EmptyValue />}];
452
453         case isPrimitiveOfType(input, CWLType.INT):
454         case isPrimitiveOfType(input, CWLType.LONG):
455             const intValue = (input as IntCommandInputParameter).value;
456
457             return intValue !== undefined &&
458                     // Missing values are empty array
459                     !(Array.isArray(intValue) && intValue.length === 0) ?
460                 [{display: <pre>{String(intValue)}</pre> }]
461                 : [{display: <EmptyValue />}];
462
463         case isPrimitiveOfType(input, CWLType.FLOAT):
464         case isPrimitiveOfType(input, CWLType.DOUBLE):
465             const floatValue = (input as FloatCommandInputParameter).value;
466
467             return floatValue !== undefined &&
468                     !(Array.isArray(floatValue) && floatValue.length === 0) ?
469                 [{display: <pre>{String(floatValue)}</pre> }]:
470                 [{display: <EmptyValue />}];
471
472         case isPrimitiveOfType(input, CWLType.STRING):
473             const stringValue = (input as StringCommandInputParameter).value || undefined;
474
475             return stringValue !== undefined &&
476                     !(Array.isArray(stringValue) && stringValue.length === 0) ?
477                 [{display: <pre>{stringValue}</pre> }] :
478                 [{display: <EmptyValue />}];
479
480         case isPrimitiveOfType(input, CWLType.FILE):
481             const mainFile = (input as FileCommandInputParameter).value;
482             // secondaryFiles: File[] is not part of CommandOutputParameter so we cast to access secondaryFiles
483             const secondaryFiles = ((mainFile as unknown) as FileWithSecondaryFiles)?.secondaryFiles || [];
484             const files = [
485                 ...(mainFile && !(Array.isArray(mainFile) && mainFile.length === 0) ? [mainFile] : []),
486                 ...secondaryFiles
487             ];
488
489             return files.length ?
490                 files.map(file => fileToProcessIOValue(file, auth, pdh)) :
491                 [{display: <EmptyValue />}];
492
493         case isPrimitiveOfType(input, CWLType.DIRECTORY):
494             const directory = (input as DirectoryCommandInputParameter).value;
495
496             return directory !== undefined &&
497                     !(Array.isArray(directory) && directory.length === 0) ?
498                 [directoryToProcessIOValue(directory, auth, pdh)] :
499                 [{display: <EmptyValue />}];
500
501         case typeof input.type === 'object' &&
502             !(input.type instanceof Array) &&
503             input.type.type === 'enum':
504             const enumValue = (input as EnumCommandInputParameter).value;
505
506             return enumValue !== undefined ?
507                 [{ display: <pre>{(input as EnumCommandInputParameter).value || ''}</pre> }] :
508                 [{display: <EmptyValue />}];
509
510         case isArrayOfType(input, CWLType.STRING):
511             const strArray = (input as StringArrayCommandInputParameter).value || [];
512             return strArray.length ?
513                 [{ display: <>{((input as StringArrayCommandInputParameter).value || []).map((val) => <Chip label={val} />)}</> }] :
514                 [{display: <EmptyValue />}];
515
516         case isArrayOfType(input, CWLType.INT):
517         case isArrayOfType(input, CWLType.LONG):
518             const intArray = (input as IntArrayCommandInputParameter).value || [];
519
520             return intArray.length ?
521                 [{ display: <>{((input as IntArrayCommandInputParameter).value || []).map((val) => <Chip label={val} />)}</> }] :
522                 [{display: <EmptyValue />}];
523
524         case isArrayOfType(input, CWLType.FLOAT):
525         case isArrayOfType(input, CWLType.DOUBLE):
526             const floatArray = (input as FloatArrayCommandInputParameter).value || [];
527
528             return floatArray.length ?
529                 [{ display: <>{floatArray.map((val) => <Chip label={val} />)}</> }] :
530                 [{display: <EmptyValue />}];
531
532         case isArrayOfType(input, CWLType.FILE):
533             const fileArrayMainFile = ((input as FileArrayCommandInputParameter).value || []);
534             const fileArraySecondaryFiles = fileArrayMainFile.map((file) => (
535                 ((file as unknown) as FileWithSecondaryFiles)?.secondaryFiles || []
536             )).reduce((acc: File[], params: File[]) => (acc.concat(params)), []);
537
538             const fileArrayFiles = [
539                 ...fileArrayMainFile,
540                 ...fileArraySecondaryFiles
541             ];
542
543             return fileArrayFiles.length ?
544                 fileArrayFiles.map(file => fileToProcessIOValue(file, auth, pdh)) :
545                 [{display: <EmptyValue />}];
546
547         case isArrayOfType(input, CWLType.DIRECTORY):
548             const directories = (input as DirectoryArrayCommandInputParameter).value || [];
549
550             return directories.length ?
551                 directories.map(directory => directoryToProcessIOValue(directory, auth, pdh)) :
552                 [{display: <EmptyValue />}];
553
554         default:
555             return [];
556     }
557 };
558
559 /*
560  * @returns keep url without keep: prefix
561  */
562 const getKeepUrl = (file: File | Directory, pdh?: string): string => {
563     const isKeepUrl = file.location?.startsWith('keep:') || false;
564     const keepUrl = isKeepUrl ?
565                         file.location?.replace('keep:', '') :
566                         pdh ? `${pdh}/${file.location}` : file.location;
567     return keepUrl || '';
568 };
569
570 interface KeepUrlProps {
571     auth: AuthState;
572     res: File | Directory;
573     pdh?: string;
574 }
575
576 const KeepUrlBase = withStyles(styles)(({auth, res, pdh, classes}: KeepUrlProps & WithStyles<CssRules>) => {
577     const keepUrl = getKeepUrl(res, pdh);
578     const pdhUrl = keepUrl ? keepUrl.split('/').slice(0, 1)[0] : '';
579     // Passing a pdh always returns a relative wb2 collection url
580     const pdhWbPath = getNavUrl(pdhUrl, auth);
581     return pdhUrl && pdhWbPath ?
582         <Tooltip title={"View collection in Workbench"}><RouterLink to={pdhWbPath} className={classes.keepLink}>{pdhUrl}</RouterLink></Tooltip> :
583         <></>;
584 });
585
586 const KeepUrlPath = withStyles(styles)(({auth, res, pdh, classes}: KeepUrlProps & WithStyles<CssRules>) => {
587     const keepUrl = getKeepUrl(res, pdh);
588     const keepUrlParts = keepUrl ? keepUrl.split('/') : [];
589     const keepUrlPath = keepUrlParts.length > 1 ? keepUrlParts.slice(1).join('/') : '';
590
591     const keepUrlPathNav = getKeepNavUrl(auth, res, pdh);
592     return keepUrlPath && keepUrlPathNav ?
593         <Tooltip title={"View in keep-web"}><a className={classes.keepLink} href={keepUrlPathNav} target="_blank" rel="noopener noreferrer">{keepUrlPath}</a></Tooltip> :
594         // Show No value for root collection io that lacks path part
595         <EmptyValue />;
596 });
597
598 const getKeepNavUrl = (auth: AuthState, file: File | Directory, pdh?: string): string => {
599     let keepUrl = getKeepUrl(file, pdh);
600     return (getInlineFileUrl(`${auth.config.keepWebServiceUrl}/c=${keepUrl}?api_token=${auth.apiToken}`, auth.config.keepWebServiceUrl, auth.config.keepWebInlineServiceUrl));
601 };
602
603 const getImageUrl = (auth: AuthState, file: File, pdh?: string): string => {
604     const keepUrl = getKeepUrl(file, pdh);
605     return getInlineFileUrl(`${auth.config.keepWebServiceUrl}/c=${keepUrl}?api_token=${auth.apiToken}`, auth.config.keepWebServiceUrl, auth.config.keepWebInlineServiceUrl);
606 };
607
608 const isFileImage = (basename?: string): boolean => {
609     return basename ? (mime.getType(basename) || "").startsWith('image/') : false;
610 };
611
612 const normalizeDirectoryLocation = (directory: Directory): Directory => {
613     if (!directory.location) {
614         return directory;
615     }
616     return {
617         ...directory,
618         location: (directory.location || '').endsWith('/') ? directory.location : directory.location + '/',
619     };
620 };
621
622 const directoryToProcessIOValue = (directory: Directory, auth: AuthState, pdh?: string): ProcessIOValue => {
623     const normalizedDirectory = normalizeDirectoryLocation(directory);
624     return {
625         display: <KeepUrlPath auth={auth} res={normalizedDirectory} pdh={pdh}/>,
626         collection: <KeepUrlBase auth={auth} res={normalizedDirectory} pdh={pdh}/>,
627     };
628 };
629
630 const fileToProcessIOValue = (file: File, auth: AuthState, pdh?: string): ProcessIOValue => {
631     return {
632         display: <KeepUrlPath auth={auth} res={file} pdh={pdh}/>,
633         imageUrl: isFileImage(file.basename) ? getImageUrl(auth, file, pdh) : undefined,
634         collection: <KeepUrlBase auth={auth} res={file} pdh={pdh}/>,
635     }
636 };
637
638 const EmptyValue = withStyles(styles)(
639     ({classes}: WithStyles<CssRules>) => <span className={classes.emptyValue}>No value</span>
640 );
641
642 const ImagePlaceholder = withStyles(styles)(
643     ({classes}: WithStyles<CssRules>) => <span className={classes.imagePlaceholder}><ImageIcon /></span>
644 );