Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
929 |
-
|
|
|
930 |
)
|
931 |
|
932 |
# --- Analytics Tab (Placeholder) ---
|
@@ -953,57 +955,60 @@ def create_ui(manager: IssueManager):
|
|
953 |
)
|
954 |
|
955 |
# 2. Issue Selection in Dataframe
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
|
|
|
|
966 |
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
#
|
983 |
-
#
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
|
|
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 |
|