@@ -62,6 +62,11 @@ const UIStrings = {
6262 *@description Error message in Framework Ignore List settings pane that declares pattern must be a valid regular expression
6363 */
6464 patternMustBeAValidRegular : 'Rule must be a valid regular expression' ,
65+ /**
66+ *@description Error message in Framework Ignore List settings pane that declares pattern already exits
67+ */
68+ patternAlreadyExistsWillBeEnables :
69+ 'This rule already exists but is disabled. Saving this value will re-enable the rule' ,
6570} ;
6671
6772const str_ = i18n . i18n . registerUIStrings ( 'panels/timeline/components/IgnoreListSetting.ts' , UIStrings ) ;
@@ -74,11 +79,13 @@ export class IgnoreListSetting extends HTMLElement {
7479 Common . Settings . Settings . instance ( ) . moduleSetting ( 'enable-ignore-listing' ) ;
7580 readonly #regexPatterns = this . #getSkipStackFramesPatternSetting( ) . getAsArray ( ) ;
7681
77- #newItemCheckbox = UI . UIUtils . CheckboxLabel . create (
82+ #newRegexCheckbox = UI . UIUtils . CheckboxLabel . create (
7883 /* title*/ undefined , /* checked*/ false , /* subtitle*/ undefined ,
7984 /* jslogContext*/ 'timeline.ignore-list-new-regex.checkbox' ) ;
80- #newItemInput = UI . UIUtils . createInput (
85+ #newRegexInput = UI . UIUtils . createInput (
8186 /* className*/ 'new-regex-text-input' , /* type*/ 'text' , /* jslogContext*/ 'timeline.ignore-list-new-regex.text' ) ;
87+ #newRegexIsValid = true ;
88+ #newRegexValidationMessage?: string ;
8289
8390 #editingRegexSetting: Common . Settings . RegExpSettingItem | null = null ;
8491
@@ -110,7 +117,7 @@ export class IgnoreListSetting extends HTMLElement {
110117 }
111118
112119 #startEditing( ) : void {
113- this . #editingRegexSetting = { pattern : this . #newItemInput . value , disabled : false , disabledForUrl : undefined } ;
120+ this . #editingRegexSetting = { pattern : this . #newRegexInput . value , disabled : false , disabledForUrl : undefined } ;
114121 // We need to push the temp regex here to update the flame chart.
115122 // We are using the "skip-stack-frames-pattern" setting to determine which is rendered on flame chart. And the push
116123 // here will update the setting's value.
@@ -135,12 +142,12 @@ export class IgnoreListSetting extends HTMLElement {
135142 }
136143
137144 #resetInput( ) : void {
138- this . #newItemCheckbox . checkboxElement . checked = false ;
139- this . #newItemInput . value = '' ;
145+ this . #newRegexCheckbox . checkboxElement . checked = false ;
146+ this . #newRegexInput . value = '' ;
140147 }
141148
142149 #onNewRegexAdded( ) : void {
143- const newRegex = this . #newItemInput . value . trim ( ) ;
150+ const newRegex = this . #newRegexInput . value . trim ( ) ;
144151
145152 this . #finishEditing( ) ;
146153 const { valid} = patternValidator ( this . #getExistingRegexes( ) , newRegex ) ;
@@ -179,25 +186,45 @@ export class IgnoreListSetting extends HTMLElement {
179186 }
180187
181188 #handleInputChange( ) : void {
189+ const newRegex = this . #newRegexInput. value . trim ( ) ;
182190 // Enable the rule if the text input field is not empty.
183- this . #newItemCheckbox. checkboxElement . checked = Boolean ( this . #newItemInput. value . trim ( ) ) ;
191+ this . #newRegexCheckbox. checkboxElement . checked = Boolean ( newRegex ) ;
192+ const { valid, message} = patternValidator ( this . #getExistingRegexes( ) , newRegex ) ;
193+
194+ this . #newRegexInput. classList . toggle ( 'error-input' , ! valid ) ;
195+ UI . ARIAUtils . setInvalid ( this . #newRegexInput, ! valid ) ;
196+ this . #newRegexIsValid = valid ;
197+ this . #newRegexValidationMessage = message ;
184198
185199 if ( this . #editingRegexSetting) {
186- this . #editingRegexSetting. pattern = this . #newItemInput . value . trim ( ) ;
200+ this . #editingRegexSetting. pattern = this . #newRegexInput . value . trim ( ) ;
187201 this . #getSkipStackFramesPatternSetting( ) . setAsArray ( this . #regexPatterns) ;
188202 }
189203 }
190204
191205 #initAddNewItem( ) : void {
192206 const checkboxHelpText = i18nString ( UIStrings . ignoreScriptsWhoseNamesMatchNewRegex ) ;
193207 const inputHelpText = i18nString ( UIStrings . addNewRegex ) ;
194- UI . Tooltip . Tooltip . install ( this . #newItemCheckbox , checkboxHelpText ) ;
195- UI . Tooltip . Tooltip . install ( this . #newItemInput , inputHelpText ) ;
208+ UI . Tooltip . Tooltip . install ( this . #newRegexCheckbox , checkboxHelpText ) ;
209+ UI . Tooltip . Tooltip . install ( this . #newRegexInput , inputHelpText ) ;
196210
197- this . #newItemInput. addEventListener ( 'blur' , this . #onNewRegexAdded. bind ( this ) , false ) ;
198- this . #newItemInput. addEventListener ( 'keydown' , this . #handleKeyDown. bind ( this ) , false ) ;
199- this . #newItemInput. addEventListener ( 'input' , this . #handleInputChange. bind ( this ) , false ) ;
200- this . #newItemInput. addEventListener ( 'focus' , this . #startEditing. bind ( this ) , false ) ;
211+ this . #newRegexInput. addEventListener ( 'blur' , this . #onNewRegexAdded. bind ( this ) , false ) ;
212+ this . #newRegexInput. addEventListener ( 'keydown' , this . #handleKeyDown. bind ( this ) , false ) ;
213+ this . #newRegexInput. addEventListener ( 'input' , this . #handleInputChange. bind ( this ) , false ) ;
214+ this . #newRegexInput. addEventListener ( 'focus' , this . #startEditing. bind ( this ) , false ) ;
215+ }
216+
217+ #renderNewRegexRow( ) : LitHtml . TemplateResult {
218+ const classes = LitHtml . Directives . classMap ( {
219+ 'input-validation' : true ,
220+ 'input-validation-error' : ! this . #newRegexIsValid,
221+ } ) ;
222+ return html `
223+ < div class ='new-regex-row '> ${ this . #newRegexCheckbox} ${ this . #newRegexInput} </ div >
224+ ${
225+ this . #newRegexValidationMessage ? html `< div class =${ classes } > ${ this . #newRegexValidationMessage} </ div > ` :
226+ LitHtml . nothing }
227+ ` ;
201228 }
202229
203230 #onRegexEnableToggled( regex : Common . Settings . RegExpSettingItem , checkbox : UI . UIUtils . CheckboxLabel ) : void {
@@ -262,7 +289,7 @@ export class IgnoreListSetting extends HTMLElement {
262289 < div class ='ignore-list-setting-content '>
263290 < div class ='ignore-list-setting-description '> ${ i18nString ( UIStrings . ignoreListDescription ) } </ div >
264291 ${ this . #getExistingRegexes( ) . map ( this . #renderItem. bind ( this ) ) }
265- < div class =' new-regex-row ' > ${ this . #newItemCheckbox } ${ this . #newItemInput } </ div >
292+ ${ this . #renderNewRegexRow ( ) }
266293 </ div >
267294 </ devtools-button-dialog >
268295 ` ;
@@ -287,21 +314,23 @@ declare global {
287314 * @param inputValue new regex in string format
288315 * @returns if the regex is valid and if not, why it is invalid
289316 */
290- export function patternValidator (
291- existingRegexes : Common . Settings . RegExpSettingItem [ ] , inputValue : string ) : ( { valid : true } | {
292- valid : false ,
293- errorMessage : string ,
294- } ) {
317+ export function patternValidator ( existingRegexes : Common . Settings . RegExpSettingItem [ ] , inputValue : string ) : {
318+ valid : boolean ,
319+ message ?: string ,
320+ } {
295321 const pattern = inputValue . trim ( ) ;
296322
297323 if ( ! pattern . length ) {
298- return { valid : false , errorMessage : i18nString ( UIStrings . patternCannotBeEmpty ) } ;
324+ return { valid : false , message : i18nString ( UIStrings . patternCannotBeEmpty ) } ;
299325 }
300326
301327 for ( let i = 0 ; i < existingRegexes . length ; ++ i ) {
302328 const regexPattern = existingRegexes [ i ] ;
303- if ( regexPattern . pattern === pattern && ! regexPattern . disabled && regexPattern . disabledForUrl === undefined ) {
304- return { valid : false , errorMessage : i18nString ( UIStrings . patternAlreadyExists ) } ;
329+ if ( regexPattern . pattern === pattern ) {
330+ if ( regexPattern . disabled || regexPattern . disabledForUrl ) {
331+ return { valid : true , message : i18nString ( UIStrings . patternAlreadyExistsWillBeEnables ) } ;
332+ }
333+ return { valid : false , message : i18nString ( UIStrings . patternAlreadyExists ) } ;
305334 }
306335 }
307336
@@ -311,7 +340,7 @@ export function patternValidator(
311340 } catch ( e ) {
312341 }
313342 if ( ! regex ) {
314- return { valid : false , errorMessage : i18nString ( UIStrings . patternMustBeAValidRegular ) } ;
343+ return { valid : false , message : i18nString ( UIStrings . patternMustBeAValidRegular ) } ;
315344 }
316345 return { valid : true } ;
317346}
0 commit comments