From 15f85069421143b28aeb0970ab2124be803f96c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 26 Oct 2020 18:42:17 +0100 Subject: [PATCH] Table row editable migrated to the new editable widget --- webapp/src/components/tableRow.tsx | 38 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/webapp/src/components/tableRow.tsx b/webapp/src/components/tableRow.tsx index c55e58773..d985750c3 100644 --- a/webapp/src/components/tableRow.tsx +++ b/webapp/src/components/tableRow.tsx @@ -6,8 +6,9 @@ import {BoardTree} from '../viewModel/boardTree' import {Card} from '../blocks/card' import mutator from '../mutator' +import Editable from '../widgets/editable' + import PropertyValueElement from './propertyValueElement' -import {Editable} from './editable' import {CardDialog} from './cardDialog' import RootPortal from './rootPortal' @@ -20,12 +21,17 @@ type Props = { type State = { showCard: boolean + title: string } class TableRow extends React.Component { private titleRef = React.createRef() - state = { - showCard: false, + constructor(props: Props) { + super(props) + this.state = { + showCard: false, + title: props.card.title, + } } shouldComponentUpdate(): boolean { @@ -44,7 +50,7 @@ class TableRow extends React.Component { const openButonRef = React.createRef() - const element = ( + return (
{
{card.icon}
{ - mutator.changeTitle(card, text) - }} - onKeyDown={(e) => { + onChange={(title: string) => this.setState({title})} + onBlur={() => mutator.changeTitle(card, this.state.title)} + onFocus={() => this.titleRef.current.focus()} + onKeyDown={(e: React.KeyboardEvent): void => { + if (e.keyCode === 27 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { // ESC + e.stopPropagation() + this.setState({title: card.title}) + setTimeout(() => this.titleRef.current.blur(), 0) + } else if (e.keyCode === 13 && !(e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) { // Return + e.stopPropagation() + mutator.changeTitle(card, this.state.title) + this.titleRef.current.blur() + } onKeyDown(e) }} /> @@ -113,9 +128,8 @@ class TableRow extends React.Component { />
) })} - ) - - return element + + ) } focusOnTitle(): void {