|
1 | 1 | import React, { useState, useEffect } from 'react'
|
2 | 2 |
|
3 |
| -import { Button, FormControl, InputLabel, MenuItem, Paper, Select, Stack, Typography } from '@mui/material' |
| 3 | +import { |
| 4 | + Button, |
| 5 | + FormControl, |
| 6 | + RadioGroup, |
| 7 | + InputLabel, |
| 8 | + MenuItem, |
| 9 | + Paper, |
| 10 | + Select, |
| 11 | + Stack, |
| 12 | + Typography, |
| 13 | + Radio, |
| 14 | + FormControlLabel, |
| 15 | + FormGroup, |
| 16 | + FormLabel, |
| 17 | + FormHelperText, |
| 18 | + Box, |
| 19 | + TextField, |
| 20 | + Tab, |
| 21 | + Tabs, |
| 22 | +} from '@mui/material' |
4 | 23 |
|
5 | 24 | import { changeStage } from './state'
|
6 | 25 |
|
7 | 26 | export const Install: React.FC = () => {
|
| 27 | + type installState = 'select-version' | 'select-db-type' |
| 28 | + const [installState, setInstallState] = useState<installState>('select-version') |
| 29 | + |
8 | 30 | const [versions, setVersions] = useState<string[]>([])
|
9 | 31 | const [selectedVersion, setSelectedVersion] = useState<string>('')
|
10 | 32 |
|
| 33 | + type dbType = 'built-in' | 'external' |
| 34 | + const [dbType, setDbType] = useState<dbType>('built-in') |
| 35 | + |
| 36 | + type dbTab = 'pgsql' | 'codeintel' | 'codeinsights' |
| 37 | + const [dbTab, setDbTab] = useState<dbTab>('pgsql') |
| 38 | + |
| 39 | + const handleDbTabChange = (event: React.SyntheticEvent, newValue: dbTab) => { |
| 40 | + setDbTab(newValue) |
| 41 | + } |
| 42 | + |
11 | 43 | useEffect(() => {
|
12 | 44 | const fetchVersions = async () => {
|
13 | 45 | try {
|
@@ -48,37 +80,107 @@ export const Install: React.FC = () => {
|
48 | 80 | fetchVersions()
|
49 | 81 | }, [])
|
50 | 82 |
|
| 83 | + const next = () => { |
| 84 | + if (selectedVersion === '') { |
| 85 | + alert('Please select a version') |
| 86 | + return |
| 87 | + } |
| 88 | + setInstallState('select-db-type') |
| 89 | + } |
| 90 | + |
| 91 | + const back = () => { |
| 92 | + setInstallState('select-version') |
| 93 | + } |
| 94 | + |
51 | 95 | const install = () => {
|
52 | 96 | changeStage({ action: 'installing', data: selectedVersion })
|
53 | 97 | }
|
54 | 98 |
|
| 99 | + const handleDbSelect = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 100 | + setDbType(event.target.value as dbType) |
| 101 | + } |
| 102 | + |
55 | 103 | return (
|
| 104 | + // Render a version selection box followed by a database configuration screen, then an install prompt |
56 | 105 | <div className="install">
|
57 |
| - <Typography variant="h5">Let's get started...</Typography> |
| 106 | + <Typography variant="h5">Setup Sourcegraph</Typography> |
58 | 107 | <Paper elevation={3} sx={{ p: 4 }}>
|
59 |
| - <Stack direction="column" spacing={2} sx={{ alignItems: 'center' }}> |
60 |
| - <FormControl sx={{ minWidth: 200 }}> |
61 |
| - <InputLabel id="demo-simple-select-label">Version</InputLabel> |
62 |
| - <Select |
63 |
| - value={selectedVersion} |
64 |
| - label="Version" |
65 |
| - onChange={e => setSelectedVersion(e.target.value)} |
66 |
| - sx={{ width: 200 }} |
67 |
| - > |
68 |
| - {versions.map(version => ( |
69 |
| - <MenuItem key={version} value={version}> |
70 |
| - {version} |
71 |
| - </MenuItem> |
72 |
| - ))} |
73 |
| - </Select> |
74 |
| - </FormControl> |
75 |
| - <div className="message"> |
76 |
| - <Typography variant="caption">Press install to begin installation.</Typography> |
77 |
| - </div> |
78 |
| - <Button variant="contained" sx={{ width: 200 }} onClick={install}> |
79 |
| - Install |
80 |
| - </Button> |
81 |
| - </Stack> |
| 108 | + {installState === 'select-version' ? ( |
| 109 | + <Stack direction="column" spacing={2} sx={{ alignItems: 'center' }}> |
| 110 | + <FormControl sx={{ minWidth: 200 }}> |
| 111 | + <InputLabel id="demo-simple-select-label">Version</InputLabel> |
| 112 | + <Select |
| 113 | + value={selectedVersion} |
| 114 | + label="Version" |
| 115 | + onChange={e => setSelectedVersion(e.target.value)} |
| 116 | + sx={{ width: 200 }} |
| 117 | + > |
| 118 | + {versions.map(version => ( |
| 119 | + <MenuItem key={version} value={version}> |
| 120 | + {version} |
| 121 | + </MenuItem> |
| 122 | + ))} |
| 123 | + </Select> |
| 124 | + </FormControl> |
| 125 | + <div className="message"> |
| 126 | + <Typography variant="caption">Proceed to database configuration.</Typography> |
| 127 | + </div> |
| 128 | + <Button variant="contained" sx={{ width: 200 }} onClick={next}> |
| 129 | + Next |
| 130 | + </Button> |
| 131 | + </Stack> |
| 132 | + ) : installState === 'select-db-type' ? ( |
| 133 | + <Stack direction="column" spacing={2} alignItems={'center'}> |
| 134 | + <FormControl> |
| 135 | + <FormLabel>Configure Sourcegraph Databases</FormLabel> |
| 136 | + <FormGroup> |
| 137 | + <RadioGroup value={dbType} onChange={handleDbSelect} defaultValue="built-in"> |
| 138 | + <FormControlLabel value="built-in" control={<Radio />} label="built-in DBs" /> |
| 139 | + <FormHelperText id="my-helper-text" fontSize="small"> |
| 140 | + Selecting built-in dbs, configures sourcegraph to use built in databases. |
| 141 | + Provisioned and controlled directly by appliance.{' '} |
| 142 | + </FormHelperText> |
| 143 | + <FormControlLabel |
| 144 | + value="external" |
| 145 | + control={<Radio />} |
| 146 | + label="External DBs (not yet supported)" |
| 147 | + /> |
| 148 | + </RadioGroup> |
| 149 | + </FormGroup> |
| 150 | + </FormControl> |
| 151 | + {dbType === 'external' ? ( |
| 152 | + <Box sx={{ width: '80%' }} alignContent={'center'}> |
| 153 | + <Box |
| 154 | + alignContent={'center'} |
| 155 | + sx={{ paddingBottom: 2.5, borderBottom: 1, borderColor: 'divider' }} |
| 156 | + > |
| 157 | + <Tabs value={dbTab} onChange={handleDbTabChange}> |
| 158 | + <Tab label="Pgsql" disabled /> |
| 159 | + <Tab label="Codeintel-db" disabled /> |
| 160 | + <Tab label="Codeinsights-db" disabled /> |
| 161 | + </Tabs> |
| 162 | + </Box> |
| 163 | + <FormGroup> |
| 164 | + <Stack spacing={2}> |
| 165 | + <TextField disabled label="Port" defaultValue="5432" /> |
| 166 | + <TextField disabled label="User" defaultValue="sg" /> |
| 167 | + <TextField disabled label="Password" defaultValue="sg" /> |
| 168 | + <TextField disabled label="Database" defaultValue="sg" /> |
| 169 | + <TextField disabled label="SSL Mode" defaultValue="disable" /> |
| 170 | + </Stack> |
| 171 | + </FormGroup> |
| 172 | + </Box> |
| 173 | + ) : null} |
| 174 | + <Stack direction="row" spacing={2}> |
| 175 | + <Button variant="contained" sx={{ width: 200 }} onClick={back}> |
| 176 | + Back |
| 177 | + </Button> |
| 178 | + <Button variant="contained" sx={{ width: 200 }} onClick={install}> |
| 179 | + Install |
| 180 | + </Button> |
| 181 | + </Stack> |
| 182 | + </Stack> |
| 183 | + ) : null} |
82 | 184 | </Paper>
|
83 | 185 | </div>
|
84 | 186 | )
|
|
0 commit comments