acecalisto3 commited on
Commit
2fcdaa8
·
verified ·
1 Parent(s): fa06ba0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -52
app.py CHANGED
@@ -924,9 +924,11 @@ def create_ui(manager: IssueManager):
924
  # Use the imported code_editor component
925
  # We'll update its value dynamically when an issue is selected
926
  # Ensure the code_editor component itself handles language setting based on input dict keys or a prop
 
927
  code_edit_component = code_editor(
928
- value="# Select an issue to load relevant code (placeholder)", # Changed to string format
929
- issue_num=0 # This is the only other parameter your function accepts
 
930
  )
931
 
932
  # --- Analytics Tab (Placeholder) ---
@@ -953,57 +955,60 @@ def create_ui(manager: IssueManager):
953
  )
954
 
955
  # 2. Issue Selection in Dataframe
956
- async def handle_issue_select(evt: gr.SelectData):
957
- """Handles issue selection: updates preview, loads code (placeholder)."""
958
- if evt.index[0] is None or evt.value is None: # No row selected or value missing
959
- logger.info("Issue deselected or invalid selection event.")
960
- return {
961
- selected_issue_id: gr.update(value=None),
962
- issue_preview_html: "<p style='color: #6b7280;'>Select an issue from the table.</p>",
963
- code_edit_component: gr.update(value={"placeholder.txt": "# Select an issue to load code."}),
964
- ai_output_display: "*AI suggestions and patches will appear here...*" # Reset AI output
965
- }
 
 
966
 
967
- try:
968
- selected_id = int(evt.value[0]) # Get ID from the first column ('ID') of the selected row value
969
- logger.info(f"Issue selected: ID {selected_id}")
970
-
971
- # Update the hidden ID field
972
- updates = {selected_issue_id: selected_id}
973
-
974
- # Generate and update the HTML preview
975
- preview_html = generate_issue_preview(selected_id)
976
- updates[issue_preview_html] = preview_html
977
-
978
- # --- Code Loading Logic (Placeholder) ---
979
- # This needs real implementation: Find relevant files for the issue
980
- # and load their content into the editor component's value format.
981
- # Example: Fetch files related to the issue (needs implementation)
982
- # files_content = await fetch_relevant_code_for_issue(selected_id)
983
- # For now, create a placeholder editor state and potentially initialize server-side OT editor
984
- files_content = {
985
- f"issue_{selected_id}_code.py": f"# Code related to issue {selected_id}\n# (Replace with actual file content)\n\nprint('Hello from issue {selected_id}')",
986
- "README.md": f"# Issue {selected_id}\n\nDetails about the issue..."
987
- }
988
- # Initialize or update the server-side OT document for this issue
989
- # This assumes OTCodeEditor takes initial content dictionary
990
- manager.code_editors[selected_id] = OTCodeEditor(value=files_content)
991
- logger.info(f"Initialized/Reset OT editor state for issue {selected_id}")
992
-
993
- updates[code_edit_component] = gr.update(value=files_content)
994
- # --- End Placeholder ---
995
-
996
- # Reset AI output display
997
- updates[ai_output_display] = "*AI suggestions and patches will appear here...*"
998
-
999
- return updates
1000
- except (ValueError, TypeError, IndexError) as e:
1001
- logger.error(f"Error processing selection event data: {evt.value}. Error: {e}")
1002
- return { # Return updates to reset state gracefully
1003
- selected_issue_id: gr.update(value=None),
1004
- issue_preview_html: "<p style='color: red;'>Error processing selection. Please try again.</p>",
1005
- code_edit_component: gr.update(value={"error.txt": "# Error processing selection"}),
1006
- ai_output_display: "*Error processing selection.*"
 
1007
  }
1008
 
1009
 
 
924
  # Use the imported code_editor component
925
  # We'll update its value dynamically when an issue is selected
926
  # Ensure the code_editor component itself handles language setting based on input dict keys or a prop
927
+ # Replace the existing code_edit_component definition with:
928
  code_edit_component = code_editor(
929
+ value={"placeholder.txt": "# Select an issue to load code."},
930
+ language="python",
931
+ key="code_editor"
932
  )
933
 
934
  # --- Analytics Tab (Placeholder) ---
 
955
  )
956
 
957
  # 2. Issue Selection in Dataframe
958
+ async def handle_issue_select(evt: gr.SelectData):
959
+ """Handles issue selection: updates preview, loads code (placeholder)."""
960
+ default_response = {
961
+ selected_issue_id: gr.update(value=None),
962
+ issue_preview_html: gr.update("<p style='color: #6b7280;'>Select an issue from the table.</p>"),
963
+ code_edit_component: gr.update(value={"placeholder.txt": "# Select an issue to load code."}),
964
+ ai_output_display: gr.update(value="*AI suggestions and patches will appear here...*")
965
+ }
966
+
967
+ if evt.index[0] is None or not hasattr(evt, 'value') or not evt.value:
968
+ logger.info("Issue deselected or invalid selection event.")
969
+ return default_response
970
 
971
+ try:
972
+ selected_id = int(evt.value[0])
973
+ logger.info(f"Issue selected: ID {selected_id}")
974
+
975
+ # Update components with progress indication
976
+ updates = {
977
+ selected_issue_id: gr.update(value=selected_id),
978
+ issue_preview_html: gr.update(generate_issue_preview(selected_id)),
979
+ code_edit_component: gr.update(value={"loading.txt": "# Loading code...\n"}),
980
+ ai_output_display: gr.update(value="*Refreshing suggestions...*")
981
+ }
982
+
983
+ # --- Simulated code loading ---
984
+ files_content = {
985
+ f"issue_{selected_id}_code.py": (
986
+ f"# Code related to issue {selected_id}\n"
987
+ "# Replace with actual file content\n\n"
988
+ f"def fix_issue_{selected_id}():\n"
989
+ " print('Implement solution here')"
990
+ ),
991
+ "README.md": f"# Issue {selected_id}\n\nResolution work in progress..."
992
+ }
993
+
994
+ # Update code editor component
995
+ updates[code_edit_component] = gr.update(value=files_content)
996
+ updates[ai_output_display] = gr.update(value="*AI suggestions ready*")
997
+
998
+ # Initialize server-side editor state
999
+ manager.code_editors[selected_id] = OTCodeEditor(value=files_content)
1000
+ logger.info(f"Initialized OT editor for issue {selected_id}")
1001
+
1002
+ return updates
1003
+
1004
+ except (ValueError, TypeError, IndexError, KeyError) as e:
1005
+ logger.error(f"Selection error: {str(e)}")
1006
+ return {
1007
+ **default_response,
1008
+ issue_preview_html: gr.update("<p style='color: red;'>Error loading issue details</p>"),
1009
+ code_edit_component: gr.update(value={"error.txt": "# Error loading code\nPlease try again"}),
1010
+ ai_output_display: gr.update(value="*Error processing selection*")
1011
+ }
1012
  }
1013
 
1014