Skip to content

Commit f3e4f80

Browse files
committed
refactor: move the table cell content to different folder
1 parent 732cf6e commit f3e4f80

File tree

8 files changed

+93
-50
lines changed

8 files changed

+93
-50
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.container {
2+
width: 100%;
3+
height: 34px;
4+
border: 1px solid var(--color-surface);
5+
font-size: 1rem;
6+
box-sizing: border-box;
7+
}
8+
9+
.changed {
10+
border: 1px solid var(--color-table-change);
11+
background: var(--color-table-change);
12+
color: #000;
13+
}
14+
15+
.focused {
16+
border: 1px solid var(--color-critical);
17+
}
18+
19+
.input {
20+
padding: 5px 10px;
21+
border: 1px solid var(--color-surface);
22+
background: var(--color-surface);
23+
color: var(--color-text);
24+
box-sizing: border-box;
25+
width: 100%;
26+
height: 100%;
27+
outline: none;
28+
font-size: 1rem;
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import styles from './TableCellInput.module.scss';
2+
3+
interface TableCellInputProps {
4+
onLostFocus?: () => void;
5+
readOnly?: boolean;
6+
value?: string | null;
7+
alignRight?: boolean;
8+
onChange?: (value: string) => void;
9+
}
10+
11+
export default function TableCellInput({
12+
onLostFocus,
13+
readOnly,
14+
value,
15+
onChange,
16+
alignRight,
17+
}: TableCellInputProps) {
18+
return (
19+
<input
20+
onKeyPress={(e) => {
21+
if (e.key === 'Enter') {
22+
if (onLostFocus) {
23+
onLostFocus();
24+
}
25+
}
26+
}}
27+
spellCheck="false"
28+
autoFocus
29+
type="text"
30+
readOnly={readOnly}
31+
className={styles.input}
32+
style={alignRight ? { textAlign: 'right' } : undefined}
33+
onBlur={onLostFocus}
34+
onChange={(e) => {
35+
if (onChange) onChange(e.currentTarget.value);
36+
}}
37+
value={value || ''}
38+
/>
39+
);
40+
}

src/renderer/components/ResizableTable/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default function ResizableTable({
7575
headers.map(() => '150px').join(' ') || '';
7676
setGridCSSPrepared(true);
7777
}
78-
}, [headers, tableRef, setGridCSSPrepared]);
78+
}, [tableRef, setGridCSSPrepared]);
7979

