Skip to content

Commit

Permalink
Avoid running SHOW ALIASES to show only non-composite aliases in da…
Browse files Browse the repository at this point in the history
…tabase dropdown (#1964)

* Revert "show only non-composite aliases in drop down (#1947)"

This reverts commit 5a96987.

* filter out composite aliases
  • Loading branch information
OskarDamkjaer authored Apr 8, 2024
1 parent 53514c9 commit db1def4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 103 deletions.
17 changes: 3 additions & 14 deletions src/browser/modules/DBMSInfo/DBMSInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import {
forceCount,
getCountAutomaticRefreshLoading,
getCountAutomaticRefreshEnabled,
getUniqueDatabases,
getAliases
getUniqueDatbases
} from 'shared/modules/dbMeta/dbMetaDuck'
import { getGraphStyleData } from 'shared/modules/grass/grassDuck'
import { Button } from '@neo4j-ndl/react'
Expand Down Expand Up @@ -74,22 +73,14 @@ export function DBMSInfo(props: any): JSX.Element {
nodes,
relationships
} = props.meta
const {
user,
onItemClick,
onDbSelect,
useDb,
uniqueDatabases = [],
aliases
} = props
const { user, onItemClick, onDbSelect, useDb, uniqueDatabases = [] } = props

return (
<Drawer id="db-drawer">
<DrawerHeader>Database Information</DrawerHeader>
<DrawerBody>
<DatabaseSelector
uniqueDatabases={uniqueDatabases}
aliases={aliases}
selectedDb={useDb ?? ''}
onChange={onDbSelect}
/>
Expand Down Expand Up @@ -150,16 +141,14 @@ const mapStateToProps = (state: any) => {
const countAutoRefreshing = getCountAutomaticRefreshEnabled(state)
const countLoading = getCountAutomaticRefreshLoading(state)

const uniqueDatabases = getUniqueDatabases(state)
const aliases = getAliases(state)
const uniqueDatabases = getUniqueDatbases(state)

return {
graphStyleData: getGraphStyleData(state),
meta: state.meta,
user: getCurrentUser(state),
useDb,
uniqueDatabases,
aliases,
countAutoRefreshing,
countLoading
}
Expand Down
26 changes: 4 additions & 22 deletions src/browser/modules/DBMSInfo/DatabaseSelector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ describe('DatabaseSelector', () => {

// When
const { container } = render(
<DatabaseSelector
selectedDb=""
uniqueDatabases={databases}
aliases={[]}
/>
<DatabaseSelector selectedDb="" uniqueDatabases={databases} />
)

// Then
Expand All @@ -62,11 +58,7 @@ describe('DatabaseSelector', () => {

// When
const { getByDisplayValue, queryByDisplayValue, rerender } = render(
<DatabaseSelector
uniqueDatabases={databases}
selectedDb={selected}
aliases={[]}
/>
<DatabaseSelector uniqueDatabases={databases} selectedDb={selected} />
)

// Then
Expand All @@ -76,11 +68,7 @@ describe('DatabaseSelector', () => {
// When
selected = 'molly'
rerender(
<DatabaseSelector
uniqueDatabases={databases}
selectedDb={selected}
aliases={[]}
/>
<DatabaseSelector uniqueDatabases={databases} selectedDb={selected} />
)

// Then
Expand All @@ -90,11 +78,7 @@ describe('DatabaseSelector', () => {
// When
selected = ''
rerender(
<DatabaseSelector
uniqueDatabases={databases}
selectedDb={selected}
aliases={[]}
/>
<DatabaseSelector uniqueDatabases={databases} selectedDb={selected} />
)

// Then select db text should be shown
Expand All @@ -113,7 +97,6 @@ describe('DatabaseSelector', () => {
uniqueDatabases={databases}
selectedDb=""
onChange={onChange}
aliases={[]}
/>
)
const select = getByTestId(testId)
Expand Down Expand Up @@ -143,7 +126,6 @@ describe('DatabaseSelector', () => {
selectedDb=""
uniqueDatabases={databases}
onChange={onChange}
aliases={[]}
/>
)
const select = getByTestId(testId)
Expand Down
41 changes: 21 additions & 20 deletions src/browser/modules/DBMSInfo/DatabaseSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
DrawerSubHeader
} from 'browser-components/drawer/drawer-styled'
import { escapeCypherIdentifier } from 'services/utils'
import { Alias, Database } from 'shared/modules/dbMeta/dbMetaDuck'
import { Database } from 'shared/modules/dbMeta/dbMetaDuck'

const Select = styled.select`
width: 100%;
Expand All @@ -43,12 +43,10 @@ type DatabaseSelectorProps = {
uniqueDatabases?: Database[]
selectedDb: string
onChange?: (dbName: string) => void
aliases: Alias[]
}
export const DatabaseSelector = ({
uniqueDatabases = [],
selectedDb,
aliases,
onChange = () => undefined
}: DatabaseSelectorProps): JSX.Element | null => {
if (uniqueDatabases.length === 0) {
Expand All @@ -66,23 +64,26 @@ export const DatabaseSelector = ({
uniqueDatabases.find(db => db.home) ||
uniqueDatabases.find(db => db.default)

const aliasList = aliases.flatMap(alias => {
const aliasedDb = uniqueDatabases.find(db => db.name === alias.database)

// Don't show composite aliases since they can't be queried directly
if (alias.composite) {
return []
}

if (aliasedDb === undefined) {
return []
}

return {
name: alias.name,
status: aliasedDb.status
}
})
const aliasList = uniqueDatabases.flatMap(db =>
db.aliases
? db.aliases
.map(alias => ({
databaseName: db.name,
name: alias,
status: db.status
}))
.filter(
// If the alias points to a composite database and the alias is listed as
// one of the constituents, we don't want to show it as it's not directly queryable
alias =>
!uniqueDatabases.some(
db =>
db.type === 'composite' &&
db.constituents?.includes(alias.name)
)
)
: []
)

const databasesAndAliases = [...aliasList, ...uniqueDatabases].sort((a, b) =>
a.name.localeCompare(b.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`hydrating state can CLEAR to reset state 1`] = `
Object {
"aliases": Array [],
"countAutomaticRefresh": Object {
"enabled": true,
"loading": false,
Expand Down Expand Up @@ -70,7 +69,6 @@ Object {

exports[`hydrating state should merge inital state and state on load 1`] = `
Object {
"aliases": Array [],
"countAutomaticRefresh": Object {
"enabled": true,
"loading": false,
Expand Down
32 changes: 10 additions & 22 deletions src/shared/modules/dbMeta/dbMetaDuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { uniq } from 'lodash-es'
import { QueryResult } from 'neo4j-driver'
import { SemVer, coerce, gte } from 'semver'
import { isConfigValFalsy } from 'services/bolt/boltHelpers'
import { GlobalState } from 'shared/globalState'
import { APP_START } from 'shared/modules/app/appDuck'
import { FIRST_MULTI_DB_SUPPORT } from '../features/versionedFeatures'
import {
extractServerInfo,
extractTrialStatus,
extractTrialStatusOld,
versionHasEditorHistorySetting
} from './utils'
import { isConfigValFalsy } from 'services/bolt/boltHelpers'
import { GlobalState } from 'shared/globalState'
import { APP_START } from 'shared/modules/app/appDuck'
import { extractServerInfo } from './utils'
import { coerce, SemVer, gte } from 'semver'
import { QueryResult } from 'neo4j-driver'
import { uniq } from 'lodash-es'
import { FIRST_MULTI_DB_SUPPORT } from '../features/versionedFeatures'

export const UPDATE_META = 'meta/UPDATE_META'
export const PARSE_META = 'meta/PARSE_META'
Expand Down Expand Up @@ -206,7 +206,6 @@ export const initialState = {
storeSize: null
},
databases: [],
aliases: [],
serverConfigDone: false,
settings: initialClientSettings,
countAutomaticRefresh: {
Expand All @@ -227,17 +226,10 @@ export type Database = {
home?: boolean // introduced in neo4j 4.3
aliases?: string[] // introduced in neo4j 4.4
type?: 'system' | 'composite' | 'standard' // introduced in neo4j 5
constituents?: string[] // introduced in neo4j 5
status: string
}

export const ALIAS_COMPOSITE_FIELD_FIRST_VERSION = '5.11.0'
export type Alias = {
name: string
database: string
location: string
composite?: string | null // introduced in neo4j 5.11
}

// Selectors
export function findDatabaseByNameOrAlias(
state: GlobalState,
Expand All @@ -258,7 +250,7 @@ export function findDatabaseByNameOrAlias(
)
}

export function getUniqueDatabases(state: GlobalState): Database[] {
export function getUniqueDatbases(state: GlobalState): Database[] {
const uniqueDatabaseNames = uniq(
state[NAME].databases.map((db: Database) => db.name)
)
Expand Down Expand Up @@ -344,10 +336,6 @@ export const getMetricsPrefix = (state: GlobalState): string =>

export const getDatabases = (state: any): Database[] =>
(state[NAME] || initialState).databases

export const getAliases = (state: any): null | Alias[] =>
(state[NAME] || initialState).aliases

export const getActiveDbName = (state: any) =>
((state[NAME] || {}).settings || {})['dbms.active_database']

Expand Down
24 changes: 1 addition & 23 deletions src/shared/modules/dbMeta/dbMetaEpics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,6 @@ async function databaseList(store: any) {
} catch {}
}

async function aliasList(store: any) {
try {
const hasMultidb = supportsMultiDb(store.getState())
if (!hasMultidb) {
return
}

const res = await bolt.backgroundWorkerlessRoutedRead(
'SHOW ALIASES FOR DATABASE',
{ useDb: SYSTEM_DB },
store
)

if (!res) return

const aliases = res.records.map((record: any) => record.toObject())

store.dispatch(update({ aliases }))
} catch {}
}

async function getLabelsAndTypes(store: any) {
const db = getCurrentDatabase(store.getState())

Expand Down Expand Up @@ -416,8 +395,7 @@ async function pollDbMeta(store: any) {
await Promise.all([
getFunctionsAndProcedures(store),
clusterRole(store),
databaseList(store),
aliasList(store)
databaseList(store)
])
}

Expand Down

0 comments on commit db1def4

Please sign in to comment.