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';
|
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';
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-04 12:30:03 +01:00
|
|
|
return (
|
2022-01-28 18:33:10 +01:00
|
|
|
<StyledWrapper className="flex flex-col h-full relative">
|
2022-01-26 16:01:49 +01:00
|
|
|
<div className="flex items-center px-3 tabs mt-1" role="tablist">
|
2021-12-04 12:30:03 +01:00
|
|
|
<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 }
|
2021-12-04 12:30:03 +01:00
|
|
|
</div>
|
2022-01-07 20:26:10 +01:00
|
|
|
<section className="flex flex-grow">
|
2021-12-04 12:30:03 +01:00
|
|
|
{getTabPanel(selectedTab)}
|
|
|
|
</section>
|
|
|
|
</StyledWrapper>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponsePane;
|