Repository: mito-ds/mito (language: python)

Issue:
Graph creates 2 steps on opening graph editor
**Describe the bug**
Graph creates 2 steps on opening graph editor. 

**To Reproduce**
Steps to reproduce the behavior:
1. Click on the graph toolbar button
2. Wait approx. 2 seconds
3. Press undo
4. Notice that the graph editor is still open
5. Press undo again
6. The graph editor closes. 

**Expected behavior**
Should only require one undo to close the graph editor. 



Discussion / hints:

Fix patch:
diff --git a/mitosheet/src/mito/Mito.tsx b/mitosheet/src/mito/Mito.tsx
index f552b6b53..2f307451c 100644
--- a/mitosheet/src/mito/Mito.tsx
+++ b/mitosheet/src/mito/Mito.tsx
@@ -335,6 +335,23 @@ export const Mito = (props: MitoProps): JSX.Element => {
         loadPlotly()
     }, [])
 
+    /**
+     * This useEffect handles when the user creates a graph, then presses undo.
+     */
+    useEffect(() => {
+        if (uiState.currOpenTaskpane.type === TaskpaneType.GRAPH &&
+            analysisData.graphDataArray.length === 0) {
+            setUIState(prevUIState => {
+                return {
+                    ...prevUIState,
+                    currOpenTaskpane: {type: TaskpaneType.NONE},
+                    selectedTabType: 'data',
+                    selectedSheetIndex: 0
+                }
+            })
+        }
+    }, [analysisData.graphDataArray.length])
+
     /* 
         When the number of sheets increases, we make sure
         that the last sheet is highlighted. If it decreases,


Test patch:
diff --git a/tests/streamlit_ui_tests/graph.spec.ts b/tests/streamlit_ui_tests/graph.spec.ts
index 256b19b1f..1ad8352a3 100644
--- a/tests/streamlit_ui_tests/graph.spec.ts
+++ b/tests/streamlit_ui_tests/graph.spec.ts
@@ -193,6 +193,14 @@ test.describe('Graph Functionality', () => {
     await expect(mito.getByText('Facet row')).toBeInViewport();
   });
 
+  test('Pressing undo after opening graph editor closes the graph editor', async ({ page }) => {
+    const mito = await getMitoFrameWithTestCSV(page);
+    await openGraphEditor(mito, page);
+    await mito.getByTitle(/Undo the most recent edit/).click();
+    await expect(mito.locator('.tab-selected', { hasText: 'test' })).toBeVisible();
+    await expect(mito.locator('.endo-column-header-final-text').first()).toHaveText('Column1');
+  });
+
   test('Make a histogram and change the histogram specific configurations', async ({ page }) => {
     const mito = await getMitoFrameWithTestCSV(page);