<commit_before>import * as React from 'react';

import { LoadingSpinner } from '@waldur/core/LoadingSpinner';
import { ENV } from '@waldur/core/services';
import { useQuery } from '@waldur/core/useQuery';
import { getLatinNameValidators, required } from '@waldur/core/validators';
import { NumberField, TextField, StringField, FormContainer, SelectField } from '@waldur/form-react';
import { translate } from '@waldur/i18n';
import { parseIntField } from '@waldur/marketplace/common/utils';
import { ProjectField } from '@waldur/marketplace/details/ProjectField';
import { OfferingConfigurationFormProps } from '@waldur/marketplace/types';

import { loadVolumeAvailabilityZones, loadVolumeTypes } from '../api';
import { formatVolumeTypeChoices, getDefaultVolumeTypeUrl } from '../openstack-instance/utils';

const validateSize = (value: number) => value < 1024 || value > 1024 * 4096 ?
  translate('Size should be between 1 and 4096 GB.') : undefined;

const loadData = async settings => {
  const zones = await loadVolumeAvailabilityZones(settings);
  const volumeTypes = await loadVolumeTypes(settings);
  return {
    zones,
    volumeTypes: formatVolumeTypeChoices(volumeTypes),
    defaultVolumeType: getDefaultVolumeTypeUrl(volumeTypes),
  };
};

export const OpenstackVolumeCreateForm: React.FC<OfferingConfigurationFormProps> = props => {
  const {call, state} = useQuery(loadData, props.offering.scope_uuid);

  React.useEffect(call, []);

  React.useEffect(() => {
    if (state.loaded) {
      return;
    }
    props.initialize({
        attributes: {
          size: 1024,
          type: state.data.defaultVolumeType,
          ...props.initialAttributes,
        },
      });
  }, [state.loaded]);

  if (state.loading) {
    return <LoadingSpinner/>;
  }
<commit_msg>Preselect default volume type in OpenStack volume provision form [WAL-2728]<commit_after>import * as React from 'react';

import { LoadingSpinner } from '@waldur/core/LoadingSpinner';
import { ENV } from '@waldur/core/services';
import { useQuery } from '@waldur/core/useQuery';
import { getLatinNameValidators, required } from '@waldur/core/validators';
import { NumberField, TextField, StringField, FormContainer, SelectField } from '@waldur/form-react';
import { translate } from '@waldur/i18n';
import { parseIntField } from '@waldur/marketplace/common/utils';
import { ProjectField } from '@waldur/marketplace/details/ProjectField';
import { OfferingConfigurationFormProps } from '@waldur/marketplace/types';

import { loadVolumeAvailabilityZones, loadVolumeTypes } from '../api';
import { formatVolumeTypeChoices, getDefaultVolumeTypeUrl } from '../openstack-instance/utils';

const validateSize = (value: number) => value < 1024 || value > 1024 * 4096 ?
  translate('Size should be between 1 and 4096 GB.') : undefined;

const loadData = async settings => {
  const zones = await loadVolumeAvailabilityZones(settings);
  const volumeTypes = await loadVolumeTypes(settings);
  return {
    zones,
    volumeTypes: formatVolumeTypeChoices(volumeTypes),
    defaultVolumeType: getDefaultVolumeTypeUrl(volumeTypes),
  };
};

export const OpenstackVolumeCreateForm: React.FC<OfferingConfigurationFormProps> = props => {
  const {call, state} = useQuery(loadData, props.offering.scope_uuid);

  React.useEffect(call, []);

  React.useEffect(() => {
    if (!state.loaded) {
      return;
    }
    props.initialize({
      attributes: {
        size: 1024,
        type: state.data.defaultVolumeType,
        ...props.initialAttributes,
      },
    });
  }, [state.loaded]);

  if (state.loading) {
    return <LoadingSpinner/>;
  }

{'fraction_non_alphanumeric': 0.12544901906604033, 'fraction_numerical': 0.013815971262779773, 'mean_word_length': 4.443609022556391, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '4668321', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1030, 'n_words': 247}