Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: script ui #3857

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import styled from 'styled-components';

const StyledWrapper = styled.div`
div.CodeMirror {
height: inherit;
height: 100%;

.script-tabs {
display: flex;
gap: 1px;
padding: 0 1px;
border-bottom: 1px solid ${(props) => props.theme.requestTabs.bottomBorder};
}

div.title {
color: var(--color-tab-inactive);
.tab {
padding: 8px 16px;
font-size: 13px;
background: transparent;
border: none;
cursor: pointer;
color: ${(props) => props.theme.requestTabs.color};
border-bottom: 2px solid transparent;
transition: all 0.2s ease;
position: relative;

&:hover {
color: ${(props) => props.theme.requestTabs.icon.hoverColor};
background: ${(props) => props.theme.requestTabs.icon.hoverBg};
}

&.active {
color: ${(props) => props.theme.tabs.active.color};
border-bottom: solid 2px ${(props) => props.theme.tabs.active.border};
background: ${(props) => props.theme.requestTabs.active.bg};
}
}

div.CodeMirror {
height: calc(100vh - 290px);
background: ${(props) => props.theme.codemirror.bg};
}
`;

export default StyledWrapper;
export default StyledWrapper;
75 changes: 46 additions & 29 deletions packages/bruno-app/src/components/RequestPane/Script/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import get from 'lodash/get';
import { useDispatch, useSelector } from 'react-redux';
import CodeEditor from 'components/CodeEditor';
Expand All @@ -8,6 +8,7 @@ import { useTheme } from 'providers/Theme';
import StyledWrapper from './StyledWrapper';

const Script = ({ item, collection }) => {
const [activeTab, setActiveTab] = useState('pre-request');
const dispatch = useDispatch();
const requestScript = item.draft ? get(item, 'draft.request.script.req') : get(item, 'request.script.req');
const responseScript = item.draft ? get(item, 'draft.request.script.res') : get(item, 'request.script.res');
Expand Down Expand Up @@ -39,37 +40,53 @@ const Script = ({ item, collection }) => {
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));

return (
<StyledWrapper className="w-full flex flex-col">
<div className="flex flex-col flex-1 mt-2 gap-y-2">
<div className="title text-xs">Pre Request</div>
<CodeEditor
collection={collection}
value={requestScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onRequestScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
<StyledWrapper className="w-full flex flex-col mt-4">
<div className="script-tabs">
<button
className={`tab ${activeTab === 'pre-request' ? 'active' : ''}`}
onClick={() => setActiveTab('pre-request')}
>
Pre Request
</button>
<button
className={`tab ${activeTab === 'post-response' ? 'active' : ''}`}
onClick={() => setActiveTab('post-response')}
>
Post Response
</button>
</div>
<div className="flex flex-col flex-1 mt-2 gap-y-2">
<div className="title text-xs">Post Response</div>
<CodeEditor
collection={collection}
value={responseScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onResponseScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>

<div className="flex flex-col flex-1 mt-2">
{activeTab === 'pre-request' && (
<CodeEditor
collection={collection}
value={requestScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onRequestScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
)}

{activeTab === 'post-response' && (
<CodeEditor
collection={collection}
value={responseScript || ''}
theme={displayedTheme}
font={get(preferences, 'font.codeFont', 'default')}
fontSize={get(preferences, 'font.codeFontSize')}
onEdit={onResponseScriptEdit}
mode="javascript"
onRun={onRun}
onSave={onSave}
/>
)}
</div>
</StyledWrapper>
);
};

export default Script;
export default Script;
Loading