Skip to content

Commit 8b8a52e

Browse files
committed
2 parents 39ae280 + 177e68a commit 8b8a52e

File tree

4 files changed

+109
-46
lines changed

4 files changed

+109
-46
lines changed

src/renderer/components/DatabaseTable/DatabaseTableList.tsx

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ import SqlTableSchemaTab from 'renderer/screens/DatabaseScreen/SqlTableSchemaTab
1717
import Layout from '../Layout';
1818
import DatabaseSelection from './DatabaseSelection';
1919
import ListViewEmptyState from '../ListView/ListViewEmptyState';
20+
import TextField from '../TextField';
21+
import { useDebounce } from 'hooks/useDebounce';
2022

2123
export default function DatabaseTableList() {
24+
const [search, setSearch] = useState('');
25+
const searchDebounce = useDebounce(search, 500);
2226
const { schema, currentDatabase } = useSchmea();
2327
const [selected, setSelected] = useState<
2428
TreeViewItemData<{
@@ -79,63 +83,97 @@ export default function DatabaseTableList() {
7983
const currentDatabaseSchema = schema[currentDatabase];
8084
if (!currentDatabaseSchema) return [];
8185

86+
const tables = Object.values(currentDatabaseSchema.tables)
87+
.map((table) => ({
88+
id: `table/${table.name}`,
89+
text: table.name,
90+
icon:
91+
table.type === 'TABLE' ? (
92+
<FontAwesomeIcon icon={faTableList} color="#3498db" />
93+
) : (
94+
<FontAwesomeIcon icon={faEye} color="#e67e22" />
95+
),
96+
data: {
97+
name: table.name,
98+
type: table.type === 'TABLE' ? 'table' : 'view',
99+
database: currentDatabase,
100+
},
101+
}))
102+
.filter((table) => {
103+
if (searchDebounce) {
104+
return table.text.indexOf(searchDebounce) >= 0;
105+
}
106+
107+
return true;
108+
});
109+
110+
const triggers = currentDatabaseSchema.triggers
111+
.map((trigger) => ({
112+
id: `trigger/${trigger}`,
113+
text: trigger,
114+
icon: <FontAwesomeIcon icon={faGear} color="#bdc3c7" />,
115+
data: {
116+
name: trigger,
117+
database: currentDatabase,
118+
type: 'trigger',
119+
},
120+
}))
121+
.filter((table) => {
122+
if (searchDebounce) {
123+
return table.text.indexOf(searchDebounce) >= 0;
124+
}
125+
126+
return true;
127+
});
128+
129+
const events = currentDatabaseSchema.events
130+
.map((event) => ({
131+
id: `event/${event}`,
132+
text: event,
133+
icon: <FontAwesomeIcon icon={faCalendar} color="#27ae60" />,
134+
data: {
135+
name: event,
136+
type: 'event',
137+
database: currentDatabase,
138+
},
139+
}))
140+
.filter((table) => {
141+
if (searchDebounce) {
142+
return table.text.indexOf(searchDebounce) >= 0;
143+
}
144+
145+
return true;
146+
});
147+
148+
tables.sort((a, b) => a.text.localeCompare(b.text));
149+
triggers.sort((a, b) => a.text.localeCompare(b.text));
150+
events.sort((a, b) => a.text.localeCompare(b.text));
151+
82152
return [
83153
{
84154
id: 'tables',
85155
text: `Tables (${Object.values(currentDatabaseSchema.tables).length})`,
86-
children: Object.values(currentDatabaseSchema.tables).map((table) => ({
87-
id: `table/${table.name}`,
88-
text: table.name,
89-
icon:
90-
table.type === 'TABLE' ? (
91-
<FontAwesomeIcon icon={faTableList} color="#3498db" />
92-
) : (
93-
<FontAwesomeIcon icon={faEye} color="#e67e22" />
94-
),
95-
data: {
96-
name: table.name,
97-
type: table.type === 'TABLE' ? 'table' : 'view',
98-
database: currentDatabase,
99-
},
100-
})),
156+
children: tables,
101157
},
102158
{
103159
id: 'events',
104160
text: `Events (${currentDatabaseSchema.events.length})`,
105-
children: currentDatabaseSchema.events.map((event) => ({
106-
id: `event/${event}`,
107-
text: event,
108-
icon: <FontAwesomeIcon icon={faCalendar} color="#27ae60" />,
109-
data: {
110-
name: event,
111-
type: 'event',
112-
database: currentDatabase,
113-
},
114-
})),
161+
children: events,
115162
},
116163
{
117164
id: 'triggers',
118165
text: `Triggers (${currentDatabaseSchema.triggers.length})`,
119-
children: currentDatabaseSchema.triggers.map((trigger) => ({
120-
id: `trigger/${trigger}`,
121-
text: trigger,
122-
icon: <FontAwesomeIcon icon={faGear} color="#bdc3c7" />,
123-
data: {
124-
name: trigger,
125-
database: currentDatabase,
126-
type: 'trigger',
127-
},
128-
})),
166+
children: triggers,
129167
},
130168
];
131-
}, [schema, currentDatabase]);
169+
}, [schema, currentDatabase, searchDebounce]);
132170

