Skip to content

Commit

Permalink
fix(#28): add info why client/bidirectional streaming is not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
notmedia committed Dec 12, 2022
1 parent 65a84fa commit 3e52e3a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { faGlobe, faWarning } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Container, Spacer, Switch, SwitchEvent, Text, Tooltip, useTheme } from '@nextui-org/react';
import React from 'react';

import { GrpcMethodType } from '@core/types';
import { GrpcProtocol, GrpcTab } from '@storage';

export interface ProtocolSwitchProps {
tab: GrpcTab<GrpcMethodType>;

onChange: (event: SwitchEvent) => void;
}

export const ProtocolSwitch: React.FC<ProtocolSwitchProps> = ({ tab, onChange }) => {
const { theme } = useTheme();

const isGrpcWebAvailable =
tab.info.methodType === GrpcMethodType.UNARY ||
tab.info.methodType === GrpcMethodType.SERVER_STREAMING;

let content = (
<Text size="$sm">
{tab.data.protocol === GrpcProtocol.GRPC_WEB ? 'Using gRPC-Web' : 'Using gRPC'}
</Text>
);

if (!isGrpcWebAvailable) {
content = (
<Container gap={0}>
<Text size="$sm">Using gRPC</Text>
<Spacer y={0.5} />
<Container gap={0} display="flex" alignItems="center">
<FontAwesomeIcon icon={faWarning} color={theme?.colors.yellow700.value} />
<Spacer x={0.5} />
<Text size="$xs">
gRPC-Web doesn&apos;t support
{tab.info.methodType === GrpcMethodType.CLIENT_STREAMING
? ' client streaming'
: ' bidirectional streaming'}
</Text>
</Container>
</Container>
);
}

return (
<Tooltip content={content} placement="left" enterDelay={500} css={{ width: 'max-content' }}>
<Switch
size="md"
bordered
borderWeight="light"
color={isGrpcWebAvailable ? 'primary' : 'error'}
disabled={!isGrpcWebAvailable}
icon={<FontAwesomeIcon icon={faGlobe} />}
checked={tab.data.protocol === GrpcProtocol.GRPC_WEB}
onChange={onChange}
/>
</Tooltip>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faFloppyDisk, faGlobe, faLock, faUnlock } from '@fortawesome/free-solid-svg-icons';
import { faFloppyDisk, faLock, faUnlock } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Button, Container, Input, Spacer, Switch, SwitchEvent, Tooltip } from '@nextui-org/react';
import { Button, Container, Input, Spacer, SwitchEvent, Tooltip } from '@nextui-org/react';
import React, { PropsWithChildren } from 'react';
import { MultiValue, SingleValue } from 'react-select';

Expand All @@ -17,6 +17,7 @@ import {

import { CreateEnvironmentModal } from '../environments';
import { TlsSettingsModal } from '../tls';
import { ProtocolSwitch } from './protocol-switch';

export interface SendHeaderProps<T extends GrpcMethodType> {
tab: GrpcTab<T>;
Expand Down Expand Up @@ -191,31 +192,7 @@ export const SendHeader: React.FC<PropsWithChildren<SendHeaderProps<GrpcMethodTy
}
/>
<Spacer x={0.5} />
<Tooltip
content={tab.data.protocol === GrpcProtocol.GRPC_WEB ? 'Using gRPC-Web' : 'Using gRPC'}
placement="left"
enterDelay={500}
css={{ width: 'max-content' }}
>
<Switch
size="md"
bordered
borderWeight="light"
color={
tab.info.methodType !== GrpcMethodType.UNARY &&
tab.info.methodType !== GrpcMethodType.SERVER_STREAMING
? 'error'
: 'primary'
}
disabled={
tab.info.methodType !== GrpcMethodType.UNARY &&
tab.info.methodType !== GrpcMethodType.SERVER_STREAMING
}
icon={<FontAwesomeIcon icon={faGlobe} />}
checked={tab.data.protocol === GrpcProtocol.GRPC_WEB}
onChange={handleGrpcProtocolChange}
/>
</Tooltip>
<ProtocolSwitch tab={tab} onChange={handleGrpcProtocolChange} />
{children}
</Container>
<CreateEnvironmentModal
Expand Down

0 comments on commit 3e52e3a

Please sign in to comment.