Skip to content

Commit

Permalink
improve handling of database statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarDamkjaer committed Sep 12, 2023
1 parent cdc3b4b commit 47d0051
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
47 changes: 18 additions & 29 deletions src/browser/modules/DBMSInfo/DatabaseSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ export const DatabaseSelector = ({
a.name.localeCompare(b.name)
)

const unavailableStatuses = [
'unknown',
'starting',
'stopping',
'store copying',
'offline'
]
const errorStatuses = ['dirty', 'quarantined']

return (
<DrawerSection>
<DrawerSubHeader>Use database</DrawerSubHeader>
Expand All @@ -102,26 +93,24 @@ export const DatabaseSelector = ({
<option value={EMPTY_OPTION}>{EMPTY_OPTION}</option>
)}

{databasesAndAliases.map(dbOrAlias => (
<option
key={dbOrAlias.name}
value={dbOrAlias.name}
disabled={
unavailableStatuses.includes(dbOrAlias.status) ||
errorStatuses.includes(dbOrAlias.status)
}
title={`status: ${dbOrAlias.status}`}
>
{dbOrAlias.name}
{dbOrAlias === homeDb ? NBSP_CHAR + HOUSE_EMOJI : ''}
{unavailableStatuses.includes(dbOrAlias.status)
? NBSP_CHAR + HOUR_GLASS_EMOJI
: ''}
{errorStatuses.includes(dbOrAlias.status)
? NBSP_CHAR + RED_EXCLAIMATION_EMOJI
: ''}
</option>
))}
{databasesAndAliases.map(dbOrAlias => {
// When deduplicating the list of databases and aliases
// we prefer to find on that is "online", so if the status is not online
// it means none of the databases on the cluster with that name
const dbNotOnline = dbOrAlias.status !== 'online'

return (
<option
key={dbOrAlias.name}
value={dbOrAlias.name}
disabled={dbNotOnline}
>
{dbOrAlias.name}
{dbOrAlias === homeDb ? NBSP_CHAR + HOUSE_EMOJI : ''}
{dbNotOnline && ` [${dbOrAlias.status}]`}
</option>
)
})}
</Select>
</DrawerSectionBody>
</DrawerSection>
Expand Down
1 change: 0 additions & 1 deletion src/browser/modules/Sidebar/GuideDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import GuideCarousel from '../GuideCarousel/GuideCarousel'
import GuidePicker from './GuidePicker'
import {
BackIconContainer,
GuideTitle,
StyledDrawerSeparator,
StyledGuideDrawer,
StyledGuideDrawerHeader
Expand Down
12 changes: 11 additions & 1 deletion src/browser/modules/Stream/ErrorFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import {
StyledHelpFrame,
StyledPreformattedArea
} from './styled'
import { UnknownCommandError, createErrorObject } from 'services/exceptions'
import {
DatabaseUnavailableErrorType,
UnknownCommandError,
createErrorObject
} from 'services/exceptions'

export const ErrorView = ({ frame }: any) => {
if (!frame) return null
Expand Down Expand Up @@ -69,6 +73,12 @@ export const ErrorView = ({ frame }: any) => {
Use <AutoExecButton cmd="help commands" /> to list available commands.
</>
) : null}
{errorCode === DatabaseUnavailableErrorType ? (
<>
Run <AutoExecButton cmd="SHOW DATABASES" isCypher /> or{' '}
<AutoExecButton cmd="sysinfo" /> for more information.
</>
) : null}
</StyledHelpFrame>
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/browser/modules/Stream/auto-exec-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { fireEvent, render } from '@testing-library/react'
import React from 'react'

import { AutoExecButtonComponent } from './auto-exec-button'
import { AutoExecCypherButton } from './auto-exec-button'

Check failure on line 20 in src/browser/modules/Stream/auto-exec-button.test.tsx

View workflow job for this annotation

GitHub Actions / run-tests

Module '"./auto-exec-button"' has no exported member 'AutoExecCypherButton'. Did you mean to use 'import AutoExecCypherButton from "./auto-exec-button"' instead?

const send = jest.fn()

Expand All @@ -28,7 +28,7 @@ describe('AutoExecButton', function () {
test('should display command with cmd char', () => {
// Given
const { getByText } = render(
<AutoExecButtonComponent bus={{ send }} cmd="help params" />
<AutoExecCypherButton bus={{ send }} cmd="help params" />
)

// Then
Expand All @@ -39,7 +39,7 @@ describe('AutoExecButton', function () {
test('should auto execute when clicked', () => {
// Given
const { getByText } = render(
<AutoExecButtonComponent bus={{ send }} cmd="help params" />
<AutoExecCypherButton bus={{ send }} cmd="help params" />
)

fireEvent.click(getByText(':help params'))
Expand All @@ -62,7 +62,7 @@ describe('AutoExecButton', function () {
test('supports any random cmd string', () => {
// Given
const { getByText } = render(
<AutoExecButtonComponent bus={{ send }} cmd="foo bar" />
<AutoExecCypherButton bus={{ send }} cmd="foo bar" />
)

fireEvent.click(getByText(':foo bar'))
Expand Down
8 changes: 6 additions & 2 deletions src/browser/modules/Stream/auto-exec-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ export function AutoExecButtonComponent({
bus,
cmd,
displayText,
isCypher = false,
...rest
}: any) {
const onClick = useCallback(() => {
const action = executeCommand(`:${cmd}`, { source: commandSources.button })
const action = executeCommand(isCypher ? cmd : `:${cmd}`, {
source: commandSources.button
})

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

return (
<StyledAutoExecButton type="button" onClick={onClick} {...rest}>
<i className="fa fa-play-circle-o" /> {displayText ?? `:${cmd}`}
<i className="fa fa-play-circle-o" />{' '}
{displayText ?? (isCypher ? cmd : `:${cmd}`)}
</StyledAutoExecButton>
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/shared/services/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,17 @@ export function DatabaseNotFoundError({
}
}

export const DatabaseUnavailableErrorType = 'DatabaseUnavailableError'
export function DatabaseUnavailableError({
dbName,
dbMeta
}: {
dbName: string
dbMeta: { status: string }
}): BrowserError {
const type = 'DatabaseUnavailableError'
return {
type,
code: type,
type: DatabaseUnavailableErrorType,
code: DatabaseUnavailableErrorType,
message: `Database "${dbName}" is unavailable, its status is "${dbMeta.status}".`
}
}
Expand Down

0 comments on commit 47d0051

Please sign in to comment.