11/* eslint-disable no-param-reassign */
2- import { formatDates , initCopyHandler } from '../table.js' ;
2+ import { formatDates , initCopyHandler , trimForDisplay } from '../table.js' ;
33import PubSub from '../../pub-sub.js' ;
44
55// all of the currently selected job IDs
@@ -9,12 +9,13 @@ let statuses = [];
99
1010/**
1111 * Build the jobs filter with filter facets like 'status' and 'user'.
12- * @param {string } currentUser - the current Harmony user
13- * @param {string[] } services - service names from services.yml
14- * @param {string[] } providers - array of provider ids
15- * @param {string[] } labels - known job labels
16- * @param {boolean } isAdminRoute - whether the current page is /admin/...
17- * @param {object[] } tableFilter - initial tags that will populate the input
12+ * @param {string } currentUser - the current Harmony user
13+ * @param {string[] } services - service names from services.yml
14+ * @param {string[] } providers - array of provider ids
15+ * @param {string[] } labels - known job labels
16+ * @param {boolean } isAdminRoute - whether the current page is /admin/...
17+ * @param {object[] } tableFilter - initial tags that will populate the input
18+ * @returns the tag input instance
1819 */
1920function initFilter ( currentUser , services , providers , labels , isAdminRoute , tableFilter ) {
2021 const filterInput = document . querySelector ( 'input[name="tableFilter"]' ) ;
@@ -33,14 +34,15 @@ function initFilter(currentUser, services, providers, labels, isAdminRoute, tabl
3334 allowedList . push ( ...serviceList ) ;
3435 const providerList = providers . map ( ( provider ) => ( { value : `provider: ${ provider } ` , dbValue : provider , field : 'provider' } ) ) ;
3536 allowedList . push ( ...providerList ) ;
36- const labelList = labels . map ( ( label ) => ( { value : `label: ${ label } ` , dbValue : label , field : 'label' } ) ) ;
37+ const labelList = labels . map ( ( label ) => ( { value : `label: ${ trimForDisplay ( label , 30 ) } ` , dbValue : label , field : 'label' , searchBy : label } ) ) ;
3738 allowedList . push ( ...labelList ) ;
3839 if ( isAdminRoute ) {
3940 allowedList . push ( { value : `user: ${ currentUser } ` , dbValue : currentUser , field : 'user' } ) ;
4041 }
4142 const allowedValues = allowedList . map ( ( t ) => t . value ) ;
4243 const tagInput = new Tagify ( filterInput , {
4344 whitelist : allowedList ,
45+ delimiters : null , // prevent characters like "," from triggering input submission
4446 validate ( tag ) {
4547 if ( allowedValues . includes ( tag . value )
4648 || / ^ p r o v i d e r : [ A - Z a - z 0 - 9 _ ] { 1 , 100 } $ / . test ( tag . value )
@@ -60,9 +62,26 @@ function initFilter(currentUser, services, providers, labels, isAdminRoute, tabl
6062 enabled : 0 ,
6163 closeOnSelect : true ,
6264 } ,
65+ templates : {
66+ tag ( tagData ) {
67+ return `<tag title="${ tagData . dbValue } "
68+ contenteditable='false'
69+ spellcheck='false'
70+ tabIndex="${ this . settings . a11y . focusableTags ? 0 : - 1 } "
71+ class="${ this . settings . classNames . tag } "
72+ ${ this . getAttributes ( tagData ) } >
73+ <x title='' class="${ this . settings . classNames . tagX } " role='button' aria-label='remove tag'></x>
74+ <div>
75+ <span class="${ this . settings . classNames . tagText } ">${ trimForDisplay ( tagData . value . split ( ': ' ) [ 1 ] , 20 ) } </span>
76+ </div>
77+ </tag>` ;
78+ } ,
79+ } ,
6380 } ) ;
6481 const initialTags = JSON . parse ( tableFilter ) ;
6582 tagInput . addTags ( initialTags ) ;
83+
84+ return tagInput ;
6685}
6786
6887/**
@@ -231,17 +250,27 @@ const jobsTable = {
231250 * tzOffsetMinutes - offset from UTC
232251 * dateKind - updatedAt or createdAt
233252 * sortGranules - sort the rows ascending ('asc') or descending ('desc')
253+ * @returns the tag input instance
234254 */
235255 async init ( params ) {
236256 PubSub . subscribe (
237257 'row-state-change' ,
238258 async ( ) => loadRows ( params ) ,
239259 ) ;
240260 formatDates ( '.date-td' ) ;
241- initFilter ( params . currentUser , params . services , params . providers , params . labels , params . isAdminRoute , params . tableFilter ) ;
261+ const tagInput = initFilter (
262+ params . currentUser ,
263+ params . services ,
264+ params . providers ,
265+ params . labels ,
266+ params . isAdminRoute ,
267+ params . tableFilter ,
268+ ) ;
242269 initCopyHandler ( '.copy-request' ) ;
243270 initSelectHandler ( '.select-job' ) ;
244271 initSelectAllHandler ( ) ;
272+
273+ return tagInput ;
245274 } ,
246275
247276 /**
0 commit comments