Skip to content

Commit 45b4a55

Browse files
authored
[TILES-V2-12] : small improvements (#1118)
# Small tiles improvments - Add Table icon in breadcrumb to differentiate v2 from v1 tiles ![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/ycT2Xb5nBEjN2kf2gy95/130bce7b-5cb8-4fbe-b33c-5165559a2cc7.png) - Improve cell editing functionality: - Allow adding line breaks with Alt+Enter - Change Shift+Enter to navigate upward - Prevent cell editing when data is being fetched - Fix cell selection behaviour to allow selecting substrings in cel
1 parent 214dbf0 commit 45b4a55

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

packages/frontend/src/pages/Tile/components/TableBanner/BreadCrumb.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useCallback } from 'react'
2+
import { BiTable } from 'react-icons/bi'
23
import { FaChevronRight } from 'react-icons/fa'
34
import { Link } from 'react-router-dom'
45
import {
@@ -10,12 +11,17 @@ import {
1011

1112
import EditableInput from '@/components/EditableInput'
1213
import * as URLS from '@/config/urls'
14+
import { DatabaseType } from '@/graphql/__generated__/graphql'
1315

1416
import { useTableContext } from '../../contexts/TableContext'
1517
import { useUpdateTable } from '../../hooks/useUpdateTable'
1618

1719
function BreadCrumb() {
18-
const { tableName: initialTableName, hasEditPermission } = useTableContext()
20+
const {
21+
tableName: initialTableName,
22+
hasEditPermission,
23+
databaseType,
24+
} = useTableContext()
1925
const { updateTableName } = useUpdateTable()
2026

2127
const onSave = useCallback(
@@ -31,8 +37,14 @@ function BreadCrumb() {
3137
separator={<Icon as={FaChevronRight} color="secondary.300" h={3} />}
3238
>
3339
<BreadcrumbItem>
34-
<BreadcrumbLink as={Link} to={URLS.TILES}>
35-
Tiles
40+
<BreadcrumbLink
41+
as={Link}
42+
to={URLS.TILES}
43+
display="flex"
44+
alignItems="center"
45+
gap={2}
46+
>
47+
{databaseType === DatabaseType.Pg && <Icon as={BiTable} />} Tiles
3648
</BreadcrumbLink>
3749
</BreadcrumbItem>
3850
<EditableInput

packages/frontend/src/pages/Tile/components/TableRow/TableCell.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useContextMenuContext } from '../../contexts/ContextMenuContext'
2323
import { useRowContext } from '../../contexts/RowContext'
2424
import { useTableContext } from '../../contexts/TableContext'
2525
import { moveCell } from '../../helpers/cell-navigation'
26+
import { addLineBreak } from '../../helpers/line-break'
2627
import { shallowCompare } from '../../helpers/shallow-compare'
2728
import { CellType, GenericRowData } from '../../types'
2829

@@ -35,7 +36,7 @@ function TableCell({
3536
table,
3637
cell,
3738
}: CellContext<GenericRowData, string>) {
38-
const { mode } = useTableContext()
39+
const { mode, isFetching } = useTableContext()
3940
const { onRightClick } = useContextMenuContext()
4041
const { sortedIndex: rowIndex, className, isEditingRow } = useRowContext()
4142
const textAreaRef = useRef<HTMLTextAreaElement>(null)
@@ -88,11 +89,13 @@ function TableCell({
8889
*/
8990
switch (e.key) {
9091
case 'Enter': {
91-
if (e.shiftKey) {
92-
return
93-
}
9492
e.preventDefault()
9593
if (!isViewMode) {
94+
// Allow Alt+Enter to add new line
95+
if (e.altKey) {
96+
addLineBreak(e.currentTarget as HTMLTextAreaElement)
97+
return
98+
}
9699
if (row.id === NEW_ROW_ID || rowIndex === -1) {
97100
if (
98101
!shallowCompare(tableMeta?.tempRowData.current, {
@@ -110,7 +113,7 @@ function TableCell({
110113
row,
111114
rowIndex,
112115
columnIndex,
113-
direction: 'down',
116+
direction: e.shiftKey ? 'up' : 'down',
114117
allowCrossBoundaries: true,
115118
})
116119
break
@@ -260,7 +263,6 @@ function TableCell({
260263
}}
261264
ref={cellContainerRef}
262265
className={styles.cell}
263-
onClick={startEditing}
264266
onContextMenu={!isViewMode ? onContextMenu : undefined}
265267
>
266268
{/* if editing new row, show text area for all cells in the row */}
@@ -286,7 +288,7 @@ function TableCell({
286288
_readOnly={{
287289
boxShadow: CELL_BOX_SHADOW.DEFAULT,
288290
}}
289-
isReadOnly={isViewMode}
291+
isReadOnly={isViewMode || isFetching}
290292
defaultValue={value}
291293
onChange={onChange}
292294
onKeyDown={onKeyDown}
@@ -297,6 +299,7 @@ function TableCell({
297299
/>
298300
) : (
299301
<div
302+
onClick={startEditing}
300303
style={{
301304
display: 'flex',
302305
height: '100%',
@@ -307,6 +310,7 @@ function TableCell({
307310
wordBreak: 'break-word',
308311
fontSize: '0.875rem',
309312
cursor: 'cell',
313+
310314
backgroundColor: isHighlightingCell
311315
? 'var(--chakra-colors-orange-200)'
312316
: hasMatchingSearch
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function addLineBreak(element: HTMLTextAreaElement) {
2+
const start = element.selectionStart
3+
const end = element.selectionEnd
4+
const value = element.value
5+
6+
element.value = value.substring(0, start) + '\n' + value.substring(end)
7+
element.selectionStart = element.selectionEnd = start + 1
8+
}

0 commit comments

Comments
 (0)