Skip to content

Commit

Permalink
Handle more database states (#1937)
Browse files Browse the repository at this point in the history
* Handle more database states

* improve handling of database statuses

* remove unused variables

* fixtest

* updatecomment

* comment
  • Loading branch information
OskarDamkjaer authored Sep 13, 2023
1 parent 1284330 commit 1171dce
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
36 changes: 22 additions & 14 deletions src/browser/modules/DBMSInfo/DatabaseSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const Select = styled.select`
const EMPTY_OPTION = 'Select db to use'

const HOUSE_EMOJI = '\u{1F3E0}'
const HOUR_GLASS_EMOJI = '\u{231B}'
const NBSP_CHAR = '\u{00A0}'

type DatabaseSelectorProps = {
Expand Down Expand Up @@ -92,19 +91,28 @@ export const DatabaseSelector = ({
<option value={EMPTY_OPTION}>{EMPTY_OPTION}</option>
)}

{databasesAndAliases.map(dbOrAlias => (
<option
key={dbOrAlias.name}
value={dbOrAlias.name}
disabled={dbOrAlias.status === 'unknown'}
>
{dbOrAlias.name}
{dbOrAlias === homeDb ? NBSP_CHAR + HOUSE_EMOJI : ''}
{dbOrAlias.status === 'unknown'
? NBSP_CHAR + HOUR_GLASS_EMOJI
: ''}
</option>
))}
{databasesAndAliases.map(dbOrAlias => {
/* When deduplicating the list of databases and aliases on clusters
we prefer to find ones that are "online". If our deduplicated
db is not online, it means none of the databases on the cluster with
that name is online, so we should disable it in the list and show
one of the statuses as a simplification (even though they could
technically be different)
*/
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: 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 1171dce

Please sign in to comment.