bruno/renderer/components/ResponsePane/index.js

82 lines
2.2 KiB
JavaScript
Raw Normal View History

import React, { useState } from 'react';
import classnames from 'classnames';
2022-01-01 18:02:27 +01:00
import QueryResult from './QueryResult';
2022-01-28 18:33:10 +01:00
import Overlay from './Overlay';
2022-03-14 22:19:14 +01:00
import Placeholder from './Placeholder';
2022-01-01 18:02:27 +01:00
import ResponseHeaders from './ResponseHeaders';
import StatusCode from './StatusCode';
import ResponseTime from './ResponseTime';
import ResponseSize from './ResponseSize';
import StyledWrapper from './StyledWrapper';
2022-01-01 19:42:38 +01:00
const ResponsePane = ({rightPaneWidth, response, isLoading}) => {
const [selectedTab, setSelectedTab] = useState('response');
2022-01-01 19:42:38 +01:00
response = response || {};
const getTabClassname = (tabName) => {
return classnames(`tab select-none ${tabName}`, {
'active': tabName === selectedTab
});
};
const getTabPanel = (tab) => {
switch(tab) {
case 'response': {
return (
<QueryResult
width={rightPaneWidth}
2022-01-01 19:42:38 +01:00
data={response.data}
/>
);
}
case 'headers': {
2021-12-31 18:55:53 +01:00
return (
2022-01-01 19:42:38 +01:00
<ResponseHeaders headers={response.headers}/>
2021-12-31 18:55:53 +01:00
);
}
default: {
return <div>404 | Not found</div>;
}
}
}
2022-01-28 18:33:10 +01:00
if(isLoading) {
return (
<StyledWrapper className="flex h-full relative">
<Overlay />
</StyledWrapper>
);
}
2022-03-14 22:19:14 +01:00
if(response.state !== 'success') {
return (
<StyledWrapper className="flex h-full relative">
<Placeholder />
</StyledWrapper>
);
}
return (
2022-01-28 18:33:10 +01:00
<StyledWrapper className="flex flex-col h-full relative">
<div className="flex items-center px-3 tabs mt-1" role="tablist">
<div className={getTabClassname('response')} role="tab" onClick={() => setSelectedTab('response')}>Response</div>
<div className={getTabClassname('headers')} role="tab" onClick={() => setSelectedTab('headers')}>Headers</div>
2022-01-01 19:42:38 +01:00
{!isLoading ? (
<div className="flex flex-grow justify-end items-center">
<StatusCode status={response.status}/>
2022-01-01 20:18:12 +01:00
<ResponseTime duration={response.duration}/>
2022-01-01 20:39:54 +01:00
<ResponseSize size={response.size}/>
2022-01-01 19:42:38 +01:00
</div>
) : null }
</div>
2022-01-07 20:26:10 +01:00
<section className="flex flex-grow">
{getTabPanel(selectedTab)}
</section>
</StyledWrapper>
)
};
export default ResponsePane;