@@ -18,13 +18,17 @@ import { tagPicker } from '../../../components/tag/tagPicker.js';
1818import { markdownInput } from '../../../components/common/markdown/markdown.js' ;
1919import spinner from '../../../components/common/spinner.js' ;
2020import { logComponent } from '../../../components/Log/log.js' ;
21+ import { filePreviewPopoverLink } from '../FilePreview/attachmentPreviewComponent.js' ;
22+ import { popover } from '../../../components/common/popover/popover.js' ;
23+ import { PopoverTriggerPreConfiguration } from '../../../components/common/popover/popoverPreConfigurations.js' ;
24+ import { PopoverAnchors } from '../../../components/common/popover/PopoverEngine.js' ;
25+ import { filePreviewComponent } from '../FilePreview/filePreviewComponent.js' ;
2126
2227/**
2328 * A function to construct the create log screen
2429 *
2530 * @param {LogCreationModel } creationModel - Log creation model
2631 * @param {Object } options component creation options
27- * @param {string } [options.authenticationToken] token to authenticate the session with the api
2832 * @param {Object } [options.parentLogMarkdownDisplayOptions] markdown display options @see logText options argument
2933 * @return {vnode } the log creation component
3034 */
@@ -47,7 +51,6 @@ export const logCreationComponent = (creationModel, options) => {
4751 * @param {LogCreationModel } creationModel the creation model
4852 * @param {Log|null } parentLog - The parent of the log being created
4953 * @param {Object } options component creation options
50- * @param {string } [options.authenticationToken] token to authenticate the session with the api
5154 * @param {Object } [options.parentLogMarkdownDisplayOptions] markdown display options @see logText options argument
5255 * @return {vnode } the form component
5356 */
@@ -75,10 +78,10 @@ const logCreationForm = (creationModel, parentLog, options) => [
7578 creationModel . isParentLogCollapsed ,
7679 ( ) => creationModel . collapseParentLog ( ) ,
7780 ( ) => creationModel . showFullParentLog ( ) ,
78- { ...options ,
81+ {
82+ ...options ,
7983 logMarkdownDisplayOpts : options . parentLogMarkdownDisplayOptions ,
8084 goToDetailsButton : true ,
81- replayButton : false ,
8285 } ,
8386 ) ,
8487
@@ -116,7 +119,9 @@ const labeledInput = (labelAttributes, labelText, content, containerAttributes)
116119 labelAttributes ,
117120 labelText ,
118121 ) ,
119- content ,
122+ ...Array . isArray ( content )
123+ ? content
124+ : [ content ] ,
120125 ] ,
121126 ) ;
122127} ;
@@ -234,28 +239,74 @@ const environmentsPanel = (logCreationModel) => labeledInput(
234239 * @return {vnode } - panel allowing the user to attach files
235240 */
236241const attachmentsPanel = ( logCreationModel ) => {
237- const { attachments } = logCreationModel ;
242+ const { attachments : attachmentsFileList } = logCreationModel ;
243+
244+ /**
245+ * @type {File[] }
246+ */
247+ const attachments = [ ...attachmentsFileList ] ;
248+
249+ let fileText ;
250+ switch ( attachments . length ) {
251+ case 0 :
252+ fileText = 'No files chosen' ;
253+ break ;
254+ case 1 :
255+ fileText = `${ attachments . length } file chosen` ;
256+ break ;
257+ default :
258+ fileText = `${ attachments . length } files chosen` ;
259+ break ;
260+ }
238261
239262 return labeledInput (
240263 { for : 'attachments' } ,
241264 'File attachments' ,
242- h ( '.flex-column.p2.g2' , [
243- h ( '.flex-row.justify-between.items-center' , [
244- h ( 'input#attachments.w-33' , {
265+ [
266+ h ( '.flex-row.justify-between.items-center.p2' , [
267+ h (
268+ 'label.flex-row.g2.items-center' ,
269+ { for : 'attachments' } ,
270+ [
271+ h ( '.btn' , 'Choose files' ) ,
272+ h ( '' , fileText ) ,
273+ ] ,
274+ ) ,
275+ h ( 'input#attachments.w-33.d-none' , {
245276 type : 'file' ,
246277 multiple : true ,
247278 onchange : ( e ) => {
248279 logCreationModel . attachments = e . target . files ;
249280 } ,
250281 } ) ,
251- attachments . length > 0 && h ( 'button#clearAttachments.btn.btn-danger.ml3' , {
252- onclick : ( ) => logCreationModel . clearAttachments ( ) ,
253- } , 'Clear' ) ,
282+ attachments . length > 0 && h (
283+ 'button#clearAttachments.btn.btn-danger.ml3' ,
284+ { onclick : ( ) => logCreationModel . clearAttachments ( ) } ,
285+ 'Clear' ,
286+ ) ,
254287 ] ) ,
255- attachments . length > 1 && h ( '#attachmentNames' , {
256- style : 'min-height: 1.5em;' ,
257- } , [ ...attachments ] . map ( ( attachment ) => attachment . name ) . join ( ', ' ) ) ,
258- ] ) ,
288+ h ( '#attachments-list.flex-row.flex-wrap.p2' , attachments . flatMap ( ( attachment ) => {
289+ const preview = filePreviewComponent ( attachment , attachment . type , attachment . name ) ;
290+ return [
291+ preview
292+ ? popover (
293+ filePreviewPopoverLink ( attachment . name ) ,
294+ h (
295+ '.p2.flex-row.items-center' ,
296+ { key : window . btoa ( `${ attachment . name } -${ attachment . size } -${ attachment . lastModified } ` ) } ,
297+ preview ,
298+ ) ,
299+ {
300+ ...PopoverTriggerPreConfiguration . click ,
301+ anchor : PopoverAnchors . TOP_MIDDLE ,
302+ setChildrenSize : true ,
303+ } ,
304+ )
305+ : h ( '' , attachment . name ) ,
306+ h ( 'span.mr2' , ',' ) ,
307+ ] ;
308+ } ) . slice ( 0 , - 1 ) ) ,
309+ ] ,
259310 ) ;
260311} ;
261312
0 commit comments