Skip to content

Commit

Permalink
OpusCapita#126 OpusCapita#127 Show initial file name within "setName…
Browse files Browse the repository at this point in the history
…Dialog" (OpusCapita#130)
  • Loading branch information
kvolkovich-sc authored Dec 26, 2017
1 parent 4d764b2 commit 924079e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ import './SetNameDialog.less';
import Dialog from '../Dialog';

const propTypes = {
headerText: PropTypes.string,
cancelButtonText: PropTypes.string,
submitButtonText: PropTypes.string,
onValidate: PropTypes.func,
onHide: PropTypes.func,
headerText: PropTypes.string,
initialValue: PropTypes.string,
onChange: PropTypes.func,
onSubmit: PropTypes.func
onHide: PropTypes.func,
onSubmit: PropTypes.func,
onValidate: PropTypes.func,
submitButtonText: PropTypes.string
};
const defaultProps = {
headerText: 'Set name',
cancelButtonText: 'Cancel',
submitButtonText: 'Create',
autofocus: false,
onValidate: () => {},
onHide: () => {},
headerText: 'Set name',
initialValue: '',
onChange: () => {},
onSubmit: () => {}
onHide: () => {},
onSubmit: () => {},
onValidate: () => {},
submitButtonText: 'Create'
};

export default
class SetNameDialog extends Component {
constructor(props) {
super(props);
this.state = {
value: '',
value: props.initialValue,
validationError: null,
valid: false
};
Expand All @@ -42,14 +43,14 @@ class SetNameDialog extends Component {

handleKeyDown = async (e) => {
if (e.which === 13) { // Enter key
if (!this.props.validationError && this.state.value) {
if (!this.state.validationError && this.state.value) {
this.handleSubmit(this.state.value);
}
}
}

handleSubmitButtonClick = async (e) => {
if (!this.props.validationError && this.state.value) {
if (!this.state.validationError && this.state.value) {
this.handleSubmit(this.state.value);
}
}
Expand All @@ -62,6 +63,12 @@ class SetNameDialog extends Component {
}
}

moveCaretAtEnd = (e) => {
let tmpValue = e.target.value;
e.target.value = '';
e.target.value = tmpValue;
}

render() {
let { onHide, headerText, submitButtonText, cancelButtonText } = this.props;
let { value, validationError, valid } = this.state;
Expand Down Expand Up @@ -95,6 +102,7 @@ class SetNameDialog extends Component {
`}
value={value}
onChange={this.handleChange}
onFocus={this.moveCaretAtEnd}
/>

<div className="oc-fm--dialog__horizontal-group oc-fm--dialog__horizontal-group--to-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function handler(apiOptions, {
let rawDialogElement = {
elementType: 'SetNameDialog',
elementProps: {
initialValue: getSelectedResources()[0].title,
onHide: hideDialog,
onSubmit: async (name) => {
let selectedResources = getSelectedResources();
Expand Down
1 change: 1 addition & 0 deletions packages/connector-node-v1/src/capabilities/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function handler(apiOptions, {
let rawDialogElement = {
elementType: 'SetNameDialog',
elementProps: {
initialValue: getSelectedResources()[0].name,
onHide: hideDialog,
onSubmit: async (name) => {
let selectedResources = getSelectedResources();
Expand Down

0 comments on commit 924079e

Please sign in to comment.