Skip to content

Commit 1171dce

Browse files
Handle more database states (#1937)
* Handle more database states * improve handling of database statuses * remove unused variables * fixtest * updatecomment * comment
1 parent 1284330 commit 1171dce

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

src/browser/modules/DBMSInfo/DatabaseSelector.tsx

+22-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const Select = styled.select`
3737
const EMPTY_OPTION = 'Select db to use'
3838

3939
const HOUSE_EMOJI = '\u{1F3E0}'
40-
const HOUR_GLASS_EMOJI = '\u{231B}'
4140
const NBSP_CHAR = '\u{00A0}'
4241

4342
type DatabaseSelectorProps = {
@@ -92,19 +91,28 @@ export const DatabaseSelector = ({
9291
<option value={EMPTY_OPTION}>{EMPTY_OPTION}</option>
9392
)}
9493

95-
{databasesAndAliases.map(dbOrAlias => (
96-
<option
97-
key={dbOrAlias.name}
98-
value={dbOrAlias.name}
99-
disabled={dbOrAlias.status === 'unknown'}
100-
>
101-
{dbOrAlias.name}
102-
{dbOrAlias === homeDb ? NBSP_CHAR + HOUSE_EMOJI : ''}
103-
{dbOrAlias.status === 'unknown'
104-
? NBSP_CHAR + HOUR_GLASS_EMOJI
105-
: ''}
106-
</option>
107-
))}
94+
{databasesAndAliases.map(dbOrAlias => {
95+
/* When deduplicating the list of databases and aliases on clusters
96+
we prefer to find ones that are "online". If our deduplicated
97+
db is not online, it means none of the databases on the cluster with
98+
that name is online, so we should disable it in the list and show
99+
one of the statuses as a simplification (even though they could
100+
technically be different)
101+
*/
102+
const dbNotOnline = dbOrAlias.status !== 'online'
103+
104+
return (
105+
<option
106+
key={dbOrAlias.name}
107+
value={dbOrAlias.name}
108+
disabled={dbNotOnline}
109+
>
110+
{dbOrAlias.name}
111+
{dbOrAlias === homeDb ? NBSP_CHAR + HOUSE_EMOJI : ''}
112+
{dbNotOnline && ` [${dbOrAlias.status}]`}
113+
</option>
114+
)
115+
})}
108116
</Select>
109117
</DrawerSectionBody>
110118
</DrawerSection>

src/browser/modules/Sidebar/GuideDrawer.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import GuideCarousel from '../GuideCarousel/GuideCarousel'
2727
import GuidePicker from './GuidePicker'
2828
import {
2929
BackIconContainer,
30-
GuideTitle,
3130
StyledDrawerSeparator,
3231
StyledGuideDrawer,
3332
StyledGuideDrawerHeader

src/browser/modules/Stream/ErrorFrame.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import {
3131
StyledHelpFrame,
3232
StyledPreformattedArea
3333
} from './styled'
34-
import { UnknownCommandError, createErrorObject } from 'services/exceptions'
34+
import {
35+
DatabaseUnavailableErrorType,
36+
UnknownCommandError,
37+
createErrorObject
38+
} from 'services/exceptions'
3539

3640
export const ErrorView = ({ frame }: any) => {
3741
if (!frame) return null
@@ -69,6 +73,12 @@ export const ErrorView = ({ frame }: any) => {
6973
Use <AutoExecButton cmd="help commands" /> to list available commands.
7074
</>
7175
) : null}
76+
{errorCode === DatabaseUnavailableErrorType ? (
77+
<>
78+
Run <AutoExecButton cmd="SHOW DATABASES" isCypher /> or{' '}
79+
<AutoExecButton cmd="sysinfo" /> for more information.
80+
</>
81+
) : null}
7282
</StyledHelpFrame>
7383
)
7484
}

src/browser/modules/Stream/auto-exec-button.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,21 @@ export function AutoExecButtonComponent({
4343
bus,
4444
cmd,
4545
displayText,
46+
isCypher = false,
4647
...rest
4748
}: any) {
4849
const onClick = useCallback(() => {
49-
const action = executeCommand(`:${cmd}`, { source: commandSources.button })
50+
const action = executeCommand(isCypher ? cmd : `:${cmd}`, {
51+
source: commandSources.button
52+
})
5053

5154
bus.send(action.type, action)
5255
}, [cmd])
5356

5457
return (
5558
<StyledAutoExecButton type="button" onClick={onClick} {...rest}>
56-
<i className="fa fa-play-circle-o" /> {displayText ?? `:${cmd}`}
59+
<i className="fa fa-play-circle-o" />{' '}
60+
{displayText ?? (isCypher ? cmd : `:${cmd}`)}
5761
</StyledAutoExecButton>
5862
)
5963
}

src/shared/services/exceptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ export function DatabaseNotFoundError({
129129
}
130130
}
131131

132+
export const DatabaseUnavailableErrorType = 'DatabaseUnavailableError'
132133
export function DatabaseUnavailableError({
133134
dbName,
134135
dbMeta
135136
}: {
136137
dbName: string
137138
dbMeta: { status: string }
138139
}): BrowserError {
139-
const type = 'DatabaseUnavailableError'
140140
return {
141-
type,
142-
code: type,
141+
type: DatabaseUnavailableErrorType,
142+
code: DatabaseUnavailableErrorType,
143143
message: `Database "${dbName}" is unavailable, its status is "${dbMeta.status}".`
144144
}
145145
}

0 commit comments

Comments
 (0)