-
Notifications
You must be signed in to change notification settings - Fork 263
/
configure.js
142 lines (132 loc) · 5.54 KB
/
configure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import React from 'react'
import _ from 'lodash'
import Tabs, { TabPane } from 'rc-tabs'
import TabContent from 'rc-tabs/lib/TabContent'
import InkTabBar from 'rc-tabs/lib/InkTabBar'
import { UnmountClosed } from 'react-collapse'
import * as State from '../state'
import * as U from '../state/update'
import * as SQLiteConnector from './sqlite'
import * as PostgresConnector from './postgres'
import * as BigQueryConnector from './bigquery'
import * as MySQLConnector from './mysql'
import * as MongoConnector from './mongo'
import * as CartoConnector from './carto'
import * as GraphQLConnector from './graphql'
const Databases = [
SQLiteConnector,
PostgresConnector,
MySQLConnector,
MongoConnector,
BigQueryConnector,
GraphQLConnector,
CartoConnector,
'Microsoft SQL Server',
'Oracle',
'IBM DB2',
'Teradata',
]
export default class Configure extends React.PureComponent {
render() {
let { config, connect, empty } = this.props
let db = DB(connect.active)
let connected = connect.status === 'connected'
let connectable = connected || connect.status === 'connecting'
let force_open = empty && !connected
return (
<div className="configure">
<div
onClick={(e) => State.apply('config', 'open', U.toggle)}
className={connect.status + ' banner ' + (force_open ? '' : 'can-toggle ')}
>
{
{
connecting: (
<div className="body">
<i className="fa fa-spinner fa-spin fa-fw" /> Connecting to{' '}
{db.name || 'database'}
</div>
),
connected: <div className="body">Connected to {db.name}</div>,
disconnected: (
<div className="body">
Disconnected from {db.name}{' '}
{connect.error ? <i>({connect.error})</i> : null}
</div>
),
unconfigured: <div className="body">Connect to a Database</div>,
}[connect.status]
}
{!force_open ? (
<div className="toggle">
<div>
Settings{' '}
<i
className={
'fa ' + (config.open ? 'fa-caret-up' : 'fa-caret-down')
}
aria-hidden="true"
/>
</div>
</div>
) : null}
</div>
<UnmountClosed
isOpened={config.open || force_open}
springConfig={{ stiffness: 150, damping: 20 }}
>
<Tabs
activeKey={connectable ? db.key : connect.active}
tabBarPosition="left"
destroyInactiveTabPane
onChange={(key) => State.apply('connect', 'active', U.replace(key))}
renderTabBar={() => <InkTabBar />}
renderTabContent={() => (
<TabContent animated={false} style={{ height: 'auto' }} />
)}
>
{Databases.map((c) => {
if (typeof c == 'string')
return (
<TabPane tab={c} key={c} disabled={true}>
{c}
</TabPane>
)
return (
<TabPane
tab={
c === db && connectable ? (
<span>
{c.name}{' '}
<i className="fa fa-plug" aria-hidden="true" />
</span>
) : (
c.name
)
}
key={c.key}
disabled={connectable && c !== db}
>
{c.Configure ? (
<c.Configure config={config} connect={connect} />
) : (
<div className="error">
No configuration interface defined for {c.name}{' '}
connector
</div>
)}
</TabPane>
)
})}
</Tabs>
</UnmountClosed>
</div>
)
}
}
export function DB(key) {
return Databases.find((k) => k.key === key)
}
export function getDB() {
return DB(State.get('connect', 'active'))
}