From 5cb68f2c7191c730355b6692adf75ca33668da6f Mon Sep 17 00:00:00 2001 From: cgu Date: Mon, 4 Jan 2021 12:38:14 -0500 Subject: [PATCH 1/3] Allow query title to be multiline --- .../webapp/components/DataDoc/DataDoc.scss | 2 +- .../components/DataDoc/DataDocCellControl.tsx | 5 +++ .../DataDoc/DataDocContentContainer.tsx | 34 ++++++++----------- .../DataDocQueryCell/DataDocQueryCell.scss | 13 ++----- .../DataDocQueryCell/DataDocQueryCell.tsx | 22 ++++++++---- datahub/webapp/hooks/useResizeObserver.ts | 23 +++++++++++++ .../ResizableTextArea/ResizableTextArea.tsx | 22 +++++++----- 7 files changed, 75 insertions(+), 46 deletions(-) create mode 100644 datahub/webapp/hooks/useResizeObserver.ts diff --git a/datahub/webapp/components/DataDoc/DataDoc.scss b/datahub/webapp/components/DataDoc/DataDoc.scss index 00a5b63df..e1af0e8a7 100644 --- a/datahub/webapp/components/DataDoc/DataDoc.scss +++ b/datahub/webapp/components/DataDoc/DataDoc.scss @@ -149,7 +149,7 @@ } .block-crud-buttons { - opacity: 0; + opacity: 1; top: -17px; position: relative; text-align: center; diff --git a/datahub/webapp/components/DataDoc/DataDocCellControl.tsx b/datahub/webapp/components/DataDoc/DataDocCellControl.tsx index 718a8e834..8038d4617 100644 --- a/datahub/webapp/components/DataDoc/DataDocCellControl.tsx +++ b/datahub/webapp/components/DataDoc/DataDocCellControl.tsx @@ -215,6 +215,10 @@ export const DataDocCellControl: React.FunctionComponent = ({ /> ) ); + } else { + // In case center buttons are empty + // push an empty span to ensure the width + centerButtons.push(); } if (leftMenuItems.length) { @@ -250,6 +254,7 @@ export const DataDocCellControl: React.FunctionComponent = ({ ) : null} {centerButtons} +   {rightButtons.length ? (
{rightButtons} diff --git a/datahub/webapp/components/DataDoc/DataDocContentContainer.tsx b/datahub/webapp/components/DataDoc/DataDocContentContainer.tsx index 3359265bf..335fe224e 100644 --- a/datahub/webapp/components/DataDoc/DataDocContentContainer.tsx +++ b/datahub/webapp/components/DataDoc/DataDocContentContainer.tsx @@ -1,4 +1,5 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useCallback } from 'react'; +import { useResizeObserver } from 'hooks/useResizeObserver'; const isChrome = /chrome/.test(navigator.userAgent.toLowerCase()); @@ -12,27 +13,20 @@ export const DataDocContentContainer: React.FunctionComponent = isChrome const [containerWidth, setContainerWidth] = useState(1200); const selfRef = React.useRef(null); - useEffect(() => { - let observer; - - if (selfRef.current) { - setContainerWidth(selfRef.current.offsetWidth); - observer = new ResizeObserver((entries) => { - for (const entry of entries) { - if (entry.contentRect) { - setContainerWidth(entry.contentRect.width); - } + useResizeObserver( + selfRef.current, + useCallback((entries) => { + for (const entry of entries) { + if (entry.contentRect) { + setContainerWidth(entry.contentRect.width); } - }); - observer.observe(selfRef.current); - } - - return () => { - if (observer) { - observer.disconnect(); } - }; - }, [selfRef.current]); + }, []), + useCallback( + () => setContainerWidth(selfRef.current.offsetWidth), + [] + ) + ); return (
diff --git a/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.scss b/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.scss index bb7025c32..63c9e91e3 100644 --- a/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.scss +++ b/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.scss @@ -50,19 +50,12 @@ .query-title { flex: 1; - input.Title, - span { + .Title, + p { font-weight: bold; - } - input.Title { font-size: var(--large-text-size); color: var(--dark-text-color); - text-overflow: ellipsis; - } - span { - font-size: var(--med-text-size); - color: var(--light-text-color); - margin-right: 8px; + padding: 8px; } } diff --git a/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.tsx b/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.tsx index c1a7f7be3..7e10fac48 100644 --- a/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.tsx +++ b/datahub/webapp/components/DataDocQueryCell/DataDocQueryCell.tsx @@ -46,6 +46,7 @@ import { Modal } from 'ui/Modal/Modal'; import { Title } from 'ui/Title/Title'; import './DataDocQueryCell.scss'; +import { ResizableTextArea } from 'ui/ResizableTextArea/ResizableTextArea'; const ON_CHANGE_DEBOUNCE_MS = 250; @@ -539,17 +540,24 @@ class DataDocQueryCellComponent extends React.Component { const { meta, selectedRange } = this.state; const queryTitleDOM = isEditable ? ( - ) : ( + // {this.dataCellTitle} ); @@ -619,7 +627,7 @@ class DataDocQueryCellComponent extends React.Component { ); const openSnippetDOM = - query.trim().length === 0 ? ( + query.trim().length === 0 && isEditable ? (