Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions modules/st2-auto-form/auto-form.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import IntegerField from './fields/integer';
import BooleanField from './fields/boolean';
import StringField from './fields/string';
import ObjectField from './fields/object';
import PasswordField from './fields/password';
import EnumField from './fields/enum';

import './style.css';
Expand Down Expand Up @@ -57,10 +56,6 @@ export default class AutoForm extends React.Component {
case 'boolean':
return BooleanField;
case 'string':
if (field.secret) {
return PasswordField;
}

return StringField;
case 'object':
return ObjectField;
Expand Down
46 changes: 37 additions & 9 deletions modules/st2-auto-form/fields/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import _ from 'lodash';
import React from 'react';
import { PropTypes } from 'prop-types';

import { TextFieldWrapper } from '../wrappers';
import { TextFieldWrapper, Button } from '../wrappers';
import TextareaAutosize from 'react-textarea-autosize';

export class Textarea extends TextareaAutosize {
Expand Down Expand Up @@ -75,6 +75,10 @@ export class BaseTextField extends React.Component {
throw new Error('not implemented');
}

toggleVisibility() {
this.setState({ visible: !this.state.visible });
}

validate(v, spec={}) {
if ((v === '' || v === undefined) && spec.required) {
return 'parameter is required';
Expand Down Expand Up @@ -111,20 +115,27 @@ export class BaseTextField extends React.Component {

render() {
const { icon } = this.constructor;
const { invalid } = this.state;
const { invalid, visible } = this.state;
const { spec={} } = this.props;
const wrapperProps = Object.assign({}, this.props);

if (invalid) {
wrapperProps.invalid = invalid;
}

const buttonProps = {
icon: visible ? 'view2' : 'view',
title: visible ? 'hide value' : 'see value',
onClick: () => this.toggleVisibility(),
};

const inputProps = {
className: 'st2-auto-form__field',
type: spec.secret ? 'password' : 'text',
className: spec.secret && !visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field',
type: 'text',
placeholder:this.toStateValue(spec.default),
disabled: this.props.disabled,
value: this.state.value,
spellCheck: spec.secret && !visible ? false : true,
onChange: (e) => this.handleChange(e, e.target.value),
'data-test': this.props['data-test'],
};
Expand All @@ -135,7 +146,10 @@ export class BaseTextField extends React.Component {

return (
<TextFieldWrapper icon={icon} {...wrapperProps}>
<input {...inputProps} />
<div >
{ !this.props.disabled && spec.secret && <Button {...buttonProps} /> }
<input {...inputProps} />
</div>
</TextFieldWrapper>
);
}
Expand All @@ -144,20 +158,31 @@ export class BaseTextField extends React.Component {
export class BaseTextareaField extends BaseTextField {
render() {
const { icon } = this.constructor;
const { invalid } = this.state;
const { spec={} } = this.props;
const { invalid, visible } = this.state;
const { spec = {} } = this.props;

const wrapperProps = Object.assign({}, this.props);

if (invalid) {
wrapperProps.invalid = invalid;
}

const buttonProps = {
icon: visible ? 'view2' : 'view',
title: visible ? 'hide value' : 'see value',
onClick: () => this.toggleVisibility(),
};

const wrapperBlockProps = {
className: 'st2-auto-form__wrapper-block',
};

const inputProps = {
className: 'st2-auto-form__field',
className: spec.secret && !visible ? 'st2-auto-form__field--secret' : 'st2-auto-form__field',
placeholder: this.toStateValue(spec.default),
disabled: this.props.disabled,
value: this.state.value,
spellCheck: spec.secret && !visible ? false : true,
onChange: (e) => this.handleChange(e, e.target.value),
minRows: 1,
maxRows: 10,
Expand All @@ -170,7 +195,10 @@ export class BaseTextareaField extends BaseTextField {

return (
<TextFieldWrapper icon={icon} {...wrapperProps}>
<Textarea {...inputProps} />
<div {...wrapperBlockProps}>
{ !this.props.disabled && spec.secret && <Button {...buttonProps} /> }
<Textarea {...inputProps} />
</div>
</TextFieldWrapper>
);
}
Expand Down
2 changes: 0 additions & 2 deletions modules/st2-auto-form/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import EnumField from './enum';
import IntegerField from './integer';
import NumberField from './number';
import ObjectField from './object';
import PasswordField from './password';
import StringField from './string';
import SelectField from './select';
import ColorStringField from './color-string';
Expand All @@ -31,7 +30,6 @@ export {
IntegerField,
NumberField,
ObjectField,
PasswordField,
StringField,
SelectField,
ColorStringField,
Expand Down
2 changes: 1 addition & 1 deletion modules/st2-auto-form/fields/integer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ export default class IntegerField extends BaseTextField {
}
}

return v && !validator.isInt(v) && `'${v}' is not an integer`;
return v && !validator.isInt(v) && `'${spec.secret ? "*".repeat(v.length) : v}' is not an integer`;
}
}
4 changes: 2 additions & 2 deletions modules/st2-auto-form/fields/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class NumberField extends BaseTextField {
if (invalid !== void 0) {
return invalid;
}

return v && !validator.isFloat(v) && `'${v}' is not a number`;
return v && !validator.isFloat(v) && `'${spec.secret ? "*".repeat(v.length) : v}' is not a number`;
}
}
27 changes: 0 additions & 27 deletions modules/st2-auto-form/fields/password.js

This file was deleted.

47 changes: 44 additions & 3 deletions modules/st2-auto-form/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
margin-bottom: 12px;
}

&__wrapper-block {
display: flex;
align-items: center;
}

&__title {
font-size: 15px;
line-height: 18px;
Expand Down Expand Up @@ -70,6 +75,21 @@
&:hover {
color: var(--aqua-base);
}

&:before {
font-family: "brocadeicons";
font-size: 18px;
font-weight: normal;
font-style: normal;
line-height: 36px;

display: flex;

vertical-align: middle;
pointer-events: none;

color: var(--grey-base);
}
}

&__field {
Expand All @@ -88,6 +108,22 @@
background-color: white;
box-shadow: 0 1px 0 var(--grey-lighten-2);

&--secret {
font-weight: normal;
font-family: Roboto, sans-serif;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
padding: 0 12px;

color: black;
border: none;
outline: 0;
box-shadow: 0 1px 0 var(--grey-lighten-2);
-webkit-text-security: disc;
}

&&[disabled] {
cursor: default;

Expand Down Expand Up @@ -144,7 +180,12 @@
color: black;
}

&__text-field &__field {
&__wrapper-block &__button {
right: 16px;
}

&__text-field &__field,
&__text-field &__field--secret {
font-size: 13px;
line-height: 18px;

Expand All @@ -161,7 +202,7 @@
&::-webkit-scrollbar {
width: 13px;
height: 13px;

background-color: transparent;
}

Expand All @@ -171,6 +212,7 @@
background-color: rgba(117, 117, 117, .3);
background-clip: padding-box;


&:hover {
background-color: rgba(117, 117, 117, .7);
}
Expand Down Expand Up @@ -249,7 +291,6 @@
padding: 0 10px 0 0;

content: "\e91c";
vertical-align: middle;
pointer-events: none;

color: black;
Expand Down