2021-12-04 12:30:03 +01:00
|
|
|
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';
|
2022-01-01 19:04:46 +01:00
|
|
|
import StatusCode from './StatusCode';
|
|
|
|
import ResponseTime from './ResponseTime';
|
|
|
|
import ResponseSize from './ResponseSize';
|
2021-12-04 12:30:03 +01:00
|
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
|
2022-01-01 19:42:38 +01:00
|
|
|
const ResponsePane = ({rightPaneWidth, response, isLoading}) => {
|
2021-12-04 12:30:03 +01:00
|
|
|
const [selectedTab, setSelectedTab] = useState('response');
|
|
|
|
|
2022-01-01 19:42:38 +01:00
|
|
|
response = response || {};
|
|
|
|
|
2021-12-04 12:30:03 +01:00
|
|
|
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}
|
2021-12-04 12:30:03 +01:00
|
|
|
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
|
|
|
);
|
2021-12-04 12:30:03 +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}/>
|
|
|
|
<ResponseTime />
|
|
|
|
<ResponseSize />
|
|
|
|
</div>
|
|
|
|
) : null }
|
2021-12-04 12:30:03 +01:00
|
|
|
</div>
|
|
|
|
<section>
|
|
|
|
{getTabPanel(selectedTab)}
|
|
|
|
</section>
|
|
|
|
</StyledWrapper>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsePane;
|