Skip to content

Commit 824e5c7

Browse files
authored
Data connector type as dropdown, write-only (#237)
* Data connector type as dropdown, write-only * Dropdown overflow * Fixes * Fix position of dropdown * No vendor needed, unique data source name * Fixes for names of data sources and servers
1 parent 69a8137 commit 824e5c7

File tree

5 files changed

+94
-58
lines changed

5 files changed

+94
-58
lines changed

ui/ConnectorList.tsx

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,57 @@ import * as React from 'react';
22
import {
33
ConnectorInfo,
44
DatabaseConnectorInfo,
5+
DatabaseConnectorInfoType,
56
ProjectState,
67
} from '../shared/state';
78
import { Button } from './components/Button';
9+
import { Dropdown } from './components/Dropdown';
810
import { Connector } from './Connector';
9-
import { VENDORS } from './connectors';
11+
import { VENDORS, VENDOR_GROUPS } from './connectors';
12+
13+
function NewConnector({
14+
onClick,
15+
}: {
16+
onClick: (type: DatabaseConnectorInfoType) => void;
17+
}) {
18+
const groups = VENDOR_GROUPS.map((g) => ({
19+
name: g.group,
20+
id: g.group,
21+
items: g.vendors.map((id) => ({
22+
render(close: () => void) {
23+
return (
24+
<Button
25+
onClick={() => {
26+
onClick(id);
27+
close();
28+
}}
29+
>
30+
{VENDORS[id].name}
31+
</Button>
32+
);
33+
},
34+
id,
35+
})),
36+
}));
37+
38+
return (
39+
<Dropdown
40+
className="add-panel"
41+
trigger={(open) => (
42+
<Button
43+
onClick={(e) => {
44+
e.preventDefault();
45+
open();
46+
}}
47+
>
48+
Add Panel
49+
</Button>
50+
)}
51+
title="Add Panel"
52+
groups={groups}
53+
/>
54+
);
55+
}
1056

1157
export function ConnectorList({
1258
state,
@@ -51,14 +97,21 @@ export function ConnectorList({
5197
))}
5298
</React.Fragment>
5399
))}
54-
<div className="text-center">
55-
<Button
56-
onClick={() => {
57-
updateConnector(new DatabaseConnectorInfo(), -1, true);
100+
<div className="new-panel">
101+
<NewConnector
102+
onClick={(type: DatabaseConnectorInfoType) => {
103+
updateConnector(
104+
new DatabaseConnectorInfo({
105+
type,
106+
name: `Untitled ${VENDORS[type].name} Data Source #${
107+
state.connectors?.length + 1
108+
}`,
109+
}),
110+
-1,
111+
true
112+
);
58113
}}
59-
>
60-
Add Data Source
61-
</Button>
114+
/>
62115
</div>
63116
</div>
64117
);

ui/DatabaseConnector.tsx

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import * as React from 'react';
2-
import {
3-
DatabaseConnectorInfo,
4-
DatabaseConnectorInfoType,
5-
} from '../shared/state';
6-
import { FormGroup } from './components/FormGroup';
7-
import { Select } from './components/Select';
8-
import { VENDORS, VENDOR_GROUPS } from './connectors';
2+
import { DatabaseConnectorInfo } from '../shared/state';
3+
import { VENDORS } from './connectors';
94
import { ProjectContext } from './state';
105

116
export function DatabaseConnector({
@@ -18,36 +13,10 @@ export function DatabaseConnector({
1813
const { servers } = React.useContext(ProjectContext).state;
1914
const { details: Details } = VENDORS[connector.database.type];
2015
return (
21-
<React.Fragment>
22-
<FormGroup>
23-
<div className="form-row">
24-
<Select
25-
label="Vendor"
26-
value={connector.database.type}
27-
onChange={(value: string) => {
28-
connector.database.type = value as DatabaseConnectorInfoType;
29-
updateConnector(connector);
30-
}}
31-
>
32-
{VENDOR_GROUPS.map((group) => (
33-
<optgroup
34-
key={group.group}
35-
label={group.group}
36-
children={group.vendors.map((v) => (
37-
<option key={v} value={v}>
38-
{VENDORS[v].name}
39-
</option>
40-
))}
41-
/>
42-
))}
43-
</Select>
44-
</div>
45-
</FormGroup>
46-
<Details
47-
connector={connector}
48-
updateConnector={updateConnector}
49-
servers={servers}
50-
/>
51-
</React.Fragment>
16+
<Details
17+
connector={connector}
18+
updateConnector={updateConnector}
19+
servers={servers}
20+
/>
5221
);
5322
}

ui/ServerList.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export function ServerList({
2626
<div className="text-center">
2727
<Button
2828
onClick={() => {
29-
updateServer(new ServerInfo(), -1, true);
29+
updateServer(
30+
new ServerInfo({
31+
name: `Untitled Server #${state.servers?.length + 1}`,
32+
}),
33+
-1,
34+
true
35+
);
3036
}}
3137
>
3238
Add Server

ui/connectors/BigQueryDetails.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { DatabaseConnectorInfo } from '../../shared/state';
3+
import { FormGroup } from '../components/FormGroup';
34
import { ApiKey } from './ApiKey';
45
import { Database } from './Database';
56

@@ -12,16 +13,18 @@ export function BigQueryDetails({
1213
}) {
1314
return (
1415
<React.Fragment>
15-
<Database
16-
label="Project ID"
17-
connector={connector}
18-
updateConnector={updateConnector}
19-
/>
20-
<ApiKey
21-
label="Service Account JSON"
22-
connector={connector}
23-
updateConnector={updateConnector}
24-
/>
16+
<FormGroup>
17+
<Database
18+
label="Project ID"
19+
connector={connector}
20+
updateConnector={updateConnector}
21+
/>
22+
<ApiKey
23+
label="Service Account JSON"
24+
connector={connector}
25+
updateConnector={updateConnector}
26+
/>
27+
</FormGroup>
2528
</React.Fragment>
2629
);
2730
}

ui/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,12 @@ input + input[type='file'] {
437437
}
438438
}
439439

440+
.input input:disabled,
441+
.input:disabled,
440442
.button:not(.button--icon):disabled,
441443
.button:not(.button--icon):disabled:hover {
442-
background: #ccc;
444+
background: #ccc !important;
445+
box-shadow: none !important;
443446
color: #999;
444447
cursor: not-allowed;
445448
pointer-events: all !important;
@@ -1183,6 +1186,8 @@ tbody tr {
11831186
background: var(--background-light);
11841187
width: 300px;
11851188
box-shadow: 0 1px 3px 0 #aaa;
1189+
max-height: 500px;
1190+
overflow: auto;
11861191
}
11871192

11881193
.dropdown-section:not(:last-of-type) {

0 commit comments

Comments
 (0)