From 2e4a74b2f71e407a3a486d0ea7e19985202c94bf Mon Sep 17 00:00:00 2001 From: Evangeline Ireland Date: Wed, 10 Jul 2024 11:05:53 -0700 Subject: [PATCH] [#187849761]Fixes styling of component title bar when dragging is initiated on top of the component title. (#1332) * Fixes styling of component title bar when dragging is initiated on top of the component title. Changed the component from and EditableInput to just Input. * Fixes broken Cypress test for finding component title. Updates deleting old command from backspaces to clear. --- .../support/elements/component-elements.ts | 5 ++- v3/cypress/support/elements/web-view-tile.ts | 3 +- v3/src/components/component-title-bar.scss | 3 +- v3/src/components/component-title-bar.tsx | 44 ++++++++++++------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/v3/cypress/support/elements/component-elements.ts b/v3/cypress/support/elements/component-elements.ts index 0e8cd4f9f5..236afd4ab8 100644 --- a/v3/cypress/support/elements/component-elements.ts +++ b/v3/cypress/support/elements/component-elements.ts @@ -46,10 +46,11 @@ export const ComponentElements = { this.getComponentTitleBar(component, index).should(check, "focusTile") }, getComponentTitle(component, index = 0) { - return this.getComponentTile(component, index).find("[data-testid=editable-component-title]") + return this.getComponentTile(component, index).find("[data-testid=title-text]") }, changeComponentTitle(component: string, title: string, index = 0) { - this.getComponentTitle(component, index).click().find("[data-testid=title-text-input]").type(`${title}{enter}`) + this.getComponentTitle(component, index).click() + cy.get("[data-testid=title-text-input]").type(`${title}{enter}`) }, getInspectorPanel() { return cy.get("[data-testid=inspector-panel]") diff --git a/v3/cypress/support/elements/web-view-tile.ts b/v3/cypress/support/elements/web-view-tile.ts index 956b9e79e1..0b436664f5 100644 --- a/v3/cypress/support/elements/web-view-tile.ts +++ b/v3/cypress/support/elements/web-view-tile.ts @@ -43,8 +43,7 @@ export const WebViewTileElements = { sendAPITesterCommand(command: string, oldCommand?: string) { // Delete the old command if it's provided if (oldCommand) { - const deleteCommand = oldCommand.split("").reduce(cmd => `${cmd}{backspace}`, "") - WebViewTileElements.getIFrame().find(`.di-message-area`).type(deleteCommand) + WebViewTileElements.getIFrame().find(`.di-message-area`).clear() } WebViewTileElements.getIFrame().find(`.di-message-area`).type(command) WebViewTileElements.getIFrame().find(`.di-send-button`).click() diff --git a/v3/src/components/component-title-bar.scss b/v3/src/components/component-title-bar.scss index 04d7bbf3b6..32265f4145 100644 --- a/v3/src/components/component-title-bar.scss +++ b/v3/src/components/component-title-bar.scss @@ -106,7 +106,7 @@ .title-text-input { display: flex !important; justify-content: center !important; - height: calc($title-bar-height - 2px) !important; + height: calc($title-bar-height) !important; width: max-content; font-size: 14px !important; text-align: center !important; @@ -115,4 +115,5 @@ cursor: text; outline: none !important; border-radius: $border-radius-top-corners !important; + border: 2px solid #66afe9; } diff --git a/v3/src/components/component-title-bar.tsx b/v3/src/components/component-title-bar.tsx index c32f6086a5..b37ba435b4 100644 --- a/v3/src/components/component-title-bar.tsx +++ b/v3/src/components/component-title-bar.tsx @@ -1,5 +1,4 @@ -import { Button, CloseButton, Editable, EditableInput, EditablePreview, Flex } from "@chakra-ui/react" -import { useDndContext } from "@dnd-kit/core" +import { Button, CloseButton, Flex, Input } from "@chakra-ui/react" import { clsx } from "clsx" import { observer } from "mobx-react-lite" import React, { useState } from "react" @@ -17,8 +16,6 @@ export const ComponentTitleBar = observer(function ComponentTitleBar( const title = getTitle?.() || tile?.title || t("DG.AppController.createDataSet.name") const [isEditing, setIsEditing] = useState(false) const [editingTitle, setEditingTitle] = useState(title) - const { active } = useDndContext() - const dragging = !!active const tileId = tile?.id || "" const tileType = tile?.content.type const draggableOptions: IUseDraggableTile = { prefix: tileType || "tile", tileId, disabled: isEditing } @@ -36,10 +33,6 @@ export const ComponentTitleBar = observer(function ComponentTitleBar( } } - const handleChange = (nextValue: string) => { - setEditingTitle(nextValue) - } - const handleSubmit = (nextValue: string) => { if (onHandleTitleChange) { onHandleTitleChange(nextValue) @@ -56,17 +49,38 @@ export const ComponentTitleBar = observer(function ComponentTitleBar( setIsEditing(false) } + const handleTitleClick = () => { + setIsEditing(true) + setEditingTitle(title) + } + + const handleInputKeyDown = (e: React.KeyboardEvent) => { + const { key } = e + e.stopPropagation() + switch (key) { + case "Escape": + handleCancel(title) + break + case "Enter": + case "Tab": + handleSubmit(editingTitle) + break + } + } + return ( {children} - setIsEditing(true)} onSubmit={handleSubmit} - onChange={handleChange} onCancel={handleCancel} data-testid="editable-component-title" - > - - - +
+ {isEditing + ? setEditingTitle(e.target.value)} onBlur={() => handleSubmit(editingTitle)} + onFocus={(e) => e.target.select()} onKeyDown={handleInputKeyDown} + /> + :
{title}
+ } +