Skip to content

Commit eb198e0

Browse files
authored
fix bug in delete file, remove file delete confirmation (Cinnamon#59)
1 parent 466adf2 commit eb198e0

File tree

1 file changed

+10
-57
lines changed
  • libs/ktem/ktem/index/file

1 file changed

+10
-57
lines changed

libs/ktem/ktem/index/file/ui.py

+10-57
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,15 @@ def on_building_ui(self):
143143
self.selected_file_id = gr.State(value=None)
144144
with gr.Column(scale=2):
145145
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-
)
153146

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",
160149
visible=False,
161150
elem_classes=["right-button"],
162151
)
163-
self.delete_no = gr.Button(
164-
"Cancel",
152+
self.delete_button = gr.Button(
153+
"Delete",
154+
variant="stop",
165155
visible=False,
166156
elem_classes=["right-button"],
167157
)
@@ -189,33 +179,12 @@ def on_subscribe_public_events(self):
189179
)
190180

191181
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)
196182
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),
201185
)
202186

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):
219188
with Session(engine) as session:
220189
source = session.execute(
221190
select(self._index._resources["Source"]).where(
@@ -250,21 +219,13 @@ def delete_no_event(self):
250219
return (
251220
gr.update(visible=True),
252221
gr.update(visible=False),
253-
gr.update(visible=False),
254222
)
255223

256224
def on_register_events(self):
257225
"""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-
265226
onDeleted = (
266-
self.delete_yes.click(
267-
fn=self.delete_yes_event,
227+
self.delete_button.click(
228+
fn=self.delete_event,
268229
inputs=[self.selected_file_id],
269230
outputs=None,
270231
)
@@ -283,12 +244,6 @@ def on_register_events(self):
283244
for event in self._app.get_event(f"onFileIndex{self._index.id}Changed"):
284245
onDeleted = onDeleted.then(**event)
285246

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-
)
292247
self.deselect_button.click(
293248
fn=lambda: (None, self.selected_panel_false),
294249
inputs=None,
@@ -301,8 +256,6 @@ def on_register_events(self):
301256
outputs=[
302257
self.deselect_button,
303258
self.delete_button,
304-
self.delete_yes,
305-
self.delete_no,
306259
],
307260
show_progress="hidden",
308261
)

0 commit comments

Comments
 (0)