133171
if (!schema) return <div />;
134172

135173
return (
136174
<div className={styles.tables}>
137175
<Layout>
138-
<Layout.Fixed shadowBottom>
176+
<Layout.Fixed>
139177
<DatabaseSelection />
140178
</Layout.Fixed>
141179
<Layout.Grow>
@@ -169,6 +207,16 @@ export default function DatabaseTableList() {
169207
<ListViewEmptyState text="Please select database to see tables, events, triggers, etc..." />
170208
)}
171209
</Layout.Grow>
210+
<Layout.Fixed>
211+
<div style={{ padding: 5 }}>
212+
<TextField
213+
label=""
214+
placeholder="Search here"
215+
value={search}
216+
onChange={setSearch}
217+
/>
218+
</div>
219+
</Layout.Fixed>
172220
</Layout>
173221
</div>
174222
);

src/renderer/components/DatabaseTable/styles.module.scss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
0% {
33
transform: scale(1);
44
background: #e74c3c;
5-
}
5+
}
66
50% {
77
transform: scale(1.5);
88
background: #ff7979;
9-
}
9+
}
1010
100% {
1111
transform: scale(1);
1212
background: #ff7979;
13-
}
13+
}
1414
}
1515

16-
1716
.tables {
1817
background: var(--color-list-surface);
19-
height: 100%
18+
height: 100%;
2019
}
2120

2221
.header {
@@ -26,9 +25,16 @@
2625
gap: 10px;
2726
align-items: center;
2827
cursor: pointer;
28+
overflow: hidden;
2929

3030
span {
3131
flex-grow: 1;
32+
overflow: hidden;
33+
text-overflow: ellipsis;
34+
35+
i {
36+
white-space: nowrap;
37+
}
3238
}
3339
}
3440

@@ -39,4 +45,4 @@
3945
background: #e74c3c;
4046
border-radius: 50%;
4147
animation: ping 1s ease-out infinite;
42-
}
48+
}

src/renderer/components/Layout/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ Layout.Grow = function ({ children }: PropsWithChildren) {
3232
Layout.Fixed = function ({
3333
children,
3434
shadowBottom,
35+
shadowTop,
3536
}: PropsWithChildren<LayoutFixedProps>) {
3637
const className = useMemo(() => {
37-
return [shadowBottom ? styles.shadowBottom : undefined]
38+
return [
39+
shadowBottom ? styles.shadowBottom : undefined,
40+
shadowTop ? styles.shadowTop : undefined,
41+
]
3842
.filter(Boolean)
3943
.join();
40-
}, [shadowBottom]);
44+
}, [shadowBottom, shadowTop]);
4145

4246
return (
4347
<div className={className} style={{ flexShrink: 0, flexGrow: 0 }}>
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
.shadowBottom {
22
box-shadow: var(--color-shadow) 0 1px 2px;
33
margin-bottom: 2px;
4-
}
4+
}
5+
6+
.shadowTop {
7+
box-shadow: var(--color-shadow) 0 -1px 2px;
8+
margin-top: 2px;
9+
}

0 commit comments

Comments
 (0)