import React, { useCallback } from 'react'; import { Banner, BannerVariant, Description, RadioBox, RadioBoxGroup, Label, spacing, css, } from '@mongodb-js/compass-components'; import type ConnectionStringUrl from 'mongodb-connection-string-url'; import type { UpdateConnectionFormField } from '../../../hooks/use-connect-form'; import type { ConnectionFormError } from '../../../utils/validation'; import { errorMessageByFieldName, fieldNameHasError, } from '../../../utils/validation'; enum MONGODB_SCHEME { MONGODB = 'MONGODB', MONGODB_SRV = 'MONGODB_SRV', } const descriptionStyles = css({ marginTop: spacing[2], }); const regularSchemeDescription = 'Standard Connection String Format. The standard format of the MongoDB connection URI is used to connect to a MongoDB deployment: standalone, replica set, or a sharded cluster.'; const srvSchemeDescription = 'DNS Seed List Connection Format. The +srv indicates to the client that the hostname that follows corresponds to a DNS SRV record.'; function SchemeInput({ connectionStringUrl, errors, updateConnectionFormField, }: { connectionStringUrl: ConnectionStringUrl; errors: ConnectionFormError[]; updateConnectionFormField: UpdateConnectionFormField; }): React.ReactElement { const { isSRV } = connectionStringUrl; const onChangeConnectionScheme = useCallback( (event: React.ChangeEvent) => { updateConnectionFormField({ type: 'update-connection-scheme', isSrv: event.target.value === MONGODB_SCHEME.MONGODB_SRV, }); }, [updateConnectionFormField] ); return ( <> mongodb mongodb+srv {isSRV ? srvSchemeDescription : regularSchemeDescription} {fieldNameHasError(errors, 'isSrv') && ( {errorMessageByFieldName(errors, 'isSrv')} )} ); } export default SchemeInput;