8080
return (
8181
<table ref={tableRef} className={styles.table}>

src/renderer/screens/DatabaseScreen/QueryResultViewer/TableCell/TableCellDecimal.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import styles from './styles.module.css';
21
import { useState, useCallback } from 'react';
32
import {
43
TableEditableEditorProps,
54
TableEditableContentProps,
65
} from './TableEditableCell';
76
import createTableCellType from './createTableCellType';
87
import { Decimal } from 'decimal.js';
9-
import TableCellContent from './TableCellContent';
8+
import TableCellContent from 'renderer/components/ResizableTable/TableCellContent';
9+
import TableCellInput from 'renderer/components/ResizableTable/TableCellInput';
1010

1111
function TableCellDecimalEditor({
1212
value,
1313
onExit,
1414
readOnly,
1515
}: TableEditableEditorProps) {
16-
const [editValue, setEditValue] = useState(value);
16+
const [editValue, setEditValue] = useState(value as string);
1717

1818
const onLostFocus = useCallback(() => {
1919
if (onExit) {
@@ -22,20 +22,12 @@ function TableCellDecimalEditor({
2222
}, [onExit, editValue]);
2323

2424
return (
25-
<input
26-
onKeyPress={(e) => {
27-
if (e.key === 'Enter') {
28-
onLostFocus();
29-
}
30-
}}
25+
<TableCellInput
3126
readOnly={readOnly}
32-
autoFocus
33-
type="text"
34-
className={`${styles.input} ${styles.number}`}
35-
style={{ textAlign: 'right' }}
36-
onBlur={onLostFocus}
37-
onChange={(e) => setEditValue(e.currentTarget.value)}
38-
value={editValue as string}
27+
alignRight
28+
onChange={setEditValue}
29+
onLostFocus={onLostFocus}
30+
value={editValue}
3931
/>
4032
);
4133
}

src/renderer/screens/DatabaseScreen/QueryResultViewer/TableCell/TableCellJson.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import createTableCellType from './createTableCellType';
99
import deepEqual from 'deep-equal';
1010
import Button from 'renderer/components/Button';
1111
import Modal from 'renderer/components/Modal';
12-
import TableCellContent from './TableCellContent';
1312
import useCodeEditorTheme from 'renderer/components/CodeEditor/useCodeEditorTheme';
13+
import TableCellContent from 'renderer/components/ResizableTable/TableCellContent';
1414

1515
function TableCellJsonEditor({
1616
value,

src/renderer/screens/DatabaseScreen/QueryResultViewer/TableCell/TableCellNumber.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import styles from './styles.module.css';
21
import { useState, useCallback } from 'react';
32
import {
43
TableEditableEditorProps,
54
TableEditableContentProps,
65
} from './TableEditableCell';
76
import createTableCellType from './createTableCellType';
8-
import TableCellContent from './TableCellContent';
7+
import TableCellContent from 'renderer/components/ResizableTable/TableCellContent';
8+
import TableCellInput from 'renderer/components/ResizableTable/TableCellInput';
99

1010
function TableCellNumberEditor({
1111
value,
@@ -23,21 +23,12 @@ function TableCellNumberEditor({
2323
}, [onExit, editValue]);
2424

2525
return (
26-
<input
27-
onKeyPress={(e) => {
28-
if (e.key === 'Enter') {
29-
onLostFocus();
30-
}
31-
}}
32-
autoFocus
26+
<TableCellInput
3327
readOnly={readOnly}
34-
type="text"
35-
className={`${styles.input} ${styles.number}`}
36-
onBlur={onLostFocus}
37-
style={{ textAlign: 'right' }}
38-
placeholder={editValue === null ? 'NULL' : ''}
39-
onChange={(e) => setEditValue(e.currentTarget.value)}
40-
value={editValue || ''}
28+
alignRight
29+
onChange={setEditValue}
30+
onLostFocus={onLostFocus}
31+
value={editValue}
4132
/>
4233
);
4334
}

src/renderer/screens/DatabaseScreen/QueryResultViewer/TableCell/TableCellString.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import styles from './styles.module.css';
21
import { useState, useCallback } from 'react';
32
import {
43
TableEditableEditorProps,
54
TableEditableContentProps,
65
} from './TableEditableCell';
76
import createTableCellType from './createTableCellType';
87
import TableCellContent from 'renderer/components/ResizableTable/TableCellContent';
8+
import TableCellInput from 'renderer/components/ResizableTable/TableCellInput';
99

1010
function TableCellStringEditor({
1111
value,
1212
onExit,
1313
readOnly,
1414
}: TableEditableEditorProps) {
15-
const [editValue, setEditValue] = useState(value);
15+
const [editValue, setEditValue] = useState(value as string);
1616

1717
const onLostFocus = useCallback(() => {
1818
if (onExit) {
@@ -21,20 +21,11 @@ function TableCellStringEditor({
2121
}, [onExit, editValue]);
2222

2323
return (
24-
<input
25-
onKeyPress={(e) => {
26-
if (e.key === 'Enter') {
27-
onLostFocus();
28-
}
29-
}}
30-
spellCheck="false"
31-
autoFocus
32-
type="text"
24+
<TableCellInput
3325
readOnly={readOnly}
34-
className={styles.input}
35-
onBlur={onLostFocus}
36-
onChange={(e) => setEditValue(e.currentTarget.value)}
37-
value={editValue as string}
26+
onChange={setEditValue}
27+
onLostFocus={onLostFocus}
28+
value={editValue}
3829
/>
3930
);
4031
}

src/renderer/screens/DatabaseScreen/SqlTableSchemaTab/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useEffect, useState } from 'react';
22
import ResizableTable from 'renderer/components/ResizableTable';
3+
import TableCellContent from 'renderer/components/ResizableTable/TableCellContent';
34
import { useSqlExecute } from 'renderer/contexts/SqlExecuteProvider';
45
import { useWindowTab } from 'renderer/contexts/WindowTabProvider';
56
import { TableDefinitionSchema } from 'types/SqlSchema';
6-
import TableCellContent from '../QueryResultViewer/TableCell/TableCellContent';
77

88
interface SqlTableSchemaProps {
99
name: string;

0 commit comments

Comments
 (0)