<commit_before>import * as React from 'react'
import { getEnterpriseAPIURL, fetchMetadata } from '../../lib/api'
import { Loading } from './loading'
import { validateURL, InvalidURLErrorName, InvalidProtocolErrorName } from './enterprise-validate-url'
import { Form } from './form'
import { TextBox } from './text-box'
import { Button } from './button'
import { Errors } from './errors'

/** The authentication methods server allows. */
export enum AuthenticationMethods {
  /** Basic auth in order to create authorization tokens. */
  BasicAuth,

  /** OAuth web flow. */
  OAuth,
}

interface IEnterpriseServerEntryProps {
  /** Called after the user has entered their Enterprise server address. */
  readonly onContinue: (endpoint: string, authMethods: Set<AuthenticationMethods>) => void
}

interface IEnterpriseServerEntryState {
  readonly serverAddress: string

  readonly loading: boolean

  readonly error: Error | null
}

/** An entry form for an Enterprise server address. */
export class EnterpriseServerEntry extends React.Component<IEnterpriseServerEntryProps, IEnterpriseServerEntryState> {
  public constructor(props: IEnterpriseServerEntryProps) {
    super(props)

    this.state = { serverAddress: '', loading: false, error: null }
  }

  public render() {
    const disableEntry = this.state.loading
    const disableSubmission = !this.state.serverAddress.length || this.state.loading
    return (
      <Form onSubmit={this.onSubmit}>
        <TextBox
          label='Enterprise server address'
          autoFocus={true}
          disabled={disableEntry}
          onChange={this.onServerAddressChanged}/>

        <Button type='submit' disabled={disableSubmission}>Continue</Button>

        {this.state.loading ? <Loading/> : null}

        {this.state.error ? <Errors>{this.state.error.message}</Errors> : null}
      </Form>
    )
  }

  private onServerAddressChanged = (event: React.FormEvent<HTMLInputElement>) => {
    this.setState({
      serverAddress: event.currentTarget.value,
      loading: false,
      error: null,
    })
  }

  private async fetchAllowedAuthenticationMethods(endpoint: string): Promise<Set<AuthenticationMethods>> {
    const response = await fetchMetadata(endpoint)

    if (response) {
      const authMethods = new Set([
        AuthenticationMethods.BasicAuth,<commit_msg>Render additional buttons in Enterprise server entry<commit_after>import * as React from 'react'
import { getEnterpriseAPIURL, fetchMetadata } from '../../lib/api'
import { Loading } from './loading'
import { validateURL, InvalidURLErrorName, InvalidProtocolErrorName } from './enterprise-validate-url'
import { Form } from './form'
import { TextBox } from './text-box'
import { Button } from './button'
import { Errors } from './errors'

/** The authentication methods server allows. */
export enum AuthenticationMethods {
  /** Basic auth in order to create authorization tokens. */
  BasicAuth,

  /** OAuth web flow. */
  OAuth,
}

interface IEnterpriseServerEntryProps {
  /** Called after the user has entered their Enterprise server address. */
  readonly onContinue: (endpoint: string, authMethods: Set<AuthenticationMethods>) => void

  /** An array of additional buttons to render after the "Continue" button. */
  readonly additionalButtons?: ReadonlyArray<JSX.Element>
}

interface IEnterpriseServerEntryState {
  readonly serverAddress: string

  readonly loading: boolean

  readonly error: Error | null
}

/** An entry form for an Enterprise server address. */
export class EnterpriseServerEntry extends React.Component<IEnterpriseServerEntryProps, IEnterpriseServerEntryState> {
  public constructor(props: IEnterpriseServerEntryProps) {
    super(props)

    this.state = { serverAddress: '', loading: false, error: null }
  }

  public render() {
    const disableEntry = this.state.loading
    const disableSubmission = !this.state.serverAddress.length || this.state.loading
    return (
      <Form onSubmit={this.onSubmit}>
        <TextBox
          label='Enterprise server address'
          autoFocus={true}
          disabled={disableEntry}
          onChange={this.onServerAddressChanged}/>

        <Button type='submit' disabled={disableSubmission}>Continue</Button>

        {this.props.additionalButtons}

        {this.state.loading ? <Loading/> : null}

        {this.state.error ? <Errors>{this.state.error.message}</Errors> : null}
      </Form>
    )
  }

  private onServerAddressChanged = (event: React.FormEvent<HTMLInputElement>) => {
    this.setState({
      serverAddress: event.currentTarget.value,
      loading: false,
      error: null,
    })
  }

  private async fetchAllowedAuthenticationMethods(endpoint: string): Promise<Set<AuthenticationMethods>> {
    const response = await fetchMetadata(endpoint)

    if (response) {
      const authMethods = new Set([
        AuthenticationMethods.BasicAuth,
{'fraction_non_alphanumeric': 0.10870010235414534, 'fraction_numerical': 0.0, 'mean_word_length': 3.725338491295938, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678461', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1259, 'n_words': 356}