From cdc3b4b0ba9f2258dce316b3625d7007ed64f535 Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Tue, 12 Sep 2023 08:27:38 +0200 Subject: [PATCH 1/6] Handle more database states --- .../modules/DBMSInfo/DatabaseSelector.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx index efca20010fa..1654467bd1f 100644 --- a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx +++ b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx @@ -38,6 +38,7 @@ const EMPTY_OPTION = 'Select db to use' const HOUSE_EMOJI = '\u{1F3E0}' const HOUR_GLASS_EMOJI = '\u{231B}' +const RED_EXCLAIMATION_EMOJI = '\u{2757}' const NBSP_CHAR = '\u{00A0}' type DatabaseSelectorProps = { @@ -79,6 +80,15 @@ export const DatabaseSelector = ({ a.name.localeCompare(b.name) ) + const unavailableStatuses = [ + 'unknown', + 'starting', + 'stopping', + 'store copying', + 'offline' + ] + const errorStatuses = ['dirty', 'quarantined'] + return ( Use database @@ -96,13 +106,20 @@ export const DatabaseSelector = ({ ))} From 47d005111f195ac1db9dd76ebd363012a530fb87 Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Tue, 12 Sep 2023 11:14:25 +0200 Subject: [PATCH 2/6] improve handling of database statuses --- .../modules/DBMSInfo/DatabaseSelector.tsx | 47 +++++++------------ src/browser/modules/Sidebar/GuideDrawer.tsx | 1 - src/browser/modules/Stream/ErrorFrame.tsx | 12 ++++- .../modules/Stream/auto-exec-button.test.tsx | 8 ++-- .../modules/Stream/auto-exec-button.tsx | 8 +++- src/shared/services/exceptions.ts | 6 +-- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx index 1654467bd1f..f2c562e0660 100644 --- a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx +++ b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx @@ -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 ( Use database @@ -102,26 +93,24 @@ export const DatabaseSelector = ({ )} - {databasesAndAliases.map(dbOrAlias => ( - - ))} + {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 ( + + ) + })} diff --git a/src/browser/modules/Sidebar/GuideDrawer.tsx b/src/browser/modules/Sidebar/GuideDrawer.tsx index 265198d8c8c..ae3b9727e7b 100644 --- a/src/browser/modules/Sidebar/GuideDrawer.tsx +++ b/src/browser/modules/Sidebar/GuideDrawer.tsx @@ -27,7 +27,6 @@ import GuideCarousel from '../GuideCarousel/GuideCarousel' import GuidePicker from './GuidePicker' import { BackIconContainer, - GuideTitle, StyledDrawerSeparator, StyledGuideDrawer, StyledGuideDrawerHeader diff --git a/src/browser/modules/Stream/ErrorFrame.tsx b/src/browser/modules/Stream/ErrorFrame.tsx index d6308cd74b1..0e4bc4a7331 100644 --- a/src/browser/modules/Stream/ErrorFrame.tsx +++ b/src/browser/modules/Stream/ErrorFrame.tsx @@ -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 @@ -69,6 +73,12 @@ export const ErrorView = ({ frame }: any) => { Use to list available commands. ) : null} + {errorCode === DatabaseUnavailableErrorType ? ( + <> + Run or{' '} + for more information. + + ) : null} ) } diff --git a/src/browser/modules/Stream/auto-exec-button.test.tsx b/src/browser/modules/Stream/auto-exec-button.test.tsx index 04e38ca19f5..57d0467586d 100644 --- a/src/browser/modules/Stream/auto-exec-button.test.tsx +++ b/src/browser/modules/Stream/auto-exec-button.test.tsx @@ -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' const send = jest.fn() @@ -28,7 +28,7 @@ describe('AutoExecButton', function () { test('should display command with cmd char', () => { // Given const { getByText } = render( - + ) // Then @@ -39,7 +39,7 @@ describe('AutoExecButton', function () { test('should auto execute when clicked', () => { // Given const { getByText } = render( - + ) fireEvent.click(getByText(':help params')) @@ -62,7 +62,7 @@ describe('AutoExecButton', function () { test('supports any random cmd string', () => { // Given const { getByText } = render( - + ) fireEvent.click(getByText(':foo bar')) diff --git a/src/browser/modules/Stream/auto-exec-button.tsx b/src/browser/modules/Stream/auto-exec-button.tsx index 67a83f097b6..fc666803712 100644 --- a/src/browser/modules/Stream/auto-exec-button.tsx +++ b/src/browser/modules/Stream/auto-exec-button.tsx @@ -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 ( - {displayText ?? `:${cmd}`} + {' '} + {displayText ?? (isCypher ? cmd : `:${cmd}`)} ) } diff --git a/src/shared/services/exceptions.ts b/src/shared/services/exceptions.ts index 6236c91c854..5bed2b326d6 100644 --- a/src/shared/services/exceptions.ts +++ b/src/shared/services/exceptions.ts @@ -129,6 +129,7 @@ export function DatabaseNotFoundError({ } } +export const DatabaseUnavailableErrorType = 'DatabaseUnavailableError' export function DatabaseUnavailableError({ dbName, dbMeta @@ -136,10 +137,9 @@ export function DatabaseUnavailableError({ 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}".` } } From 7a9214cfe966c272bc7b25162e42a38898010b84 Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Tue, 12 Sep 2023 11:46:56 +0200 Subject: [PATCH 3/6] remove unused variables --- src/browser/modules/DBMSInfo/DatabaseSelector.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx index f2c562e0660..9b39bc5325f 100644 --- a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx +++ b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx @@ -37,8 +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 RED_EXCLAIMATION_EMOJI = '\u{2757}' const NBSP_CHAR = '\u{00A0}' type DatabaseSelectorProps = { From 31d84d270ab79fc59dae790f8b8c3a80af3f4450 Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Wed, 13 Sep 2023 09:47:10 +0200 Subject: [PATCH 4/6] fixtest --- src/browser/modules/Stream/auto-exec-button.test.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/browser/modules/Stream/auto-exec-button.test.tsx b/src/browser/modules/Stream/auto-exec-button.test.tsx index 57d0467586d..04e38ca19f5 100644 --- a/src/browser/modules/Stream/auto-exec-button.test.tsx +++ b/src/browser/modules/Stream/auto-exec-button.test.tsx @@ -17,7 +17,7 @@ import { fireEvent, render } from '@testing-library/react' import React from 'react' -import { AutoExecCypherButton } from './auto-exec-button' +import { AutoExecButtonComponent } from './auto-exec-button' const send = jest.fn() @@ -28,7 +28,7 @@ describe('AutoExecButton', function () { test('should display command with cmd char', () => { // Given const { getByText } = render( - + ) // Then @@ -39,7 +39,7 @@ describe('AutoExecButton', function () { test('should auto execute when clicked', () => { // Given const { getByText } = render( - + ) fireEvent.click(getByText(':help params')) @@ -62,7 +62,7 @@ describe('AutoExecButton', function () { test('supports any random cmd string', () => { // Given const { getByText } = render( - + ) fireEvent.click(getByText(':foo bar')) From a8dd6e6fa02519f85a55efeab62aee3d94c03451 Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Wed, 13 Sep 2023 09:49:57 +0200 Subject: [PATCH 5/6] updatecomment --- src/browser/modules/DBMSInfo/DatabaseSelector.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx index 9b39bc5325f..65f62abdde7 100644 --- a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx +++ b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx @@ -93,8 +93,10 @@ export const DatabaseSelector = ({ {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 + // we prefer to find on that is "online", so if out 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 (they are likely all the same) const dbNotOnline = dbOrAlias.status !== 'online' return ( From 1363a3fde77bc0c0194d8f97460be388bfa56c53 Mon Sep 17 00:00:00 2001 From: Oskar Damkjaer Date: Wed, 13 Sep 2023 09:52:07 +0200 Subject: [PATCH 6/6] comment --- src/browser/modules/DBMSInfo/DatabaseSelector.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx index 65f62abdde7..9939c4d1a65 100644 --- a/src/browser/modules/DBMSInfo/DatabaseSelector.tsx +++ b/src/browser/modules/DBMSInfo/DatabaseSelector.tsx @@ -92,11 +92,13 @@ export const DatabaseSelector = ({ )} {databasesAndAliases.map(dbOrAlias => { - // When deduplicating the list of databases and aliases - // we prefer to find on that is "online", so if out 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 (they are likely all the same) + /* 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 (