Skip to content

Commit d40fba4

Browse files
Fix wrong cluster role reported in sidebar (#1869)
1 parent da2aa55 commit d40fba4

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

src/browser/modules/DBMSInfo/DatabaseKernelInfo.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ import {
4141
} from 'shared/modules/commands/commandsDuck'
4242
import {
4343
Database,
44-
getClusterRoleForDb,
4544
getDatabases,
4645
getEdition,
4746
getStoreSize,
4847
getRawVersion
4948
} from 'shared/modules/dbMeta/dbMetaDuck'
5049
import { getUsedDbName } from 'shared/modules/features/versionedFeatures'
50+
import { getClusterRoleForCurrentDb } from 'shared/utils/selectors'
5151

5252
type DatabaseKernelInfo = {
5353
role: any
@@ -133,13 +133,12 @@ export const DatabaseKernelInfo = ({
133133
}
134134

135135
const mapStateToProps = (state: any) => {
136-
const dbName = getUsedDbName(state)
137136
return {
138137
version: getRawVersion(state),
139138
edition: getEdition(state),
140-
dbName,
139+
dbName: getUsedDbName(state),
141140
storeSize: getStoreSize(state),
142-
role: getClusterRoleForDb(state, dbName),
141+
role: getClusterRoleForCurrentDb(state),
143142
databases: getDatabases(state)
144143
}
145144
}

src/shared/modules/dbMeta/dbMetaDuck.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,6 @@ export const isOnCluster = (state: GlobalState): boolean => {
309309
return hasProcedure(state, 'dbms.cluster.overview')
310310
}
311311
}
312-
export const getClusterRoleForDb = (state: GlobalState, activeDb: string) => {
313-
const version = getSemanticVersion(state)
314-
if (!version) return false
315-
316-
if (gte(version, VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB)) {
317-
return getDatabases(state).find(database => database.name === activeDb)
318-
?.role
319-
} else {
320-
return state[NAME].role
321-
}
322-
}
323312

324313
export const getCountAutomaticRefreshEnabled = (
325314
state: GlobalState

src/shared/utils/selectors.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
import { gte } from 'semver'
2+
import { stripScheme } from 'services/boltscheme.utils'
13
import { GlobalState } from 'shared/globalState'
24
import { inDesktop } from 'shared/modules/app/appDuck'
35
import {
6+
getConnectedHost,
47
getUseDb,
58
isConnected,
6-
isConnectedAuraHost,
7-
useDb
9+
isConnectedAuraHost
810
} from 'shared/modules/connections/connectionsDuck'
911
import {
1012
Database,
1113
findDatabaseByNameOrAlias,
1214
getAllowOutgoingConnections,
1315
getClientsAllowTelemetry,
16+
getDatabases,
17+
getSemanticVersion,
1418
isServerConfigDone,
19+
NAME,
1520
shouldAllowOutgoingConnections,
16-
SYSTEM_DB
21+
SYSTEM_DB,
22+
VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB
1723
} from 'shared/modules/dbMeta/dbMetaDuck'
1824
import {
1925
getAllowCrashReports,
@@ -38,6 +44,30 @@ export function isSystemOrCompositeDb(db: Database): boolean {
3844
return db?.name === SYSTEM_DB || db?.type === 'composite'
3945
}
4046

47+
export const getClusterRoleForCurrentDb = (state: GlobalState) => {
48+
const version = getSemanticVersion(state)
49+
if (!version) return null
50+
51+
if (gte(version, VERSION_FOR_CLUSTER_ROLE_IN_SHOW_DB)) {
52+
// In a cluster setup, there are many databases with the same name, often one per member
53+
// So our "cluster role" is the role we have on the database that lives
54+
// at the adress we're connected to
55+
const dbName = getUseDb(state)
56+
const host = getConnectedHost(state)
57+
if (dbName && host) {
58+
const databases = getDatabases(state)
59+
const currentDb = databases
60+
.filter(db => db.address === stripScheme(host))
61+
.find(database => database.name === dbName)
62+
return currentDb?.role
63+
} else {
64+
return null
65+
}
66+
} else {
67+
return state[NAME].role
68+
}
69+
}
70+
4171
export type TelemetrySettingSource =
4272
| 'AURA'
4373
| 'BROWSER_SETTING'

0 commit comments

Comments
 (0)