@@ -143,25 +143,15 @@ def on_building_ui(self):
143
143
self .selected_file_id = gr .State (value = None )
144
144
with gr .Column (scale = 2 ):
145
145
self .selected_panel = gr .Markdown (self .selected_panel_false )
146
- with gr .Column (scale = 1 ):
147
- self .deselect_button = gr .Button (
148
- "Deselect" ,
149
- scale = 1 ,
150
- visible = False ,
151
- elem_classes = ["right-button" ],
152
- )
153
146
154
- self .delete_button = gr .Button (
155
- "Delete" , variant = "stop" , elem_classes = ["right-button" ]
156
- )
157
- self .delete_yes = gr .Button (
158
- "Confirm Delete" ,
159
- variant = "stop" ,
147
+ self .deselect_button = gr .Button (
148
+ "Deselect" ,
160
149
visible = False ,
161
150
elem_classes = ["right-button" ],
162
151
)
163
- self .delete_no = gr .Button (
164
- "Cancel" ,
152
+ self .delete_button = gr .Button (
153
+ "Delete" ,
154
+ variant = "stop" ,
165
155
visible = False ,
166
156
elem_classes = ["right-button" ],
167
157
)
@@ -189,33 +179,12 @@ def on_subscribe_public_events(self):
189
179
)
190
180
191
181
def file_selected (self , file_id ):
192
- if file_id is None :
193
- deselect = gr .update (visible = False )
194
- else :
195
- deselect = gr .update (visible = True )
196
182
return (
197
- deselect ,
198
- gr .update (visible = True ),
199
- gr .update (visible = False ),
200
- gr .update (visible = False ),
183
+ gr .update (visible = file_id is not None ),
184
+ gr .update (visible = file_id is not None ),
201
185
)
202
186
203
- def to_confirm_delete (self , file_id ):
204
- if file_id is None :
205
- gr .Warning ("No file is selected" )
206
- return (
207
- gr .update (visible = True ),
208
- gr .update (visible = False ),
209
- gr .update (visible = False ),
210
- )
211
-
212
- return (
213
- gr .update (visible = False ),
214
- gr .update (visible = True ),
215
- gr .update (visible = True ),
216
- )
217
-
218
- def delete_yes_event (self , file_id ):
187
+ def delete_event (self , file_id ):
219
188
with Session (engine ) as session :
220
189
source = session .execute (
221
190
select (self ._index ._resources ["Source" ]).where (
@@ -250,21 +219,13 @@ def delete_no_event(self):
250
219
return (
251
220
gr .update (visible = True ),
252
221
gr .update (visible = False ),
253
- gr .update (visible = False ),
254
222
)
255
223
256
224
def on_register_events (self ):
257
225
"""Register all events to the app"""
258
- self .delete_button .click (
259
- fn = self .to_confirm_delete ,
260
- inputs = [self .selected_file_id ],
261
- outputs = [self .delete_button , self .delete_yes , self .delete_no ],
262
- show_progress = "hidden" ,
263
- )
264
-
265
226
onDeleted = (
266
- self .delete_yes .click (
267
- fn = self .delete_yes_event ,
227
+ self .delete_button .click (
228
+ fn = self .delete_event ,
268
229
inputs = [self .selected_file_id ],
269
230
outputs = None ,
270
231
)
@@ -283,12 +244,6 @@ def on_register_events(self):
283
244
for event in self ._app .get_event (f"onFileIndex{ self ._index .id } Changed" ):
284
245
onDeleted = onDeleted .then (** event )
285
246
286
- self .delete_no .click (
287
- fn = self .delete_no_event ,
288
- inputs = None ,
289
- outputs = [self .delete_button , self .delete_yes , self .delete_no ],
290
- show_progress = "hidden" ,
291
- )
292
247
self .deselect_button .click (
293
248
fn = lambda : (None , self .selected_panel_false ),
294
249
inputs = None ,
@@ -301,8 +256,6 @@ def on_register_events(self):
301
256
outputs = [
302
257
self .deselect_button ,
303
258
self .delete_button ,
304
- self .delete_yes ,
305
- self .delete_no ,
306
259
],
307
260
show_progress = "hidden" ,
308
261
)
0 commit comments