Skip to content

Commit

Permalink
Add new page/route for notebooks create and rename (#152) (#250)
Browse files Browse the repository at this point in the history
* initial commit to get new page rendered for notebook create

Signed-off-by: Derek Ho <[email protected]>

* clean up and new file for create

Signed-off-by: Derek Ho <[email protected]>

* get breadcrumb working and page styling

Signed-off-by: Derek Ho <[email protected]>

* pushing work

Signed-off-by: Derek Ho <[email protected]>

* get it mainly working

Signed-off-by: Derek Ho <[email protected]>

* fix existing test

Signed-off-by: Derek Ho <[email protected]>

* clean up code and include two trivial tests

Signed-off-by: Derek Ho <[email protected]>

* push work

Signed-off-by: Derek Ho <[email protected]>

* remove clone for now

Signed-off-by: Derek Ho <[email protected]>

* fix component

Signed-off-by: Derek Ho <[email protected]>

* update a test

Signed-off-by: Derek Ho <[email protected]>

* add test for create

Signed-off-by: Derek Ho <[email protected]>

* fix cypress test

Signed-off-by: Derek Ho <[email protected]>

* PR comment fixes

Signed-off-by: Derek Ho <[email protected]>

* fix test

Signed-off-by: Derek Ho <[email protected]>

* fix up

Signed-off-by: Derek Ho <[email protected]>

* clean up

Signed-off-by: Derek Ho <[email protected]>

* revert integration test changes

Signed-off-by: Derek Ho <[email protected]>

* fix test

Signed-off-by: Derek Ho <[email protected]>

* fix test

Signed-off-by: Derek Ho <[email protected]>

* PR comments

Signed-off-by: Derek Ho <[email protected]>

* fix test

Signed-off-by: Derek Ho <[email protected]>

---------

Signed-off-by: Derek Ho <[email protected]>
(cherry picked from commit d2ca1b6)

Co-authored-by: Derek Ho <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and derek-ho authored Feb 7, 2023
1 parent a008f71 commit c3c1c50
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ exports[`<NoteTable /> spec renders the component 1`] = `
<div
class="euiFlexItem"
>
<button
<a
class="euiButton euiButton--primary euiButton--fill"
type="button"
href="#/notebooks/create"
rel="noreferrer"
>
<span
class="euiButtonContent euiButton__content"
Expand All @@ -145,7 +146,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
Create notebook
</span>
</span>
</button>
</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -1022,9 +1023,10 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
<div
class="euiFlexItem"
>
<button
<a
class="euiButton euiButton--primary euiButton--fill"
type="button"
href="#/notebooks/create"
rel="noreferrer"
>
<span
class="euiButtonContent euiButton__content"
Expand All @@ -1035,7 +1037,7 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
Create notebook
</span>
</span>
</button>
</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -1080,10 +1082,11 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
<a
class="euiButton euiButton--primary"
data-test-subj="note-table-empty-state-create-notebook-button"
type="button"
href="#/notebooks/create"
rel="noreferrer"
>
<span
class="euiButtonContent euiButton__content"
Expand All @@ -1094,7 +1097,7 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
Create notebook
</span>
</span>
</button>
</a>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { fireEvent, render } from '@testing-library/react';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { configure, mount, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { NoteTable } from '../note_table';

jest.mock('react-router-dom', () => ({
useLocation: jest.fn().mockReturnValue({
pathname: '/notebooks',
search: '',
hash: '',
state: null,
key: '',
}),
useHistory: jest.fn()
}));

describe('<NoteTable /> spec', () => {
configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -81,4 +92,40 @@ describe('<NoteTable /> 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(
<NoteTable
loading={false}
fetchNotebooks={fetchNotebooks}
addSampleNotebooks={addSampleNotebooks}
notebooks={notebooks}
createNotebook={createNotebook}
renameNotebook={renameNotebook}
cloneNotebook={cloneNotebook}
deleteNotebook={deleteNotebook}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
setToast={setToast}
/>
);
utils.getByText('Create notebook').click();
await waitFor(() => {
expect(global.window.location.href).toContain('/create')
});
});
});
42 changes: 22 additions & 20 deletions public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,8 @@ export class Main extends React.Component<MainProps, MainState> {
/>
<Switch>
<Route
path="/notebooks/:id"
render={(props) => (
<Notebook
pplService={this.props.pplService}
openedNoteId={props.match.params.id}
DashboardContainerByValueRenderer={this.props.DashboardContainerByValueRenderer}
http={this.props.http}
parentBreadcrumb={this.props.parentBreadcrumb}
setBreadcrumbs={this.props.setBreadcrumbs}
renameNotebook={this.renameNotebook}
cloneNotebook={this.cloneNotebook}
deleteNotebook={this.deleteNotebook}
setToast={this.setToast}
location={this.props.location}
history={this.props.history}
/>
)}
/>
<Route
path="/notebooks"
exact
path={['/notebooks/create', '/notebooks']}
render={(props) => (
<ObservabilitySideBar>
<NoteTable
Expand All @@ -346,6 +328,26 @@ export class Main extends React.Component<MainProps, MainState> {
</ObservabilitySideBar>
)}
/>
<Route
exact
path="/notebooks/:id"
render={(props) => (
<Notebook
pplService={this.props.pplService}
openedNoteId={props.match.params.id}
DashboardContainerByValueRenderer={this.props.DashboardContainerByValueRenderer}
http={this.props.http}
parentBreadcrumb={this.props.parentBreadcrumb}
setBreadcrumbs={this.props.setBreadcrumbs}
renameNotebook={this.renameNotebook}
cloneNotebook={this.cloneNotebook}
deleteNotebook={this.deleteNotebook}
setToast={this.setToast}
location={this.props.location}
history={this.props.history}
/>
)}
/>
</Switch>
</>
</HashRouter>
Expand Down
20 changes: 16 additions & 4 deletions public/components/notebooks/components/note_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,6 +65,8 @@ export function NoteTable(props: NoteTableProps) {
const [isActionsPopoverOpen, setIsActionsPopoverOpen] = useState(false);
const [selectedNotebooks, setSelectedNotebooks] = useState<NotebookType[]>([]);
const [searchQuery, setSearchQuery] = useState('');
const location = useLocation();
const history = useHistory();
const { notebooks, createNotebook, renameNotebook, cloneNotebook, deleteNotebook } = props;

useEffect(() => {
Expand All @@ -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);
};
Expand Down Expand Up @@ -114,7 +124,10 @@ export function NoteTable(props: NoteTableProps) {
setModalLayout(
getCustomModal(
onCreate,
closeModal,
() => {
closeModal()
history.goBack();
},
'Name',
'Create notebook',
'Cancel',
Expand Down Expand Up @@ -306,7 +319,7 @@ export function NoteTable(props: NoteTableProps) {
</EuiPopover>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton fill onClick={() => createNote()}>
<EuiButton fill href="#/notebooks/create">
Create notebook
</EuiButton>
</EuiFlexItem>
Expand Down Expand Up @@ -367,10 +380,9 @@ export function NoteTable(props: NoteTableProps) {
<EuiSpacer size="m" />
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiButton
<EuiButton href="#/notebooks/create"
data-test-subj="note-table-empty-state-create-notebook-button"
fullWidth={false}
onClick={() => createNote()}
>
Create notebook
</EuiButton>
Expand Down

0 comments on commit c3c1c50

Please sign in to comment.