From c3c1c50af6c960c7c2f717e8b288819c6529c820 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 12:40:41 -0500 Subject: [PATCH] Add new page/route for notebooks create and rename (#152) (#250) * initial commit to get new page rendered for notebook create Signed-off-by: Derek Ho * clean up and new file for create Signed-off-by: Derek Ho * get breadcrumb working and page styling Signed-off-by: Derek Ho * pushing work Signed-off-by: Derek Ho * get it mainly working Signed-off-by: Derek Ho * fix existing test Signed-off-by: Derek Ho * clean up code and include two trivial tests Signed-off-by: Derek Ho * push work Signed-off-by: Derek Ho * remove clone for now Signed-off-by: Derek Ho * fix component Signed-off-by: Derek Ho * update a test Signed-off-by: Derek Ho * add test for create Signed-off-by: Derek Ho * fix cypress test Signed-off-by: Derek Ho * PR comment fixes Signed-off-by: Derek Ho * fix test Signed-off-by: Derek Ho * fix up Signed-off-by: Derek Ho * clean up Signed-off-by: Derek Ho * revert integration test changes Signed-off-by: Derek Ho * fix test Signed-off-by: Derek Ho * fix test Signed-off-by: Derek Ho * PR comments Signed-off-by: Derek Ho * fix test Signed-off-by: Derek Ho --------- Signed-off-by: Derek Ho (cherry picked from commit d2ca1b60cd7750ff787c9d61d5fa6851969d10b8) Co-authored-by: Derek Ho --- .../__snapshots__/note_table.test.tsx.snap | 21 ++++---- .../components/__tests__/note_table.test.tsx | 51 ++++++++++++++++++- .../components/notebooks/components/main.tsx | 42 +++++++-------- .../notebooks/components/note_table.tsx | 20 ++++++-- 4 files changed, 99 insertions(+), 35 deletions(-) diff --git a/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap b/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap index e4bd2c8fa..4d3fbeeb0 100644 --- a/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap +++ b/public/components/notebooks/components/__tests__/__snapshots__/note_table.test.tsx.snap @@ -132,9 +132,10 @@ exports[` spec renders the component 1`] = `
- +
@@ -1022,9 +1023,10 @@ exports[` spec renders the empty component 1`] = `
- +
@@ -1080,10 +1082,11 @@ exports[` spec renders the empty component 1`] = `
- +
({ + useLocation: jest.fn().mockReturnValue({ + pathname: '/notebooks', + search: '', + hash: '', + state: null, + key: '', + }), + useHistory: jest.fn() +})); + describe(' spec', () => { configure({ adapter: new Adapter() }); @@ -81,4 +92,40 @@ describe(' spec', () => { utils.getByText('Actions').click(); utils.getByText('Rename').click(); }); -}); + + it('create notebook', async () => { + const fetchNotebooks = jest.fn(); + const addSampleNotebooks = jest.fn(); + const createNotebook = jest.fn(); + const renameNotebook = jest.fn(); + const cloneNotebook = jest.fn(); + const deleteNotebook = jest.fn(); + const setBreadcrumbs = jest.fn(); + const setToast = jest.fn(); + const notebooks = Array.from({ length: 5 }, (v, k) => ({ + path: `path-${k}`, + id: `id-${k}`, + dateCreated: 'date-created', + dateModified: 'date-modified', + })); + const utils = render( + + ); + utils.getByText('Create notebook').click(); + await waitFor(() => { + expect(global.window.location.href).toContain('/create') + }); + }); +}); \ No newline at end of file diff --git a/public/components/notebooks/components/main.tsx b/public/components/notebooks/components/main.tsx index 9ba18c8e7..36d81a96b 100644 --- a/public/components/notebooks/components/main.tsx +++ b/public/components/notebooks/components/main.tsx @@ -308,26 +308,8 @@ export class Main extends React.Component { /> ( - - )} - /> - ( { )} /> + ( + + )} + /> diff --git a/public/components/notebooks/components/note_table.tsx b/public/components/notebooks/components/note_table.tsx index d7ba77625..3c5da6df8 100644 --- a/public/components/notebooks/components/note_table.tsx +++ b/public/components/notebooks/components/note_table.tsx @@ -43,6 +43,7 @@ import { } from './helpers/modal_containers'; import { NotebookType } from './main'; import { pageStyles } from '../../../../common/constants/shared'; +import { useHistory, useLocation } from 'react-router-dom'; interface NoteTableProps { loading: boolean; @@ -64,6 +65,8 @@ export function NoteTable(props: NoteTableProps) { const [isActionsPopoverOpen, setIsActionsPopoverOpen] = useState(false); const [selectedNotebooks, setSelectedNotebooks] = useState([]); const [searchQuery, setSearchQuery] = useState(''); + const location = useLocation(); + const history = useHistory(); const { notebooks, createNotebook, renameNotebook, cloneNotebook, deleteNotebook } = props; useEffect(() => { @@ -77,6 +80,13 @@ export function NoteTable(props: NoteTableProps) { props.fetchNotebooks(); }, []); + useEffect(() => { + const url = window.location.hash.split('/') + if (url[url.length-1] === 'create') { + createNote(); + } + }, [location]); + const closeModal = () => { setIsModalVisible(false); }; @@ -114,7 +124,10 @@ export function NoteTable(props: NoteTableProps) { setModalLayout( getCustomModal( onCreate, - closeModal, + () => { + closeModal() + history.goBack(); + }, 'Name', 'Create notebook', 'Cancel', @@ -306,7 +319,7 @@ export function NoteTable(props: NoteTableProps) { - createNote()}> + Create notebook @@ -367,10 +380,9 @@ export function NoteTable(props: NoteTableProps) { - createNote()} > Create notebook