Skip to content

Commit

Permalink
Feature/response panel split horizontal 1041 (#1)
Browse files Browse the repository at this point in the history
feature: UI Response Panel Split Horizontally (usebruno#1041)
  • Loading branch information
busy-panda committed Apr 28, 2024
1 parent c17e4ef commit 9702906
Show file tree
Hide file tree
Showing 27 changed files with 441 additions and 104 deletions.
60 changes: 56 additions & 4 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,66 @@ done
find . -type f -name "package-lock.json" -delete
```

### Testing
### Run Unit Tests

```bash
# bruno-schema
npm test --workspace=packages/bruno-query
npm test --workspace=packages/bruno-lang
npm test --workspace=packages/bruno-schema
npm test --workspace=packages/bruno-app
npm test --workspace=packages/bruno-js
npm test --workspace=packages/bruno-common
npm test --workspace=packages/bruno-cli
npm test --workspace=packages/bruno-electron
```

# bruno-lang
npm test --workspace=packages/bruno-lang
### Run CLI Tests

```bash
cd packages/bruno-tests/collection
npm install
node ../../bruno-cli/bin/bru.js run --env Prod --output junit.xml --format junit
```

### Debugging in Visual Studio Code

Add a file `.vscode/launch.json` with the following configuration:

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Electron UI",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/bruno-electron",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"args": ["."],
"outputCapture": "std"
},
{
"name": "Debug Cli",
"program": "${workspaceFolder}/packages/bruno-cli/bin/bru.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"type": "node",
"cwd": "${workspaceFolder}/packages/bruno-tests/collection/",
"args": ["run", "--env", "Local"],
"console": "integratedTerminal"
},
{
"name": "Debug Backend Cli",
"command": "npm start",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}/packages/bruno-tests"
}
]
}
```

### Raising Pull Requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import styled from 'styled-components';

const StyledWrapper = styled.div`
div.CodeMirror {
/* todo: find a better way */
height: calc(100vh - 240px);
.CodeMirror-scroll {
padding-bottom: 0px;
}
}
.editing-mode {
cursor: pointer;
Expand Down
44 changes: 26 additions & 18 deletions packages/bruno-app/src/components/Documentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ import 'github-markdown-css/github-markdown.css';
import get from 'lodash/get';
import { updateRequestDocs } from 'providers/ReduxStore/slices/collections';
import { useTheme } from 'providers/Theme';
import { useState } from 'react';
import { useState, useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import Markdown from 'components/MarkDown';
import CodeEditor from 'components/CodeEditor';
import StyledWrapper from './StyledWrapper';
import { updateCodeMirrorsHeight } from 'utils/common/codemirror';

const Documentation = ({ item, collection }) => {
const dispatch = useDispatch();
const { displayedTheme } = useTheme();
const [isEditing, setIsEditing] = useState(false);
const docs = item.draft ? get(item, 'draft.request.docs') : get(item, 'request.docs');
const preferences = useSelector((state) => state.app.preferences);
const componentRef = useRef(null);

useEffect(() => {
updateCodeMirrorsHeight(componentRef.current, 80, 'calc(100vh - 260px)');
});

const toggleViewMode = () => {
setIsEditing((prev) => !prev);
Expand All @@ -37,24 +43,26 @@ const Documentation = ({ item, collection }) => {
}

return (
<StyledWrapper className="mt-1 h-full w-full relative">
<div className="editing-mode mb-2" role="tab" onClick={toggleViewMode}>
{isEditing ? 'Preview' : 'Edit'}
</div>
<StyledWrapper ref={componentRef} className="h-full w-full">
<div className="flex flex-col">
<div className="editing-mode mb-2 mt-1" role="tab" onClick={toggleViewMode}>
{isEditing ? 'Preview' : 'Edit'}
</div>

{isEditing ? (
<CodeEditor
collection={collection}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
value={docs || ''}
onEdit={onEdit}
onSave={onSave}
mode="application/text"
/>
) : (
<Markdown onDoubleClick={toggleViewMode} content={docs} />
)}
{isEditing ? (
<CodeEditor
collection={collection}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
value={docs || ''}
onEdit={onEdit}
onSave={onSave}
mode="application/text"
/>
) : (
<Markdown onDoubleClick={toggleViewMode} content={docs} />
)}
</div>
</StyledWrapper>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const GraphQLRequestPane = ({ item, collection, leftPaneWidth, onSchemaLoad, tog
</div>
<GraphQLSchemaActions item={item} collection={collection} onSchemaLoad={setSchema} toggleDocs={toggleDocs} />
</div>
<section className="flex w-full mt-5">{getTabPanel(focusedTab.requestPaneTab)}</section>
<section className="flex w-full mt-5 overflow-y-auto">{getTabPanel(focusedTab.requestPaneTab)}</section>
</StyledWrapper>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const HttpRequestPane = ({ item, collection, leftPaneWidth }) => {
) : null}
</div>
<section
className={`flex w-full ${
className={`flex w-full overflow-y-auto ${
['script', 'vars', 'auth', 'docs'].includes(focusedTab.requestPaneTab) ? '' : 'mt-5'
}`}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import styled from 'styled-components';

const Wrapper = styled.div`
div.CodeMirror {
/* todo: find a better way */
height: calc(100vh - 220px);
}
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import get from 'lodash/get';
import CodeEditor from 'components/CodeEditor';
import FormUrlEncodedParams from 'components/RequestPane/FormUrlEncodedParams';
Expand All @@ -8,13 +8,19 @@ import { useTheme } from 'providers/Theme';
import { updateRequestBody } from 'providers/ReduxStore/slices/collections';
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import StyledWrapper from './StyledWrapper';
import { updateCodeMirrorsHeight } from 'utils/common/codemirror';

const RequestBody = ({ item, collection }) => {
const dispatch = useDispatch();
const body = item.draft ? get(item, 'draft.request.body') : get(item, 'request.body');
const bodyMode = item.draft ? get(item, 'draft.request.body.mode') : get(item, 'request.body.mode');
const { displayedTheme } = useTheme();
const preferences = useSelector((state) => state.app.preferences);
const componentRef = useRef(null);

useEffect(() => {
updateCodeMirrorsHeight(componentRef.current, 65, 'calc(100vh - 250px)');
});

const onEdit = (value) => {
dispatch(
Expand Down Expand Up @@ -45,7 +51,7 @@ const RequestBody = ({ item, collection }) => {
};

return (
<StyledWrapper className="w-full">
<StyledWrapper ref={componentRef} className="w-full">
<CodeEditor
collection={collection}
theme={displayedTheme}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import styled from 'styled-components';

const StyledWrapper = styled.div`
div.CodeMirror {
height: inherit;
}
div.title {
Expand Down
62 changes: 35 additions & 27 deletions packages/bruno-app/src/components/RequestPane/Script/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import get from 'lodash/get';
import { useDispatch, useSelector } from 'react-redux';
import CodeEditor from 'components/CodeEditor';
import { updateRequestScript, updateResponseScript } from 'providers/ReduxStore/slices/collections';
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import { useTheme } from 'providers/Theme';
import StyledWrapper from './StyledWrapper';
import { updateCodeMirrorsHeight } from 'utils/common/codemirror';

const Script = ({ item, collection }) => {
const dispatch = useDispatch();
Expand All @@ -14,6 +15,11 @@ const Script = ({ item, collection }) => {

const { displayedTheme } = useTheme();
const preferences = useSelector((state) => state.app.preferences);
const componentRef = useRef(null);

useEffect(() => {
updateCodeMirrorsHeight(componentRef.current, 125, 'calc((100vh - 280px) / 2');
});

const onRequestScriptEdit = (value) => {
dispatch(
Expand All @@ -39,32 +45,34 @@ const Script = ({ item, collection }) => {
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));

return (
<StyledWrapper className="w-full flex flex-col">
<div className="flex-1 mt-2">
<div className="mb-1 title text-xs">Pre Request</div>
<CodeEditor
collection={collection}
value={requestScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
onEdit={onRequestScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
</div>
<div className="flex-1 mt-6">
<div className="mt-1 mb-1 title text-xs">Post Response</div>
<CodeEditor
collection={collection}
value={responseScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
onEdit={onResponseScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
<StyledWrapper ref={componentRef} className="w-full">
<div className="flex flex-col">
<div className="flex-1 mt-2">
<div className="mb-1 title text-xs">Pre Request</div>
<CodeEditor
collection={collection}
value={requestScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
onEdit={onRequestScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
</div>
<div className="flex-1 mt-6">
<div className="mt-1 mb-1 title text-xs">Post Response</div>
<CodeEditor
collection={collection}
value={responseScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
onEdit={onResponseScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
</div>
</div>
</StyledWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import styled from 'styled-components';

const StyledWrapper = styled.div`
div.CodeMirror {
/* todo: find a better way */
height: calc(100vh - 220px);
}
`;

Expand Down
10 changes: 8 additions & 2 deletions packages/bruno-app/src/components/RequestPane/Tests/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import get from 'lodash/get';
import { useDispatch, useSelector } from 'react-redux';
import CodeEditor from 'components/CodeEditor';
import { updateRequestTests } from 'providers/ReduxStore/slices/collections';
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import { useTheme } from 'providers/Theme';
import StyledWrapper from './StyledWrapper';
import { updateCodeMirrorsHeight } from 'utils/common/codemirror';

const Tests = ({ item, collection }) => {
const dispatch = useDispatch();
const tests = item.draft ? get(item, 'draft.request.tests') : get(item, 'request.tests');

const { displayedTheme } = useTheme();
const preferences = useSelector((state) => state.app.preferences);
const componentRef = useRef(null);

const onEdit = (value) => {
dispatch(
Expand All @@ -24,11 +26,15 @@ const Tests = ({ item, collection }) => {
);
};

useEffect(() => {
updateCodeMirrorsHeight(componentRef.current, 65, 'calc(100vh - 250px)');
});

const onRun = () => dispatch(sendRequest(item, collection.uid));
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));

return (
<StyledWrapper className="w-full">
<StyledWrapper ref={componentRef} className="w-full">
<CodeEditor
collection={collection}
value={tests || ''}
Expand Down
25 changes: 25 additions & 0 deletions packages/bruno-app/src/components/RequestTabPanel/StyledWrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import styled from 'styled-components';

const StyledWrapper = styled.div`
section.main {
max-height: calc(100vh - 150px);
}
&.dragging {
cursor: col-resize;
}
Expand All @@ -26,6 +30,27 @@ const StyledWrapper = styled.div`
}
}
div.drag-request-horizontal {
display: flex;
justify-content: center;
height: 10px;
cursor: row-resize;
background: transparent;
div.drag-request-horizontal-border {
display: flex;
width: 100%;
height: 1px;
border-top: solid 1px ${(props) => props.theme.requestTabPanel.dragbar.border};
}
&:hover div.drag-request-horizontal-border {
border-top: solid 1px ${(props) => props.theme.requestTabPanel.dragbar.activeBorder};
}
}
div.graphql-docs-explorer-container {
background: white;
outline: none;
Expand Down

0 comments on commit 9702906

Please sign in to comment.