feat: more request and response pane ui responsive

This commit is contained in:
Donus(ADA) 2023-10-08 10:00:27 +07:00
parent 36caa5c2d3
commit 250227a134
11 changed files with 254 additions and 172 deletions

View File

@ -1,6 +1,16 @@
import styled from 'styled-components'; import styled from 'styled-components';
const Wrapper = styled.div` const Wrapper = styled.div`
.scroll {
::-webkit-scrollbar {
width: 0px;
}
::-webkit-scrollbar-button {
display: none;
}
}
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState, useEffect, useRef } from 'react';
import get from 'lodash/get'; import get from 'lodash/get';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
@ -6,11 +6,23 @@ import { addAssertion, updateAssertion, deleteAssertion } from 'providers/ReduxS
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import AssertionRow from './AssertionRow'; import AssertionRow from './AssertionRow';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
import { useTheme } from 'providers/Theme/index';
const Assertions = ({ item, collection }) => { const Assertions = ({ item, collection }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { theme } = useTheme();
const assertions = item.draft ? get(item, 'draft.request.assertions') : get(item, 'request.assertions'); const assertions = item.draft ? get(item, 'draft.request.assertions') : get(item, 'request.assertions');
const [countItems, setCountItems] = useState(assertions.length);
const ref = useRef();
useEffect(() => {
setCountItems(assertions.length);
if (assertions.length > countItems) {
ref.current.scrollIntoView();
}
}, [assertions]);
const handleAddAssertion = () => { const handleAddAssertion = () => {
dispatch( dispatch(
addAssertion({ addAssertion({
@ -59,34 +71,37 @@ const Assertions = ({ item, collection }) => {
return ( return (
<StyledWrapper className="w-full"> <StyledWrapper className="w-full">
<table> <div className="scroll" style={{ maxHeight: '55vh', overflowY: 'auto' }}>
<thead> <table>
<tr> <thead style={{ backgroundColor: theme.table.thead.bg, position: 'sticky', top: -1, zIndex: 2 }}>
<td>Expr</td> <tr>
<td>Operator</td> <td>Expr</td>
<td>Value</td> <td>Operator</td>
<td></td> <td>Value</td>
</tr> <td></td>
</thead> </tr>
<tbody> </thead>
{assertions && assertions.length <tbody>
? assertions.map((assertion) => { {assertions && assertions.length
return ( ? assertions.map((assertion) => {
<AssertionRow return (
key={assertion.uid} <AssertionRow
assertion={assertion} key={assertion.uid}
item={item} assertion={assertion}
collection={collection} item={item}
handleAssertionChange={handleAssertionChange} collection={collection}
handleRemoveAssertion={handleRemoveAssertion} handleAssertionChange={handleAssertionChange}
onSave={onSave} handleRemoveAssertion={handleRemoveAssertion}
handleRun={handleRun} onSave={onSave}
/> handleRun={handleRun}
); />
}) );
: null} })
</tbody> : null}
</table> </tbody>
</table>
<div ref={ref} />
</div>
<button className="btn-add-assertion text-link pr-2 py-3 mt-2 select-none" onClick={handleAddAssertion}> <button className="btn-add-assertion text-link pr-2 py-3 mt-2 select-none" onClick={handleAddAssertion}>
+ Add Assertion + Add Assertion
</button> </button>

View File

@ -1,6 +1,16 @@
import styled from 'styled-components'; import styled from 'styled-components';
const Wrapper = styled.div` const Wrapper = styled.div`
.scroll {
::-webkit-scrollbar {
width: 0px;
}
::-webkit-scrollbar-button {
display: none;
}
}
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState, useEffect, useRef } from 'react';
import get from 'lodash/get'; import get from 'lodash/get';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import { IconTrash } from '@tabler/icons'; import { IconTrash } from '@tabler/icons';
@ -12,8 +12,17 @@ import StyledWrapper from './StyledWrapper';
const QueryParams = ({ item, collection }) => { const QueryParams = ({ item, collection }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { storedTheme } = useTheme(); const { storedTheme, theme } = useTheme();
const params = item.draft ? get(item, 'draft.request.params') : get(item, 'request.params'); const params = item.draft ? get(item, 'draft.request.params') : get(item, 'request.params');
const [countItems, setCountItems] = useState(params.length);
const ref = useRef();
useEffect(() => {
setCountItems(params.length);
if (params.length > countItems) {
ref.current.scrollIntoView();
}
}, [params]);
const handleAddParam = () => { const handleAddParam = () => {
dispatch( dispatch(
@ -65,71 +74,74 @@ const QueryParams = ({ item, collection }) => {
return ( return (
<StyledWrapper className="w-full"> <StyledWrapper className="w-full">
<table> <div className="scroll" style={{ maxHeight: '55vh', overflowY: 'auto' }}>
<thead> <table>
<tr> <thead style={{ backgroundColor: theme.table.thead.bg, position: 'sticky', top: -1, zIndex: 2 }}>
<td>Name</td> <tr>
<td>Value</td> <td>Name</td>
<td></td> <td>Value</td>
</tr> <td></td>
</thead> </tr>
<tbody> </thead>
{params && params.length <tbody>
? params.map((param, index) => { {params && params.length
return ( ? params.map((param, index) => {
<tr key={param.uid}> return (
<td> <tr key={param.uid}>
<input <td>
type="text"
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck="false"
value={param.name}
className="mousetrap"
onChange={(e) => handleParamChange(e, param, 'name')}
/>
</td>
<td>
<SingleLineEditor
value={param.value}
theme={storedTheme}
onSave={onSave}
onChange={(newValue) =>
handleParamChange(
{
target: {
value: newValue
}
},
param,
'value'
)
}
onRun={handleRun}
collection={collection}
/>
</td>
<td>
<div className="flex items-center">
<input <input
type="checkbox" type="text"
checked={param.enabled} autoComplete="off"
tabIndex="-1" autoCorrect="off"
className="mr-3 mousetrap" autoCapitalize="off"
onChange={(e) => handleParamChange(e, param, 'enabled')} spellCheck="false"
value={param.name}
className="mousetrap"
onChange={(e) => handleParamChange(e, param, 'name')}
/> />
<button tabIndex="-1" onClick={() => handleRemoveParam(param)}> </td>
<IconTrash strokeWidth={1.5} size={20} /> <td>
</button> <SingleLineEditor
</div> value={param.value}
</td> theme={storedTheme}
</tr> onSave={onSave}
); onChange={(newValue) =>
}) handleParamChange(
: null} {
</tbody> target: {
</table> value: newValue
}
},
param,
'value'
)
}
onRun={handleRun}
collection={collection}
/>
</td>
<td>
<div className="flex items-center">
<input
type="checkbox"
checked={param.enabled}
tabIndex="-1"
className="mr-3 mousetrap"
onChange={(e) => handleParamChange(e, param, 'enabled')}
/>
<button tabIndex="-1" onClick={() => handleRemoveParam(param)}>
<IconTrash strokeWidth={1.5} size={20} />
</button>
</div>
</td>
</tr>
);
})
: null}
</tbody>
</table>
<div ref={ref} />
</div>
<button className="btn-add-param text-link pr-2 py-3 mt-2 select-none" onClick={handleAddParam}> <button className="btn-add-param text-link pr-2 py-3 mt-2 select-none" onClick={handleAddParam}>
+&nbsp;<span>Add Param</span> +&nbsp;<span>Add Param</span>
</button> </button>

View File

@ -9,6 +9,8 @@ import { IconDeviceFloppy, IconArrowRight } from '@tabler/icons';
import SingleLineEditor from 'components/SingleLineEditor'; import SingleLineEditor from 'components/SingleLineEditor';
import { isMacOS } from 'utils/common/platform'; import { isMacOS } from 'utils/common/platform';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
import { showDocs } from 'providers/ReduxStore/slices/docs';
import { IconFileDescription } from '@tabler/icons';
const QueryUrl = ({ item, collection, handleRun }) => { const QueryUrl = ({ item, collection, handleRun }) => {
const { theme, storedTheme } = useTheme(); const { theme, storedTheme } = useTheme();
@ -49,6 +51,10 @@ const QueryUrl = ({ item, collection, handleRun }) => {
); );
}; };
const onDocsClick = () => {
dispatch(showDocs());
};
return ( return (
<StyledWrapper className="flex items-center"> <StyledWrapper className="flex items-center">
<div className="flex items-center h-full method-selector-container"> <div className="flex items-center h-full method-selector-container">
@ -92,6 +98,11 @@ const QueryUrl = ({ item, collection, handleRun }) => {
<IconArrowRight color={theme.requestTabPanel.url.icon} strokeWidth={1.5} size={22} /> <IconArrowRight color={theme.requestTabPanel.url.icon} strokeWidth={1.5} size={22} />
</div> </div>
</div> </div>
<button className="m-2" onClick={onDocsClick}>
<div className="flex items-center">
<IconFileDescription /> Docs
</div>
</button>
</StyledWrapper> </StyledWrapper>
); );
}; };

View File

@ -1,6 +1,16 @@
import styled from 'styled-components'; import styled from 'styled-components';
const Wrapper = styled.div` const Wrapper = styled.div`
.scroll {
::-webkit-scrollbar {
width: 0px;
}
::-webkit-scrollbar-button {
display: none;
}
}
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect, useRef, useState } from 'react';
import get from 'lodash/get'; import get from 'lodash/get';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import { IconTrash } from '@tabler/icons'; import { IconTrash } from '@tabler/icons';
@ -13,9 +13,19 @@ const headerAutoCompleteList = StandardHTTPHeaders.map((e) => e.header);
const RequestHeaders = ({ item, collection }) => { const RequestHeaders = ({ item, collection }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { storedTheme } = useTheme(); const { storedTheme, theme } = useTheme();
const headers = item.draft ? get(item, 'draft.request.headers') : get(item, 'request.headers'); const headers = item.draft ? get(item, 'draft.request.headers') : get(item, 'request.headers');
const [countItems, setCountItems] = useState(headers.length);
const ref = useRef();
useEffect(() => {
setCountItems(headers.length);
if (headers.length > countItems) {
ref.current.scrollIntoView();
}
}, [headers]);
const addHeader = () => { const addHeader = () => {
dispatch( dispatch(
addRequestHeader({ addRequestHeader({
@ -64,80 +74,83 @@ const RequestHeaders = ({ item, collection }) => {
return ( return (
<StyledWrapper className="w-full"> <StyledWrapper className="w-full">
<table> <div class="scroll" style={{ maxHeight: '55vh', overflowY: 'auto' }}>
<thead> <table>
<tr> <thead style={{ backgroundColor: theme.table.thead.bg, position: 'sticky', top: -1, zIndex: 2 }}>
<td>Name</td> <tr>
<td>Value</td> <td>Name</td>
<td></td> <td>Value</td>
</tr> <td></td>
</thead> </tr>
<tbody> </thead>
{headers && headers.length <tbody>
? headers.map((header) => { {headers && headers.length
return ( ? headers.map((header) => {
<tr key={header.uid}> return (
<td> <tr key={header.uid}>
<SingleLineEditor <td>
value={header.name} <SingleLineEditor
theme={storedTheme} value={header.name}
onSave={onSave} theme={storedTheme}
onChange={(newValue) => onSave={onSave}
handleHeaderValueChange( onChange={(newValue) =>
{ handleHeaderValueChange(
target: { {
value: newValue target: {
} value: newValue
}, }
header, },
'name' header,
) 'name'
} )
autocomplete={headerAutoCompleteList} }
onRun={handleRun} autocomplete={headerAutoCompleteList}
collection={collection} onRun={handleRun}
/> collection={collection}
</td>
<td>
<SingleLineEditor
value={header.value}
theme={storedTheme}
onSave={onSave}
onChange={(newValue) =>
handleHeaderValueChange(
{
target: {
value: newValue
}
},
header,
'value'
)
}
onRun={handleRun}
collection={collection}
/>
</td>
<td>
<div className="flex items-center">
<input
type="checkbox"
checked={header.enabled}
tabIndex="-1"
className="mr-3 mousetrap"
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
/> />
<button tabIndex="-1" onClick={() => handleRemoveHeader(header)}> </td>
<IconTrash strokeWidth={1.5} size={20} /> <td>
</button> <SingleLineEditor
</div> value={header.value}
</td> theme={storedTheme}
</tr> onSave={onSave}
); onChange={(newValue) =>
}) handleHeaderValueChange(
: null} {
</tbody> target: {
</table> value: newValue
}
},
header,
'value'
)
}
onRun={handleRun}
collection={collection}
/>
</td>
<td>
<div className="flex items-center">
<input
type="checkbox"
checked={header.enabled}
tabIndex="-1"
className="mr-3 mousetrap"
onChange={(e) => handleHeaderValueChange(e, header, 'enabled')}
/>
<button tabIndex="-1" onClick={() => handleRemoveHeader(header)}>
<IconTrash strokeWidth={1.5} size={20} />
</button>
</div>
</td>
</tr>
);
})
: null}
</tbody>
<div ref={ref} />
</table>
</div>
<button className="btn-add-header text-link pr-2 py-3 mt-2 select-none" onClick={addHeader}> <button className="btn-add-header text-link pr-2 py-3 mt-2 select-none" onClick={addHeader}>
+ Add Header + Add Header
</button> </button>

View File

@ -38,7 +38,7 @@ const Script = ({ item, collection }) => {
const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); const onSave = () => dispatch(saveRequest(item.uid, collection.uid));
return ( return (
<StyledWrapper className="w-full flex flex-col"> <StyledWrapper className="w-full h-1/2 flex flex-col">
<div className="flex-1 mt-2"> <div className="flex-1 mt-2">
<div className="mb-1 title text-xs">Pre Request</div> <div className="mb-1 title text-xs">Pre Request</div>
<CodeEditor <CodeEditor

View File

@ -150,7 +150,7 @@ const RequestTabPanel = () => {
<div className="pt-4 pb-3 px-4"> <div className="pt-4 pb-3 px-4">
<QueryUrl item={item} collection={collection} handleRun={handleRun} /> <QueryUrl item={item} collection={collection} handleRun={handleRun} />
</div> </div>
<section className="main flex flex-grow pb-4 relative"> <section className="main flex flex-grow relative">
<section className="request-pane"> <section className="request-pane">
<div <div
className="px-4" className="px-4"

View File

@ -2,7 +2,6 @@ import styled from 'styled-components';
const Wrapper = styled.div` const Wrapper = styled.div`
table { table {
width: 100%;
border-collapse: collapse; border-collapse: collapse;
thead { thead {

View File

@ -1,6 +1,8 @@
import styled from 'styled-components'; import styled from 'styled-components';
const StyledWrapper = styled.div` const StyledWrapper = styled.div`
height: 80vh;
overflow-y: auto;
div.tabs { div.tabs {
div.tab { div.tab {
padding: 6px 0px; padding: 6px 0px;