11import { Notification , showDialog , Dialog } from '@jupyterlab/apputils' ;
22import { Widget } from '@lumino/widgets' ;
3- import { copyIcon } from '@jupyterlab/ui-components' ;
43
54const MAX_VISIBLE_CHARS = 140 ;
65const VIEW_DETAILS_LABEL = 'View details' ;
@@ -18,55 +17,25 @@ function createViewDetailsAction(fullMessage: string, dialogTitle = 'Details'):
1817 label : VIEW_DETAILS_LABEL ,
1918 caption : 'Show full message' ,
2019 callback : async ( ) => {
21- const DURATION = 1200 ;
22-
2320 const dialogBody = new Widget ( ) ;
2421 dialogBody . addClass ( 'xircuits-notification-details' ) ;
2522
26- const wrap = document . createElement ( 'div' ) ;
27- wrap . className = 'x-details-copyWrap' ;
28-
29- const copyBtn = document . createElement ( 'button' ) ;
30- copyBtn . className = 'x-copy-icon-btn jp-Button jp-mod-minimal' ;
31- copyBtn . type = 'button' ;
32- copyBtn . title = 'Copy' ;
33- copyBtn . setAttribute ( 'aria-label' , 'Copy' ) ;
34- copyIcon . element ( { container : copyBtn , height : '16px' , width : '16px' } ) ;
35-
36- wrap . appendChild ( copyBtn ) ;
37-
3823 const pre = document . createElement ( 'pre' ) ;
39- pre . className = 'x-details-pre' ;
4024 pre . textContent = fullMessage ;
25+ dialogBody . node . appendChild ( pre ) ;
4126
42- dialogBody . node . append ( wrap , pre ) ;
43-
44- let timer : number | null = null ;
45- copyBtn . addEventListener ( 'click' , async ( ) => {
46- try {
47- await navigator . clipboard . writeText ( fullMessage ) ;
27+ const copyButton = Dialog . createButton ( { label : 'Copy' } ) ;
28+ const closeButton = Dialog . okButton ( { label : 'Close' } ) ;
4829
49- copyBtn . classList . add ( 'is-copied' ) ;
50- copyBtn . title = 'Copied' ;
51- copyBtn . setAttribute ( 'aria-label' , 'Copied' ) ;
52-
53- if ( timer ) clearTimeout ( timer ) ;
54- timer = window . setTimeout ( ( ) => {
55- copyBtn . classList . remove ( 'is-copied' ) ;
56- copyBtn . title = 'Copy' ;
57- copyBtn . setAttribute ( 'aria-label' , 'Copy' ) ;
58- timer = null ;
59- } , DURATION ) ;
60- } catch ( err ) {
61- console . error ( 'Copy failed' , err ) ;
62- }
63- } ) ;
64-
65- await showDialog ( {
30+ const result = await showDialog ( {
6631 title : dialogTitle ,
6732 body : dialogBody ,
68- buttons : [ Dialog . okButton ( { label : 'Close' } ) ]
33+ buttons : [ copyButton , closeButton ]
6934 } ) ;
35+
36+ if ( result . button . label === 'Copy' ) {
37+ await navigator . clipboard . writeText ( fullMessage ) ;
38+ }
7039 }
7140 } ;
7241}
0 commit comments