2021-05-12 06:35:00 +00:00
|
|
|
import React, { FunctionComponent } from 'react';
|
2021-07-22 23:04:56 +00:00
|
|
|
|
2020-11-10 00:30:27 +00:00
|
|
|
import type { GrpcRequest } from '../../../models/grpc-request';
|
2020-11-11 22:44:03 +00:00
|
|
|
import { useGrpcRequestState } from '../../context/grpc';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { GrpcSpinner } from '../grpc-spinner';
|
2021-09-15 20:16:04 +00:00
|
|
|
import { GrpcStatusTag } from '../tags/grpc-status-tag';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { GrpcTabbedMessages } from '../viewers/grpc-tabbed-messages';
|
2021-07-22 23:04:56 +00:00
|
|
|
import { Pane, PaneBody, PaneHeader } from './pane';
|
2020-11-02 22:09:45 +00:00
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
interface Props {
|
|
|
|
forceRefreshKey: number;
|
|
|
|
activeRequest: GrpcRequest;
|
|
|
|
}
|
2020-11-09 01:36:35 +00:00
|
|
|
|
2021-11-25 04:26:08 +00:00
|
|
|
export const GrpcResponsePane: FunctionComponent<Props> = ({ activeRequest, forceRefreshKey }) => {
|
2020-11-10 00:30:27 +00:00
|
|
|
// Used to refresh input fields to their default value when switching between requests.
|
|
|
|
// This is a common pattern in this codebase.
|
|
|
|
const uniquenessKey = `${forceRefreshKey}::${activeRequest._id}`;
|
2020-11-11 22:44:03 +00:00
|
|
|
const { responseMessages, status, error } = useGrpcRequestState(activeRequest._id);
|
2020-11-09 01:36:35 +00:00
|
|
|
return (
|
|
|
|
<Pane type="response">
|
|
|
|
<PaneHeader className="row-spaced">
|
|
|
|
<div className="no-wrap scrollable scrollable--no-bars pad-left">
|
2020-11-11 22:44:03 +00:00
|
|
|
<GrpcSpinner requestId={activeRequest._id} className="margin-right-sm" />
|
|
|
|
{status && <GrpcStatusTag statusCode={status.code} statusMessage={status.details} />}
|
|
|
|
{!status && error && <GrpcStatusTag statusMessage={error.message} />}
|
2020-11-09 01:36:35 +00:00
|
|
|
</div>
|
|
|
|
</PaneHeader>
|
|
|
|
<PaneBody>
|
2020-11-11 22:44:03 +00:00
|
|
|
{!!responseMessages.length && (
|
|
|
|
<GrpcTabbedMessages
|
|
|
|
uniquenessKey={uniquenessKey}
|
|
|
|
tabNamePrefix="Response"
|
|
|
|
messages={responseMessages}
|
|
|
|
/>
|
|
|
|
)}
|
2020-11-09 01:36:35 +00:00
|
|
|
</PaneBody>
|
|
|
|
</Pane>
|
|
|
|
);
|
|
|
|
};
|