add option to save insight as note

This commit is contained in:
LUIS NOVO 2024-11-13 17:33:38 -03:00
parent bba5bf88ed
commit 1e35f069b0
3 changed files with 22 additions and 5 deletions

View file

@ -130,6 +130,16 @@ class SourceInsight(ObjectModel):
logger.exception(e)
raise DatabaseOperationError(e)
def save_as_note(self, notebook_id: str = None) -> Any:
note = Note(
title=f"{self.insight_type} from source {self.source.title}",
content=self.content,
)
note.save()
if notebook_id:
note.add_to_notebook(notebook_id)
return note
class Source(ObjectModel):
table_name: ClassVar[str] = "source"

View file

@ -8,7 +8,7 @@ from open_notebook.utils import surreal_clean
from pages.stream_app.utils import run_patterns
def source_panel(source_id: str, modal=False):
def source_panel(source_id: str, notebook_id=None, modal=False):
source: Source = Source.get(source_id)
if not source:
raise ValueError(f"Source not found: {source_id}")
@ -36,11 +36,18 @@ def source_panel(source_id: str, modal=False):
for insight in source.insights:
with st.expander(f"**{insight.insight_type}**"):
st.markdown(insight.content)
if st.button(
x1, x2 = st.columns(2)
if x1.button(
"Delete", type="primary", key=f"delete_insight_{insight.id}"
):
insight.delete()
st.rerun(scope="fragment" if modal else "app")
if notebook_id:
if x2.button(
"Save as Note", icon="📝", key=f"save_note_{insight.id}"
):
insight.save_as_note(notebook_id)
st.toast("Saved as Note. Refresh the Notebook to see it.")
with c2:
transformations = Transformation.get_all()

View file

@ -17,8 +17,8 @@ from .consts import source_context_icons
@st.dialog("Source", width="large")
def source_panel_dialog(source_id):
source_panel(source_id, modal=True)
def source_panel_dialog(source_id, notebook_id=None):
source_panel(source_id, notebook_id=notebook_id, modal=True)
@st.dialog("Add a Source", width="large")
@ -121,7 +121,7 @@ def source_card(source, notebook_id):
f"Updated: {naturaltime(source.updated)}, **{len(source.insights)}** insights"
)
if st.button("Expand", icon="📝", key=source.id):
source_panel_dialog(source.id)
source_panel_dialog(source.id, notebook_id)
st.session_state[notebook_id]["context_config"][source.id] = context_state