From a352a5b8ffa1adcc2ac5fd0cbad7fff80723500c Mon Sep 17 00:00:00 2001 From: David Newell Date: Mon, 18 Sep 2023 11:07:15 +0100 Subject: [PATCH] feat: detach saved insights in notebooks (#17443) --- .../scenes/notebooks/Nodes/NodeWrapper.tsx | 50 +++++++++--------- .../notebooks/Nodes/NotebookNodeQuery.tsx | 52 +++++++++++++++++-- .../scenes/notebooks/Notebook/Notebook.scss | 5 -- 3 files changed, 73 insertions(+), 34 deletions(-) diff --git a/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx b/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx index 463d2ed4664d0..6d90866fe208e 100644 --- a/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx +++ b/frontend/src/scenes/notebooks/Nodes/NodeWrapper.tsx @@ -156,33 +156,35 @@ export function NodeWrapper({ {title} - {parsedHref && } to={parsedHref} />} +
+ {parsedHref && } to={parsedHref} />} - {expandable && ( - setExpanded(!expanded)} - size="small" - icon={expanded ? : } - /> - )} + {expandable && ( + setExpanded(!expanded)} + size="small" + icon={expanded ? : } + /> + )} - {widgets.length > 0 ? ( - setIsShowingSidebar(!isShowingSidebar)} - size="small" - icon={} - active={isShowingSidebar && selected} - /> - ) : null} + {widgets.length > 0 ? ( + setIsShowingSidebar(!isShowingSidebar)} + size="small" + icon={} + active={isShowingSidebar && selected} + /> + ) : null} - {isEditable && ( - deleteNode()} - size="small" - status="danger" - icon={} - /> - )} + {isEditable && ( + deleteNode()} + size="small" + status="danger" + icon={} + /> + )} +
): J const { expanded } = useValues(nodeLogic) const modifiedQuery = useMemo(() => { - const modifiedQuery = { ...query } + const modifiedQuery = { ...query, full: false } if (NodeKind.DataTableNode === modifiedQuery.kind || NodeKind.SavedInsightNode === modifiedQuery.kind) { // We don't want to show the insights button for now @@ -75,7 +77,7 @@ export const Settings = ({ const { query } = attributes const modifiedQuery = useMemo(() => { - const modifiedQuery = { ...query } + const modifiedQuery = { ...query, full: false } if (NodeKind.DataTableNode === modifiedQuery.kind || NodeKind.SavedInsightNode === modifiedQuery.kind) { // We don't want to show the insights button for now @@ -95,7 +97,47 @@ export const Settings = ({ return modifiedQuery }, [query]) - return ( + const detachSavedInsight = (): void => { + if (attributes.query.kind === NodeKind.SavedInsightNode) { + const insightProps: InsightLogicProps = { dashboardItemId: attributes.query.shortId } + const dataLogic = insightDataLogic.findMounted(insightProps) + + if (dataLogic) { + updateAttributes({ query: dataLogic.values.query as QuerySchema }) + } + } + } + + return attributes.query.kind === NodeKind.SavedInsightNode ? ( +
+
Insight created outside of this notebook
+
+ Changes made to the original insight will be reflected in the notebook. Or you can detach from the + insight to make changes independently in the notebook. +
+ +
+ + Edit the insight + + + Detach from insight + +
+
+ ) : (