Skip to content

Commit 70aaa52

Browse files
authored
Web2 editor back button (#334)
* added back button * fixed tests
1 parent 3c8ccf5 commit 70aaa52

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

frontend/src/App.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
2+
import { Routes, Route } from "react-router-dom";
33
import { Provider } from "react-redux";
44
import { GlobalStore } from "src/redux-state/index";
55

@@ -13,12 +13,10 @@ const App: React.FC = () => {
1313
<div className="App">
1414
<GlobalStyle />
1515
<Provider store={GlobalStore}>
16-
<Router>
1716
<Routes>
1817
<Route path="/" element={<Dashboard/>}/>
1918
<Route path="/editor/:id" element={<Editor/>}/>
2019
</Routes>
21-
</Router>
2220
</Provider>
2321
</div>
2422
);

frontend/src/cse-testing-lib/test-utils.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ import { Provider } from 'react-redux';
33
import { GlobalStore } from 'src/redux-state/index';
44
import {render, queries, RenderOptions} from '@testing-library/react'
55
import * as customQueries from './custom-queries'
6+
import { BrowserRouter } from 'react-router-dom';
67

78
// with redux
89
const AllTheProviders: React.FC = ({ children }) => {
910
return (
10-
<Provider store={GlobalStore}>
11-
{children}
12-
</Provider>
11+
<BrowserRouter>
12+
<Provider store={GlobalStore}>
13+
{children}
14+
</Provider>
15+
</BrowserRouter>
1316
)
1417
}
1518

1619
const customRender = (
1720
ui: React.ReactElement,
1821
options?: Omit<RenderOptions, 'queries'>,
19-
) => render(ui, {
22+
) => render(
23+
ui, {
2024
queries: {...queries, ...customQueries},
2125
wrapper: AllTheProviders,
2226
...options

frontend/src/deprecated/components/Editor/EditorHeader.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from 'react';
22
import styled from 'styled-components';
33
import Button from '@mui/material/Button';
4+
import IconButton from "@mui/material/IconButton";
5+
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
6+
import { useNavigate } from 'react-router-dom';
7+
48

59
const Container = styled.div`
610
height: 65px;
@@ -16,7 +20,7 @@ const HeaderFlex = styled.div`
1620
display: flex;
1721
flex-direction: row;
1822
flex-wrap: nowrap;
19-
justify-content: flex-end;
23+
justify-content: space-between;
2024
align-items: center;
2125
padding: 0.3rem 0.5rem;
2226
`
@@ -37,13 +41,30 @@ const ButtonStyle = styled(Button)`
3741
min-width: 2px;
3842
}
3943
`
44+
45+
const ButtonContainer = styled.div`
46+
display: flex;
47+
justify-content: flex-end;
48+
flex-direction: row;
49+
align-items: center;
50+
`
51+
4052
/* Preview and text to be changed into a dropdown menu */
4153

4254
const EditorHeader: React.FC = (props) => {
55+
56+
const navigate = useNavigate();
57+
4358
return (
4459
<Container>
4560
<HeaderFlex>
46-
{props.children}
61+
62+
<IconButton aria-label="back" onClick={() => navigate(-1)}>
63+
<ArrowBackIcon fontSize="inherit" />
64+
</IconButton>
65+
<ButtonContainer>
66+
{props.children}
67+
</ButtonContainer>
4768
{/* <ButtonGroup>
4869
<ButtonStyle>
4970

frontend/src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import App from './App';
44
import reportWebVitals from './reportWebVitals';
5+
import { BrowserRouter } from 'react-router-dom';
56

67
ReactDOM.render(
78
<React.StrictMode>
8-
<App />
9+
<BrowserRouter>
10+
<App />
11+
</BrowserRouter>
912
</React.StrictMode>,
13+
1014
document.getElementById('root')
1115
);
1216

frontend/src/packages/dashboard/components/SideBar/SideBar.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { render } from "src/cse-testing-lib";
22
import { queryByDataAnchor } from "src/cse-testing-lib/custom-queries";
33
import SideBar from "./SideBar";
4-
import { BrowserRouter as Router } from "react-router-dom";
54
import React from "react";
65

76
describe("Side bar tests", () => {
@@ -11,14 +10,12 @@ describe("Side bar tests", () => {
1110
const mockSetModalState = jest.fn();
1211
const mockSelectedFileID = "5";
1312
const { queryByDataAnchor } = render(
14-
<Router>
1513
<SideBar
1614
setModalState={mockSetModalState}
1715
selectedFile={mockSelectedFileID}
1816
isOpen={true}
1917
setOpen={mockSetOpen}
2018
/>
21-
</Router>
2219
);
2320

2421
expect(queryByDataAnchor("NewPageButton")).toBeTruthy();

frontend/src/packages/editor/EditorBlock.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import EditorPage from "./index";
55

66
describe("Editor Block tests", () => {
77
it("On CreateContentBlockButton click should create content block", () => {
8+
89
const { queryByDataAnchor, queryAllByDataAnchor } = render(<EditorPage/>);
910
const CreateContentBlockButton = queryByDataAnchor("CreateContentBlockButton");
1011

0 commit comments

Comments
 (0)