Skip to content

Commit

Permalink
Merge pull request #109 from dbcls/fix/dataset-title-length
Browse files Browse the repository at this point in the history
タイトル編集時にEnterで保存
  • Loading branch information
sasaujp authored Jan 28, 2021
2 parents 8945688 + a23bbd6 commit 743391c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
16 changes: 1 addition & 15 deletions node/src/ts/components/DataSetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,17 @@ export default class DataSetList extends React.Component<Props, {}> {
}

private renderDataSetList() {
const { didEdit, isLoading } = this.props
const { isLoading } = this.props
if (isLoading) {
return <Loading />
}

let updateButton = null
if (didEdit) {
updateButton = (
<a
onClick={this.onClickUpdate}
href="/"
className="layout-datalist__titlesavebtn"
>
<FormattedMessage id="dataSetList.updateTitle" />
</a>
)
}
return (
<section className="layout-datalist">
<table>
<tbody>
<tr>
<th>
<FormattedMessage id="dataSetList.tableTitle" />
{updateButton}
</th>
<th>
<FormattedMessage id="dataSetList.tableUrl" />
Expand Down
14 changes: 13 additions & 1 deletion node/src/ts/components/EditableDataSetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { Link } from 'react-router-dom'
import { FormattedMessage } from 'react-intl'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPen } from '@fortawesome/free-solid-svg-icons'

import { Url } from '../constants'
import {
DataSet,
EditedDataSet,
EditDataSetAction,
UpdateAction,
} from '../actions/data-set-list'
import { OpenModalAction as OpenDeleteModalAction } from '../actions/data-set-delete'

interface Props {
dataSetList: DataSet[]
actions: {
editDataSet: (editedDataSet: EditedDataSet) => EditDataSetAction
update: () => UpdateAction
}
deleteModalActions: {
openModal: (dataSet: DataSet) => OpenDeleteModalAction
Expand All @@ -31,6 +32,7 @@ export default class EditableDataSetList extends React.Component<Props, {}> {

this.onClickDelete = this.onClickDelete.bind(this)
this.onChangeTitle = this.onChangeTitle.bind(this)
this.onKeyPress = this.onKeyPress.bind(this)
}

private onClickDelete(
Expand All @@ -52,6 +54,15 @@ export default class EditableDataSetList extends React.Component<Props, {}> {
}
}

private onKeyPress(e: React.KeyboardEvent<HTMLDivElement>) {
if (e.key === 'Enter') {
e.preventDefault()
const { actions } = this.props
actions.update()
e.currentTarget.blur()
}
}

render() {
const { dataSetList } = this.props
const urlPrefix = `${window.location.protocol}//${window.location.host}${Url.VISUALIZER_PREFIX}`
Expand All @@ -63,6 +74,7 @@ export default class EditableDataSetList extends React.Component<Props, {}> {
<ContentEditable
innerRef={this.titleEditableRefs[index]}
onChange={() => this.onChangeTitle(d.id, index)}
onKeyPress={this.onKeyPress}
html={`<span>${d.title}</span>`}
tagName="td"
/>
Expand Down

0 comments on commit 743391c

Please sign in to comment.