bruno/packages/grafnode-components/src/components/ResponsePane/index.js

65 lines
1.8 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';
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}
isLoading={isLoading}
/>
);
}
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>;
}
}
}
return (
<StyledWrapper className="">
<div className="flex items-center 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>
<section>
{getTabPanel(selectedTab)}
</section>
</StyledWrapper>
)
};
export default ResponsePane;