Sha256: 01ec8b2472494b40fcf5e962f3d9bf6f5e7a52965d9e25793eced67db9d2077e

Contents?: true

Size: 1.67 KB

Versions: 26

Compression:

Stored size: 1.67 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';

import { formatValue } from './AnsibleVariableOverridesTableHelper';

import {
  TextAreaField,
  TextInputField,
  SelectField,
} from './EditableValueHelper';

const EditableValue = props => {
  if (!props.editing) {
    return formatValue(props.variable);
  }

  const type = props.variable.parameterType;

  if (['json', 'yaml', 'array', 'hash'].includes(type)) {
    return (
      <TextAreaField
        aria-label="Edit override field"
        onChange={props.onChange}
        value={JSON.stringify(props.value)}
        validation={props.validation}
        isDisabled={props.working}
      />
    );
  }

  if (type === 'boolean') {
    return (
      <SelectField
        aria-label="Edit override field"
        selectItems={[
          { id: 'trueSelectOpt', value: true, name: __('true') },
          { id: 'falseSelectOpt', value: false, name: __('false') },
        ]}
        onChange={props.onChange}
        validation={props.validation}
        isDisabled={props.working}
        value={props.value}
      />
    );
  }

  return (
    <TextInputField
      onChange={props.onChange}
      value={props.value}
      validation={props.validation}
      isDisabled={props.working}
      aria-label="Edit override field"
    />
  );
};

EditableValue.propTypes = {
  editing: PropTypes.bool.isRequired,
  variable: PropTypes.object.isRequired,
  onChange: PropTypes.func.isRequired,
  value: PropTypes.any,
  validation: PropTypes.object.isRequired,
  working: PropTypes.bool.isRequired,
};

EditableValue.defaultProps = {
  value: '',
};

export default EditableValue;

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foreman_ansible-13.0.2 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-13.0.1 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-13.0.0 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.7 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-10.4.4 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.6 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.5 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-10.4.3 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.4 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-10.4.2 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.3 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.2 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.1 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-12.0.0 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-11.2.1 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-11.2.0 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-11.1.2 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-11.1.1 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-10.4.1 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js
foreman_ansible-11.1.0 webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/EditableValue.js