Skip to content

Commit 8184812

Browse files
authored
Merge pull request #2081 from mito-ds/feature/spreadsheet-footer-btn
Spreadsheet Footer Button
2 parents 3a63966 + 72ab6bb commit 8184812

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

mito-ai/src/Extensions/NotebookFooter/NotebookFooter.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import '../../../style/NotebookFooter.css';
1212
import LoadingCircle from "../../components/LoadingCircle";
1313
import CodeIcon from "../../icons/NotebookFooter/CodeIcon";
1414
import TextIcon from "../../icons/NotebookFooter/TextIcon";
15+
import SpreadsheetIcon from "../../icons/NotebookFooter/SpreadsheetIcon";
1516
import { userSignupEvents } from '../../utils/userSignupEvents';
1617
import { useUserSignup } from '../AiChat/hooks/useUserSignup';
1718

@@ -25,12 +26,18 @@ const NotebookFooter: React.FC<NotebookFooterProps> = ({ notebookTracker, app })
2526

2627
const [inputValue, setInputValue] = useState('');
2728
const [isGenerating, setIsGenerating] = useState(false);
29+
const [hasMitosheet, setHasMitosheet] = useState(false);
2830
const { isSignedUp, refreshUserSignupState } = useUserSignup();
2931

3032
useEffect(() => {
3133
void refreshUserSignupState();
3234
}, []);
3335

36+
// Check if mitosheet command exists
37+
useEffect(() => {
38+
setHasMitosheet(app.commands.hasCommand('mitosheet:create-empty-mitosheet'));
39+
}, [app]);
40+
3441
// Listen for signup success events from other components
3542
useEffect(() => {
3643
const handleSignupSuccess = (): void => {
@@ -60,13 +67,15 @@ const NotebookFooter: React.FC<NotebookFooterProps> = ({ notebookTracker, app })
6067
}
6168
};
6269

63-
const addCell = (cellType: 'code' | 'markdown' = 'code'): void => {
70+
const addCell = (cellType: 'code' | 'markdown' | 'spreadsheet' = 'code'): void => {
6471
if (notebook.widgets.length && notebook.widgets.length > 0) {
6572
notebook.activeCellIndex = notebook.widgets.length - 1;
6673
}
6774

6875
if (cellType === 'code') {
6976
NotebookActions.insertBelow(notebook);
77+
} else if (cellType === 'spreadsheet') {
78+
void app.commands.execute('mitosheet:create-empty-mitosheet');
7079
} else {
7180
NotebookActions.insertBelow(notebook);
7281
// Change the cell type after insertion
@@ -190,6 +199,22 @@ const NotebookFooter: React.FC<NotebookFooterProps> = ({ notebookTracker, app })
190199
<span className="button-label">Text</span>
191200
</div>
192201
</button>
202+
203+
{/* Spreadsheet button */}
204+
{hasMitosheet && (
205+
<button
206+
onClick={() => addCell('spreadsheet')}
207+
className="footer-button"
208+
onMouseDown={(e) => e.stopPropagation()}
209+
>
210+
<div className="button-content">
211+
<div className="button-icon">
212+
<SpreadsheetIcon />
213+
</div>
214+
<span className="button-label">Spreadsheet</span>
215+
</div>
216+
</button>
217+
)}
193218
</div>
194219
</div>
195220
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) Saga Inc.
3+
* Distributed under the terms of the GNU Affero General Public License v3.0 License.
4+
*/
5+
6+
import React from 'react';
7+
8+
const SpreadsheetIcon: React.FC = () => (
9+
<svg width="16" height="12" viewBox="0 0 16 12" fill="none" xmlns="http://www.w3.org/2000/svg">
10+
<g fill='currentColor'>
11+
<path fillRule="evenodd" clipRule="evenodd" d="M15.5 9.75V1.75C15.5 0.784 14.717 0 13.75 0H1.75C0.783 0 0 0.784 0 1.75V9.75C0 10.716 0.783 11.5 1.75 11.5H13.75C14.717 11.5 15.5 10.716 15.5 9.75ZM14 1.75V9.75C14 9.888 13.888 10 13.75 10H1.75C1.612 10 1.5 9.888 1.5 9.75V1.75C1.5 1.612 1.612 1.5 1.75 1.5H13.75C13.888 1.5 14 1.612 14 1.75Z" />
12+
<path fillRule="evenodd" clipRule="evenodd" d="M0.75 8.25H14.75C15.164 8.25 15.5 7.914 15.5 7.5C15.5 7.086 15.164 6.75 14.75 6.75H0.75C0.336 6.75 0 7.086 0 7.5C0 7.914 0.336 8.25 0.75 8.25Z" />
13+
<path fillRule="evenodd" clipRule="evenodd" d="M9.5 0.75V10.75C9.5 11.164 9.836 11.5 10.25 11.5C10.664 11.5 11 11.164 11 10.75V0.75C11 0.336 10.664 0 10.25 0C9.836 0 9.5 0.336 9.5 0.75Z" />
14+
<path fillRule="evenodd" clipRule="evenodd" d="M0.75 4.75H14.75C15.164 4.75 15.5 4.414 15.5 4C15.5 3.586 15.164 3.25 14.75 3.25H0.75C0.336 3.25 0 3.586 0 4C0 4.414 0.336 4.75 0.75 4.75Z" />
15+
<path fillRule="evenodd" clipRule="evenodd" d="M4.5 0.75V10.75C4.5 11.164 4.836 11.5 5.25 11.5C5.664 11.5 6 11.164 6 10.75V0.75C6 0.336 5.664 0 5.25 0C4.836 0 4.5 0.336 4.5 0.75Z" />
16+
</g>
17+
</svg>
18+
);
19+
20+
export default SpreadsheetIcon;
21+

mito-ai/src/tests/NotebookFooter/notebookFooter.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ const createMockNotebook = (widgetCount = 3) => {
9090
// Create mock app
9191
const createMockApp = () => ({
9292
commands: {
93-
execute: jest.fn().mockResolvedValue(undefined)
93+
execute: jest.fn().mockResolvedValue(undefined),
94+
hasCommand: jest.fn().mockReturnValue(false)
9495
}
9596
}) as unknown as JupyterFrontEnd;
9697

@@ -287,7 +288,8 @@ describe('NotebookFooter Component', () => {
287288

288289
const mockApp = {
289290
commands: {
290-
execute: jest.fn().mockReturnValue(mockPromise)
291+
execute: jest.fn().mockReturnValue(mockPromise),
292+
hasCommand: jest.fn().mockReturnValue(false)
291293
}
292294
} as unknown as JupyterFrontEnd;
293295

@@ -345,7 +347,8 @@ describe('NotebookFooter Component', () => {
345347

346348
const mockApp = {
347349
commands: {
348-
execute: jest.fn().mockReturnValue(mockPromise)
350+
execute: jest.fn().mockReturnValue(mockPromise),
351+
hasCommand: jest.fn().mockReturnValue(false)
349352
}
350353
} as unknown as JupyterFrontEnd;
351354

0 commit comments

Comments
 (0)