File tree Expand file tree Collapse file tree 3 files changed +61
-8
lines changed
Expand file tree Collapse file tree 3 files changed +61
-8
lines changed Original file line number Diff line number Diff line change 1+ import Box from "@material-ui/core/Box" ;
12import Button from "@material-ui/core/Button" ;
23import CircularProgress from "@material-ui/core/CircularProgress" ;
34import Dialog , { DialogProps } from "@material-ui/core/Dialog" ;
@@ -108,6 +109,7 @@ const FileDetailsWithAPI = withAPI(FileDetails);
108109export default function FileDetailsDialog (
109110 props : {
110111 filename : string ;
112+ canBePrinted : boolean ;
111113 path : string ;
112114 onCancel : ( ) => void ;
113115 onPrint : ( ) => void ;
@@ -125,6 +127,25 @@ export default function FileDetailsDialog(
125127 props . onDelete ( ) ;
126128 } ;
127129
130+ let fileDetails : React . ReactElement ;
131+ if ( props . canBePrinted ) {
132+ fileDetails = (
133+ < FileDetailsWithAPI filename = { props . filename } path = { props . path } />
134+ ) ;
135+ } else {
136+ fileDetails = (
137+ < Box
138+ display = "flex"
139+ width = { 350 }
140+ height = { 80 }
141+ alignItems = "center"
142+ justifyContent = "center"
143+ >
144+ < Typography > This file cannot be printed.</ Typography >
145+ </ Box >
146+ ) ;
147+ }
148+
128149 return (
129150 < Dialog { ...props } >
130151 < DialogTitle className = { classes . dialogTitle } disableTypography >
@@ -158,13 +179,17 @@ export default function FileDetailsDialog(
158179 </ Dialog >
159180 </ DialogTitle >
160181 < DialogContent style = { { padding : 0 } } dividers >
161- < FileDetailsWithAPI filename = { props . filename } path = { props . path } />
182+ { fileDetails }
162183 </ DialogContent >
163184 < DialogActions >
164185 < Button onClick = { props . onCancel } color = "primary" >
165186 Cancel
166187 </ Button >
167- < Button onClick = { props . onPrint } color = "primary" >
188+ < Button
189+ onClick = { props . onPrint }
190+ color = "primary"
191+ disabled = { ! props . canBePrinted }
192+ >
168193 Print
169194 </ Button >
170195 </ DialogActions >
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ function FileListItem({
5757 onDelete : ( ) => void ;
5858} ) : React . ReactElement {
5959 const [ open , setOpen ] = React . useState ( false ) ;
60- const handleClickOpen = ( ) => file . can_be_printed && setOpen ( true ) ;
60+ const handleClickOpen = ( ) => setOpen ( true ) ;
6161 const handleClose = ( ) => setOpen ( false ) ;
6262
6363 const printTime = file . print_time_secs
@@ -67,18 +67,15 @@ function FileListItem({
6767 const api = useAPI ( ) ;
6868 return (
6969 < React . Fragment >
70- < ListItem
71- button
72- key = { file . filename }
73- onClick = { file . can_be_printed ? handleClickOpen : undefined }
74- >
70+ < ListItem button key = { file . filename } onClick = { handleClickOpen } >
7571 < ListItemIcon >
7672 { file . can_be_printed ? < LayersIcon /> : < InsertDriveFileIcon /> }
7773 </ ListItemIcon >
7874 < ListItemText primary = { file . filename } secondary = { printTime } />
7975 </ ListItem >
8076 < FileDetailsDialog
8177 filename = { file . filename }
78+ canBePrinted = { file . can_be_printed }
8279 path = { file . path }
8380 onCancel = { handleClose }
8481 onClose = { handleClose }
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ const Template: Story = (_args) => {
3838 < Button onClick = { handleClickOpen } > Open</ Button >
3939 < FileDetailsDialog
4040 filename = "stairs.ctb"
41+ canBePrinted = { true }
4142 path = "stairs.ctb"
4243 onCancel = { handleClose }
4344 onClose = { handleClose }
@@ -73,6 +74,7 @@ export const Loading = (): React.ReactElement => {
7374 < Button onClick = { handleClickOpen } > Open</ Button >
7475 < FileDetailsDialog
7576 filename = "stairs.ctb"
77+ canBePrinted = { true }
7678 path = "stairs.ctb"
7779 onCancel = { handleClose }
7880 onClose = { handleClose }
@@ -87,3 +89,32 @@ export const Loading = (): React.ReactElement => {
8789 </ div >
8890 ) ;
8991} ;
92+
93+ export const UnprintableFile = ( ) : React . ReactElement => {
94+ const [ open , setOpen ] = React . useState ( false ) ;
95+
96+ const handleClickOpen = ( ) => {
97+ setOpen ( true ) ;
98+ } ;
99+
100+ const handleClose = ( ) => {
101+ setOpen ( false ) ;
102+ } ;
103+
104+ return (
105+ < div >
106+ < Button onClick = { handleClickOpen } > Open</ Button >
107+ < FileDetailsDialog
108+ filename = "some_file.txt"
109+ canBePrinted = { false }
110+ path = "some_file.txt"
111+ onCancel = { handleClose }
112+ onClose = { handleClose }
113+ onPrint = { handleClose }
114+ onDelete = { handleClose }
115+ open = { open }
116+ scroll = "paper"
117+ />
118+ </ div >
119+ ) ;
120+ } ;
You can’t perform that action at this time.
0 commit comments