Skip to content

Commit

Permalink
💫 feat: add protocol field on build setting (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandiheath authored Mar 10, 2021
1 parent a2b8c33 commit b5a613a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
45 changes: 38 additions & 7 deletions src/components/organisms/editService/BuildSettingsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@ import StyledForm from 'components/atoms/StyledForm';
import TwoColumns from 'components/atoms/TwoColumns';
import { FormikProps } from 'formik';
import React from 'react';
import { useSelector } from 'react-redux';
import { AppState } from 'states/app/types';
import { RootState } from 'states/types';
import { EditServiceTabProps } from 'types/props/editService';
import { EditServicePageValues } from 'types/service';
import { Block, RunConfig } from 'types/proto/models_pb';

import Divider from '@material-ui/core/Divider';

import FormikSelect, { InputProps } from 'components/atoms/FormikSelect';
import { useAppState } from 'components/hooks/ReduxStateHook';
import LanguageSelector from './LanguageSelector';

const ProtocolOptions: InputProps[] = [
{
label: 'HTTP',
value: RunConfig.Protocol.HTTP,
disabled: false,
},
{
label: 'GRPC',
value: RunConfig.Protocol.GRPC,
disabled: false,
},
];

export default ({
tabIndex,
isCreate,
isPromotedService,
serviceType,
...formikProps
}: FormikProps<EditServicePageValues> & EditServiceTabProps) => {
const { config } = useSelector<RootState, AppState>(
(state: RootState) => state.app
);
const { config } = useAppState();
return (
<StyledForm>
<FormContainer>
Expand All @@ -51,6 +62,26 @@ export default ({
withPort={true}
disabled={isPromotedService}
/>
<VerticalSpacer size={40} />
{serviceType === Block.Type.BACKEND_API && (
<TwoColumns layout="EVEN" responsive>
<FormikSelect
name="protocol"
label="Protocol"
variant="outlined"
type="number"
handleChange={(evt) => {
formikProps.setFieldValue(
'protocol',
parseInt(evt.target.value, 10)
);
}}
handleBlur={formikProps.handleBlur}
options={ProtocolOptions}
disabled={isPromotedService}
/>
</TwoColumns>
)}
</FormContainer>
</StyledForm>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/organisms/sidePanel/EditService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ export default ({
isCreate={isCreate}
service={service}
release={release}
serviceType={serviceType}
isPromotedService={isPromotedService}
{...formikProps}
/>
Expand Down
20 changes: 10 additions & 10 deletions src/libraries/helpers/editService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@ import {
MESSAGE_INVALID_CRON_PATTERN,
MESSAGE_PORT_MUST_BE_INTEGER,
MESSAGE_STATIC_OUTPUT_PATH_MUST_BE_RELATIVE,
MESSAGE_SUBFOLDER_PATH_MUST_BE_RELATIVE,
MESSAGE_SUBFOLDER_PATH_MUST_BE_RELATIVE
} from 'libraries/constants';
import { REACT_APP_SLEEP_MODE_TTL_MINUTES } from 'libraries/envVars';
import { getIndexFromValue, getValueFromIndex, round } from 'libraries/helpers';
import { KintoConfig } from 'types';
import CatalogSchema from 'types/catalog';
import {
AutoScaling,
Block,
BuildConfig,
Release,
Repository,
Resources,
RunConfig,
} from 'types/proto/models_pb';
import { AutoScaling, Block, BuildConfig, Release, Repository, Resources, RunConfig } from 'types/proto/models_pb';
import { EditServicePageValues, EnvVar, ServiceType } from 'types/service';
import * as Yup from 'yup';

import { EnvVarSchema, ServiceNameSchema } from './yup';



const LanguageSchema = {
language: Yup.number().required(),
dockerfile: Yup.string().when('language', {
Expand Down Expand Up @@ -186,6 +180,7 @@ export const getInitialValuesByType = (
languageVersion: buildConfig.getLanguageversion() || '',
subfolderPath: buildConfig.getPathtocode() || '.',
staticOutputPath: buildConfig.getPathtostaticoutput() || 'public',
protocol: runConfig.getProtocol() || RunConfig.Protocol.HTTP,
envVars:
runConfig
.getEnvvarsMap()
Expand Down Expand Up @@ -340,6 +335,11 @@ export const generateConfigsFromValuesAndType = (
runConfig.setSleepmodettlseconds(60 * REACT_APP_SLEEP_MODE_TTL_MINUTES);
}

// only backend API support HTTP/GRPC protocols
if (serviceType === Block.Type.BACKEND_API) {
runConfig.setProtocol(values.protocol);
}

guardRunConfig(serviceType, runConfig);

if (values.language !== BuildConfig.Language.DOCKERFILE) {
Expand Down
2 changes: 2 additions & 0 deletions src/types/props/editService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Block, Release } from 'types/proto/models_pb';
import { ServiceType } from '../service';

// Separating into this file is to avoid dependency cycle
export interface EditServiceTabProps {
Expand All @@ -7,4 +8,5 @@ export interface EditServiceTabProps {
isPromotedService: boolean;
service: Block;
release: Release;
serviceType: ServiceType;
}
3 changes: 3 additions & 0 deletions src/types/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Block,
BuildConfig,
JobStatus as JobStatusModel,
RunConfig
} from 'types/proto/models_pb';
import { Moment } from 'moment';

Expand Down Expand Up @@ -40,6 +41,7 @@ export interface EditServicePageValues {
dockerfile: string;
port: string;
subfolderPath: string;
protocol: ProtocolType;

// only for static websites
staticOutputPath: string;
Expand Down Expand Up @@ -86,6 +88,7 @@ export interface ServiceMetrics {
export type ServiceStateType = BlockStatus.StateMap[keyof BlockStatus.StateMap];
export type ServiceType = Block.TypeMap[keyof Block.TypeMap];
export type LanguageType = BuildConfig.LanguageMap[keyof BuildConfig.LanguageMap];
export type ProtocolType = RunConfig.ProtocolMap[keyof RunConfig.ProtocolMap];

export type JobStateType = JobStatusModel.StateMap[keyof JobStatusModel.StateMap];

Expand Down

0 comments on commit b5a613a

Please sign in to comment.